Improve handling of receiver actions

This commit is contained in:
hensm
2022-08-26 06:09:52 +01:00
parent ee492802e0
commit 90b00c0ce4
10 changed files with 275 additions and 356 deletions

View File

@@ -316,26 +316,6 @@ export default class {
break;
}
case "cast:selectReceiver/stopped": {
const { receiverDevice } = message.data;
logger.info("Stopped receiver");
if (this.#sessionRequest) {
this.#sessionRequest = undefined;
for (const listener of this.#receiverActionListeners) {
listener(
// TODO: Use existing receiver object?
createReceiver(receiverDevice),
ReceiverAction.STOP
);
}
}
break;
}
// Popup closed before session established
case "cast:selectReceiver/cancelled": {
if (this.#sessionRequest) {
@@ -349,6 +329,17 @@ export default class {
break;
}
case "cast:receiverStoppedAction": {
const device = this.#receiverDevices.get(message.data.deviceId);
if (!device) break;
for (const actionListener of this.#receiverActionListeners) {
actionListener(createReceiver(device), ReceiverAction.STOP);
}
break;
}
// Session request initiated via receiver selector
case "cast:launchApp": {
if (this.#sessionRequest) {

View File

@@ -92,7 +92,7 @@ interface ReqBase {
// NS: urn:x-cast:com.google.cast.receiver
export type SenderMessage =
| (ReqBase & { type: "LAUNCH"; appId: string })
| (ReqBase & { type: "STOP"; sessionId: string })
| (ReqBase & { type: "STOP"; sessionId?: string })
| (ReqBase & { type: "GET_STATUS" })
| (ReqBase & { type: "GET_APP_AVAILABILITY"; appId: string[] })
| (ReqBase & { type: "SET_VOLUME"; volume: Partial<Volume> });