mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-09 17:19:59 +00:00
Add better support for handling device capabilities and receiver objects
This commit is contained in:
@@ -137,7 +137,7 @@ browser.menus.onClicked.addListener(async (info, tab) => {
|
||||
if (selection.mediaType === ReceiverSelectorMediaType.App) {
|
||||
await browser.tabs.executeScript(tab.id, {
|
||||
code: stringify`
|
||||
window.receiver = ${selection.receiver};
|
||||
window.receiver = ${selection.receiverDevice};
|
||||
window.mediaUrl = ${info.srcUrl};
|
||||
window.targetElementId = ${info.targetElementId};
|
||||
`,
|
||||
|
||||
@@ -5,7 +5,7 @@ import logger from "../lib/logger";
|
||||
import { TypedEventTarget } from "../lib/TypedEventTarget";
|
||||
|
||||
import { Message, Port } from "../messaging";
|
||||
import { ReceiverDevice } from "../types";
|
||||
import { ReceiverDevice, ReceiverDeviceCapabilities } from "../types";
|
||||
import { ReceiverStatus } from "../cast/api/types";
|
||||
|
||||
interface EventMap {
|
||||
@@ -84,6 +84,16 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
case "main:receiverDeviceUp": {
|
||||
const { deviceId, deviceInfo } = message.data;
|
||||
|
||||
// TODO: Add proper support for Chromecast Audio devices
|
||||
if (
|
||||
!(
|
||||
deviceInfo.capabilities &
|
||||
ReceiverDeviceCapabilities.VIDEO_OUT
|
||||
)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.receiverDevices.set(deviceId, deviceInfo);
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("receiverDeviceUp", {
|
||||
@@ -112,9 +122,7 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
case "main:receiverDeviceStatusUpdated": {
|
||||
const { deviceId, status } = message.data;
|
||||
const receiverDevice = this.receiverDevices.get(deviceId);
|
||||
|
||||
if (!receiverDevice) {
|
||||
logger.error(`Receiver ID \`${deviceId}\` not found!`);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
private messagePort?: Port;
|
||||
private messagePortDisconnected?: boolean;
|
||||
|
||||
private receivers?: ReceiverDevice[];
|
||||
private receiverDevices?: ReceiverDevice[];
|
||||
private defaultMediaType?: ReceiverSelectorMediaType;
|
||||
private availableMediaTypes?: ReceiverSelectorMediaType;
|
||||
|
||||
@@ -69,7 +69,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
}
|
||||
|
||||
public async open(
|
||||
receivers: ReceiverDevice[],
|
||||
receiverDevices: ReceiverDevice[],
|
||||
defaultMediaType: ReceiverSelectorMediaType,
|
||||
availableMediaTypes: ReceiverSelectorMediaType,
|
||||
appId?: string,
|
||||
@@ -83,7 +83,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
await browser.windows.remove(this.windowId);
|
||||
}
|
||||
|
||||
this.receivers = receivers;
|
||||
this.receiverDevices = receiverDevices;
|
||||
this.defaultMediaType = defaultMediaType;
|
||||
this.availableMediaTypes = availableMediaTypes;
|
||||
|
||||
@@ -135,12 +135,12 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
}
|
||||
}
|
||||
|
||||
public update(receivers: ReceiverDevice[]) {
|
||||
this.receivers = receivers;
|
||||
public update(receiverDevices: ReceiverDevice[]) {
|
||||
this.receiverDevices = receiverDevices;
|
||||
this.messagePort?.postMessage({
|
||||
subject: "popup:update",
|
||||
data: {
|
||||
receivers: this.receivers
|
||||
receiverDevices: this.receiverDevices
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -176,7 +176,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
});
|
||||
|
||||
if (
|
||||
this.receivers === undefined ||
|
||||
this.receiverDevices === undefined ||
|
||||
this.defaultMediaType === undefined ||
|
||||
this.availableMediaTypes === undefined
|
||||
) {
|
||||
@@ -191,7 +191,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
this.messagePort.postMessage({
|
||||
subject: "popup:update",
|
||||
data: {
|
||||
receivers: this.receivers,
|
||||
receiverDevices: this.receiverDevices,
|
||||
defaultMediaType: this.defaultMediaType,
|
||||
availableMediaTypes: this.availableMediaTypes
|
||||
}
|
||||
@@ -250,7 +250,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
// Cleanup
|
||||
this.windowId = undefined;
|
||||
this.messagePort = undefined;
|
||||
this.receivers = undefined;
|
||||
this.receiverDevices = undefined;
|
||||
this.defaultMediaType = undefined;
|
||||
this.availableMediaTypes = undefined;
|
||||
this.wasReceiverSelected = false;
|
||||
|
||||
@@ -174,7 +174,7 @@ async function getSelection(
|
||||
logger.info("Selected receiver", ev.detail);
|
||||
resolve({
|
||||
actionType: ReceiverSelectionActionType.Cast,
|
||||
receiver: ev.detail.receiver,
|
||||
receiverDevice: ev.detail.receiverDevice,
|
||||
mediaType: ev.detail.mediaType,
|
||||
filePath: ev.detail.filePath
|
||||
});
|
||||
@@ -203,11 +203,11 @@ async function getSelection(
|
||||
"stop",
|
||||
storeListener("stop", async ev => {
|
||||
logger.info("Stopping receiver app...", ev.detail);
|
||||
receiverDevices.stopReceiverApp(ev.detail.receiver.id);
|
||||
receiverDevices.stopReceiverApp(ev.detail.receiverDevice.id);
|
||||
|
||||
resolve({
|
||||
actionType: ReceiverSelectionActionType.Stop,
|
||||
receiver: ev.detail.receiver
|
||||
receiverDevice: ev.detail.receiverDevice
|
||||
});
|
||||
removeListeners();
|
||||
})
|
||||
|
||||
@@ -17,13 +17,13 @@ export enum ReceiverSelectionActionType {
|
||||
|
||||
export interface ReceiverSelectionCast {
|
||||
actionType: ReceiverSelectionActionType.Cast;
|
||||
receiver: ReceiverDevice;
|
||||
receiverDevice: ReceiverDevice;
|
||||
mediaType: ReceiverSelectorMediaType;
|
||||
filePath?: string;
|
||||
}
|
||||
export interface ReceiverSelectionStop {
|
||||
actionType: ReceiverSelectionActionType.Stop;
|
||||
receiver: ReceiverDevice;
|
||||
receiverDevice: ReceiverDevice;
|
||||
}
|
||||
|
||||
export type ReceiverSelection = ReceiverSelectionCast | ReceiverSelectionStop;
|
||||
|
||||
Reference in New Issue
Block a user