1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fixed default export, fixed some occurrences of this and rewrote some for loops

This commit is contained in:
Cromefire_ 2020-04-19 17:38:03 +02:00
parent 6bc599aace
commit eb14b7a129
No known key found for this signature in database
GPG key ID: D3D3DB179F435F0C

View file

@ -394,10 +394,10 @@ function supportsTextTracks() {
// Listen for error events. // Listen for error events.
player.addEventListener('error', this.onShakaError.bind(this)); player.addEventListener('error', this.onShakaError.bind(this));
self._shakaPlayer = player; this._shakaPlayer = player;
// This is needed in setCurrentTrackElement // This is needed in setCurrentTrackElement
self._currentSrc = url; this._currentSrc = url;
// Try to load a manifest. // Try to load a manifest.
// This is an asynchronous process. // This is an asynchronous process.
@ -555,7 +555,7 @@ function supportsTextTracks() {
setTracks(elem, tracks, options.item, options.mediaSource); setTracks(elem, tracks, options.item, options.mediaSource);
return setSrcWithShakaPlayer(self, elem, options, val); return setSrcWithShakaPlayer(this, elem, options, val);
} else*/ } else*/
if (browser.chromecast && val.indexOf('.m3u8') !== -1 && options.mediaSource.RunTimeTicks) { if (browser.chromecast && val.indexOf('.m3u8') !== -1 && options.mediaSource.RunTimeTicks) {
@ -722,9 +722,9 @@ function supportsTextTracks() {
* @private * @private
*/ */
getSupportedAudioStreams() { getSupportedAudioStreams() {
const profile = self._lastProfile; const profile = this._lastProfile;
return getMediaStreamAudioTracks(self._currentPlayOptions.mediaSource).filter((stream) => { return getMediaStreamAudioTracks(this._currentPlayOptions.mediaSource).filter((stream) => {
return this.isAudioStreamSupported(stream, profile); return this.isAudioStreamSupported(stream, profile);
}); });
} }
@ -739,12 +739,8 @@ function supportsTextTracks() {
} }
let audioIndex = -1; let audioIndex = -1;
let i;
let length;
let stream;
for (i = 0, length = streams.length; i < length; i++) { for (const stream of streams) {
stream = streams[i];
audioIndex++; audioIndex++;
@ -757,7 +753,7 @@ function supportsTextTracks() {
return; return;
} }
const elem = self._mediaElement; const elem = this._mediaElement;
if (!elem) { if (!elem) {
return; return;
} }
@ -767,16 +763,15 @@ function supportsTextTracks() {
const elemAudioTracks = elem.audioTracks || []; const elemAudioTracks = elem.audioTracks || [];
console.debug('found ' + elemAudioTracks.length + ' audio tracks'); console.debug('found ' + elemAudioTracks.length + ' audio tracks');
for (i = 0, length = elemAudioTracks.length; i < length; i++) { elemAudioTracks.forEach((audioTrack, i) => {
if (audioIndex === i) { if (audioIndex === i) {
console.debug('setting audio track ' + i + ' to enabled'); console.debug(`setting audio track ${i} to enabled`);
elemAudioTracks[i].enabled = true; audioTrack.enabled = true;
} else { } else {
console.debug('setting audio track ' + i + ' to disabled'); console.debug(`setting audio track ${i} to disabled`);
elemAudioTracks[i].enabled = false; audioTrack.enabled = false;
}
} }
});
} }
stop(destroyPlayer) { stop(destroyPlayer) {
@ -896,8 +891,8 @@ function supportsTextTracks() {
// If this causes a failure during navigation we end up in an awkward UI state // If this causes a failure during navigation we end up in an awkward UI state
this.setCurrentTrackElement(this.subtitleTrackIndexToSetOnPlaying); this.setCurrentTrackElement(this.subtitleTrackIndexToSetOnPlaying);
if (this.audioTrackIndexToSetOnPlaying != null && self.canSetAudioStreamIndex()) { if (this.audioTrackIndexToSetOnPlaying != null && this.canSetAudioStreamIndex()) {
self.setAudioStreamIndex(this.audioTrackIndexToSetOnPlaying); this.setAudioStreamIndex(this.audioTrackIndexToSetOnPlaying);
} }
} }
@ -1005,8 +1000,8 @@ function supportsTextTracks() {
break; break;
case 3: case 3:
// MEDIA_ERR_DECODE // MEDIA_ERR_DECODE
if (self._hlsPlayer) { if (this._hlsPlayer) {
htmlMediaHelper.handleHlsJsMediaError(self); htmlMediaHelper.handleHlsJsMediaError(this);
return; return;
} else { } else {
type = 'mediadecodeerror'; type = 'mediadecodeerror';
@ -1046,12 +1041,9 @@ function supportsTextTracks() {
if (videoElement) { if (videoElement) {
const allTracks = videoElement.textTracks || []; // get list of tracks const allTracks = videoElement.textTracks || []; // get list of tracks
for (let i = 0; i < allTracks.length; i++) { for (const track of allTracks) {
if (track.label.includes('manualTrack')) {
const currentTrack = allTracks[i]; track.mode = 'disabled';
if (currentTrack.label.indexOf('manualTrack') !== -1) {
currentTrack.mode = 'disabled';
} }
} }
} }
@ -1129,7 +1121,7 @@ function supportsTextTracks() {
} }
this.resetSubtitleOffset(); this.resetSubtitleOffset();
const item = self._currentPlayOptions.item; const item = this._currentPlayOptions.item;
this.destroyCustomTrack(videoElement); this.destroyCustomTrack(videoElement);
this.customTrackIndex = track.Index; this.customTrackIndex = track.Index;
@ -1141,7 +1133,7 @@ function supportsTextTracks() {
* @private * @private
*/ */
renderSsaAss(videoElement, track, item) { renderSsaAss(videoElement, track, item) {
const attachments = self._currentPlayOptions.mediaSource.MediaAttachments || []; const attachments = this._currentPlayOptions.mediaSource.MediaAttachments || [];
const apiClient = connectionManager.getApiClient(item); const apiClient = connectionManager.getApiClient(item);
const options = { const options = {
video: videoElement, video: videoElement,
@ -1152,7 +1144,7 @@ function supportsTextTracks() {
workerUrl: appRouter.baseUrl() + '/libraries/subtitles-octopus-worker.js', workerUrl: appRouter.baseUrl() + '/libraries/subtitles-octopus-worker.js',
legacyWorkerUrl: appRouter.baseUrl() + '/libraries/subtitles-octopus-worker-legacy.js', legacyWorkerUrl: appRouter.baseUrl() + '/libraries/subtitles-octopus-worker-legacy.js',
onError() { onError() {
htmlMediaHelper.onErrorInternal(self, 'mediadecodeerror'); htmlMediaHelper.onErrorInternal(this, 'mediadecodeerror');
}, },
timeOffset: (this._currentPlayOptions.transcodingOffsetTicks || 0) / 10000000, timeOffset: (this._currentPlayOptions.transcodingOffsetTicks || 0) / 10000000,
@ -1254,10 +1246,8 @@ function supportsTextTracks() {
* @private * @private
*/ */
setCueAppearance() { setCueAppearance() {
Promise.all([import('userSettings'), import('subtitleAppearanceHelper')]).then(([userSettings, subtitleAppearanceHelper]) => { Promise.all([import('userSettings'), import('subtitleAppearanceHelper')]).then(([userSettings, subtitleAppearanceHelper]) => {
const elementId = this.id + "-cuestyle";
const elementId = self.id + "-cuestyle";
let styleElem = document.querySelector("#" + elementId); let styleElem = document.querySelector("#" + elementId);
if (!styleElem) { if (!styleElem) {
@ -1348,11 +1338,9 @@ function supportsTextTracks() {
if (trackEvents && subtitleTextElement) { if (trackEvents && subtitleTextElement) {
const ticks = timeMs * 10000; const ticks = timeMs * 10000;
let selectedTrackEvent; let selectedTrackEvent;
for (let i = 0; i < trackEvents.length; i++) { for (const trackEvent of trackEvents) {
if (trackEvent.StartPositionTicks <= ticks && trackEvent.EndPositionTicks >= ticks) {
const currentTrackEvent = trackEvents[i]; selectedTrackEvent = trackEvent;
if (currentTrackEvent.StartPositionTicks <= ticks && currentTrackEvent.EndPositionTicks >= ticks) {
selectedTrackEvent = currentTrackEvent;
break; break;
} }
} }
@ -1960,4 +1948,4 @@ function supportsTextTracks() {
} }
/* eslint-enable indent */ /* eslint-enable indent */
export default HtmlVideoPlayer; export default () => new HtmlVideoPlayer();