]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/junction.js
Fixes
[rbdr/junction] / extension / junction.js
index e78a02bc0755301ca59def111a7a84050b265467..73befa209a8d34d2bae7657d1b61b8478fc20a1f 100644 (file)
@@ -1,3 +1,5 @@
+const io = require('socket.io-client');
+
 const internals = {
 
   promisesSupported: !!(window.browser),
 const internals = {
 
   promisesSupported: !!(window.browser),
@@ -15,6 +17,10 @@ const internals = {
     }
   },
 
     }
   },
 
+  socket: null,
+
+  peers: 0,
+
   onClick() {
     if (internals.isInCall()) {
       return internals.hangUp();
   onClick() {
     if (internals.isInCall()) {
       return internals.hangUp();
@@ -29,11 +35,44 @@ const internals = {
     internals.setIcon('hangUp');
     const activeTabs = await internals.getActiveTabs();
 
     internals.setIcon('hangUp');
     const activeTabs = await internals.getActiveTabs();
 
+    const socketUrl = 'http://localhost:8000/';
+    const currentUrl = activeTabs[0].url;
+
+    this.socket = io(socketUrl);
+
+    var that = this;
+
+    this.socket.on('connect', function() {
+      console.log("Connected to signaling server");
+
+      that.socket.emit('join', {
+        'url': currentUrl,
+      });
+    });
+
+    this.socket.on('disconnect', function() {
+      console.log("disconnected from signaling server");
+    });
+
+    this.socket.on('addPeer', function(data) {
+      console.log(data);
+      that.peers++;
+      console.log(`There are now ${that.peers} participants`);
+    });
+
+    this.socket.on('removePeer', function() {
+      that.peers--;
+      console.log(`There are now ${that.peers} participants`);
+    });
+
     console.log(activeTabs[0].url); // placeholder while we connect backend.
     internals.createAudioElement(internals.getRoot().runtime.getURL('sounds/tada.wav'));
   },
 
   hangUp() {
     console.log(activeTabs[0].url); // placeholder while we connect backend.
     internals.createAudioElement(internals.getRoot().runtime.getURL('sounds/tada.wav'));
   },
 
   hangUp() {
+    this.socket.close();
+
+
 
     document.querySelectorAll('audio').forEach((audioElement) => audioElement.remove());
     internals.setIcon('call');
 
     document.querySelectorAll('audio').forEach((audioElement) => audioElement.remove());
     internals.setIcon('call');