From e775e4a2402cef6d24b5802f67ac7fc65e5f5e7b Mon Sep 17 00:00:00 2001 From: Bronwen Date: Sat, 6 Aug 2022 17:28:43 -0400 Subject: [PATCH] blank video stream --- rtc-test/index.html | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/rtc-test/index.html b/rtc-test/index.html index 70905f9..c428d6d 100644 --- a/rtc-test/index.html +++ b/rtc-test/index.html @@ -68,6 +68,8 @@ let localMediaStream = null; let remoteMediaStream = null; let incommingCall = null; + let currentVideoTrackId = null; + let currentAudioTrackId = null; function closeLocalMediaStream() { for(const track of localMediaStream.getTracks()) { @@ -92,7 +94,21 @@ } } }); - } + + if(eVideoOptions.value === 'none') { + const canvas = Object.assign(document.createElement("canvas"), { + width: 160, + height: 90 + }); + canvas.getContext("2d").fillRect(0, 0, 160, 90); + const blankStream = canvas.captureStream(); + const videoTrack = blankStream.getVideoTracks()[0]; + console.log('empty tracks', blankStream, videoTrack); + localMediaStream.addTrack(videoTrack); + } + + updateOutgoing(); + }; console.dir(eAudioOptions); @@ -104,20 +120,14 @@ .filter(track => track.kind === 'audio')[0]; const videoTrack = localMediaStream.getTracks() .filter(track => track.kind === 'video')[0]; + call.peerConnection.getSenders() .filter(sender => sender.track.kind === 'audio')[0] .replaceTrack(audioTrack); - const currentVideoTrack = call.peerConnection.getSenders() - .filter(sender => sender.track.kind === 'video')[0]; - - console.log(videoTrack, currentVideoTrack); - - if(videoTrack !== undefined && currentVideoTrack === undefined) { - call.peerConnection.addTrack(videoTrack); - } else { - currentVideoTrack.replaceTrack(videoTrack); - } + call.peerConnection.getSenders() + .filter(sender => sender.track.kind === 'video')[0] + .replaceTrack(videoTrack) } } @@ -202,6 +212,9 @@ }); peer.on('call', (call) => { + if(incommingCall !== null) { + return; // reject the call request. + } eIncommingStatus.innerText = 'Incomming call from ' + call.peer; eAnswerBtn.disabled = false; incommingCall = call;