From 7292bc3cab1bc4dc1059a66374a0f2ee905492c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20N=C3=A9grier?= Date: Wed, 3 Jun 2020 22:57:00 +0200 Subject: [PATCH] More strict fixes --- front/src/WebRtc/MediaManager.ts | 2 +- front/src/WebRtc/SimplePeer.ts | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index a80cb6a..bb3f0cb 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -248,7 +248,7 @@ export class MediaManager { } private getElementByIdOrFail(id: string): T { - let elem = document.getElementById("activeCam"); + let elem = document.getElementById(id); if (elem === null) { throw new Error("Cannot find HTML element with id '"+id+"'"); } diff --git a/front/src/WebRtc/SimplePeer.ts b/front/src/WebRtc/SimplePeer.ts index 68925e9..2af0be2 100644 --- a/front/src/WebRtc/SimplePeer.ts +++ b/front/src/WebRtc/SimplePeer.ts @@ -232,20 +232,25 @@ export class SimplePeer { private addMedia (userId : any = null) { try { let transceiver : any = null; - if(!this.MediaManager.localStream){ + let localStream: MediaStream|null = this.MediaManager.localStream; + let peer = this.PeerConnectionArray.get(userId); + if(localStream === null) { //send fake signal - if(!this.PeerConnectionArray.has(userId)){ + if(peer === undefined){ return; } - this.PeerConnectionArray.get(userId).write(new Buffer(JSON.stringify({ + peer.write(new Buffer(JSON.stringify({ type: "stream", stream: null }))); return; } - this.MediaManager.localStream.getTracks().forEach( - transceiver = (track: MediaStreamTrack) => this.PeerConnectionArray.get(userId).addTrack(track, this.MediaManager.localStream) - ) + if (peer === undefined) { + throw new Error('While adding media, cannot find user with ID '+userId); + } + for (const track of localStream.getTracks()) { + peer.addTrack(track, localStream); + } }catch (e) { console.error(`addMedia => addMedia => ${userId}`, e); } -- 2.25.1