Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
emit webRtcConnected event when connected
Browse files Browse the repository at this point in the history
  • Loading branch information
hmuurine committed Feb 21, 2023
1 parent 353f565 commit b2fb702
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export class PeerConnectionController {
'ice connection state change: ' + state,
6
);
this.onIceConnectionStateChange(state);
}

/**
Expand Down Expand Up @@ -329,6 +330,15 @@ export class PeerConnectionController {
// Default Functionality: Do Nothing
}

/**
* An override method for onIceConnectionStateChange for use outside of the PeerConnectionController
* @param event - The webRtc iceconnectionstatechange event
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onIceConnectionStateChange(event: Event) {
// Default Functionality: Do Nothing
}

/**
* An override method for onPeerIceCandidate for use outside of the PeerConnectionController
* @param peerConnectionIceEvent - The peer ice candidate
Expand Down
11 changes: 11 additions & 0 deletions Frontend/library/src/WebRtcPlayer/WebRtcPlayerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,17 @@ export class WebRtcPlayerController {
this.pixelStreaming._onWebRtcConnecting();
this.peerConnectionController.showTextOverlaySetupFailure = () =>
this.pixelStreaming._onWebRtcFailed();
let webRtcConnectedSent = false;
this.peerConnectionController.onIceConnectionStateChange = () => {
// Browsers emit "connected" when getting first connection and "completed" when finishing
// candidate checking. However, sometimes browsers can skip "connected" and only emit "completed".
// Therefore need to check both cases and emit onWebRtcConnected only once on the first hit.
if (!webRtcConnectedSent &&
["connected", "completed"].includes(this.peerConnectionController.peerConnection.iceConnectionState)) {
this.pixelStreaming._onWebRtcConnected();
webRtcConnectedSent = true;
}
};

/* RTC Peer Connection on Track event -> handle on track */
this.peerConnectionController.onTrack = (trackEvent: RTCTrackEvent) =>
Expand Down

0 comments on commit b2fb702

Please sign in to comment.