diff --git a/.changes/last-spoke-at b/.changes/last-spoke-at new file mode 100644 index 000000000..30ec62561 --- /dev/null +++ b/.changes/last-spoke-at @@ -0,0 +1 @@ +patch type="added" "Add lastSpokeAt property to Participant" diff --git a/Sources/LiveKit/Core/Room+EngineDelegate.swift b/Sources/LiveKit/Core/Room+EngineDelegate.swift index 8f32b4cbb..6e00f5dbf 100644 --- a/Sources/LiveKit/Core/Room+EngineDelegate.swift +++ b/Sources/LiveKit/Core/Room+EngineDelegate.swift @@ -107,6 +107,9 @@ extension Room { if participantSid == localParticipant.sid { localParticipant._state.mutate { $0.audioLevel = speaker.level + if !$0.isSpeaking { + $0.lastSpokeAt = Date() + } $0.isSpeaking = true } activeSpeakers.append(localParticipant) @@ -114,6 +117,9 @@ extension Room { if let participant = state.remoteParticipant(forSid: participantSid) { participant._state.mutate { $0.audioLevel = speaker.level + if !$0.isSpeaking { + $0.lastSpokeAt = Date() + } $0.isSpeaking = true } activeSpeakers.append(participant) diff --git a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift index 39f32b376..3298e72c4 100644 --- a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift +++ b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift @@ -146,6 +146,9 @@ extension Room: SignalClientDelegate { participant._state.mutate { $0.audioLevel = speaker.level + if !$0.isSpeaking, speaker.active { + $0.lastSpokeAt = Date() + } $0.isSpeaking = speaker.active } diff --git a/Sources/LiveKit/Participant/Participant.swift b/Sources/LiveKit/Participant/Participant.swift index 380e4dfba..310c7654f 100644 --- a/Sources/LiveKit/Participant/Participant.swift +++ b/Sources/LiveKit/Participant/Participant.swift @@ -40,6 +40,9 @@ public class Participant: NSObject, @unchecked Sendable, ObservableObject, Logga @objc public var isSpeaking: Bool { _state.isSpeaking } + @objc + public var lastSpokeAt: Date? { _state.lastSpokeAt } + @objc public var metadata: String? { _state.metadata } @@ -88,6 +91,7 @@ public class Participant: NSObject, @unchecked Sendable, ObservableObject, Logga var name: String? var audioLevel: Float = 0.0 var isSpeaking: Bool = false + var lastSpokeAt: Date? var metadata: String? var joinedAt: Date? var kind: Kind = .unknown