mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update promises
This commit is contained in:
parent
a67f62c079
commit
ddb9a7cdc4
9 changed files with 164 additions and 179 deletions
|
@ -370,9 +370,11 @@
|
|||
self.setDefaultPlayerActive = function () {
|
||||
|
||||
var player = self.getDefaultPlayer();
|
||||
var target = player.getTargets()[0];
|
||||
|
||||
self.setActivePlayer(player, target);
|
||||
player.getTargets().then(function (targets) {
|
||||
|
||||
self.setActivePlayer(player, targets[0]);
|
||||
});
|
||||
};
|
||||
|
||||
self.removeActivePlayer = function (name) {
|
||||
|
@ -449,13 +451,11 @@
|
|||
|
||||
self.getTargets = function () {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
var promises = players.map(function (p) {
|
||||
return p.getTargets();
|
||||
});
|
||||
|
||||
Promise.all(promises).then(function (responses) {
|
||||
return Promise.all(promises).then(function (responses) {
|
||||
|
||||
var targets = [];
|
||||
|
||||
|
@ -481,10 +481,8 @@
|
|||
return aVal.localeCompare(bVal);
|
||||
});
|
||||
|
||||
deferred.resolveWith(null, [targets]);
|
||||
return targets;
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
function doWithPlaybackValidation(player, fn) {
|
||||
|
@ -831,40 +829,35 @@
|
|||
|
||||
self.getPlaybackInfo = function (itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId) {
|
||||
|
||||
var deferred = DeferredBuilder.Deferred();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
require(['localassetmanager'], function () {
|
||||
require(['localassetmanager'], function () {
|
||||
|
||||
var serverInfo = ApiClient.serverInfo();
|
||||
var serverInfo = ApiClient.serverInfo();
|
||||
|
||||
if (serverInfo.Id) {
|
||||
LocalAssetManager.getLocalMediaSource(serverInfo.Id, itemId).then(function (localMediaSource) {
|
||||
// Use the local media source if a specific one wasn't requested, or the smae one was requested
|
||||
if (localMediaSource && (!mediaSource || mediaSource.Id == localMediaSource.Id)) {
|
||||
if (serverInfo.Id) {
|
||||
LocalAssetManager.getLocalMediaSource(serverInfo.Id, itemId).then(function (localMediaSource) {
|
||||
// Use the local media source if a specific one wasn't requested, or the smae one was requested
|
||||
if (localMediaSource && (!mediaSource || mediaSource.Id == localMediaSource.Id)) {
|
||||
|
||||
var playbackInfo = getPlaybackInfoFromLocalMediaSource(itemId, deviceProfile, startPosition, localMediaSource);
|
||||
var playbackInfo = getPlaybackInfoFromLocalMediaSource(itemId, deviceProfile, startPosition, localMediaSource);
|
||||
|
||||
deferred.resolveWith(null, [playbackInfo]);
|
||||
return;
|
||||
}
|
||||
resolve(playbackInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
getPlaybackInfoWithoutLocalMediaSource(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId, deferred);
|
||||
});
|
||||
return;
|
||||
}
|
||||
getPlaybackInfoWithoutLocalMediaSource(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId, resolve, reject);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
getPlaybackInfoWithoutLocalMediaSource(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId, deferred);
|
||||
getPlaybackInfoWithoutLocalMediaSource(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId, resolve, reject);
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
function getPlaybackInfoWithoutLocalMediaSource(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId, deferred) {
|
||||
self.getPlaybackInfoInternal(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId).then(function (result) {
|
||||
deferred.resolveWith(null, [result]);
|
||||
}, function () {
|
||||
deferred.reject();
|
||||
});
|
||||
function getPlaybackInfoWithoutLocalMediaSource(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId, resolve, reject) {
|
||||
self.getPlaybackInfoInternal(itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId).then(resolve, reject);
|
||||
}
|
||||
|
||||
self.getPlaybackInfoInternal = function (itemId, deviceProfile, startPosition, mediaSource, audioStreamIndex, subtitleStreamIndex, liveStreamId) {
|
||||
|
@ -934,36 +927,36 @@
|
|||
|
||||
self.supportsDirectPlay = function (mediaSource) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
if (mediaSource.SupportsDirectPlay) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (mediaSource.SupportsDirectPlay) {
|
||||
|
||||
if (mediaSource.Protocol == 'Http' && !mediaSource.RequiredHttpHeaders.length) {
|
||||
if (mediaSource.Protocol == 'Http' && !mediaSource.RequiredHttpHeaders.length) {
|
||||
|
||||
// If this is the only way it can be played, then allow it
|
||||
if (!mediaSource.SupportsDirectStream && !mediaSource.SupportsTranscoding) {
|
||||
deferred.resolveWith(null, [true]);
|
||||
// If this is the only way it can be played, then allow it
|
||||
if (!mediaSource.SupportsDirectStream && !mediaSource.SupportsTranscoding) {
|
||||
resolve(true);
|
||||
}
|
||||
else {
|
||||
var val = mediaSource.Path.toLowerCase().replace('https:', 'http').indexOf(ApiClient.serverAddress().toLowerCase().replace('https:', 'http').substring(0, 14)) == 0;
|
||||
resolve(val);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var val = mediaSource.Path.toLowerCase().replace('https:', 'http').indexOf(ApiClient.serverAddress().toLowerCase().replace('https:', 'http').substring(0, 14)) == 0;
|
||||
deferred.resolveWith(null, [val]);
|
||||
}
|
||||
}
|
||||
|
||||
if (mediaSource.Protocol == 'File') {
|
||||
if (mediaSource.Protocol == 'File') {
|
||||
|
||||
require(['localassetmanager'], function () {
|
||||
require(['localassetmanager'], function () {
|
||||
|
||||
LocalAssetManager.fileExists(mediaSource.Path).then(function (exists) {
|
||||
console.log('LocalAssetManager.fileExists: path: ' + mediaSource.Path + ' result: ' + exists);
|
||||
deferred.resolveWith(null, [exists]);
|
||||
LocalAssetManager.fileExists(mediaSource.Path).then(function (exists) {
|
||||
console.log('LocalAssetManager.fileExists: path: ' + mediaSource.Path + ' result: ' + exists);
|
||||
resolve(exists);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
deferred.resolveWith(null, [false]);
|
||||
}
|
||||
return deferred.promise();
|
||||
else {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.showPlayerSelection = showPlayerSelection;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue