mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 01:59:58 +00:00
Cleanup ShimManager listeners
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import bridge from "../lib/bridge";
|
import bridge from "../lib/bridge";
|
||||||
import loadSender from "../lib/loadSender";
|
import loadSender from "../lib/loadSender";
|
||||||
import logger from "../lib/logger";
|
import logger from "../lib/logger";
|
||||||
import { Message, Port } from "../messaging";
|
import messaging, { Message, Port } from "../messaging";
|
||||||
import options from "../lib/options";
|
import options from "../lib/options";
|
||||||
|
|
||||||
import { ReceiverSelectionActionType
|
import { ReceiverSelectionActionType
|
||||||
@@ -30,7 +30,30 @@ export default new class ShimManager {
|
|||||||
private activeShims = new Set<Shim>();
|
private activeShims = new Set<Shim>();
|
||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
await this.initStatusListeners();
|
// Wait for "shim" ports
|
||||||
|
messaging.onConnect.addListener(async port => {
|
||||||
|
if (port.name === "shim") {
|
||||||
|
this.createShim(port);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
StatusManager.addEventListener("serviceUp", ev => {
|
||||||
|
for (const shim of this.activeShims) {
|
||||||
|
shim.contentPort.postMessage({
|
||||||
|
subject: "shim:serviceUp"
|
||||||
|
, data: { id: ev.detail.id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
StatusManager.addEventListener("serviceDown", ev => {
|
||||||
|
for (const shim of this.activeShims) {
|
||||||
|
shim.contentPort.postMessage({
|
||||||
|
subject: "shim:serviceDown"
|
||||||
|
, data: { id: ev.detail.id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getShim(tabId: number, frameId?: number) {
|
public getShim(tabId: number, frameId?: number) {
|
||||||
@@ -244,24 +267,4 @@ export default new class ShimManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initStatusListeners() {
|
|
||||||
StatusManager.addEventListener("serviceUp", ev => {
|
|
||||||
for (const shim of this.activeShims) {
|
|
||||||
shim.contentPort.postMessage({
|
|
||||||
subject: "shim:serviceUp"
|
|
||||||
, data: { id: ev.detail.id }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
StatusManager.addEventListener("serviceDown", ev => {
|
|
||||||
for (const shim of this.activeShims) {
|
|
||||||
shim.contentPort.postMessage({
|
|
||||||
subject: "shim:serviceDown"
|
|
||||||
, data: { id: ev.detail.id }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -175,7 +175,6 @@ async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selection = await ReceiverSelectorManager.getSelection(tab.id);
|
const selection = await ReceiverSelectorManager.getSelection(tab.id);
|
||||||
|
|
||||||
if (selection) {
|
if (selection) {
|
||||||
loadSender({
|
loadSender({
|
||||||
tabId: tab.id
|
tabId: tab.id
|
||||||
@@ -184,18 +183,6 @@ async function init() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When a message port connection with the name "shim" is
|
|
||||||
* established, pass it to createShim to handle the setup
|
|
||||||
* and maintenance.
|
|
||||||
*/
|
|
||||||
messaging.onConnect.addListener(async port => {
|
|
||||||
if (port.name === "shim") {
|
|
||||||
ShimManager.createShim(port);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|||||||
Reference in New Issue
Block a user