Convert mediaCast sender to typescript

This commit is contained in:
hensm
2019-06-14 12:49:10 +01:00
parent 2996e50f5e
commit 0427e08b6a
5 changed files with 127 additions and 90 deletions

34
ext/src/shim/export.ts Normal file
View 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;