mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-09 09:09:58 +00:00
Splits some background script functionality into separate modules: - Receiver selector handling is moved to ./SelectorManager. - Status bridge handling is moved to ./StatusManager. - Menu creation and updates are handled in ./createMenus. - Shim creation is handled in ./createShim. TypedEventTarget allows EventTarget-derived classes to export typed events. Options type definition is moved to ./lib/options, module assumes more responsibility for update handling and provides a "changed" event. Private cast._requestSession method allows bypassing receiver selector.
35 lines
1004 B
TypeScript
35 lines
1004 B
TypeScript
"use strict";
|
|
|
|
import { loadScript } from "../lib/utils";
|
|
import { Message } from "../types";
|
|
import { onMessageResponse, sendMessage } from "./eventMessageChannel";
|
|
|
|
|
|
const { isFramework }
|
|
: { isFramework: boolean } = (window as any);
|
|
|
|
/**
|
|
* Framework API library requires webcomponents for the cast
|
|
* button custom element (<google-cast-launcher>).
|
|
*/
|
|
if (isFramework) {
|
|
loadScript(browser.runtime.getURL("vendor/webcomponents-lite.js"));
|
|
}
|
|
|
|
|
|
// Message port to background script
|
|
export const backgroundPort = browser.runtime.connect({ name: "shim" });
|
|
|
|
const forwardToShim = (message: Message) => sendMessage(message);
|
|
const forwardToMain = (message: Message) => backgroundPort.postMessage(message);
|
|
|
|
// Add message listeners
|
|
backgroundPort.onMessage.addListener(forwardToShim);
|
|
const listener = onMessageResponse(forwardToMain);
|
|
|
|
// Remove listeners
|
|
backgroundPort.onDisconnect.addListener(() => {
|
|
backgroundPort.onMessage.removeListener(forwardToShim);
|
|
listener.disconnect();
|
|
});
|