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

refactor: linearize promises

This commit is contained in:
Dmitry Lyzo 2022-10-27 22:55:27 +03:00
parent 1b8f6c56af
commit eb463c0adb

View file

@ -2256,35 +2256,37 @@ class PlaybackManager {
playOptions.isFirstItem = true; playOptions.isFirstItem = true;
} }
return runInterceptors(item, playOptions).then(function () { const apiClient = ServerConnections.getApiClient(item.ServerId);
if (playOptions.fullscreen) {
loading.show();
}
// TODO: This should be the media type requested, not the original media type // TODO: This should be the media type requested, not the original media type
const mediaType = item.MediaType; const mediaType = item.MediaType;
const onBitrateDetectionFailure = function () { return runInterceptors(item, playOptions)
return playAfterBitrateDetect(getSavedMaxStreamingBitrate(ServerConnections.getApiClient(item.ServerId), mediaType), item, playOptions, onPlaybackStartedFn, prevSource); .then(() => {
}; if (playOptions.fullscreen) {
loading.show();
if (!isServerItem(item) || itemHelper.isLocalItem(item)) {
return onBitrateDetectionFailure();
}
const apiClient = ServerConnections.getApiClient(item.ServerId);
apiClient.getEndpointInfo().then(function (endpointInfo) {
if ((mediaType === 'Video' || mediaType === 'Audio') && appSettings.enableAutomaticBitrateDetection(endpointInfo.IsInNetwork, mediaType)) {
return apiClient.detectBitrate().then(function (bitrate) {
appSettings.maxStreamingBitrate(endpointInfo.IsInNetwork, mediaType, bitrate);
return playAfterBitrateDetect(bitrate, item, playOptions, onPlaybackStartedFn, prevSource);
}, onBitrateDetectionFailure);
} else {
onBitrateDetectionFailure();
} }
}, onBitrateDetectionFailure);
}, onInterceptorRejection); if (!isServerItem(item) || itemHelper.isLocalItem(item)) {
return Promise.reject('skip bitrate detection');
}
return apiClient.getEndpointInfo().then((endpointInfo) => {
if ((mediaType === 'Video' || mediaType === 'Audio') && appSettings.enableAutomaticBitrateDetection(endpointInfo.IsInNetwork, mediaType)) {
return apiClient.detectBitrate().then((bitrate) => {
appSettings.maxStreamingBitrate(endpointInfo.IsInNetwork, mediaType, bitrate);
return bitrate;
});
}
return Promise.reject('skip bitrate detection');
});
})
.catch(() => getSavedMaxStreamingBitrate(apiClient, mediaType))
.then((bitrate) => {
return playAfterBitrateDetect(bitrate, item, playOptions, onPlaybackStartedFn, prevSource);
})
.catch(onInterceptorRejection);
} }
function cancelPlayback() { function cancelPlayback() {