From 81dcfe3ec3e8832156f16539f55b88608ce85e4f Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 14 Dec 2024 11:27:12 +1100 Subject: [PATCH] Define a type for the type parameter on BusMessage --- src/components/jellyfinActions.ts | 7 +++++-- src/components/maincontroller.ts | 4 ++-- src/types/global.d.ts | 13 ++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/jellyfinActions.ts b/src/components/jellyfinActions.ts index 7612d05d..45d026ac 100644 --- a/src/components/jellyfinActions.ts +++ b/src/components/jellyfinActions.ts @@ -17,7 +17,10 @@ import { AppStatus } from '../types/appStatus'; import { JellyfinApi } from './jellyfinApi'; import { DocumentManager } from './documentManager'; import { PlaybackManager, type PlaybackState } from './playbackManager'; -import type { JellyfinMediaInformationCustomData } from '~/types/global'; +import type { + BusMessageType, + JellyfinMediaInformationCustomData +} from '~/types/global'; let pingInterval: number; let lastTranscoderPing = 0; @@ -93,7 +96,7 @@ export async function reportPlaybackProgress( state: PlaybackState, reportingParams: PlaybackProgressInfo, reportToServer = true, - broadcastEventName = 'playbackprogress' + broadcastEventName: BusMessageType = 'playbackprogress' ): Promise { broadcastToMessageBus({ data: getSenderReportingData(state, reportingParams), diff --git a/src/components/maincontroller.ts b/src/components/maincontroller.ts index bd51b317..cf4a04b2 100644 --- a/src/components/maincontroller.ts +++ b/src/components/maincontroller.ts @@ -28,7 +28,7 @@ import { JellyfinApi } from './jellyfinApi'; import { PlaybackManager, type PlaybackState } from './playbackManager'; import { CommandHandler } from './commandHandler'; import { getMaxBitrateSupport } from './codecSupportHelper'; -import type { PlayRequest, StreamInfo } from '~/types/global'; +import type { BusMessageType, PlayRequest, StreamInfo } from '~/types/global'; window.castReceiverContext = cast.framework.CastReceiverContext.getInstance(); window.playerManager = window.castReceiverContext.getPlayerManager(); @@ -353,7 +353,7 @@ export function processMessage(data: any): void { * @returns Promise */ export function reportEvent( - name: string, + name: BusMessageType, reportToServer: boolean ): Promise { const playbackState = PlaybackManager.playbackState; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 9b07561f..15ba78b1 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -14,9 +14,20 @@ import type { Track } from 'chromecast-caf-receiver/cast.framework.messages'; +type BusMessageType = + | 'connectionerror' + | 'error' + | 'playbackerror' + | 'playbackprogress' + | 'playbackstart' + | 'playbackstop' + | 'playstatechange' + | 'repeatmodechange' + | 'volumechange'; + // Messagebus message export interface BusMessage { - type: string; + type: BusMessageType; message?: string; data?: string; }