Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-11697): 2 captions are selected in the menu #161

Merged
merged 21 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const launchers = {
module.exports = function (config) {
let karmaConf = {
logLevel: config.LOG_INFO,
browserNoActivityTimeout: 90000,
browsers: ['Chrome', 'Firefox'],
customLaunchers: launchers,
concurrency: 1,
Expand All @@ -43,7 +42,8 @@ module.exports = function (config) {
client: {
mocha: {
reporter: 'html',
timeout: 90000
timeout: 40000
// timeout: 2000 - this is the default, see https://mochajs.org/#-timeout-ms-t-ms
}
}
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"pushTaggedRelease": "git push --follow-tags --no-verify origin master",
"release": "standard-version",
"test": "NODE_ENV=test karma start --color --mode development",
"test:watch": "NODE_ENV=test karma start --browsers=Chrome --single-run=false --auto-watch",
"watch": "webpack --progress --colors --watch --mode development"
},
"husky": {
Expand Down
52 changes: 35 additions & 17 deletions src/hls-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
*/
_loadPromise: ?Promise<Object>;

/**
* the _loadPromise handlers
* @member {{resolve: (result: Promise<R> | R) => void, reject: (error: any) => void}} - _loadPromiseHandlers
* @type {{resolve: (result: Promise<R> | R) => void, reject: (error: any) => void}}
* @private
*/
_loadPromiseHandlers: {resolve: (result: Promise<*> | *) => void, reject: (error: any) => void} | null;

/**
* Reference to the player tracks.
* @member {Array<Track>} - _playerTracks
Expand All @@ -123,7 +131,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
_mediaAttachedPromise: Promise<*>;
_requestFilterError: boolean = false;
_responseFilterError: boolean = false;
_nativeTextTracksMap = [];
_nativeTextTracksMap = {};
_lastLoadedFragSN: number = -1;
_sameFragSNLoadedCount: number = 0;
/**
Expand Down Expand Up @@ -525,8 +533,8 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
load(startTime: ?number): Promise<Object> {
if (!this._loadPromise) {
this._startTime = startTime;
this._loadPromise = new Promise(resolve => {
this._resolveLoad = resolve;
this._loadPromise = new Promise((resolve, reject) => {
this._loadPromiseHandlers = {resolve, reject};
yairans marked this conversation as resolved.
Show resolved Hide resolved
this._loadInternal();
});
}
Expand All @@ -544,6 +552,8 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._hls.loadSource(this._sourceObj.url);
this._hls.attachMedia(this._videoElement);
this._trigger(EventType.ABR_MODE_CHANGED, {mode: this.isAdaptiveBitrateEnabled() ? 'auto' : 'manual'});
} else {
this._loadPromiseHandlers?.reject(new window.Error('no url provided'));
}
}

Expand Down Expand Up @@ -576,15 +586,14 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
super.destroy().then(
() => {
HlsAdapter._logger.debug('destroy');
this._loadPromise = null;
this._playerTracks = [];
this._nativeTextTracksMap = [];
this._nativeTextTracksMap = {};
this._sameFragSNLoadedCount = 0;
this._lastLoadedFragSN = -1;
this._reset();
resolve();
},
() => reject
() => reject()
);
});
}
Expand All @@ -600,6 +609,11 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._responseFilterError = false;
this._hls.detachMedia();
this._hls.destroy();
if (this._loadPromiseHandlers) {
JonathanTGold marked this conversation as resolved.
Show resolved Hide resolved
this._loadPromiseHandlers.reject('The adapter has been reset/destoryed while loading');
}
this._loadPromiseHandlers = null;
this._loadPromise = null;
}

/**
Expand Down Expand Up @@ -667,15 +681,14 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
*/
_parseTextTracks(hlsTextTracks: Array<Object>): Array<TextTrack> {
let textTracks = [];
for (let i = 0; i < hlsTextTracks.length; i++) {
for (const hlsTextTrack of hlsTextTracks) {
// Create text tracks
let settings = {
id: hlsTextTracks[i].id,
active: hlsTextTracks[i].default,
label: hlsTextTracks[i].name,
kind: hlsTextTracks[i].type.toLowerCase(),
language: hlsTextTracks[i].lang,
index: i
id: hlsTextTrack.id,
active: hlsTextTrack.default,
label: hlsTextTrack.name,
kind: hlsTextTrack.type.toLowerCase(),
language: hlsTextTrack.lang
};
textTracks.push(new TextTrack(settings));
}
Expand All @@ -696,11 +709,10 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
active: CEATextTrack.mode === 'showing',
label: CEATextTrack.label,
kind: CEATextTrack.kind,
language: CEATextTrack.language,
index: this._playerTracks.filter(track => track instanceof TextTrack).length
language: CEATextTrack.language
};
textTrack = new TextTrack(settings);
this._nativeTextTracksMap[settings.index] = CEATextTrack;
this._nativeTextTracksMap[textTrack.index] = CEATextTrack;
JonathanTGold marked this conversation as resolved.
Show resolved Hide resolved
}
return textTrack;
}
Expand Down Expand Up @@ -928,7 +940,8 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._hls.currentLevel = 0;
}
this._mediaAttachedPromise.then(() => {
this._resolveLoad({tracks: this._playerTracks});
this._loadPromiseHandlers?.resolve({tracks: this._playerTracks});
this._loadPromiseHandlers = null;
});
const {loading} = data.stats;
const manifestDownloadTime = loading.end - loading.start;
Expand Down Expand Up @@ -1080,6 +1093,11 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
const errorFatal = data.fatal;
let errorDataObject = this._getErrorDataObject(data);
if (errorFatal) {
if (this._loadPromiseHandlers) {
JonathanTGold marked this conversation as resolved.
Show resolved Hide resolved
const {type, details, url} = data;
this._loadPromiseHandlers.reject({type, details, url});
yairans marked this conversation as resolved.
Show resolved Hide resolved
this._loadPromiseHandlers = null;
}
let error: typeof Error;
switch (errorType) {
case Hlsjs.ErrorTypes.NETWORK_ERROR:
Expand Down
Loading