From e1b6fb617975115ec29c82a7c42765795ac74ea6 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 7 Jul 2021 12:53:20 +0200 Subject: [PATCH] openvidu-browser: fix subscription process when transcievers API not available --- .../OpenViduInternal/Logger/OpenViduLogger.ts | 2 +- .../OpenViduInternal/WebRtcPeer/WebRtcPeer.ts | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/openvidu-browser/src/OpenViduInternal/Logger/OpenViduLogger.ts b/openvidu-browser/src/OpenViduInternal/Logger/OpenViduLogger.ts index b6e7747a..922e10c5 100644 --- a/openvidu-browser/src/OpenViduInternal/Logger/OpenViduLogger.ts +++ b/openvidu-browser/src/OpenViduInternal/Logger/OpenViduLogger.ts @@ -89,7 +89,7 @@ export class OpenViduLogger { const seen = new WeakSet(); return (key, value) => { if (typeof value === "object" && value != null) { - if (seen.has(value) || value instanceof HTMLElement) { + if (seen.has(value) || (HTMLElement && value instanceof HTMLElement)) { return; } seen.add(value); diff --git a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts index 11863787..269d5486 100644 --- a/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts +++ b/openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts @@ -259,10 +259,7 @@ export class WebRtcPeer { // "offerToReceiveAudio" and "offerToReceiveVideo". if (!!this.configuration.mediaStream) { - for (const track of this.configuration.mediaStream.getTracks()) { - // @ts-ignore - Compiler is too clever and thinks this branch will never execute. - this.pc.addTrack(track, this.configuration.mediaStream); - } + this.deprecatedPeerConnectionTrackApi(); } const hasAudio = this.configuration.mediaConstraints.audio; @@ -286,6 +283,12 @@ export class WebRtcPeer { }); } + deprecatedPeerConnectionTrackApi() { + for (const track of this.configuration.mediaStream!.getTracks()) { + this.pc.addTrack(track, this.configuration.mediaStream!); + } + } + /** * Creates an SDP answer from the local RTCPeerConnection to send to the other peer * Only if the negotiation was initiated by the other peer @@ -324,6 +327,29 @@ export class WebRtcPeer { .createAnswer() .then((sdpAnswer) => resolve(sdpAnswer)) .catch((error) => reject(error)); + + } else { + + // TODO: Delete else branch when all supported browsers are + // modern enough to implement the Transceiver methods + + let offerAudio, offerVideo = true; + if (!!this.configuration.mediaConstraints) { + offerAudio = (typeof this.configuration.mediaConstraints.audio === 'boolean') ? + this.configuration.mediaConstraints.audio : true; + offerVideo = (typeof this.configuration.mediaConstraints.video === 'boolean') ? + this.configuration.mediaConstraints.video : true; + const constraints: RTCOfferOptions = { + offerToReceiveAudio: offerAudio, + offerToReceiveVideo: offerVideo + }; + this.pc!.createAnswer(constraints).then(sdpAnswer => { + resolve(sdpAnswer); + }).catch(error => { + reject(error); + }); + } + } // else, there is nothing to do; the legacy createAnswer() options do