Skip to content

Commit 06a007f

Browse files
authored
Add lastSpokeAt property to Swift SDK (#818)
This PR adds the lastSpokeAt property to the Swift SDK to align with Android and JS implementations. It represents the last time a participant spoke, allowing consistent behavior across platforms.
1 parent 017ea2d commit 06a007f

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

.changes/last-spoke-at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="added" "Add lastSpokeAt property to Participant"

Sources/LiveKit/Core/Room+EngineDelegate.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,19 @@ extension Room {
107107
if participantSid == localParticipant.sid {
108108
localParticipant._state.mutate {
109109
$0.audioLevel = speaker.level
110+
if !$0.isSpeaking {
111+
$0.lastSpokeAt = Date()
112+
}
110113
$0.isSpeaking = true
111114
}
112115
activeSpeakers.append(localParticipant)
113116
} else {
114117
if let participant = state.remoteParticipant(forSid: participantSid) {
115118
participant._state.mutate {
116119
$0.audioLevel = speaker.level
120+
if !$0.isSpeaking {
121+
$0.lastSpokeAt = Date()
122+
}
117123
$0.isSpeaking = true
118124
}
119125
activeSpeakers.append(participant)

Sources/LiveKit/Core/Room+SignalClientDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ extension Room: SignalClientDelegate {
146146

147147
participant._state.mutate {
148148
$0.audioLevel = speaker.level
149+
if !$0.isSpeaking, speaker.active {
150+
$0.lastSpokeAt = Date()
151+
}
149152
$0.isSpeaking = speaker.active
150153
}
151154

Sources/LiveKit/Participant/Participant.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class Participant: NSObject, @unchecked Sendable, ObservableObject, Logga
4040
@objc
4141
public var isSpeaking: Bool { _state.isSpeaking }
4242

43+
@objc
44+
public var lastSpokeAt: Date? { _state.lastSpokeAt }
45+
4346
@objc
4447
public var metadata: String? { _state.metadata }
4548

@@ -88,6 +91,7 @@ public class Participant: NSObject, @unchecked Sendable, ObservableObject, Logga
8891
var name: String?
8992
var audioLevel: Float = 0.0
9093
var isSpeaking: Bool = false
94+
var lastSpokeAt: Date?
9195
var metadata: String?
9296
var joinedAt: Date?
9397
var kind: Kind = .unknown

0 commit comments

Comments
 (0)