@@ -34,23 +34,32 @@ extension Room: SignalClientDelegate {
3434 // engine is currently connected state
3535 case . connected = _state. connectionState
3636 {
37- do {
38- try await startReconnect ( reason: . websocket)
39- } catch {
40- log ( " Failed calling startReconnect, error: \( error) " , . error)
37+ Task {
38+ do {
39+ try await startReconnect ( reason: . websocket)
40+ } catch {
41+ log ( " Failed calling startReconnect, error: \( error) " , . error)
42+ }
4143 }
4244 }
4345 }
4446
45- func signalClient( _: SignalClient , didReceiveLeave canReconnect : Bool , reason: Livekit_DisconnectReason ) async {
46- log ( " canReconnect : \( canReconnect ) , reason: \( reason) " )
47+ func signalClient( _: SignalClient , didReceiveLeave action : Livekit_LeaveRequest . Action , reason: Livekit_DisconnectReason ) async {
48+ log ( " action : \( action ) , reason: \( reason) " )
4749
48- if canReconnect {
49- // force .full for next reconnect
50+ let error = LiveKitError . from ( reason: reason)
51+ switch action {
52+ case . reconnect:
53+ // Force .full for next reconnect
5054 _state. mutate { $0. nextReconnectMode = . full }
51- } else {
52- // Server indicates it's not recoverable
53- await cleanUp ( withError: LiveKitError . from ( reason: reason) )
55+ fallthrough
56+ case . resume:
57+ // Abort current attempt
58+ await signalClient. cleanUp ( withError: error)
59+ case . disconnect:
60+ await cleanUp ( withError: error)
61+ default :
62+ log ( " Unknown leave action: \( action) , ignoring " , . warning)
5463 }
5564 }
5665
@@ -341,17 +350,19 @@ extension Room: SignalClientDelegate {
341350 }
342351 }
343352
344- func signalClient( _: SignalClient , didReceiveAnswer answer: LKRTCSessionDescription ) async {
353+ func signalClient( _: SignalClient , didReceiveAnswer answer: LKRTCSessionDescription , offerId: UInt32 ) async {
354+ log ( " Received answer for offerId: \( offerId) " )
355+
345356 do {
346357 let publisher = try requirePublisher ( )
347- try await publisher. set ( remoteDescription: answer)
358+ try await publisher. set ( remoteDescription: answer, offerId : offerId )
348359 } catch {
349- log ( " Failed to set remote description, error: \( error) " , . error)
360+ log ( " Failed to set remote description with offerId: \( offerId ) , error: \( error) " , . error)
350361 }
351362 }
352363
353- func signalClient( _ signalClient: SignalClient , didReceiveOffer offer: LKRTCSessionDescription ) async {
354- log ( " Received offer, creating & sending answer... " )
364+ func signalClient( _ signalClient: SignalClient , didReceiveOffer offer: LKRTCSessionDescription , offerId : UInt32 ) async {
365+ log ( " Received offer with offerId: \( offerId ) , creating & sending answer... " )
355366
356367 guard let subscriber = _state. subscriber else {
357368 log ( " Failed to send answer, subscriber is nil " , . error)
@@ -362,9 +373,9 @@ extension Room: SignalClientDelegate {
362373 try await subscriber. set ( remoteDescription: offer)
363374 let answer = try await subscriber. createAnswer ( )
364375 try await subscriber. set ( localDescription: answer)
365- try await signalClient. send ( answer: answer)
376+ try await signalClient. send ( answer: answer, offerId : offerId )
366377 } catch {
367- log ( " Failed to send answer with error: \( error) " , . error)
378+ log ( " Failed to send answer for offerId: \( offerId ) , error: \( error) " , . error)
368379 }
369380 }
370381
0 commit comments