From 98cb93dfb81f4fae8abf9de3a295c042085c0bf0 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:06:48 +0900 Subject: [PATCH] Delayed room id (Protocol 12) (#293) --- Sources/LiveKit/Core/Room.swift | 9 +++++++++ Sources/LiveKit/Protocols/RoomDelegate.swift | 4 ++++ Sources/LiveKit/Types/Options/ConnectOptions.swift | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/LiveKit/Core/Room.swift b/Sources/LiveKit/Core/Room.swift index 407d2d53e..a47f1b387 100644 --- a/Sources/LiveKit/Core/Room.swift +++ b/Sources/LiveKit/Core/Room.swift @@ -29,6 +29,8 @@ public class Room: NSObject, ObservableObject, Loggable { // MARK: - Public @objc + /// Server assigned id of the Room. + /// This will be empty until ``RoomDelegate/room(_:didUpdateRoomId:)`` is called. public var sid: Sid? { _state.sid } @objc @@ -170,6 +172,13 @@ public class Room: NSObject, ObservableObject, Loggable { guard let self else { return } + // roomId updated + if let roomId = newState.sid, roomId != oldState.sid { + self.delegates.notify(label: { "room.didUpdateRoomId:" }) { + $0.room?(self, didUpdateRoomId: roomId) + } + } + // metadata updated if let metadata = newState.metadata, metadata != oldState.metadata, // don't notify if empty string (first time only) diff --git a/Sources/LiveKit/Protocols/RoomDelegate.swift b/Sources/LiveKit/Protocols/RoomDelegate.swift index fb8bd3879..c4bd91bc2 100644 --- a/Sources/LiveKit/Protocols/RoomDelegate.swift +++ b/Sources/LiveKit/Protocols/RoomDelegate.swift @@ -58,6 +58,10 @@ public protocol RoomDelegate: AnyObject { @objc(room:didDisconnectWithError:) optional func room(_ room: Room, didDisconnectWithError error: LiveKitError?) + /// ``Room``'s id has been updated after a successful connection. + @objc(room:didUpdateRoomId:) optional + func room(_ room: Room, didUpdateRoomId roomId: String) + /// ``Room``'s metadata has been updated. @objc(room:didUpdateMetadata:) optional func room(_ room: Room, didUpdateMetadata metadata: String?) diff --git a/Sources/LiveKit/Types/Options/ConnectOptions.swift b/Sources/LiveKit/Types/Options/ConnectOptions.swift index 3f5a6e1a6..8e0f927ef 100644 --- a/Sources/LiveKit/Types/Options/ConnectOptions.swift +++ b/Sources/LiveKit/Types/Options/ConnectOptions.swift @@ -52,7 +52,7 @@ public class ConnectOptions: NSObject { reconnectAttempts = 3 reconnectAttemptDelay = .defaultReconnectAttemptDelay iceServers = [] - protocolVersion = .v11 + protocolVersion = .v12 } @objc @@ -61,7 +61,7 @@ public class ConnectOptions: NSObject { reconnectAttempts: Int = 3, reconnectAttemptDelay: TimeInterval = .defaultReconnectAttemptDelay, iceServers: [IceServer] = [], - protocolVersion: ProtocolVersion = .v11) + protocolVersion: ProtocolVersion = .v12) { self.autoSubscribe = autoSubscribe self.publishOnlyMode = publishOnlyMode