Skip to content

Commit 7ba0e0b

Browse files
committed
2 parents 6a9c525 + f8f1eb9 commit 7ba0e0b

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

Sources/LiveKit/Core/SignalClient.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,20 @@ internal extension SignalClient {
582582
return sendRequest(r)
583583
}
584584

585+
func sendUpdateLocalMetadata(_ metadata: String, name: String) -> Promise<Void> {
586+
587+
log()
588+
589+
let r = Livekit_SignalRequest.with {
590+
$0.updateMetadata = Livekit_UpdateParticipantMetadata.with {
591+
$0.metadata = metadata
592+
$0.name = name
593+
}
594+
}
595+
596+
return sendRequest(r)
597+
}
598+
585599
func sendSyncState(answer: Livekit_SessionDescription,
586600
offer: Livekit_SessionDescription?,
587601
subscription: Livekit_UpdateSubscription,

Sources/LiveKit/Participant/LocalParticipant.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,30 @@ public class LocalParticipant: Participant {
344344
return sendTrackSubscriptionPermissions()
345345
}
346346

347+
/// Sets and updates the metadata of the local participant.
348+
///
349+
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
350+
public func set(metadata: String) -> Promise<Void> {
351+
// mutate state to set metadata and copy name from state
352+
let name = _state.mutate {
353+
$0.metadata = metadata
354+
return $0.name
355+
}
356+
return room.engine.signalClient.sendUpdateLocalMetadata(metadata, name: name)
357+
}
358+
359+
/// Sets and updates the name of the local participant.
360+
///
361+
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
362+
public func set(name: String) -> Promise<Void> {
363+
// mutate state to set name and copy metadata from state
364+
let metadata = _state.mutate {
365+
$0.name = name
366+
return $0.metadata
367+
}
368+
return room.engine.signalClient.sendUpdateLocalMetadata(metadata ?? "", name: name)
369+
}
370+
347371
internal func sendTrackSubscriptionPermissions() -> Promise<Void> {
348372

349373
guard room.engine._state.connectionState == .connected else {

Sources/LiveKit/Participant/Participant.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,20 @@ public class Participant: NSObject, ObservableObject, Loggable {
129129
}
130130
}
131131

132+
// name updated
133+
if newState.name != oldState.name {
134+
// notfy participant delegates
135+
self.delegates.notify(label: { "participant.didUpdateName: \(newState.name)" }) {
136+
$0.participant?(self, didUpdateName: newState.name)
137+
}
138+
// notify room delegates
139+
self.room.delegates.notify(label: { "room.didUpdateName: \(newState.name)" }) {
140+
$0.room?(self.room, participant: self, didUpdateName: newState.name)
141+
}
142+
}
143+
132144
if newState.connectionQuality != oldState.connectionQuality {
145+
133146
self.delegates.notify(label: { "participant.didUpdate connectionQuality: \(self.connectionQuality)" }) {
134147
$0.participant?(self, didUpdate: self.connectionQuality)
135148
}

Sources/LiveKit/Protocols/ParticipantDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public protocol ParticipantDelegate: AnyObject {
3232
@objc(participant:didUpdateMetadata:) optional
3333
func participant(_ participant: Participant, didUpdate metadata: String?)
3434

35+
/// A ``Participant``'s name has updated.
36+
/// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``.
37+
@objc(participant:didUpdateName:) optional
38+
func participant(_ participant: Participant, didUpdateName: String)
39+
3540
/// The isSpeaking status of a ``Participant`` has changed.
3641
/// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``.
3742
@objc(participant:didUpdateSpeaking:) optional

Sources/LiveKit/Protocols/RoomDelegate.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public protocol RoomDelegateObjC: AnyObject {
7777
@objc(room:participant:didUpdateMetadata:) optional
7878
func room(_ room: Room, participant: Participant, didUpdate metadata: String?)
7979

80+
/// Same with ``ParticipantDelegate/participant(_:didUpdateName:)``.
81+
@objc(room:participant:didUpdateName:) optional
82+
func room(_ room: Room, participant: Participant, didUpdateName: String)
83+
8084
/// Same with ``ParticipantDelegate/participant(_:didUpdate:)-7zxk1``.
8185
@objc(room:participant:didUpdateConnectionQuality:) optional
8286
func room(_ room: Room, participant: Participant, didUpdate connectionQuality: ConnectionQuality)

0 commit comments

Comments
 (0)