mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 01:59:58 +00:00
Convert mediaCast sender to typescript
This commit is contained in:
34
ext/src/shim/export.ts
Normal file
34
ext/src/shim/export.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "./cast";
|
||||
|
||||
import { BridgeInfo } from "../lib/getBridgeInfo";
|
||||
import { Message } from "../types";
|
||||
import { onMessage } from "./messageBridge";
|
||||
|
||||
|
||||
/**
|
||||
* To support exporting an API from a module, we need to
|
||||
* retain the event-based message passing despite not
|
||||
* actually crossing any context boundaries. The shim listens
|
||||
* for and emits these messages, and changing that behavior
|
||||
* is too messy.
|
||||
*/
|
||||
export function init (): Promise<BridgeInfo> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
// Trigger message port setup side-effects
|
||||
import("./content");
|
||||
|
||||
onMessage(message => {
|
||||
switch (message.subject) {
|
||||
case "shim:/initialized": {
|
||||
const bridgeInfo: BridgeInfo = message.data;
|
||||
resolve(bridgeInfo);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export default cast;
|
||||
Reference in New Issue
Block a user