Skip to content

Commit

Permalink
feat: Trigger event when AdaptationSet is removed due to all represen…
Browse files Browse the repository at this point in the history
…tations being incompatible (#3910)
  • Loading branch information
vodlogic authored Apr 1, 2022
1 parent 3dc7251 commit 095ad26
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,11 @@ declare namespace dashjs {

on(type: TtmlToParseEvent['type'], listener: (e: TtmlToParseEvent) => void, scope?: object): void;

on(type: AdaptationSetRemovedNoCapabilitiesEvent['type'], listener: (e: AdaptationSetRemovedNoCapabilitiesEvent) => void, scope?: object): void;

on(type: string, listener: (e: Event) => void, scope?: object): void;


off(type: string, listener: (e: any) => void, scope?: object): void;

extend(parentNameString: string, childInstance: object, override: boolean): void;
Expand Down Expand Up @@ -728,6 +731,7 @@ declare namespace dashjs {
OFFLINE_RECORD_STOPPED: 'public_offlineRecordStopped';
PERIOD_SWITCH_STARTED: 'periodSwitchStarted';
PERIOD_SWITCH_COMPLETED: 'periodSwitchCompleted';
ADAPTATION_SET_REMOVED_NO_CAPABILITIES: 'adaptationSetRemovedNoCapabilities';
PLAYBACK_ENDED: 'playbackEnded';
PLAYBACK_ERROR: 'playbackError';
PLAYBACK_LOADED_DATA: 'playbackLoadedData';
Expand Down Expand Up @@ -1017,6 +1021,11 @@ declare namespace dashjs {
fromStreamInfo?: StreamInfo | null;
}

export interface AdaptationSetRemovedNoCapabilitiesEvent extends Event {
type: MediaPlayerEvents['ADAPTATION_SET_REMOVED_NO_CAPABILITIES'];
adaptationSet: object;
}

export interface PlaybackErrorEvent extends Event {
type: MediaPlayerEvents['PLAYBACK_ERROR'];
error: string;
Expand Down
6 changes: 6 additions & 0 deletions src/streaming/MediaPlayerEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ class MediaPlayerEvents extends EventsBase {
* @event MediaPlayerEvents#REPRESENTATION_SWITCH
*/
this.REPRESENTATION_SWITCH = 'representationSwitch';

/**
* Event that is dispatched whenever an adaptation set is removed due to all representations not being supported.
* @event MediaPlayerEvents#ADAPTATION_SET_REMOVED_NO_CAPABILITIES
*/
this.ADAPTATION_SET_REMOVED_NO_CAPABILITIES = 'adaptationSetRemovedNoCapabilities';
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/streaming/utils/CapabilitiesFilter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import FactoryMaker from '../../core/FactoryMaker';
import Debug from '../../core/Debug';
import Constants from '../constants/Constants';
import EventBus from '../../core/EventBus';
import Events from '../../core/events/Events';

function CapabilitiesFilter() {

const context = this.context;
const eventBus = EventBus(context).getInstance();

let instance,
adapter,
capabilities,
Expand Down Expand Up @@ -91,6 +96,9 @@ function CapabilitiesFilter() {
const supported = as.Representation_asArray && as.Representation_asArray.length > 0;

if (!supported) {
eventBus.trigger(Events.ADAPTATION_SET_REMOVED_NO_CAPABILITIES, {
adaptationSet: as
});
logger.warn(`AdaptationSet has been removed because of no supported Representation`);
}

Expand Down

0 comments on commit 095ad26

Please sign in to comment.