mirror of
https://api.glitch.com/git/yaswvc
synced 2026-01-12 03:18:10 +00:00
🎨🌄 Checkpoint
./public/main.js:5975361/1046
This commit is contained in:
parent
f726b2589f
commit
a1c20c43e8
1 changed files with 17 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ var app = new Vue({
|
||||||
}),
|
}),
|
||||||
stream: null,
|
stream: null,
|
||||||
calls: [],
|
calls: [],
|
||||||
|
connections: [],
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
logMessage: function(message) {
|
logMessage: function(message) {
|
||||||
|
|
@ -24,13 +25,22 @@ var app = new Vue({
|
||||||
this.logMessage(`Connecting to ${peerId}...`);
|
this.logMessage(`Connecting to ${peerId}...`);
|
||||||
|
|
||||||
let conn = this.peer.connect(peerId);
|
let conn = this.peer.connect(peerId);
|
||||||
|
this.connections.push(conn);
|
||||||
|
console.log('[Out] connected', conn);
|
||||||
conn.on('data', (data) => {
|
conn.on('data', (data) => {
|
||||||
this.logMessage(`received: ${data}`);
|
this.logMessage(`received: ${data}`);
|
||||||
});
|
});
|
||||||
conn.on('open', () => {
|
conn.on('open', () => {
|
||||||
conn.send('hi!');
|
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);
|
let call = this.peer.call(peerId, this.stream);
|
||||||
call.on('stream', (stream) => this.renderVideo(stream, '#video-'+call.connectionId));
|
call.on('stream', (stream) => this.renderVideo(stream, '#video-'+call.connectionId));
|
||||||
call.on('close', () => {
|
call.on('close', () => {
|
||||||
|
|
@ -61,7 +71,8 @@ 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.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) => {
|
conn.on('data', (data) => {
|
||||||
this.logMessage(`received: ${data}`);
|
this.logMessage(`received: ${data}`);
|
||||||
});
|
});
|
||||||
|
|
@ -69,11 +80,12 @@ var app = new Vue({
|
||||||
conn.send('hello!');
|
conn.send('hello!');
|
||||||
});
|
});
|
||||||
conn.on('close', () => {
|
conn.on('close', () => {
|
||||||
|
this.connections = this.connections.filter(c => c.connectionId === conn.connectionId);
|
||||||
this.logMessage('Connection closed.');
|
this.logMessage('Connection closed.');
|
||||||
|
console.log('[Inc] closed conenction', conn)
|
||||||
});
|
});
|
||||||
conn.on('error', (error) => {
|
conn.on('error', () => {
|
||||||
console.error('Error:', error);
|
console.warn(`[Inc] Connection error ${conn.connectionId} with ${conn.peer}.`);
|
||||||
this.logMessage('Error'+error);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue