]> git.r.bdr.sh - rbdr/junction/blobdiff - extension/content_script.js
Add a contributing guide
[rbdr/junction] / extension / content_script.js
index c344bd945ca94e23ef5f954460f201cc98b6a61f..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();
@@ -56,7 +61,7 @@ const internals = {
           shouldCreateOffer,
           mediaStream,
           onOffer: (data) => socket.emit("relayOffer", data),
-          socket
+          socket,
         });
         playTada();
       });
@@ -84,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");