mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Cleanup ShimManager listeners
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import bridge from "../lib/bridge";
|
||||
import loadSender from "../lib/loadSender";
|
||||
import logger from "../lib/logger";
|
||||
import { Message, Port } from "../messaging";
|
||||
import messaging, { Message, Port } from "../messaging";
|
||||
import options from "../lib/options";
|
||||
|
||||
import { ReceiverSelectionActionType
|
||||
@@ -30,7 +30,30 @@ export default new class ShimManager {
|
||||
private activeShims = new Set<Shim>();
|
||||
|
||||
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) {
|
||||
@@ -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);
|
||||
|
||||
if (selection) {
|
||||
loadSender({
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user