]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/content_script.js
Format and update docs
[rbdr/junction] / extension / content_script.js
index 721176e8330e19ea21168656053634ff4457c3d2..0c7012b7939c8f34fa6e2c0414f12fc3fee597f6 100644 (file)
@@ -26,6 +26,11 @@ const internals = {
     console.error(error.stack || error);
   },
 
+  connect() {
+    internals.port = chrome.runtime.connect({ name: "content" });
+    internals.port.onMessage.addListener(internals.onMessage);
+  },
+
   async joinAudioCall({ currentUrl, tada }) {
     try {
       const mediaStream = await startMedia();
@@ -50,12 +55,13 @@ const internals = {
         console.debug("disconnected from signaling server");
       });
 
-      socket.on("addPeer", ({ peerId }) => {
+      socket.on("addPeer", ({ peerId, shouldCreateOffer }) => {
         addPeer({
           peerId,
+          shouldCreateOffer,
           mediaStream,
           onOffer: (data) => socket.emit("relayOffer", data),
-          socket
+          socket,
         });
         playTada();
       });
@@ -83,8 +89,10 @@ const internals = {
   },
 };
 
-internals.port = chrome.runtime.connect({ name: "content" });
-internals.port.onMessage.addListener(internals.onMessage);
+internals.connect();
+chrome.runtime.onConnect.addListener(() => {
+  internals.connect();
+});
 
 console.debug("Content Script Loaded");