From c6270289f7219b2a79a2dc3e5a0cadaa9c699b1e Mon Sep 17 00:00:00 2001 From: hensm Date: Tue, 27 Apr 2021 08:14:02 +0100 Subject: [PATCH] Improve receiver status handling --- app/src/bridge/types.ts | 50 ++++++++++++++++++++++++------------ ext/src/shim/cast/Session.ts | 18 ++++++------- ext/src/types.ts | 39 ++++++++++++++++++---------- 3 files changed, 67 insertions(+), 40 deletions(-) diff --git a/app/src/bridge/types.ts b/app/src/bridge/types.ts index 2a70229..fb9e639 100644 --- a/app/src/bridge/types.ts +++ b/app/src/bridge/types.ts @@ -1,22 +1,23 @@ "use strict"; export interface ReceiverStatus { - volume: { - muted: boolean; - stepInterval: number; - controlType: string; - level: number; - }; - applications?: Array<{ - displayName: string; - statusText: string; - transportId: string; - isIdleScreen: boolean; - sessionId: string; - namespaces: Array<{ name: string }>; - appId: string; - }>; - userEq?: {}; + applications?: Array<{ + appId: string + , appType: string + , displayName: string + , iconUrl: string + , isIdleScreen: boolean + , launchedFromCloud: boolean + , namespaces: Array<{ name: string }> + , sessionId: string + , statusText: string + , transportId: string + , universalAppId: string + }> + , isActiveInput: boolean + , isStandBy: boolean + , userEq: unknown + , volume: Volume } export interface MediaStatus { @@ -84,3 +85,20 @@ export interface Receiver { port: number; status?: ReceiverStatus; } + + +export enum VolumeControlType { + ATTENUATION = "attenuation" + , FIXED = "fixed" + , MASTER = "master" +} + + +export class Volume { + public controlType?: VolumeControlType; + public stepInterval?: number; + + constructor( + public level: (number | null) = null + , public muted: (boolean | null) = null) {} +} diff --git a/ext/src/shim/cast/Session.ts b/ext/src/shim/cast/Session.ts index 3926446..60dcc2a 100644 --- a/ext/src/shim/cast/Session.ts +++ b/ext/src/shim/cast/Session.ts @@ -80,21 +80,19 @@ export default class Session { } case "shim:session/updateStatus": { - const volume: Volume = message.data.volume; + const status = message.data; - if (volume) { + if (status.volume) { if (!this.receiver.volume) { const receiverVolume = new Volume( - volume.level - , volume.muted); + status.volume.level, status.volume.muted); - receiverVolume.controlType = volume.controlType; - receiverVolume.stepInterval = volume.stepInterval; - - this.receiver.volume = receiverVolume; + receiverVolume.controlType = status.volume.controlType; + receiverVolume.stepInterval = + status.volume.stepInterval; } else { - this.receiver.volume.level = volume.level; - this.receiver.volume.muted = volume.muted; + this.receiver.volume.level = status.volume.level; + this.receiver.volume.muted = status.volume.muted; } } diff --git a/ext/src/types.ts b/ext/src/types.ts index 7ecac96..c7b1b11 100644 --- a/ext/src/types.ts +++ b/ext/src/types.ts @@ -1,21 +1,32 @@ "use strict"; +import { Volume } from "./shim/cast/dataClasses"; + + export interface Receiver { - host: string; - friendlyName: string; - id: string; - port: number; - status?: ReceiverStatus; + host: string + friendlyName: string + , id: string + , port: number + , status?: ReceiverStatus } export interface ReceiverStatus { - application: { - displayName: string; - isIdleScreen: boolean; - statusText: string; - }; - volume: { - level: number; - muted: boolean - }; + applications?: Array<{ + appId: string + , appType: string + , displayName: string + , iconUrl: string + , isIdleScreen: boolean + , launchedFromCloud: boolean + , namespaces: Array<{ name: string }> + , sessionId: string + , statusText: string + , transportId: string + , universalAppId: string + }> + , isActiveInput: boolean + , isStandBy: boolean + , userEq: unknown + , volume: Volume }