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/7152
./views/index.ejs:5975361/569
This commit is contained in:
Glitch (peerjs-video) 2020-09-12 22:12:31 +00:00
parent 0756b8f05a
commit 27e91cc10f
2 changed files with 63 additions and 0 deletions

View file

@ -66,6 +66,44 @@ var app = new Vue({
console.log('Started call', call);
this.handleCall(call);
},
connectToPeer2: async function(peerId) {
if (peerId === this.peer.id) {
this.logMessage(`You played yourself! Can't connect to yourself.`);
return;
};
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(`${conn.peer}: ${data}`);
});
conn.on('open', () => {
conn.send('hi!');
});
conn.on('close', () => {
this.connections = this.connections.filter(c => c.connectionId === 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', () => {
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}.`);
});
const audioStream = await this.getAudioStream();
let audioCall = this.peer.call(peerId, audioStream);
console.log('Started audioCall', audioCall);
this.calls.push(audioCall);
const videoStream = await this.getVideoStream();
let videoCall = this.peer.call(peerId, videoStream);
console.log('Started videoCall', videoCall);
this.calls.push(videoCall);
// this.handleCall(call);
},
hangUp: function() {
this.calls.forEach(c => {
console.log('hangUp - closing', c);
@ -227,6 +265,28 @@ var app = new Vue({
// Refresh button list in case labels have become available
return navigator.mediaDevices.enumerateDevices();
},
getAudioStream: async function getAudioStream() {
const audioSource = document.querySelector('select#audioSource').value;
// const videoSource = document.querySelector('select#videoSource').value;
const constraints = {
audio: {deviceId: audioSource ? {exact: audioSource} : undefined},
// video: {deviceId: undefined}
};
const audioStream = await navigator.mediaDevices.getUserMedia(constraints).catch(this.handleError);
console.log('GOT AUDIO STREAM', audioStream);
return audioStream;
},
getVideoStream: async function getVideoStream() {
// const audioSource = document.querySelector('select#audioSource').value;
const videoSource = document.querySelector('select#videoSource').value;
const constraints = {
// audio: {deviceId: audioSource ? {exact: audioSource} : undefined},
video: {deviceId: videoSource ? {exact: videoSource} : undefined}
};
const videoStream = await navigator.mediaDevices.getUserMedia(constraints).catch(this.handleError);
console.log('GOT VIDEO STREAM', videoStream);
return videoStream;
},
shareScreen: async function shareScreen() {
// if (!displayMediaStream) {
const displayMediaStream = await navigator.mediaDevices.getDisplayMedia();

View file

@ -95,6 +95,9 @@
<button class="btn btn-sm btn-success" v-on:click="connectToPeer($refs.connectPeer.value);$refs.connectPeer.value = '';">
Connect
</button>
<button class="btn btn-sm btn-primary" v-on:click="connectToPeer2($refs.connectPeer.value);$refs.connectPeer.value = '';">
Connect 2
</button>
<button class="btn btn-sm btn-danger" v-on:click="hangUp()">
Disconnect
</button>