diff --git a/www/js/channel/webRTCHandler.js b/www/js/channel/webRTCHandler.js index 166f306..62a399a 100644 --- a/www/js/channel/webRTCHandler.js +++ b/www/js/channel/webRTCHandler.js @@ -93,13 +93,17 @@ class webRTCHandler{ //If we didn't get any audio tracks from the DisplayMedia portion of the API if(this.broadcastingStream == null || this.broadcastingStream.getAudioTracks().length == 0){ - //Bug user for an audio device - const tempStream = await navigator.mediaDevices.getUserMedia({video: false, audio: true}); + try{ + //Bug user for an audio device + const tempStream = await navigator.mediaDevices.getUserMedia({video: false, audio: true}); - //For each track received from audio device - for(const track of tempStream.getAudioTracks()){ - //Add to existing broadcast stream - this.broadcastingStream.addTrack(track); + //For each track received from audio device + for(const track of tempStream.getAudioTracks()){ + //Add to existing broadcast stream + this.broadcastingStream.addTrack(track); + } + }catch(err){ + console.warn("Unable to get audio for stream!"); } } } @@ -231,7 +235,9 @@ class webRTCHandler{ handleIceCandidate(data){ //If we're broadcasting if(this.isBroadcasting){ + //Find the related user object const user = this.currentViewers.get(data.source.user); + //allow them to handle it user.handleIceCandidate(data); //If we're receiving a stream }else{ @@ -267,7 +273,7 @@ class webRTCHandler{ } handleConnectionState(data){ - if(this.currentStream.connectionState == "failed"){ + if(!this.isBroadcasting && this.currentStream.connectionState == "failed"){ let icon = document.createElement('img'); icon.src = "/img/rtcerror.png"; @@ -355,7 +361,7 @@ class connectedViewer{ await peer.setLocalDescription(answer); //Setup peer ICE Candidate event listner - peer.addEventListener('icecandidate', this.sendIceCandidate.bind(this)); + peer.addEventListener('icecandidate', (event)=>{this.sendIceCandidate(event, socket)}); //Save peer by socket identifier this.peers.set(socket, peer); @@ -368,14 +374,14 @@ class connectedViewer{ }); } - sendIceCandidate(event){ + sendIceCandidate(event, socket){ //If we have a candidate if(event.candidate != null){ //Send that shit off! this.client.socket.emit('relayRTCData',{ type: 'candidate', body: event.candidate, - recipient: this.socket + recipient: socket }); } }