const internals = {
promisesSupported: !!window.browser,
+ injectedScript: {},
port: null,
currentUrl: null,
return internals.hangUp();
}
- return internals.joinAudioCall();
+ return internals.initializeContentScript();
},
- onConnect(port) {
- internals.port = port;
- port.onDisconnect.addListener(internals.onDisconnect);
- port.onMessage.addListener(internals.onMessage);
- port.postMessage({
+ joinAudioCall() {
+ internals.port.postMessage({
action: "joinAudioCall",
data: {
currentUrl: internals.currentUrl,
internals.setIcon("hangUp");
},
+ onConnect(port) {
+ internals.port = port;
+ port.onDisconnect.addListener(internals.onDisconnect);
+ port.onMessage.addListener(internals.onMessage);
+ internals.joinAudioCall();
+ },
+
onMessage(message) {
if (message.action === "error") {
internals.getRoot().browserAction.setBadgeText({ text: "x" }, () => {});
internals.getRoot().browserAction.enable();
},
- async joinAudioCall() {
+ async initializeContentScript() {
internals.getRoot().browserAction.disable();
const activeTabs = await internals.getActiveTabs();
internals.currentUrl = activeTabs[0].url;
- const execution = await internals.getRoot().tabs.executeScript(
- activeTabs[0].id,
- {
- file: "/build/content_script.js",
- },
- () => {
- if (internals.getRoot().runtime.lastError) {
- internals.onDisconnect();
- }
- },
- );
-
- if (execution && !execution[0]) {
- internals.onDisconnect();
+ const id = activeTabs[0].id;
+ if (!internals.injectedScript[id]) {
+ const execution = await internals.getRoot().tabs.executeScript(
+ activeTabs[0].id,
+ {
+ file: "/build/content_script.js",
+ },
+ () => {
+ internals.injectedScript[id] = true;
+ },
+ );
+
+ if (execution && !execution[0]) {
+ internals.onDisconnect();
+ }
+ } else {
+ internals.getRoot().tabs.connect(activeTabs[0].id);
}
},
+
hangUp() {
internals.getRoot().browserAction.disable();
internals.port.postMessage({