mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Document extension messages and remove unnecessary messages/message data
This commit is contained in:
@@ -67,7 +67,8 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
private wasReceiverSelected = false;
|
||||
|
||||
private appId?: string;
|
||||
private pageInfo?: ReceiverSelectorPageInfo;
|
||||
|
||||
pageInfo?: ReceiverSelectorPageInfo;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@@ -93,7 +93,7 @@ export default new (class {
|
||||
|
||||
instance.contentPort.postMessage({
|
||||
subject: "cast:initialized",
|
||||
data: await bridge.getInfo()
|
||||
data: { isAvailable: (await bridge.getInfo()).isVersionCompatible }
|
||||
});
|
||||
|
||||
return instance;
|
||||
@@ -197,12 +197,26 @@ export default new (class {
|
||||
) {
|
||||
// Intercept messages to store relevant info
|
||||
switch (message.subject) {
|
||||
case "cast:sessionCreated":
|
||||
case "cast:sessionCreated": {
|
||||
// Close after session is created
|
||||
const selector = ReceiverSelector.sharedInstance;
|
||||
if (
|
||||
selector.isOpen &&
|
||||
// If selector context is the same as the instance context
|
||||
selector.pageInfo?.tabId === instance.contentTabId &&
|
||||
selector.pageInfo?.frameId === instance.contentFrameId &&
|
||||
// If selector is supposed to close
|
||||
(await options.get("receiverSelectorWaitForConnection"))
|
||||
) {
|
||||
selector.close();
|
||||
}
|
||||
|
||||
instance.session = {
|
||||
deviceId: message.data.receiverId,
|
||||
sessionId: message.data.sessionId
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
instance.contentPort.postMessage(message);
|
||||
@@ -296,23 +310,6 @@ export default new (class {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: If we're closing a selector, make sure it's the
|
||||
* same one that caused the session creation.
|
||||
*/
|
||||
case "main:closeReceiverSelector": {
|
||||
const selector = ReceiverSelector.sharedInstance;
|
||||
const shouldClose = await options.get(
|
||||
"receiverSelectorWaitForConnection"
|
||||
);
|
||||
|
||||
if (selector.isOpen && shouldClose) {
|
||||
selector.close();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +97,7 @@ export function ensureInit(): Promise<TypedMessagePort<Message>> {
|
||||
function handleIncomingMessageToCast(message: Message) {
|
||||
switch (message.subject) {
|
||||
case "cast:initialized": {
|
||||
initializedBridgeInfo = message.data;
|
||||
|
||||
if (initializedBridgeInfo.isVersionCompatible) {
|
||||
if (message.data.isAvailable) {
|
||||
resolve(initializedBackgroundPort);
|
||||
} else {
|
||||
reject();
|
||||
|
||||
@@ -49,7 +49,7 @@ eventMessaging.page.addListener(async message => {
|
||||
// Call page script/framework API script's init function
|
||||
const initFn = _window.__onGCastApiAvailable;
|
||||
if (initFn && typeof initFn === "function") {
|
||||
initFn(message.data.isVersionCompatible);
|
||||
initFn(message.data.isAvailable);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -143,11 +143,6 @@ export default class {
|
||||
* and data needed to create cast API objects is sent.
|
||||
*/
|
||||
case "cast:sessionCreated": {
|
||||
// Notify background to close UI
|
||||
eventMessaging.page.sendMessage({
|
||||
subject: "main:closeReceiverSelector"
|
||||
});
|
||||
|
||||
const status = message.data;
|
||||
const receiverDevice = this.#receiverDevices.get(
|
||||
status.receiverId
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import type { TypedPort } from "./lib/TypedPort";
|
||||
import type { BridgeInfo } from "./lib/bridge";
|
||||
|
||||
import type {
|
||||
ReceiverSelection,
|
||||
@@ -39,6 +38,7 @@ import type { ReceiverDevice, ReceiverSelectorMediaType } from "./types";
|
||||
* components.
|
||||
*/
|
||||
type ExtMessageDefinitions = {
|
||||
/** Initial data to send to selector popup. */
|
||||
"popup:init": {
|
||||
appId?: string;
|
||||
pageInfo?: {
|
||||
@@ -47,30 +47,49 @@ type ExtMessageDefinitions = {
|
||||
frameId: number;
|
||||
};
|
||||
};
|
||||
/** Updates selector popup with new data. */
|
||||
"popup:update": {
|
||||
receiverDevices: ReceiverDevice[];
|
||||
defaultMediaType?: ReceiverSelectorMediaType;
|
||||
availableMediaTypes?: ReceiverSelectorMediaType;
|
||||
};
|
||||
"popup:close": undefined;
|
||||
|
||||
/**
|
||||
* Sent from the selector popup when a receiver has been
|
||||
* selected.
|
||||
*/
|
||||
"main:receiverSelected": ReceiverSelection;
|
||||
/**
|
||||
* Sent from the selector popup when a receiver has been
|
||||
* stopped. Used to provide cast API receiver action updates.
|
||||
*/
|
||||
"main:receiverStopped": { deviceId: string };
|
||||
/** Allows the selector popup to send cast NS_RECEIVER messages. */
|
||||
"main:sendReceiverMessage": ReceiverSelectorReceiverMessage;
|
||||
/** Allows the selector popup to send cast NS_MEDIA messages. */
|
||||
"main:sendMediaMessage": ReceiverSelectorMediaMessage;
|
||||
|
||||
/**
|
||||
* Sent from the cast API to trigger receiver selection on session
|
||||
* request.
|
||||
*/
|
||||
"main:selectReceiver": {
|
||||
sessionRequest: SessionRequest;
|
||||
};
|
||||
/** Return message to the cast API when a receiver is selected. */
|
||||
"cast:selectReceiver/selected": ReceiverSelection;
|
||||
/** Return message to the cast API when a selection is cancelled. */
|
||||
"cast:selectReceiver/cancelled": undefined;
|
||||
|
||||
/** Sent to the cast API when a receiver app is stopped. */
|
||||
"cast:receiverStoppedAction": { deviceId: string };
|
||||
|
||||
"main:closeReceiverSelector": undefined;
|
||||
|
||||
/**
|
||||
* Tells the cast manager to provide the cast API instance with
|
||||
* receiver data.
|
||||
*/
|
||||
"main:initializeCast": { appId: string };
|
||||
"cast:initialized": BridgeInfo;
|
||||
"cast:initialized": { isAvailable: boolean };
|
||||
|
||||
"cast:receiverDeviceUp": { receiverDevice: ReceiverDevice };
|
||||
"cast:receiverDeviceDown": { receiverDeviceId: string };
|
||||
|
||||
@@ -152,10 +152,6 @@
|
||||
pageInfo = message.data.pageInfo;
|
||||
break;
|
||||
|
||||
case "popup:close":
|
||||
window.close();
|
||||
break;
|
||||
|
||||
case "popup:update": {
|
||||
if (
|
||||
message.data.availableMediaTypes !== undefined &&
|
||||
|
||||
Reference in New Issue
Block a user