From 98c4ca2af8098c41d88008372e4e9155c3d4e7e5 Mon Sep 17 00:00:00 2001 From: Ammar Ansari Date: Fri, 24 Jan 2025 18:04:39 +0500 Subject: [PATCH] set the active peer after the negotiation finishes --- packages/webrtc/src/BaseConnection.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/webrtc/src/BaseConnection.ts b/packages/webrtc/src/BaseConnection.ts index 3e072e594..e7e06e40c 100644 --- a/packages/webrtc/src/BaseConnection.ts +++ b/packages/webrtc/src/BaseConnection.ts @@ -374,6 +374,16 @@ export class BaseConnection< const rtcPeer = this._buildPeer('offer') this.logger.debug('Trigger start for the new RTCPeer!', rtcPeer.uuid) await rtcPeer.start() + + /** + * Ideally, the SDK set the active peer when the `room.subscribed` or + * `verto.display` event is received. However, in some cases, while + * promoting/demoting, the RTC Peer negotiates successfully but then + * starts the negotiation again. + * So, without waiting for the events, we can safely set the active + * Peer once the initial negotiation succeeds. + */ + this.setActiveRTCPeer(rtcPeer.uuid) } catch (error) { this.logger.error('Error building new RTCPeer to promote/demote', error) } @@ -828,12 +838,7 @@ export class BaseConnection< this.logger.error('UpdateMedia invalid SDP answer', response) } - this.logger.debug( - 'UpdateMedia response', - response, - this.peer?.uuid, - rtcPeerId - ) + this.logger.debug('UpdateMedia response', response) /** * At a time, there can be multiple RTC Peers.