mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-09 17:19:59 +00:00
Rename shim -> cast
This commit is contained in:
21
ext/src/cast/contentBridge.ts
Normal file
21
ext/src/cast/contentBridge.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
import { onMessageResponse, sendMessage } from "./eventMessageChannel";
|
||||
|
||||
import messaging, { Message } from "../messaging";
|
||||
|
||||
// Message port to background script
|
||||
export const backgroundPort = messaging.connect({ name: "cast" });
|
||||
|
||||
const forwardToCast = (message: Message) => sendMessage(message);
|
||||
const forwardToMain = (message: Message) => backgroundPort.postMessage(message);
|
||||
|
||||
// Add message listeners
|
||||
backgroundPort.onMessage.addListener(forwardToCast);
|
||||
const listener = onMessageResponse(forwardToMain);
|
||||
|
||||
// Remove listeners
|
||||
backgroundPort.onDisconnect.addListener(() => {
|
||||
backgroundPort.onMessage.removeListener(forwardToCast);
|
||||
listener.disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user