Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed May 16, 2023
2 parents 6a9c525 + f8f1eb9 commit 7ba0e0b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/LiveKit/Core/SignalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ internal extension SignalClient {
return sendRequest(r)
}

func sendUpdateLocalMetadata(_ metadata: String, name: String) -> Promise<Void> {

log()

let r = Livekit_SignalRequest.with {
$0.updateMetadata = Livekit_UpdateParticipantMetadata.with {
$0.metadata = metadata
$0.name = name
}
}

return sendRequest(r)
}

func sendSyncState(answer: Livekit_SessionDescription,
offer: Livekit_SessionDescription?,
subscription: Livekit_UpdateSubscription,
Expand Down
24 changes: 24 additions & 0 deletions Sources/LiveKit/Participant/LocalParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,30 @@ public class LocalParticipant: Participant {
return sendTrackSubscriptionPermissions()
}

/// Sets and updates the metadata of the local participant.
///
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
public func set(metadata: String) -> Promise<Void> {
// mutate state to set metadata and copy name from state
let name = _state.mutate {
$0.metadata = metadata
return $0.name
}
return room.engine.signalClient.sendUpdateLocalMetadata(metadata, name: name)
}

/// Sets and updates the name of the local participant.
///
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
public func set(name: String) -> Promise<Void> {
// mutate state to set name and copy metadata from state
let metadata = _state.mutate {
$0.name = name
return $0.metadata
}
return room.engine.signalClient.sendUpdateLocalMetadata(metadata ?? "", name: name)
}

internal func sendTrackSubscriptionPermissions() -> Promise<Void> {

guard room.engine._state.connectionState == .connected else {
Expand Down
13 changes: 13 additions & 0 deletions Sources/LiveKit/Participant/Participant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ public class Participant: NSObject, ObservableObject, Loggable {
}
}

// name updated
if newState.name != oldState.name {
// notfy participant delegates
self.delegates.notify(label: { "participant.didUpdateName: \(newState.name)" }) {
$0.participant?(self, didUpdateName: newState.name)
}
// notify room delegates
self.room.delegates.notify(label: { "room.didUpdateName: \(newState.name)" }) {
$0.room?(self.room, participant: self, didUpdateName: newState.name)
}
}

if newState.connectionQuality != oldState.connectionQuality {

self.delegates.notify(label: { "participant.didUpdate connectionQuality: \(self.connectionQuality)" }) {
$0.participant?(self, didUpdate: self.connectionQuality)
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/LiveKit/Protocols/ParticipantDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public protocol ParticipantDelegate: AnyObject {
@objc(participant:didUpdateMetadata:) optional
func participant(_ participant: Participant, didUpdate metadata: String?)

/// A ``Participant``'s name has updated.
/// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``.
@objc(participant:didUpdateName:) optional
func participant(_ participant: Participant, didUpdateName: String)

/// The isSpeaking status of a ``Participant`` has changed.
/// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``.
@objc(participant:didUpdateSpeaking:) optional
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveKit/Protocols/RoomDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public protocol RoomDelegateObjC: AnyObject {
@objc(room:participant:didUpdateMetadata:) optional
func room(_ room: Room, participant: Participant, didUpdate metadata: String?)

/// Same with ``ParticipantDelegate/participant(_:didUpdateName:)``.
@objc(room:participant:didUpdateName:) optional
func room(_ room: Room, participant: Participant, didUpdateName: String)

/// Same with ``ParticipantDelegate/participant(_:didUpdate:)-7zxk1``.
@objc(room:participant:didUpdateConnectionQuality:) optional
func room(_ room: Room, participant: Participant, didUpdate connectionQuality: ConnectionQuality)
Expand Down

0 comments on commit 7ba0e0b

Please sign in to comment.