X-Git-Url: https://git.r.bdr.sh/rbdr/junction/blobdiff_plain/06b7617a863d00dbcc91d1e46f09942c6aad366e..6717f3d8b71abf255b0e07a5024caa602b5a3d3c:/extension/content_script.js diff --git a/extension/content_script.js b/extension/content_script.js index 721176e..0c7012b 100644 --- a/extension/content_script.js +++ b/extension/content_script.js @@ -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");