From 073b10a3c0350d5f687a2640f295089c7c2ef14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Fri, 1 Jan 2021 19:03:25 +0100 Subject: [PATCH] Automatic eslint fix --- src/components/fetchhelper.ts | 8 +- src/components/jellyfinActions.ts | 40 +++++++--- src/components/maincontroller.ts | 122 +++++++++++++++++++++++++----- src/helpers.ts | 34 ++++----- 4 files changed, 156 insertions(+), 48 deletions(-) diff --git a/src/components/fetchhelper.ts b/src/components/fetchhelper.ts index f1846a24..948d2a7d 100644 --- a/src/components/fetchhelper.ts +++ b/src/components/fetchhelper.ts @@ -50,19 +50,19 @@ function fetchWithTimeout( timeoutMs: number ): Promise { console.log('fetchWithTimeout: timeoutMs: ' + timeoutMs + ', url: ' + url); - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { const timeout = setTimeout(reject, timeoutMs); options = options || {}; options.credentials = 'same-origin'; fetch(url, options).then( - function (response) { + (response) => { clearTimeout(timeout); console.log( 'fetchWithTimeout: succeeded connecting to url: ' + url ); resolve(response); }, - function () { + () => { clearTimeout(timeout); console.log( 'fetchWithTimeout: timed out connecting to url: ' + url @@ -127,7 +127,7 @@ export function ajax(request: any): Promise { return response; } }, - function (err) { + (err) => { console.log('request failed to url: ' + request.url); throw err; } diff --git a/src/components/jellyfinActions.ts b/src/components/jellyfinActions.ts index ab9fe0e8..d715c132 100644 --- a/src/components/jellyfinActions.ts +++ b/src/components/jellyfinActions.ts @@ -58,7 +58,7 @@ function restartPingInterval( stopPingInterval(); if (reportingParams.PlayMethod == 'Transcode') { - pingInterval = setInterval(function () { + pingInterval = setInterval(() => { pingTranscoder(reportingParams); }, 1000); } @@ -179,7 +179,7 @@ export function pingTranscoder( // 10s is the timeout value, so use half that to report often enough if (now - lastTranscoderPing < 5000) { console.debug('Skipping ping due to recent progress check-in'); - return new Promise(function (resolve) { + return new Promise((resolve) => { resolve(); }); } @@ -218,7 +218,7 @@ export function startBackdropInterval(): void { setRandomUserBackdrop(); - backdropInterval = setInterval(function () { + backdropInterval = setInterval(() => { setRandomUserBackdrop(); }, 30000); } @@ -242,7 +242,7 @@ function setRandomUserBackdrop(): Promise { // not everyone will want to see adult backdrops rotating on their TV. MaxOfficialRating: 'PG-13' } - }).then(function (result: BaseItemDtoQueryResult) { + }).then((result: BaseItemDtoQueryResult) => { let url = ''; if (result.Items && result.Items[0]) { url = getBackdropUrl(result.Items[0]) || ''; @@ -366,7 +366,7 @@ export function play($scope: GlobalScope): void { $scope.status == 'playing' || $scope.status == 'audio' ) { - setTimeout(function () { + setTimeout(() => { window.mediaManager.play(); setAppStatus('playing-with-controls'); @@ -381,11 +381,21 @@ export function play($scope: GlobalScope): void { * Don't actually stop, just show the idle view after 20ms */ export function stop(): void { - setTimeout(function () { + setTimeout(() => { setAppStatus('waiting'); }, 20); } +/** + * @param item + * @param maxBitrate + * @param deviceProfile + * @param startPosition + * @param mediaSourceId + * @param audioStreamIndex + * @param subtitleStreamIndex + * @param liveStreamId + */ export function getPlaybackInfo( item: BaseItemDto, maxBitrate: number, @@ -429,6 +439,16 @@ export function getPlaybackInfo( }); } +/** + * @param item + * @param playSessionId + * @param maxBitrate + * @param deviceProfile + * @param startPosition + * @param mediaSource + * @param audioStreamIndex + * @param subtitleStreamIndex + */ export function getLiveStream( item: BaseItemDto, playSessionId: string, @@ -485,11 +505,11 @@ export function getDownloadSpeed(byteSize: number): Promise { type: 'GET', timeout: 5000 }) - .then(function (response) { + .then((response) => { // Need to wait for the whole response before calculating speed return response.blob(); }) - .then(function () { + .then(() => { const responseTimeSeconds = (new Date().getTime() - now) / 1000; const bytesPerSecond = byteSize / responseTimeSeconds; const bitrate = Math.round(bytesPerSecond * 8); @@ -506,12 +526,12 @@ export function getDownloadSpeed(byteSize: number): Promise { */ export function detectBitrate(): Promise { // First try a small amount so that we don't hang up their mobile connection - return getDownloadSpeed(1000000).then(function (bitrate) { + return getDownloadSpeed(1000000).then((bitrate) => { if (bitrate < 1000000) { return Math.round(bitrate * 0.8); } else { // If that produced a fairly high speed, try again with a larger size to get a more accurate result - return getDownloadSpeed(2400000).then(function (bitrate) { + return getDownloadSpeed(2400000).then((bitrate) => { return Math.round(bitrate * 0.8); }); } diff --git a/src/components/maincontroller.ts b/src/components/maincontroller.ts index ea0d2291..3ff095cd 100644 --- a/src/components/maincontroller.ts +++ b/src/components/maincontroller.ts @@ -48,6 +48,9 @@ let broadcastToServer = new Date(); let hasReportedCapabilities = false; +/** + * + */ export function onMediaElementTimeUpdate(): void { if ($scope.isChangingStream) { return; @@ -67,6 +70,9 @@ export function onMediaElementTimeUpdate(): void { } } +/** + * + */ export function onMediaElementPause(): void { if ($scope.isChangingStream) { return; @@ -75,6 +81,9 @@ export function onMediaElementPause(): void { reportEvent('playstatechange', true); } +/** + * + */ export function onMediaElementPlaying(): void { if ($scope.isChangingStream) { return; @@ -82,6 +91,9 @@ export function onMediaElementPlaying(): void { reportEvent('playstatechange', true); } +/** + * @param event + */ function onMediaElementVolumeChange(event: cast.framework.system.Event): void { window.volume = (( event @@ -90,6 +102,9 @@ function onMediaElementVolumeChange(event: cast.framework.system.Event): void { if (JellyfinApi.serverAddress !== null) reportEvent('volumechange', true); } +/** + * + */ export function enableTimeUpdateListener(): void { window.mediaManager.addEventListener( cast.framework.events.EventType.TIME_UPDATE, @@ -109,6 +124,9 @@ export function enableTimeUpdateListener(): void { ); } +/** + * + */ export function disableTimeUpdateListener(): void { window.mediaManager.removeEventListener( cast.framework.events.EventType.TIME_UPDATE, @@ -130,7 +148,7 @@ export function disableTimeUpdateListener(): void { enableTimeUpdateListener(); -window.addEventListener('beforeunload', function () { +window.addEventListener('beforeunload', () => { // Try to cleanup after ourselves before the page closes disableTimeUpdateListener(); reportPlaybackStopped($scope, getReportingParams($scope)); @@ -145,6 +163,9 @@ mgr.addEventListener(cast.framework.events.EventType.PAUSE, (): void => { reportPlaybackProgress($scope, getReportingParams($scope)); }); +/** + * + */ function defaultOnStop(): void { playbackMgr.stop(); } @@ -155,7 +176,7 @@ mgr.addEventListener( ); mgr.addEventListener(cast.framework.events.EventType.ABORT, defaultOnStop); -mgr.addEventListener(cast.framework.events.EventType.ENDED, function () { +mgr.addEventListener(cast.framework.events.EventType.ENDED, () => { // Ignore if ($scope.isChangingStream) { return; @@ -182,6 +203,9 @@ window.mediaManager.addEventListener( } ); +/** + * + */ export function reportDeviceCapabilities(): Promise { return getMaxBitrate().then((maxBitrate) => { const deviceProfile = getDeviceProfile({ @@ -205,6 +229,9 @@ export function reportDeviceCapabilities(): Promise { }); } +/** + * @param data + */ export function processMessage(data: any): void { if ( !data.command || @@ -268,6 +295,10 @@ export function processMessage(data: any): void { } } +/** + * @param name + * @param reportToServer + */ export function reportEvent( name: string, reportToServer: boolean @@ -280,6 +311,10 @@ export function reportEvent( ); } +/** + * @param $scope + * @param index + */ export function setSubtitleStreamIndex( $scope: GlobalScope, index: number @@ -289,7 +324,7 @@ export function setSubtitleStreamIndex( let positionTicks; const currentSubtitleStream = $scope.mediaSource.MediaStreams.filter( - function (m: any) { + (m: any) => { return ( m.Index == $scope.subtitleStreamIndex && m.Type == 'Subtitle' ); @@ -350,6 +385,10 @@ export function setSubtitleStreamIndex( } } +/** + * @param $scope + * @param index + */ export function setAudioStreamIndex( $scope: GlobalScope, index: number @@ -360,10 +399,17 @@ export function setAudioStreamIndex( }); } +/** + * @param ticks + */ export function seek(ticks: number): Promise { return changeStream(ticks); } +/** + * @param ticks + * @param params + */ export function changeStream( ticks: number, params: any = undefined @@ -446,7 +492,7 @@ export function changeStream( // TODO save namespace somewhere global? window.castReceiverContext.addCustomMessageListener( 'urn:x-cast:com.connectsdk', - function (evt: any) { + (evt: any) => { let data: any = evt.data; // Apparently chromium likes to pass it as json, not as object. @@ -466,6 +512,11 @@ window.castReceiverContext.addCustomMessageListener( } ); +/** + * @param data + * @param options + * @param method + */ export function translateItems( data: any, options: PlayRequest, @@ -473,7 +524,7 @@ export function translateItems( ): Promise { const playNow = method != 'PlayNext' && method != 'PlayLast'; return translateRequestedItems(data.userId, options.items, playNow).then( - function (result: BaseItemDtoQueryResult) { + (result: BaseItemDtoQueryResult) => { if (result.Items) options.items = result.Items; if (method == 'PlayNext' || method == 'PlayLast') { @@ -491,28 +542,42 @@ export function translateItems( ); } +/** + * @param data + * @param options + * @param item + */ export function instantMix( data: any, options: any, item: BaseItemDto ): Promise { - return getInstantMixItems(data.userId, item).then(function (result) { + return getInstantMixItems(data.userId, item).then((result) => { options.items = result.Items; playbackMgr.playFromOptions(data.options); }); } +/** + * @param data + * @param options + * @param item + */ export function shuffle( data: any, options: any, item: BaseItemDto ): Promise { - return getShuffleItems(data.userId, item).then(function (result) { + return getShuffleItems(data.userId, item).then((result) => { options.items = result.Items; playbackMgr.playFromOptions(data.options); }); } +/** + * @param item + * @param options + */ export function onStopPlayerBeforePlaybackDone( item: BaseItemDto, options: any @@ -520,7 +585,7 @@ export function onStopPlayerBeforePlaybackDone( return JellyfinApi.authAjaxUser('Items/' + item.Id, { dataType: 'json', type: 'GET' - }).then(function (data) { + }).then((data) => { // Attach the custom properties we created like userId, serverAddress, itemId, etc extend(data, item); @@ -530,10 +595,13 @@ export function onStopPlayerBeforePlaybackDone( let lastBitrateDetect = 0; let detectedBitrate = 0; +/** + * + */ export function getMaxBitrate(): Promise { console.log('getMaxBitrate'); - return new Promise(function (resolve) { + return new Promise((resolve) => { // The client can set this number if (window.MaxBitrate) { console.log('bitrate is set to ' + window.MaxBitrate); @@ -573,6 +641,9 @@ export function getMaxBitrate(): Promise { }); } +/** + * @param result + */ export function validatePlaybackInfoResult(result: any): boolean { if (result.ErrorCode) { showPlaybackInfoErrorMessage(result.ErrorCode); @@ -581,31 +652,40 @@ export function validatePlaybackInfoResult(result: any): boolean { return true; } +/** + * @param error + */ export function showPlaybackInfoErrorMessage(error: string): void { broadcastToMessageBus({ type: 'playbackerror', message: error }); } +/** + * @param versions + */ export function getOptimalMediaSource(versions: Array): any { - let optimalVersion = versions.filter(function (v) { + let optimalVersion = versions.filter((v) => { checkDirectPlay(v); return v.SupportsDirectPlay; })[0]; if (!optimalVersion) { - optimalVersion = versions.filter(function (v) { + optimalVersion = versions.filter((v) => { return v.SupportsDirectStream; })[0]; } return ( optimalVersion || - versions.filter(function (s) { + versions.filter((s) => { return s.SupportsTranscoding; })[0] ); } // Disable direct play on non-http sources +/** + * @param mediaSource + */ export function checkDirectPlay(mediaSource: MediaSourceInfo): void { if ( mediaSource.SupportsDirectPlay && @@ -618,6 +698,9 @@ export function checkDirectPlay(mediaSource: MediaSourceInfo): void { mediaSource.SupportsDirectPlay = false; } +/** + * @param index + */ export function setTextTrack(index: number | null): void { try { const textTracksManager = window.mediaManager.getTextTracksManager(); @@ -631,11 +714,11 @@ export function setTextTrack(index: number | null): void { const tracks: Array = textTracksManager.getTracks(); const subtitleTrack: | cast.framework.messages.Track - | undefined = tracks.find(function ( - track: cast.framework.messages.Track - ) { - return track.trackId === index; - }); + | undefined = tracks.find( + (track: cast.framework.messages.Track) => { + return track.trackId === index; + } + ); if (subtitleTrack && subtitleTrack.trackId !== undefined) { textTracksManager.setActiveByIds([subtitleTrack.trackId]); const subtitleAppearance = window.subtitleAppearance; @@ -692,6 +775,11 @@ export function setTextTrack(index: number | null): void { } // TODO no any types +/** + * @param playSessionId + * @param item + * @param streamInfo + */ export function createMediaInformation( playSessionId: string, item: BaseItemDto, diff --git a/src/helpers.ts b/src/helpers.ts index 0cfabd61..b0d592a8 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -132,7 +132,7 @@ export function getSenderReportingData( nowPlayingItem.Chapters = item.Chapters || []; // TODO: Fill these - const mediaSource = item.MediaSources.filter(function (m: any) { + const mediaSource = item.MediaSources.filter((m: any) => { return m.Id == reportingData.MediaSourceId; })[0]; @@ -436,11 +436,11 @@ export function createStreamInfo( }; const subtitleStreams = - mediaSource.MediaStreams?.filter(function (stream: any) { + mediaSource.MediaStreams?.filter((stream: any) => { return stream.Type === 'Subtitle'; }) ?? []; const subtitleTracks: Array = []; - subtitleStreams.forEach(function (subtitleStream: any) { + subtitleStreams.forEach((subtitleStream: any) => { if (subtitleStream.DeliveryUrl === undefined) { /* The CAF v3 player only supports vtt currently, * SRT subs can be "transcoded" to vtt by jellyfin. @@ -487,7 +487,7 @@ export function getStreamByIndex( type: string, index: number ): any { - return streams.filter(function (s) { + return streams.filter((s) => { return s.Type == type && s.Index == index; })[0]; } @@ -727,7 +727,7 @@ export function getItemsForPlayback( return JellyfinApi.authAjaxUser('Items/' + query.Ids.split(',')[0], { type: 'GET', dataType: 'json' - }).then(function (item) { + }).then((item) => { return { Items: [item], TotalRecordCount: 1 @@ -871,19 +871,19 @@ export async function translateRequestedItems( ); let foundItem = false; - episodesResult.Items = episodesResult.Items?.filter(function ( - e: BaseItemDto - ) { - if (foundItem) { - return true; - } - if (e.Id == episode.Id) { - foundItem = true; - return true; - } + episodesResult.Items = episodesResult.Items?.filter( + (e: BaseItemDto) => { + if (foundItem) { + return true; + } + if (e.Id == episode.Id) { + foundItem = true; + return true; + } - return false; - }); + return false; + } + ); episodesResult.TotalRecordCount = episodesResult.Items?.length || 0;