mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 16:49:58 +00:00
Rename shim -> cast
This commit is contained in:
@@ -17,7 +17,7 @@ import receiverDevices from "./receiverDevices";
|
||||
|
||||
type AnyPort = Port | MessagePort;
|
||||
|
||||
export interface Shim {
|
||||
export interface CastInstance {
|
||||
bridgePort: Port;
|
||||
contentPort: AnyPort;
|
||||
contentTabId?: number;
|
||||
@@ -25,109 +25,109 @@ export interface Shim {
|
||||
appId?: string;
|
||||
}
|
||||
|
||||
export default new (class ShimManager {
|
||||
private activeShims = new Set<Shim>();
|
||||
export default new (class CastManager {
|
||||
private activeInstances = new Set<CastInstance>();
|
||||
|
||||
public async init() {
|
||||
// Wait for "shim" ports
|
||||
// Wait for "cast" ports
|
||||
messaging.onConnect.addListener(async port => {
|
||||
if (port.name === "shim") {
|
||||
this.createShim(port);
|
||||
if (port.name === "cast") {
|
||||
this.createInstance(port);
|
||||
}
|
||||
});
|
||||
|
||||
receiverDevices.addEventListener("receiverDeviceUp", ev => {
|
||||
for (const shim of this.activeShims) {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:serviceUp",
|
||||
data: { receiverDevice: ev.detail.receiverDevice }
|
||||
for (const instance of this.activeInstances) {
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:serviceUp",
|
||||
data: { receiverDevice: ev.detail.deviceInfo }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
receiverDevices.addEventListener("receiverDeviceDown", ev => {
|
||||
for (const shim of this.activeShims) {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:serviceDown",
|
||||
data: { receiverDeviceId: ev.detail.receiverDeviceId }
|
||||
for (const instance of this.activeInstances) {
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:serviceDown",
|
||||
data: { receiverDeviceId: ev.detail.deviceId }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public getShim(tabId: number, frameId?: number) {
|
||||
for (const activeShim of this.activeShims) {
|
||||
if (activeShim.contentTabId === tabId) {
|
||||
if (frameId && activeShim.contentFrameId !== frameId) {
|
||||
public getInstance(tabId: number, frameId?: number) {
|
||||
for (const instance of this.activeInstances) {
|
||||
if (instance.contentTabId === tabId) {
|
||||
if (frameId && instance.contentFrameId !== frameId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return activeShim;
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async createShim(port: AnyPort) {
|
||||
const shim = await (port instanceof MessagePort
|
||||
? this.createShimFromBackground(port)
|
||||
: this.createShimFromContent(port));
|
||||
public async createInstance(port: AnyPort) {
|
||||
const instance = await (port instanceof MessagePort
|
||||
? this.createInstanceFromBackground(port)
|
||||
: this.createInstanceFromContent(port));
|
||||
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:initialized",
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:initialized",
|
||||
data: await bridge.getInfo()
|
||||
});
|
||||
|
||||
this.activeShims.add(shim);
|
||||
this.activeInstances.add(instance);
|
||||
}
|
||||
|
||||
private async createShimFromBackground(
|
||||
private async createInstanceFromBackground(
|
||||
contentPort: MessagePort
|
||||
): Promise<Shim> {
|
||||
const shim: Shim = {
|
||||
): Promise<CastInstance> {
|
||||
const instance: CastInstance = {
|
||||
bridgePort: await bridge.connect(),
|
||||
contentPort
|
||||
};
|
||||
|
||||
shim.bridgePort.onDisconnect.addListener(() => {
|
||||
instance.bridgePort.onDisconnect.addListener(() => {
|
||||
contentPort.close();
|
||||
this.activeShims.delete(shim);
|
||||
this.activeInstances.delete(instance);
|
||||
});
|
||||
|
||||
shim.bridgePort.onMessage.addListener(message => {
|
||||
instance.bridgePort.onMessage.addListener(message => {
|
||||
contentPort.postMessage(message);
|
||||
});
|
||||
|
||||
contentPort.addEventListener("message", ev => {
|
||||
this.handleContentMessage(shim, ev.data);
|
||||
this.handleContentMessage(instance, ev.data);
|
||||
});
|
||||
|
||||
return shim;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private async createShimFromContent(contentPort: Port): Promise<Shim> {
|
||||
private async createInstanceFromContent(contentPort: Port): Promise<CastInstance> {
|
||||
if (
|
||||
contentPort.sender?.tab?.id === undefined ||
|
||||
contentPort.sender?.frameId === undefined
|
||||
) {
|
||||
throw logger.error(
|
||||
"Content shim created with an invalid port context."
|
||||
"Cast instance created from content with an invalid port context."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's already an active shim for the sender
|
||||
* If there's already an active instance for the sender
|
||||
* tab/frame ID, disconnect it.
|
||||
*/
|
||||
for (const activeShim of this.activeShims) {
|
||||
for (const instance of this.activeInstances) {
|
||||
if (
|
||||
activeShim.contentTabId === contentPort.sender.tab.id &&
|
||||
activeShim.contentFrameId === contentPort.sender.frameId
|
||||
instance.contentTabId === contentPort.sender.tab.id &&
|
||||
instance.contentFrameId === contentPort.sender.frameId
|
||||
) {
|
||||
activeShim.bridgePort.disconnect();
|
||||
instance.bridgePort.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
const shim: Shim = {
|
||||
const instance: CastInstance = {
|
||||
bridgePort: await bridge.connect(),
|
||||
contentPort,
|
||||
contentTabId: contentPort.sender.tab.id,
|
||||
@@ -135,7 +135,7 @@ export default new (class ShimManager {
|
||||
};
|
||||
|
||||
const onContentPortMessage = (message: Message) => {
|
||||
this.handleContentMessage(shim, message);
|
||||
this.handleContentMessage(instance, message);
|
||||
};
|
||||
|
||||
const onBridgePortMessage = (message: Message) => {
|
||||
@@ -143,37 +143,37 @@ export default new (class ShimManager {
|
||||
};
|
||||
|
||||
const onDisconnect = () => {
|
||||
shim.bridgePort.onMessage.removeListener(onBridgePortMessage);
|
||||
instance.bridgePort.onMessage.removeListener(onBridgePortMessage);
|
||||
contentPort.onMessage.removeListener(onContentPortMessage);
|
||||
|
||||
shim.bridgePort.disconnect();
|
||||
instance.bridgePort.disconnect();
|
||||
contentPort.disconnect();
|
||||
|
||||
this.activeShims.delete(shim);
|
||||
this.activeInstances.delete(instance);
|
||||
};
|
||||
|
||||
shim.bridgePort.onDisconnect.addListener(onDisconnect);
|
||||
shim.bridgePort.onMessage.addListener(onBridgePortMessage);
|
||||
instance.bridgePort.onDisconnect.addListener(onDisconnect);
|
||||
instance.bridgePort.onMessage.addListener(onBridgePortMessage);
|
||||
|
||||
contentPort.onDisconnect.addListener(onDisconnect);
|
||||
contentPort.onMessage.addListener(onContentPortMessage);
|
||||
|
||||
return shim;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private async handleContentMessage(shim: Shim, message: Message) {
|
||||
private async handleContentMessage(instance: CastInstance, message: Message) {
|
||||
const [destination] = message.subject.split(":");
|
||||
if (destination === "bridge") {
|
||||
shim.bridgePort.postMessage(message);
|
||||
instance.bridgePort.postMessage(message);
|
||||
}
|
||||
|
||||
switch (message.subject) {
|
||||
case "main:shimReady": {
|
||||
shim.appId = message.data.appId;
|
||||
case "main:castReady": {
|
||||
instance.appId = message.data.appId;
|
||||
|
||||
for (const receiverDevice of receiverDevices.getDevices()) {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:serviceUp",
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:serviceUp",
|
||||
data: { receiverDevice }
|
||||
});
|
||||
}
|
||||
@@ -183,25 +183,25 @@ export default new (class ShimManager {
|
||||
|
||||
case "main:selectReceiver": {
|
||||
if (
|
||||
shim.contentTabId === undefined ||
|
||||
shim.contentFrameId === undefined
|
||||
instance.contentTabId === undefined ||
|
||||
instance.contentFrameId === undefined
|
||||
) {
|
||||
throw logger.error(
|
||||
"Shim associated with content sender missing tab/frame ID"
|
||||
"Cast instance associated with content sender missing tab/frame ID"
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const selection =
|
||||
await ReceiverSelectorManager.getSelection(
|
||||
shim.contentTabId,
|
||||
shim.contentFrameId
|
||||
instance.contentTabId,
|
||||
instance.contentFrameId
|
||||
);
|
||||
|
||||
// Handle cancellation
|
||||
if (!selection) {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:selectReceiver/cancelled"
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:selectReceiver/cancelled"
|
||||
});
|
||||
|
||||
break;
|
||||
@@ -218,21 +218,21 @@ export default new (class ShimManager {
|
||||
selection.mediaType !==
|
||||
ReceiverSelectorMediaType.App
|
||||
) {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:selectReceiver/cancelled"
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:selectReceiver/cancelled"
|
||||
});
|
||||
|
||||
loadSender({
|
||||
tabId: shim.contentTabId,
|
||||
frameId: shim.contentFrameId,
|
||||
tabId: instance.contentTabId,
|
||||
frameId: instance.contentFrameId,
|
||||
selection
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:selectReceiver/selected",
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:selectReceiver/selected",
|
||||
data: selection
|
||||
});
|
||||
|
||||
@@ -240,8 +240,8 @@ export default new (class ShimManager {
|
||||
}
|
||||
|
||||
case ReceiverSelectionActionType.Stop: {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:selectReceiver/stopped",
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:selectReceiver/stopped",
|
||||
data: selection
|
||||
});
|
||||
|
||||
@@ -250,8 +250,8 @@ export default new (class ShimManager {
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO: Report errors properly
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:selectReceiver/cancelled"
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:selectReceiver/cancelled"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
import defaultOptions from "../defaultOptions";
|
||||
import loadSender from "../lib/loadSender";
|
||||
import logger from "../lib/logger";
|
||||
import messaging from "../messaging";
|
||||
import options from "../lib/options";
|
||||
import bridge, { BridgeInfo } from "../lib/bridge";
|
||||
|
||||
import ReceiverSelectorManager from "./receiverSelector/ReceiverSelectorManager";
|
||||
|
||||
import ShimManager from "./ShimManager";
|
||||
import CastManager from "./CastManager";
|
||||
|
||||
import receiverDevices from "./receiverDevices";
|
||||
|
||||
@@ -150,7 +149,7 @@ async function init() {
|
||||
await notifyBridgeCompat();
|
||||
|
||||
await receiverDevices.init();
|
||||
await ShimManager.init();
|
||||
await CastManager.init();
|
||||
|
||||
await initMenus();
|
||||
await initWhitelist();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { TypedEventTarget } from "../lib/TypedEventTarget";
|
||||
|
||||
import { Message, Port } from "../messaging";
|
||||
import { ReceiverDevice } from "../types";
|
||||
import { ReceiverStatus } from "../shim/cast/types";
|
||||
import { ReceiverStatus } from "../cast/api/types";
|
||||
|
||||
interface EventMap {
|
||||
receiverDeviceUp: { deviceInfo: ReceiverDevice };
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import options from "../../lib/options";
|
||||
import logger from "../../lib/logger";
|
||||
|
||||
import ShimManager from "../ShimManager";
|
||||
import CastManager from "../CastManager";
|
||||
import receiverDevices from "../receiverDevices";
|
||||
|
||||
import { getMediaTypesForPageUrl } from "../../lib/utils";
|
||||
@@ -50,14 +50,17 @@ async function getSelection(
|
||||
withMediaSender = false
|
||||
): Promise<ReceiverSelection | null> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let currentShim = ShimManager.getShim(contextTabId, contextFrameId);
|
||||
let castInstance = CastManager.getInstance(
|
||||
contextTabId,
|
||||
contextFrameId
|
||||
);
|
||||
|
||||
/**
|
||||
* If the current context is running the mirroring app, pretend
|
||||
* it doesn't exist because it shouldn't be launched like this.
|
||||
*/
|
||||
if (currentShim?.appId === (await options.get("mirroringAppId"))) {
|
||||
currentShim = undefined;
|
||||
if (castInstance?.appId === (await options.get("mirroringAppId"))) {
|
||||
castInstance = undefined;
|
||||
}
|
||||
|
||||
let defaultMediaType = ReceiverSelectorMediaType.Tab;
|
||||
@@ -78,7 +81,7 @@ async function getSelection(
|
||||
}
|
||||
|
||||
// Enable app media type if initialized sender app is found
|
||||
if (currentShim || withMediaSender) {
|
||||
if (castInstance || withMediaSender) {
|
||||
defaultMediaType = ReceiverSelectorMediaType.App;
|
||||
availableMediaTypes |= ReceiverSelectorMediaType.App;
|
||||
}
|
||||
@@ -215,7 +218,7 @@ async function getSelection(
|
||||
receiverDevices.getDevices(),
|
||||
defaultMediaType,
|
||||
availableMediaTypes,
|
||||
currentShim?.appId
|
||||
castInstance?.appId
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ function onWhitelistedChildBeforeSendHeaders(
|
||||
* hosted script.
|
||||
*
|
||||
* We can redirect this and inject our own script to setup
|
||||
* the API shim.
|
||||
* the API.
|
||||
*/
|
||||
async function onBeforeCastSDKRequest(details: OnBeforeRequestDetails) {
|
||||
if (!details.originUrl || details.tabId === -1) {
|
||||
@@ -179,13 +179,13 @@ async function onBeforeCastSDKRequest(details: OnBeforeRequestDetails) {
|
||||
});
|
||||
|
||||
await browser.tabs.executeScript(details.tabId, {
|
||||
file: "shim/contentBridge.js",
|
||||
file: "cast/contentBridge.js",
|
||||
frameId: details.frameId,
|
||||
runAt: "document_start"
|
||||
});
|
||||
|
||||
return {
|
||||
redirectUrl: browser.runtime.getURL("shim/index.js")
|
||||
redirectUrl: browser.runtime.getURL("cast/index.js")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
0
ext/src/shim/cast/enums.ts → ext/src/cast/api/enums.ts
Executable file → Normal file
0
ext/src/shim/cast/enums.ts → ext/src/cast/api/enums.ts
Executable file → Normal file
24
ext/src/shim/cast/index.ts → ext/src/cast/api/index.ts
Executable file → Normal file
24
ext/src/shim/cast/index.ts → ext/src/cast/api/index.ts
Executable file → Normal file
@@ -133,7 +133,7 @@ export function initialize(
|
||||
apiConfig = newApiConfig;
|
||||
|
||||
sendMessageResponse({
|
||||
subject: "main:shimReady",
|
||||
subject: "main:castReady",
|
||||
data: { appId: apiConfig.sessionRequest.appId }
|
||||
});
|
||||
|
||||
@@ -243,7 +243,7 @@ export function precache(_data: string) {
|
||||
|
||||
onMessage(message => {
|
||||
switch (message.subject) {
|
||||
case "shim:initialized": {
|
||||
case "cast:initialized": {
|
||||
isAvailable = true;
|
||||
break;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ onMessage(message => {
|
||||
* Once the bridge detects a session creation, session info
|
||||
* and data needed to create cast API objects is sent.
|
||||
*/
|
||||
case "shim:castSessionCreated": {
|
||||
case "cast:sessionCreated": {
|
||||
// Notify background to close UI
|
||||
sendMessageResponse({
|
||||
subject: "main:sessionCreated"
|
||||
@@ -282,7 +282,7 @@ onMessage(message => {
|
||||
sessions.set(session.sessionId, session);
|
||||
}
|
||||
// eslint-disable-next-line no-fallthrough
|
||||
case "shim:castSessionUpdated": {
|
||||
case "cast:sessionUpdated": {
|
||||
const status = message.data;
|
||||
const session = sessions.get(status.sessionId);
|
||||
if (!session) {
|
||||
@@ -303,7 +303,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:castSessionStopped": {
|
||||
case "cast:sessionStopped": {
|
||||
const { sessionId } = message.data;
|
||||
const session = sessions.get(sessionId);
|
||||
if (session) {
|
||||
@@ -320,7 +320,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:receivedCastSessionMessage": {
|
||||
case "cast:receivedSessionMessage": {
|
||||
const { sessionId, namespace, messageData } = message.data;
|
||||
const session = sessions.get(sessionId);
|
||||
if (session) {
|
||||
@@ -337,7 +337,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:impl_sendCastMessage": {
|
||||
case "cast:impl_sendMessage": {
|
||||
const { sessionId, messageId, error } = message.data;
|
||||
|
||||
const session = sessions.get(sessionId);
|
||||
@@ -360,7 +360,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:serviceUp": {
|
||||
case "cast:serviceUp": {
|
||||
const { receiverDevice } = message.data;
|
||||
if (receiverDevices.has(receiverDevice.id)) {
|
||||
break;
|
||||
@@ -376,7 +376,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:serviceDown": {
|
||||
case "cast:serviceDown": {
|
||||
const { receiverDeviceId } = message.data;
|
||||
|
||||
receiverDevices.delete(receiverDeviceId);
|
||||
@@ -392,7 +392,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:selectReceiver/selected": {
|
||||
case "cast:selectReceiver/selected": {
|
||||
logger.info("Selected receiver");
|
||||
|
||||
if (!sessionRequest) {
|
||||
@@ -403,7 +403,7 @@ onMessage(message => {
|
||||
break;
|
||||
}
|
||||
|
||||
case "shim:selectReceiver/stopped": {
|
||||
case "cast:selectReceiver/stopped": {
|
||||
const { receiver } = message.data;
|
||||
|
||||
logger.info("Stopped receiver");
|
||||
@@ -427,7 +427,7 @@ onMessage(message => {
|
||||
/**
|
||||
* Popup closed before session established.
|
||||
*/
|
||||
case "shim:selectReceiver/cancelled": {
|
||||
case "cast:selectReceiver/cancelled": {
|
||||
if (sessionRequest) {
|
||||
sessionRequest = null;
|
||||
|
||||
0
ext/src/shim/cast/media/enums.ts → ext/src/cast/api/media/enums.ts
Executable file → Normal file
0
ext/src/shim/cast/media/enums.ts → ext/src/cast/api/media/enums.ts
Executable file → Normal file
0
ext/src/shim/cast/media/index.ts → ext/src/cast/api/media/index.ts
Executable file → Normal file
0
ext/src/shim/cast/media/index.ts → ext/src/cast/api/media/index.ts
Executable file → Normal file
@@ -1,22 +1,21 @@
|
||||
"use strict";
|
||||
|
||||
import { loadScript } from "../lib/utils";
|
||||
import { onMessageResponse, sendMessage } from "./eventMessageChannel";
|
||||
|
||||
import messaging, { Message } from "../messaging";
|
||||
|
||||
// Message port to background script
|
||||
export const backgroundPort = messaging.connect({ name: "shim" });
|
||||
export const backgroundPort = messaging.connect({ name: "cast" });
|
||||
|
||||
const forwardToShim = (message: Message) => sendMessage(message);
|
||||
const forwardToCast = (message: Message) => sendMessage(message);
|
||||
const forwardToMain = (message: Message) => backgroundPort.postMessage(message);
|
||||
|
||||
// Add message listeners
|
||||
backgroundPort.onMessage.addListener(forwardToShim);
|
||||
backgroundPort.onMessage.addListener(forwardToCast);
|
||||
const listener = onMessageResponse(forwardToMain);
|
||||
|
||||
// Remove listeners
|
||||
backgroundPort.onDisconnect.addListener(() => {
|
||||
backgroundPort.onMessage.removeListener(forwardToShim);
|
||||
backgroundPort.onMessage.removeListener(forwardToCast);
|
||||
listener.disconnect();
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "./cast";
|
||||
import * as cast from "./api";
|
||||
import { Message } from "../messaging";
|
||||
|
||||
import { BridgeInfo } from "../lib/bridge";
|
||||
@@ -18,9 +18,9 @@ let initializedBackgroundPort: MessagePort;
|
||||
/**
|
||||
* 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.
|
||||
* actually crossing any context boundaries. The cast instance
|
||||
* listens for and emits these messages, and changing that
|
||||
* behavior is too messy.
|
||||
*/
|
||||
export function ensureInit(): Promise<TypedMessagePort<Message>> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
@@ -45,24 +45,24 @@ export function ensureInit(): Promise<TypedMessagePort<Message>> {
|
||||
* URL.
|
||||
*/
|
||||
if (window.location.protocol === "moz-extension:") {
|
||||
const { default: ShimManager } = await import(
|
||||
"../background/ShimManager"
|
||||
const { default: CastManager } = await import(
|
||||
"../background/CastManager"
|
||||
);
|
||||
|
||||
// port2 will post bridge messages to port 1
|
||||
await ShimManager.init();
|
||||
await ShimManager.createShim(channel.port2);
|
||||
await CastManager.init();
|
||||
await CastManager.createInstance(channel.port2);
|
||||
|
||||
// bridge -> shim
|
||||
// bridge -> cast instance
|
||||
channel.port1.onmessage = ev => {
|
||||
const message = ev.data as Message;
|
||||
|
||||
// Send message to shim
|
||||
// Send message to cast instance
|
||||
sendMessage(message);
|
||||
handleIncomingMessageToShim(message);
|
||||
handleIncomingMessageToCast(message);
|
||||
};
|
||||
|
||||
// shim -> bridge
|
||||
// cast instance -> bridge
|
||||
onMessageResponse(message => {
|
||||
channel.port1.postMessage(message);
|
||||
});
|
||||
@@ -85,13 +85,13 @@ export function ensureInit(): Promise<TypedMessagePort<Message>> {
|
||||
backgroundPort.postMessage(message);
|
||||
};
|
||||
|
||||
// Handle shim messages
|
||||
onMessage(handleIncomingMessageToShim);
|
||||
// Handle cast messages
|
||||
onMessage(handleIncomingMessageToCast);
|
||||
}
|
||||
|
||||
function handleIncomingMessageToShim(message: Message) {
|
||||
function handleIncomingMessageToCast(message: Message) {
|
||||
switch (message.subject) {
|
||||
case "shim:initialized": {
|
||||
case "cast:initialized": {
|
||||
initializedBridgeInfo = message.data;
|
||||
|
||||
if (initializedBridgeInfo.isVersionCompatible) {
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "../../cast";
|
||||
import * as cast from "../../api";
|
||||
|
||||
export default class ApplicationMetadata {
|
||||
public applicationId: string;
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "../../cast";
|
||||
import * as cast from "../../api";
|
||||
|
||||
export default class CastOptions {
|
||||
public autoJoinPolicy: string = cast.AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import logger from "../../../lib/logger";
|
||||
|
||||
import * as cast from "../../cast";
|
||||
import * as cast from "../../api";
|
||||
|
||||
import ApplicationMetadata from "./ApplicationMetadata";
|
||||
|
||||
@@ -91,17 +91,17 @@ export default class CastSession extends EventTarget {
|
||||
_namespace: string,
|
||||
// @ts-ignore
|
||||
_data: any
|
||||
): Promise<string> {
|
||||
): Promise<void> {
|
||||
logger.info("STUB :: CastSession#sendMessage");
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
public setMute(_isMute: boolean): Promise<string> {
|
||||
public setMute(_isMute: boolean): Promise<void> {
|
||||
logger.info("STUB :: CastSession#setMute");
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
public setVolume(_volume: number): Promise<string> {
|
||||
public setVolume(_volume: number): Promise<void> {
|
||||
logger.info("STUB :: CastSession#setVolume");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "../../cast";
|
||||
import * as cast from "../../api";
|
||||
|
||||
import EventData from "./EventData";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "../../cast";
|
||||
import * as cast from "../../api";
|
||||
|
||||
import RemotePlayerController from "./RemotePlayerController";
|
||||
|
||||
4
ext/src/shim/index.ts → ext/src/cast/index.ts
Executable file → Normal file
4
ext/src/shim/index.ts → ext/src/cast/index.ts
Executable file → Normal file
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import * as cast from "./cast";
|
||||
import * as cast from "./api";
|
||||
|
||||
import { CAST_FRAMEWORK_SCRIPT_URL } from "../lib/endpoints";
|
||||
import { loadScript } from "../lib/utils";
|
||||
@@ -60,7 +60,7 @@ if (document.currentScript) {
|
||||
|
||||
onMessage(message => {
|
||||
switch (message.subject) {
|
||||
case "shim:initialized": {
|
||||
case "cast:initialized": {
|
||||
bridgeInfo = message.data;
|
||||
|
||||
if (!isFramework) {
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
import { Error as Error_ } from "./cast/dataClasses";
|
||||
import { Media } from "./cast/media";
|
||||
import { Error as Error_ } from "./api/dataClasses";
|
||||
import { Media } from "./api/media";
|
||||
|
||||
export type SuccessCallback = () => void;
|
||||
export type ErrorCallback = (err: Error_) => void;
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
ReceiverSelectorMediaType
|
||||
} from "../background/receiverSelector";
|
||||
|
||||
import ShimManager from "../background/ShimManager";
|
||||
import CastManager from "../background/CastManager";
|
||||
|
||||
interface LoadSenderOptions {
|
||||
tabId: number;
|
||||
@@ -33,15 +33,15 @@ export default async function loadSender(opts: LoadSenderOptions) {
|
||||
|
||||
switch (opts.selection.mediaType) {
|
||||
case ReceiverSelectorMediaType.App: {
|
||||
const shim = ShimManager.getShim(opts.tabId, opts.frameId);
|
||||
if (!shim) {
|
||||
const instance = CastManager.getInstance(opts.tabId, opts.frameId);
|
||||
if (!instance) {
|
||||
throw logger.error(
|
||||
`Shim not found at tabId ${opts.tabId} / frameId ${opts.frameId}`
|
||||
`Cast instance not found at tabId ${opts.tabId} / frameId ${opts.frameId}`
|
||||
);
|
||||
}
|
||||
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:launchApp",
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:launchApp",
|
||||
data: { receiver: opts.selection.receiver }
|
||||
});
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
{
|
||||
"all_frames": true
|
||||
, "js": [
|
||||
"shim/content.js"
|
||||
"cast/content.js"
|
||||
]
|
||||
, "matches": [ "<all_urls>" ]
|
||||
, "run_at": "document_start"
|
||||
@@ -65,7 +65,7 @@
|
||||
, "<all_urls>"
|
||||
]
|
||||
, "web_accessible_resources": [
|
||||
"shim/index.js"
|
||||
"cast/index.js"
|
||||
, "senders/media/overlay/overlayContent.js"
|
||||
, "senders/media/overlay/AirPlay_Audio.svg"
|
||||
, "senders/media/overlay/AirPlay_Video.svg"
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
MediaStatus,
|
||||
ReceiverStatus,
|
||||
SenderMessage
|
||||
} from "./shim/cast/types";
|
||||
} from "./cast/api/types";
|
||||
|
||||
import { ReceiverDevice } from "./types";
|
||||
|
||||
@@ -47,18 +47,23 @@ type ExtMessageDefinitions = {
|
||||
availableMediaTypes?: ReceiverSelectorMediaType;
|
||||
};
|
||||
"popup:close": {};
|
||||
|
||||
"receiverSelector:selected": ReceiverSelection;
|
||||
"receiverSelector:stop": ReceiverSelection;
|
||||
"main:shimReady": { appId: string };
|
||||
|
||||
"main:castReady": { appId: string };
|
||||
|
||||
"main:selectReceiver": {};
|
||||
"shim:selectReceiver/selected": ReceiverSelectionCast;
|
||||
"shim:selectReceiver/stopped": ReceiverSelectionStop;
|
||||
"shim:selectReceiver/cancelled": {};
|
||||
"cast:selectReceiver/selected": ReceiverSelectionCast;
|
||||
"cast:selectReceiver/stopped": ReceiverSelectionStop;
|
||||
"cast:selectReceiver/cancelled": {};
|
||||
|
||||
"main:sessionCreated": {};
|
||||
"shim:initialized": BridgeInfo;
|
||||
"shim:serviceUp": { receiverDevice: ReceiverDevice };
|
||||
"shim:serviceDown": { receiverDeviceId: ReceiverDevice["id"] };
|
||||
"shim:launchApp": { receiver: ReceiverDevice };
|
||||
|
||||
"cast:initialized": BridgeInfo;
|
||||
"cast:serviceUp": { receiverDevice: ReceiverDevice };
|
||||
"cast:serviceDown": { receiverDeviceId: ReceiverDevice["id"] };
|
||||
"cast:launchApp": { receiver: ReceiverDevice };
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -67,17 +72,17 @@ type ExtMessageDefinitions = {
|
||||
* app/src/bridge/messaging.ts > MessageDefinitions
|
||||
*/
|
||||
type AppMessageDefinitions = {
|
||||
"shim:castSessionCreated": CastSessionCreated;
|
||||
"shim:castSessionUpdated": CastSessionUpdated;
|
||||
"shim:castSessionStopped": {
|
||||
"cast:sessionCreated": CastSessionCreated;
|
||||
"cast:sessionUpdated": CastSessionUpdated;
|
||||
"cast:sessionStopped": {
|
||||
sessionId: string;
|
||||
};
|
||||
"shim:receivedCastSessionMessage": {
|
||||
"cast:receivedSessionMessage": {
|
||||
sessionId: string;
|
||||
namespace: string;
|
||||
messageData: string;
|
||||
};
|
||||
"shim:impl_sendCastMessage": {
|
||||
"cast:impl_sendMessage": {
|
||||
sessionId: string;
|
||||
messageId: string;
|
||||
error?: string;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import logger from "../../lib/logger";
|
||||
import options from "../../lib/options";
|
||||
import cast, { ensureInit } from "../../shim/export";
|
||||
import cast, { ensureInit } from "../../cast/export";
|
||||
|
||||
import { Message } from "../../messaging";
|
||||
import { ReceiverDevice } from "../../types";
|
||||
@@ -363,7 +363,7 @@ export async function init(opts: InitOptions) {
|
||||
if (targetElement instanceof HTMLMediaElement) {
|
||||
registerMediaElementListeners(targetElement);
|
||||
|
||||
if (options.get("mediaOverlayEnabled")) {
|
||||
if (await options.get("mediaOverlayEnabled")) {
|
||||
// TODO: Un-hide overlay here
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
import options from "../lib/options";
|
||||
import cast, { ensureInit } from "../shim/export";
|
||||
import cast, { ensureInit } from "../cast/export";
|
||||
|
||||
import { ReceiverSelectorMediaType } from "../background/receiverSelector";
|
||||
import { ReceiverDevice } from "../types";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import { ReceiverStatus } from "./shim/cast/types";
|
||||
import { ReceiverStatus } from "./cast/api/types";
|
||||
|
||||
export interface ReceiverDevice {
|
||||
host: string;
|
||||
|
||||
Reference in New Issue
Block a user