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:
parent
1b8f6c56af
commit
eb463c0adb
1 changed files with 28 additions and 26 deletions
|
@ -2256,35 +2256,37 @@ class PlaybackManager {
|
|||
playOptions.isFirstItem = true;
|
||||
}
|
||||
|
||||
return runInterceptors(item, playOptions).then(function () {
|
||||
if (playOptions.fullscreen) {
|
||||
loading.show();
|
||||
}
|
||||
const apiClient = ServerConnections.getApiClient(item.ServerId);
|
||||
|
||||
// TODO: This should be the media type requested, not the original media type
|
||||
const mediaType = item.MediaType;
|
||||
|
||||
const onBitrateDetectionFailure = function () {
|
||||
return playAfterBitrateDetect(getSavedMaxStreamingBitrate(ServerConnections.getApiClient(item.ServerId), mediaType), item, playOptions, onPlaybackStartedFn, prevSource);
|
||||
};
|
||||
return runInterceptors(item, playOptions)
|
||||
.then(() => {
|
||||
if (playOptions.fullscreen) {
|
||||
loading.show();
|
||||
}
|
||||
|
||||
if (!isServerItem(item) || itemHelper.isLocalItem(item)) {
|
||||
return onBitrateDetectionFailure();
|
||||
return Promise.reject('skip bitrate detection');
|
||||
}
|
||||
|
||||
const apiClient = ServerConnections.getApiClient(item.ServerId);
|
||||
apiClient.getEndpointInfo().then(function (endpointInfo) {
|
||||
return apiClient.getEndpointInfo().then((endpointInfo) => {
|
||||
if ((mediaType === 'Video' || mediaType === 'Audio') && appSettings.enableAutomaticBitrateDetection(endpointInfo.IsInNetwork, mediaType)) {
|
||||
return apiClient.detectBitrate().then(function (bitrate) {
|
||||
return apiClient.detectBitrate().then((bitrate) => {
|
||||
appSettings.maxStreamingBitrate(endpointInfo.IsInNetwork, mediaType, bitrate);
|
||||
|
||||
return playAfterBitrateDetect(bitrate, item, playOptions, onPlaybackStartedFn, prevSource);
|
||||
}, onBitrateDetectionFailure);
|
||||
} else {
|
||||
onBitrateDetectionFailure();
|
||||
return bitrate;
|
||||
});
|
||||
}
|
||||
}, onBitrateDetectionFailure);
|
||||
}, onInterceptorRejection);
|
||||
|
||||
return Promise.reject('skip bitrate detection');
|
||||
});
|
||||
})
|
||||
.catch(() => getSavedMaxStreamingBitrate(apiClient, mediaType))
|
||||
.then((bitrate) => {
|
||||
return playAfterBitrateDetect(bitrate, item, playOptions, onPlaybackStartedFn, prevSource);
|
||||
})
|
||||
.catch(onInterceptorRejection);
|
||||
}
|
||||
|
||||
function cancelPlayback() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue