diff --git a/public/main.js b/public/main.js
index 320be53..2e5a8af 100644
--- a/public/main.js
+++ b/public/main.js
@@ -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();
diff --git a/views/index.ejs b/views/index.ejs
index cfb8934..50a79ce 100644
--- a/views/index.ejs
+++ b/views/index.ejs
@@ -95,6 +95,9 @@
+