Skip to content

Commit

Permalink
Delayed room id (Protocol 12) (livekit#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Jan 8, 2024
1 parent 233fda7 commit 98cb93d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Sources/LiveKit/Core/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
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 @@ -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?)
Expand Down
4 changes: 2 additions & 2 deletions Sources/LiveKit/Types/Options/ConnectOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ConnectOptions: NSObject {
reconnectAttempts = 3
reconnectAttemptDelay = .defaultReconnectAttemptDelay
iceServers = []
protocolVersion = .v11
protocolVersion = .v12
}

@objc
Expand All @@ -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
Expand Down

0 comments on commit 98cb93d

Please sign in to comment.