From b1fab6672c073e34a4ca71b5aa28ae3b2f5d6537 Mon Sep 17 00:00:00 2001 From: Bertrand Berthelot Date: Wed, 6 Nov 2024 13:45:44 +0100 Subject: [PATCH] Fix Event id attribute parsing (#4614) * Fix Event id attribute value parsing * Fix typings for Event.id property * index.d.ts: Define base type MediaPlayerEvent for player events --- index.d.ts | 112 ++++++++++++++------------- src/dash/models/DashManifestModel.js | 2 +- 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0c66bf78b7..e79d2af473 100644 --- a/index.d.ts +++ b/index.d.ts @@ -509,7 +509,7 @@ declare namespace dashjs { type: string; duration: number; presentationTime: number; - id: string | number; + id: number; messageData: string; eventStream: EventStream; presentationTimeDelta: number; @@ -788,7 +788,7 @@ declare namespace dashjs { on(type: AdaptationSetRemovedNoCapabilitiesEvent['type'], listener: (e: AdaptationSetRemovedNoCapabilitiesEvent) => void, scope?: object): void; - on(type: string, listener: (e: Event) => void, scope?: object): void; + on(type: string, listener: (e: MediaPlayerEvent) => void, scope?: object): void; off(type: string, listener: (e: any) => void, scope?: object): void; @@ -1405,7 +1405,7 @@ declare namespace dashjs { on(type: AdaptationSetRemovedNoCapabilitiesEvent['type'], listener: (e: AdaptationSetRemovedNoCapabilitiesEvent) => void, scope?: object): void; - on(type: string, listener: (e: Event) => void, scope?: object, options?: object): void; + on(type: string, listener: (e: MediaPlayerEvent) => void, scope?: object, options?: object): void; off(type: string, listener: (e: any) => void, scope?: object): void; @@ -1759,17 +1759,21 @@ declare namespace dashjs { TTML_TO_PARSE: 'ttmlToParse'; } - export interface AstInFutureEvent extends Event { + export interface MediaPlayerEvent { + type: string + + } + export interface AstInFutureEvent extends MediaPlayerEvent { type: MediaPlayerEvents['AST_IN_FUTURE']; delay: number; } - export interface BufferEvent extends Event { + export interface BufferEvent extends MediaPlayerEvent { type: MediaPlayerEvents['BUFFER_EMPTY' | 'BUFFER_LOADED']; mediaType: MediaType; } - export interface BufferStateChangedEvent extends Event { + export interface BufferStateChangedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['BUFFER_LEVEL_STATE_CHANGED']; mediaType: MediaType; sender: object; @@ -1777,13 +1781,13 @@ declare namespace dashjs { streamInfo: StreamInfo; } - export interface GenericErrorEvent extends Event { + export interface GenericErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['ERROR']; error: 'capability' | 'mediasource' | 'key_session' | 'key_message'; event: string; } - export interface DownloadErrorEvent extends Event { + export interface DownloadErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['ERROR']; error: 'download'; event: { @@ -1793,7 +1797,7 @@ declare namespace dashjs { }; } - export interface ManifestErrorEvent extends Event { + export interface ManifestErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['ERROR']; error: 'manifestError'; event: { @@ -1804,7 +1808,7 @@ declare namespace dashjs { }; } - export interface TimedTextErrorEvent extends Event { + export interface TimedTextErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['ERROR']; error: 'cc'; event: { @@ -1814,7 +1818,7 @@ declare namespace dashjs { }; } - export interface MediaPlayerErrorEvent extends Event { + export interface MediaPlayerErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['ERROR']; error: { code: MediaPlayerErrors['MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE'] | @@ -1885,57 +1889,57 @@ declare namespace dashjs { | TimedTextErrorEvent | MediaPlayerErrorEvent; - export interface CaptionRenderedEvent extends Event { + export interface CaptionRenderedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['CAPTION_RENDERED']; captionDiv: HTMLDivElement; currentTrackIdx: number; } - export interface CaptionContainerResizeEvent extends Event { + export interface CaptionContainerResizeEvent extends MediaPlayerEvent { type: MediaPlayerEvents['CAPTION_CONTAINER_RESIZE']; } - export interface dvbFontDownloadAdded extends Event { + export interface dvbFontDownloadAdded extends MediaPlayerEvent { type: MediaPlayerEvents['DVB_FONT_DOWNLOAD_ADDED']; font: FontInfo; } - export interface dvbFontDownloadComplete extends Event { + export interface dvbFontDownloadComplete extends MediaPlayerEvent { type: MediaPlayerEvents['DVB_FONT_DOWNLOAD_COMPLETE']; font: FontInfo; } - export interface dvbFontDownloadFailed extends Event { + export interface dvbFontDownloadFailed extends MediaPlayerEvent { type: MediaPlayerEvents['DVB_FONT_DOWNLOAD_FAILED']; font: FontInfo; } - export interface DynamicToStaticEvent extends Event { + export interface DynamicToStaticEvent extends MediaPlayerEvent { type: MediaPlayerEvents['DYNAMIC_TO_STATIC']; } - export interface FragmentLoadingCompletedEvent extends Event { + export interface FragmentLoadingCompletedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['FRAGMENT_LOADING_COMPLETED']; request: FragmentRequest; response: ArrayBuffer; sender: object; } - export interface FragmentLoadingAbandonedEvent extends Event { + export interface FragmentLoadingAbandonedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['FRAGMENT_LOADING_ABANDONED']; streamProcessor: object; request: object; mediaType: MediaType; } - export interface InbandPrftReceivedEvent extends Event { + export interface InbandPrftReceivedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['INBAND_PRFT_RECEIVED']; streamInfo: StreamInfo; mediaType: MediaType; data: object } - export interface KeyErrorEvent extends Event { + export interface KeyErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['KEY_ERROR']; error: DashJSError; } @@ -1949,36 +1953,36 @@ declare namespace dashjs { messageType: string; } - export interface KeyMessageEvent extends Event { + export interface KeyMessageEvent extends MediaPlayerEvent { type: MediaPlayerEvents['KEY_MESSAGE']; data: KeyMessage; } - export interface KeySessionClosedEvent extends Event { + export interface KeySessionClosedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['KEY_SESSION_CLOSED' | 'KEY_SESSION_REMOVED']; data: string | null; error?: string; } - export interface KeySessionEvent extends Event { + export interface KeySessionEvent extends MediaPlayerEvent { type: MediaPlayerEvents['KEY_SESSION_CREATED']; data: SessionToken | null; error?: DashJSError; } - export interface KeyStatusesChangedEvent extends Event { + export interface KeyStatusesChangedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['KEY_STATUSES_CHANGED']; data: SessionToken; error?: DashJSError; } - export interface KeySystemSelectedEvent extends Event { + export interface KeySystemSelectedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['KEY_SYSTEM_SELECTED']; data: object | null; error?: DashJSError; } - export interface LicenseRequestCompleteEvent extends Event { + export interface LicenseRequestCompleteEvent extends MediaPlayerEvent { type: MediaPlayerEvents['LICENSE_REQUEST_COMPLETE']; data: { sessionToken: SessionToken; @@ -1987,110 +1991,110 @@ declare namespace dashjs { error?: DashJSError; } - export interface LogEvent extends Event { + export interface LogEvent extends MediaPlayerEvent { type: MediaPlayerEvents['LOG']; message: string; } - export interface ManifestLoadedEvent extends Event { + export interface ManifestLoadedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['MANIFEST_LOADED']; data: object; } - export interface MetricEvent extends Event { + export interface MetricEvent extends MediaPlayerEvent { type: MediaPlayerEvents['METRIC_ADDED' | 'METRIC_UPDATED']; mediaType: MediaType; metric: MetricType; value: object; } - export interface MetricChangedEvent extends Event { + export interface MetricChangedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['METRIC_CHANGED']; mediaType: MediaType; } - export interface OfflineRecordEvent extends Event { + export interface OfflineRecordEvent extends MediaPlayerEvent { type: MediaPlayerEvents['OFFLINE_RECORD_FINISHED' | 'OFFLINE_RECORD_STARTED' | 'OFFLINE_RECORD_STOPPED']; id: string; } - export interface OfflineRecordLoademetadataEvent extends Event { + export interface OfflineRecordLoademetadataEvent extends MediaPlayerEvent { type: MediaPlayerEvents['OFFLINE_RECORD_LOADEDMETADATA']; madiaInfos: MediaInfo[]; } - export interface PeriodSwitchEvent extends Event { + export interface PeriodSwitchEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PERIOD_SWITCH_COMPLETED' | 'PERIOD_SWITCH_STARTED']; toStreamInfo: StreamInfo | null; fromStreamInfo?: StreamInfo | null; } - export interface PlaybackErrorEvent extends Event { + export interface PlaybackErrorEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_ERROR']; error: MediaError; } - export interface PlaybackPausedEvent extends Event { + export interface PlaybackPausedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_PAUSED']; ended: boolean | null; } - export interface PlaybackPlayingEvent extends Event { + export interface PlaybackPlayingEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_PLAYING']; playingTime: number | null; } - export interface PlaybackRateChangedEvent extends Event { + export interface PlaybackRateChangedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_RATE_CHANGED']; playbackRate: number | null; } - export interface PlaybackSeekingEvent extends Event { + export interface PlaybackSeekingEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_SEEKING']; seekTime: number | null; } - export interface PlaybackStartedEvent extends Event { + export interface PlaybackStartedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_STARTED']; startTime: number | null; } - export interface PlaybackTimeUpdatedEvent extends Event { + export interface PlaybackTimeUpdatedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_TIME_UPDATED']; time: number | null; timeToEnd: number; } - export interface PlaybackWaitingEvent extends Event { + export interface PlaybackWaitingEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PLAYBACK_WAITING']; playingTime: number | null; } - export interface ProtectionCreatedEvent extends Event { + export interface ProtectionCreatedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PROTECTION_CREATED']; controller: object; } - export interface ProtectionDestroyedEvent extends Event { + export interface ProtectionDestroyedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['PROTECTION_DESTROYED']; data: string; } - export interface TrackChangeRenderedEvent extends Event { + export interface TrackChangeRenderedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['TRACK_CHANGE_RENDERED']; mediaType: MediaType; oldMediaInfo: MediaInfo; newMediaInfo: MediaInfo; } - export interface QualityChangeRenderedEvent extends Event { + export interface QualityChangeRenderedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['QUALITY_CHANGE_RENDERED']; mediaType: MediaType; oldQuality: number; newQuality: number; } - export interface QualityChangeRequestedEvent extends Event { + export interface QualityChangeRequestedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['QUALITY_CHANGE_REQUESTED']; mediaType: MediaType; oldQuality: number; @@ -2102,31 +2106,31 @@ declare namespace dashjs { } | null; } - export interface StreamInitializedEvent extends Event { + export interface StreamInitializedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['STREAM_INITIALIZED']; streamInfo: StreamInfo; error: Error | null; } - export interface TextTracksAddedEvent extends Event { + export interface TextTracksAddedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['TEXT_TRACKS_ADDED']; enabled: boolean; index: number; tracks: TextTrackInfo[]; } - export interface TtmlParsedEvent extends Event { + export interface TtmlParsedEvent extends MediaPlayerEvent { type: MediaPlayerEvents['TTML_PARSED']; ttmlString: string; ttmlDoc: object; } - export interface TtmlToParseEvent extends Event { + export interface TtmlToParseEvent extends MediaPlayerEvent { type: MediaPlayerEvents['TTML_TO_PARSE']; content: object; } - export interface CueEnterEvent extends Event { + export interface CueEnterEvent extends MediaPlayerEvent { type: MediaPlayerEvents['CUE_ENTER']; id: string, text: string, @@ -2134,12 +2138,12 @@ declare namespace dashjs { end: number } - export interface CueExitEvent extends Event { + export interface CueExitEvent extends MediaPlayerEvent { type: MediaPlayerEvents['CUE_EXIT']; id: string, } - export interface AdaptationSetRemovedNoCapabilitiesEvent extends Event { + export interface AdaptationSetRemovedNoCapabilitiesEvent extends MediaPlayerEvent { type: MediaPlayerEvents['ADAPTATION_SET_REMOVED_NO_CAPABILITIES']; adaptationSet: object; } diff --git a/src/dash/models/DashManifestModel.js b/src/dash/models/DashManifestModel.js index 61e40226c4..d49b35c9c4 100644 --- a/src/dash/models/DashManifestModel.js +++ b/src/dash/models/DashManifestModel.js @@ -1056,7 +1056,7 @@ function DashManifestModel() { event.duration = currentMpdEvent.duration / eventStream.timescale; } if (currentMpdEvent.hasOwnProperty(DashConstants.ID)) { - event.id = currentMpdEvent.id; + event.id = parseInt(currentMpdEvent.id); } else { event.id = null; }