From 88dbb0458a911cd522c426ff6ee5fa96d2725174 Mon Sep 17 00:00:00 2001 From: "Glitch (peerjs-video)" Date: Sat, 12 Sep 2020 21:15:14 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=BB=E2=9B=B0=20Checkpoint=20./public/m?= =?UTF-8?q?ain.js:5975361/3858?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/main.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/public/main.js b/public/main.js index 2b8b51a..996d2c5 100644 --- a/public/main.js +++ b/public/main.js @@ -64,12 +64,7 @@ var app = new Vue({ let call = this.peer.call(peerId, this.stream); console.log('Started call', call); - call.on('stream', (stream) => this.renderVideo(stream, '#video-'+call.connectionId)); - call.on('close', () => { - console.log(`[OUT] Call with ${peerId} was closed.`); - this.calls = this.calls.filter(c => c.connectionId === call.connectionId); - }); - this.calls.push(call); + this.handleCall(call); }, hangUp: function() { this.calls.forEach(c => { @@ -122,17 +117,24 @@ var app = new Vue({ this.peer.on('call', (call) => { console.log('INCOMING CALL', call); call.answer(this.stream); // Answer the call with an A/V stream. - call.on('stream', (stream) => this.renderVideo(stream, '#video-'+call.connectionId)); - call.on('close', () => { - console.log(`[INC] Call with ${call.peer} was closed.`); - this.calls = this.calls.filter(c => c.connectionId === call.connectionId); - }); - this.calls.push(call); - // TOOD vereinheitlichen mit selbstgestartetem stream - call.peerConnection.onTrack(); + this.handleCall(call); }); }, - handleStream; function handleStream + handleCall: function handleCall(call) { + call.on('stream', (stream) => this.renderVideo(stream, '#video-'+call.connectionId)); + call.on('close', () => { + console.log(`Call with ${call.peer} was closed.`); + this.calls = this.calls.filter(c => c.connectionId === call.connectionId); + }); + this.calls.push(call); + console.log('Call', call); + call.peerConnection.onaddstream = (a,b) => { + console.log('stream add', a, b) + }; + call.peerConnection.onremovestream =(a,b) => { + console.log('stream remove', a, b) + }; + }, gotDevices: function gotDevices(deviceInfos) { const selectors = [document.querySelector('select#audioSource'), document.querySelector('select#audioOutput'), document.querySelector('select#videoSource')]; // Handles being called several times to update labels. Preserve values. @@ -193,12 +195,13 @@ var app = new Vue({ console.log('gotStream', this.stream, stream); if (this.calls && (this.calls.length > 0)) { this.calls.forEach(call => { - console.log('local streams',call.peerConnection.getLocalStreams()); - call.peerConnection.removeStream(this.stream); - console.log('local streams',call.peerConnection.getLocalStreams()); - console.log('Adding stream', stream) - call.peerConnection.addStream(stream); - console.log('local streams',call.peerConnection.getLocalStreams()); + // console.log('local streams',call.peerConnection.getLocalStreams()); + // call.peerConnection.removeStream(this.stream); + // console.log('local streams',call.peerConnection.getLocalStreams()); + // console.log('Adding stream', stream) + // call.peerConnection.addStream(stream); + // console.log('local streams',call.peerConnection.getLocalStreams()); + console.log(call.peerConnection, stream.getTracks()) }); } this.stream = stream; // make stream available to console