From ac0e93ea27bf5f7effd373cdcfba6c8a3110f44e Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Thu, 27 May 2021 21:28:17 +0200 Subject: [PATCH] openvidu-browser: rename WebRtcPeer handler methods --- openvidu-browser/src/OpenVidu/Stream.ts | 11 +++++++---- .../src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index fd9a2b3a..dd13686f 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -814,8 +814,8 @@ export class Stream { const options: WebRtcPeerConfiguration = { mediaStream: this.mediaStream, mediaConstraints: userMediaConstraints, - onicecandidate: this.connection.sendIceCandidate.bind(this.connection), - onexception: (exceptionName: ExceptionEventName, message: string, data?: any) => { this.session.emitEvent('exception', [new ExceptionEvent(this.session, exceptionName, this, message, data)]) }, + onIceCandidate: this.connection.sendIceCandidate.bind(this.connection), + onIceConnectionStateException: this.onIceConnectionStateExceptionHandler.bind(this), iceServers: this.getIceServersConf(), simulcast: false }; @@ -943,9 +943,9 @@ export class Stream { logger.debug("'Session.subscribe(Stream)' called. Constraints of generate SDP offer", offerConstraints); const options = { - onicecandidate: this.connection.sendIceCandidate.bind(this.connection), - onexception: (exceptionName: ExceptionEventName, message: string, data?: any) => { this.session.emitEvent('exception', [new ExceptionEvent(this.session, exceptionName, this, message, data)]) }, mediaConstraints: offerConstraints, + onIceCandidate: this.connection.sendIceCandidate.bind(this.connection), + onIceConnectionStateException: this.onIceConnectionStateExceptionHandler.bind(this), iceServers: this.getIceServersConf(), simulcast: false }; @@ -968,6 +968,9 @@ export class Stream { }); }; + if (reconnect) { + this.disposeWebRtcPeer(); + } this.webRtcPeer = new WebRtcPeerRecvonly(options); this.webRtcPeer.addIceConnectionStateChangeListener(this.streamId); this.webRtcPeer.processRemoteOffer(sdpOffer) diff --git a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts index e39154e4..00eaee5e 100644 --- a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts +++ b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts @@ -37,8 +37,8 @@ export interface WebRtcPeerConfiguration { video: boolean }; simulcast: boolean; - onicecandidate: (event: RTCIceCandidate) => void; - onexception: (exceptionName: ExceptionEventName, message: string, data?: any) => void; + onIceCandidate: (event: RTCIceCandidate) => void; + onIceConnectionStateException: (exceptionName: ExceptionEventName, message: string, data?: any) => void; iceServers: RTCIceServer[] | undefined; mediaStream?: MediaStream; mode?: 'sendonly' | 'recvonly' | 'sendrecv'; @@ -64,7 +64,7 @@ export class WebRtcPeer { this.pc.addEventListener('icecandidate', (event: RTCPeerConnectionIceEvent) => { if (event.candidate != null) { const candidate: RTCIceCandidate = event.candidate; - this.configuration.onicecandidate(candidate); + this.configuration.onIceCandidate(candidate); if (candidate.candidate !== '') { this.localCandidatesQueue.push({ candidate: candidate.candidate }); } @@ -326,12 +326,12 @@ export class WebRtcPeer { // Possible network disconnection const msg1 = 'IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') change to "disconnected". Possible network disconnection'; logger.warn(msg1); - this.configuration.onexception(ExceptionEventName.ICE_CONNECTION_DISCONNECTED, msg1); + this.configuration.onIceConnectionStateException(ExceptionEventName.ICE_CONNECTION_DISCONNECTED, msg1); break; case 'failed': const msg2 = 'IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') to "failed"'; logger.error(msg2); - this.configuration.onexception(ExceptionEventName.ICE_CONNECTION_FAILED, msg2); + this.configuration.onIceConnectionStateException(ExceptionEventName.ICE_CONNECTION_FAILED, msg2); break; case 'closed': logger.log('IceConnectionState of RTCPeerConnection ' + this.id + ' (' + otherId + ') change to "closed"');