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}.`); }); });