More strict fixes

This commit is contained in:
David Négrier 2020-06-03 22:57:00 +02:00
parent 111bfcfe8c
commit 7292bc3cab
2 changed files with 12 additions and 7 deletions

View File

@ -248,7 +248,7 @@ export class MediaManager {
} }
private getElementByIdOrFail<T extends HTMLElement>(id: string): T { private getElementByIdOrFail<T extends HTMLElement>(id: string): T {
let elem = document.getElementById("activeCam"); let elem = document.getElementById(id);
if (elem === null) { if (elem === null) {
throw new Error("Cannot find HTML element with id '"+id+"'"); throw new Error("Cannot find HTML element with id '"+id+"'");
} }

View File

@ -232,20 +232,25 @@ export class SimplePeer {
private addMedia (userId : any = null) { private addMedia (userId : any = null) {
try { try {
let transceiver : any = null; 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 //send fake signal
if(!this.PeerConnectionArray.has(userId)){ if(peer === undefined){
return; return;
} }
this.PeerConnectionArray.get(userId).write(new Buffer(JSON.stringify({ peer.write(new Buffer(JSON.stringify({
type: "stream", type: "stream",
stream: null stream: null
}))); })));
return; return;
} }
this.MediaManager.localStream.getTracks().forEach( if (peer === undefined) {
transceiver = (track: MediaStreamTrack) => this.PeerConnectionArray.get(userId).addTrack(track, this.MediaManager.localStream) throw new Error('While adding media, cannot find user with ID '+userId);
) }
for (const track of localStream.getTracks()) {
peer.addTrack(track, localStream);
}
}catch (e) { }catch (e) {
console.error(`addMedia => addMedia => ${userId}`, e); console.error(`addMedia => addMedia => ${userId}`, e);
} }