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