From a1c20c43e84f0e6df3ca94db7309bb4dd8a3d7e1 Mon Sep 17 00:00:00 2001 From: "Glitch (peerjs-video)" Date: Tue, 8 Sep 2020 21:46:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=F0=9F=8C=84=20Checkpoint=20./publi?= =?UTF-8?q?c/main.js:5975361/1046?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/main.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/public/main.js b/public/main.js index ef7a0d0..e50ec90 100644 --- a/public/main.js +++ b/public/main.js @@ -9,6 +9,7 @@ var app = new Vue({ }), stream: null, calls: [], + connections: [], }, methods: { logMessage: function(message) { @@ -24,13 +25,22 @@ var app = new Vue({ this.logMessage(`Connecting to ${peerId}...`); let conn = this.peer.connect(peerId); + this.connections.push(conn); + console.log('[Out] connected', conn); conn.on('data', (data) => { this.logMessage(`received: ${data}`); }); conn.on('open', () => { conn.send('hi!'); }); - + conn.on('close', () => { + this.connections = this.connections.filter(c => c.connectionId === conn.connectionId); + console.log('[Out] Connection closed', conn.connectionId); + }); + conn.on('error', () => { + console.warn(`[Out] Connection error ${conn.connectionId} with ${conn.peer}.`); + }); + let call = this.peer.call(peerId, this.stream); call.on('stream', (stream) => this.renderVideo(stream, '#video-'+call.connectionId)); call.on('close', () => { @@ -61,7 +71,8 @@ var app = new Vue({ // Handle incoming data connection this.peer.on('connection', (conn) => { this.logMessage('incoming peer connection!'); - console.log('incoming peer connection!', conn); + this.connections.push(conn); + console.log('[INC] incoming peer connection!', conn); conn.on('data', (data) => { this.logMessage(`received: ${data}`); }); @@ -69,11 +80,12 @@ var app = new Vue({ conn.send('hello!'); }); conn.on('close', () => { + this.connections = this.connections.filter(c => c.connectionId === conn.connectionId); this.logMessage('Connection closed.'); + console.log('[Inc] closed conenction', conn) }); - conn.on('error', (error) => { - console.error('Error:', error); - this.logMessage('Error'+error); + conn.on('error', () => { + console.warn(`[Inc] Connection error ${conn.connectionId} with ${conn.peer}.`); }); });