Skip to content

Commit

Permalink
Fix Event id attribute parsing (#4614)
Browse files Browse the repository at this point in the history
* Fix Event id attribute value parsing

* Fix typings for Event.id property

* index.d.ts: Define base type MediaPlayerEvent for player events
  • Loading branch information
bbert authored Nov 6, 2024
1 parent 8f35d6b commit b1fab66
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 55 deletions.
112 changes: 58 additions & 54 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ declare namespace dashjs {
type: string;
duration: number;
presentationTime: number;
id: string | number;
id: number;
messageData: string;
eventStream: EventStream;
presentationTimeDelta: number;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1759,31 +1759,35 @@ 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;
state: 'bufferStalled' | 'bufferLoaded';
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: {
Expand All @@ -1793,7 +1797,7 @@ declare namespace dashjs {
};
}

export interface ManifestErrorEvent extends Event {
export interface ManifestErrorEvent extends MediaPlayerEvent {
type: MediaPlayerEvents['ERROR'];
error: 'manifestError';
event: {
Expand All @@ -1804,7 +1808,7 @@ declare namespace dashjs {
};
}

export interface TimedTextErrorEvent extends Event {
export interface TimedTextErrorEvent extends MediaPlayerEvent {
type: MediaPlayerEvents['ERROR'];
error: 'cc';
event: {
Expand All @@ -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'] |
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -2102,44 +2106,44 @@ 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,
start: number,
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dash/models/DashManifestModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b1fab66

Please sign in to comment.