1
0
Fork 0
mirror of https://api.glitch.com/git/yaswvc synced 2026-01-12 03:18:10 +00:00

🚣🎷 Checkpoint

./public/main.js:5975361/1553
This commit is contained in:
Glitch (peerjs-video) 2020-09-08 21:58:07 +00:00
parent a1c20c43e8
commit 9bc41435e3

View file

@ -28,16 +28,20 @@ var app = new Vue({
this.connections.push(conn); this.connections.push(conn);
console.log('[Out] connected', conn); console.log('[Out] connected', conn);
conn.on('data', (data) => { conn.on('data', (data) => {
this.logMessage(`received: ${data}`); this.logMessage(`${conn.peer}: ${data}`);
}); });
conn.on('open', () => { conn.on('open', () => {
conn.send('hi!'); conn.send('hi!');
}); });
conn.on('close', () => { conn.on('close', () => {
this.connections = this.connections.filter(c => c.connectionId === conn.connectionId); this.connections = this.connections.filter(c => c.connectionId === conn.connectionId);
console.log('[Out] Connection closed', conn.connectionId); this.calls = this.calls.filter(c => c.peer !== conn.peer);
this.logMessage(`${conn.peer} closed connection.`);
console.log(`[Out] Connection closed with ${conn.peer}.`);
}); });
conn.on('error', () => { conn.on('error', () => {
this.connections = this.connections.filter(c => c.connectionId === conn.connectionId);
this.calls = this.calls.filter(c => c.peer !== conn.peer);
console.warn(`[Out] Connection error ${conn.connectionId} with ${conn.peer}.`); console.warn(`[Out] Connection error ${conn.connectionId} with ${conn.peer}.`);
}); });
@ -51,17 +55,14 @@ var app = new Vue({
}, },
hangUp: function() { hangUp: function() {
this.calls.forEach(c => { this.calls.forEach(c => {
this.disconnectCall(c); c.close();
});
this.connections.forEach(c => {
c.close();
}); });
},
disconnectCall: function(call) {
if (!call) return;
console.log('CALL', call);
call.close();
}, },
listenForPeerEvents: function () { listenForPeerEvents: function () {
this.peer.on('open', (id) => { this.peer.on('open', (id) => {
this.logMessage('My peer ID is: ' + id);
localStorage.setItem('yaswvc-peerId', id); localStorage.setItem('yaswvc-peerId', id);
}); });
this.peer.on('error', (error) => { this.peer.on('error', (error) => {
@ -70,21 +71,22 @@ var app = new Vue({
// Handle incoming data connection // Handle incoming data connection
this.peer.on('connection', (conn) => { this.peer.on('connection', (conn) => {
this.logMessage('incoming peer connection!');
this.connections.push(conn); this.connections.push(conn);
console.log('[INC] incoming peer connection!', conn); console.log('[INC] incoming peer connection!', conn);
conn.on('data', (data) => { conn.on('data', (data) => {
this.logMessage(`received: ${data}`); this.logMessage(`${conn.peer}: ${data}`);
}); });
conn.on('open', () => { conn.on('open', () => {
conn.send('hello!'); conn.send('hello!');
}); });
conn.on('close', () => { conn.on('close', () => {
this.connections = this.connections.filter(c => c.connectionId === conn.connectionId); this.connections = this.connections.filter(c => c.connectionId === conn.connectionId);
this.logMessage('Connection closed.'); this.calls = this.calls.filter(c => c.peer !== conn.peer);
this.logMessage(`${conn.peer} closed connection.`);
console.log('[Inc] closed conenction', conn) console.log('[Inc] closed conenction', conn)
}); });
conn.on('error', () => { conn.on('error', () => {
this.connections = this.connections.filter(c => c.connectionId === conn.connectionId);
console.warn(`[Inc] Connection error ${conn.connectionId} with ${conn.peer}.`); console.warn(`[Inc] Connection error ${conn.connectionId} with ${conn.peer}.`);
}); });
}); });