diff --git a/ext/src/background/ReceiverSelector.ts b/ext/src/background/ReceiverSelector.ts index 5ac8f2a..773774b 100644 --- a/ext/src/background/ReceiverSelector.ts +++ b/ext/src/background/ReceiverSelector.ts @@ -67,7 +67,8 @@ export default class ReceiverSelector extends TypedEventTarget> { function handleIncomingMessageToCast(message: Message) { switch (message.subject) { case "cast:initialized": { - initializedBridgeInfo = message.data; - - if (initializedBridgeInfo.isVersionCompatible) { + if (message.data.isAvailable) { resolve(initializedBackgroundPort); } else { reject(); diff --git a/ext/src/cast/index.ts b/ext/src/cast/index.ts index 1de6adc..4ad377f 100644 --- a/ext/src/cast/index.ts +++ b/ext/src/cast/index.ts @@ -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; diff --git a/ext/src/cast/sdk/index.ts b/ext/src/cast/sdk/index.ts index cadc5f0..f4f7e9f 100644 --- a/ext/src/cast/sdk/index.ts +++ b/ext/src/cast/sdk/index.ts @@ -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 diff --git a/ext/src/messaging.ts b/ext/src/messaging.ts index efec414..f998f5c 100644 --- a/ext/src/messaging.ts +++ b/ext/src/messaging.ts @@ -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 }; diff --git a/ext/src/ui/popup/Popup.svelte b/ext/src/ui/popup/Popup.svelte index 337531f..1beb63a 100644 --- a/ext/src/ui/popup/Popup.svelte +++ b/ext/src/ui/popup/Popup.svelte @@ -152,10 +152,6 @@ pageInfo = message.data.pageInfo; break; - case "popup:close": - window.close(); - break; - case "popup:update": { if ( message.data.availableMediaTypes !== undefined &&