mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 03:18:19 -07:00
update promises
This commit is contained in:
parent
e340d7a40b
commit
3fc5d39784
@ -675,14 +675,16 @@
|
||||
|
||||
self.getTargets = function () {
|
||||
|
||||
var targets = [];
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (castPlayer.hasReceivers) {
|
||||
targets.push(self.getCurrentTargetInfo());
|
||||
}
|
||||
var targets = [];
|
||||
|
||||
return targets;
|
||||
if (castPlayer.hasReceivers) {
|
||||
targets.push(self.getCurrentTargetInfo());
|
||||
}
|
||||
|
||||
resolve(targets);
|
||||
});
|
||||
};
|
||||
|
||||
self.getCurrentTargetInfo = function () {
|
||||
|
@ -107,11 +107,11 @@
|
||||
|
||||
getSavedViewSetting: function (key) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
var val = LibraryBrowser.getSavedView(key);
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
deferred.resolveWith(null, [val]);
|
||||
return deferred.promise();
|
||||
var val = LibraryBrowser.getSavedView(key);
|
||||
resolve(val);
|
||||
});
|
||||
},
|
||||
|
||||
needsRefresh: function (elem) {
|
||||
|
@ -404,9 +404,7 @@
|
||||
|
||||
function getUserViews(apiClient, userId) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
apiClient.getUserViews({}, userId).then(function (result) {
|
||||
return apiClient.getUserViews({}, userId).then(function (result) {
|
||||
|
||||
var items = result.Items;
|
||||
|
||||
@ -442,10 +440,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
deferred.resolveWith(null, [list]);
|
||||
return list;
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
function updateLibraryMenu(user) {
|
||||
|
@ -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;
|
||||
|
@ -1004,8 +1004,8 @@
|
||||
};
|
||||
|
||||
//if (!browserInfo.animate) {
|
||||
onfinish();
|
||||
return;
|
||||
onfinish();
|
||||
return;
|
||||
//}
|
||||
|
||||
requestAnimationFrame(function () {
|
||||
@ -1025,7 +1025,7 @@
|
||||
|
||||
elem.classList.remove('hide');
|
||||
|
||||
if (!browserInfo.animate) {
|
||||
if (!browserInfo.animate || browserInfo.mobile) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,14 @@
|
||||
|
||||
self.getTargets = function () {
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
resolve(self.getTargetsInternal());
|
||||
});
|
||||
};
|
||||
|
||||
self.getTargetsInternal = function () {
|
||||
|
||||
var targets = [{
|
||||
name: Globalize.translate('MyDevice'),
|
||||
id: AppInfo.deviceId,
|
||||
@ -565,7 +573,7 @@
|
||||
var liveStreamId = getParameterByName('LiveStreamId', currentSrc);
|
||||
|
||||
self.getDeviceProfile().then(function (deviceProfile) {
|
||||
|
||||
|
||||
var audioStreamIndex = params.AudioStreamIndex == null ? (getParameterByName('AudioStreamIndex', currentSrc) || null) : params.AudioStreamIndex;
|
||||
if (typeof (audioStreamIndex) == 'string') {
|
||||
audioStreamIndex = parseInt(audioStreamIndex);
|
||||
@ -823,13 +831,11 @@
|
||||
|
||||
function getOptimalMediaSource(mediaType, versions) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
var promises = versions.map(function (v) {
|
||||
return MediaController.supportsDirectPlay(v);
|
||||
});
|
||||
|
||||
Promise.all(promises).then(function (responses) {
|
||||
return Promise.all(promises).then(function (responses) {
|
||||
|
||||
for (var i = 0, length = versions.length; i < length; i++) {
|
||||
versions[i].enableDirectPlay = responses[i] || false;
|
||||
@ -852,10 +858,8 @@
|
||||
return s.SupportsTranscoding;
|
||||
})[0];
|
||||
|
||||
deferred.resolveWith(null, [optimalVersion]);
|
||||
return optimalVersion;
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
self.createStreamInfo = function (type, item, mediaSource, startPosition) {
|
||||
@ -1021,8 +1025,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
var onBitrateDetected = function() {
|
||||
self.getDeviceProfile().then(function(deviceProfile) {
|
||||
var onBitrateDetected = function () {
|
||||
self.getDeviceProfile().then(function (deviceProfile) {
|
||||
playOnDeviceProfileCreated(deviceProfile, item, startPosition, callback);
|
||||
});
|
||||
};
|
||||
@ -1540,13 +1544,11 @@
|
||||
|
||||
self.getPlayerState = function () {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var result = self.getPlayerStateInternal(self.currentMediaRenderer, self.currentItem, self.currentMediaSource);
|
||||
|
||||
deferred.resolveWith(null, [result]);
|
||||
|
||||
return deferred.promise();
|
||||
var result = self.getPlayerStateInternal(self.currentMediaRenderer, self.currentItem, self.currentMediaSource);
|
||||
resolve(result);
|
||||
});
|
||||
};
|
||||
|
||||
self.getPlayerStateInternal = function (mediaRenderer, item, mediaSource) {
|
||||
@ -1967,16 +1969,17 @@
|
||||
|
||||
self.tryPair = function (target) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
deferred.resolve();
|
||||
return deferred.promise();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
window.MediaPlayer = new mediaPlayer();
|
||||
|
||||
window.MediaController.registerPlayer(window.MediaPlayer);
|
||||
window.MediaController.setActivePlayer(window.MediaPlayer, window.MediaPlayer.getTargets()[0]);
|
||||
window.MediaController.setActivePlayer(window.MediaPlayer, window.MediaPlayer.getTargetsInternal()[0]);
|
||||
|
||||
|
||||
})(document, setTimeout, clearTimeout, screen, setInterval, window);
|
@ -2,12 +2,12 @@
|
||||
|
||||
var supporterPlaybackKey = 'lastSupporterPlaybackMessage4';
|
||||
|
||||
function validatePlayback(deferred) {
|
||||
function validatePlayback(resolve, reject) {
|
||||
|
||||
Dashboard.getPluginSecurityInfo().then(function (pluginSecurityInfo) {
|
||||
|
||||
if (pluginSecurityInfo.IsMBSupporter) {
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
} else {
|
||||
|
||||
var lastMessage = parseInt(appStorage.getItem(supporterPlaybackKey) || '0');
|
||||
@ -16,13 +16,13 @@
|
||||
|
||||
// Don't show on the very first playback attempt
|
||||
appStorage.setItem(supporterPlaybackKey, new Date().getTime());
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
}
|
||||
else if ((new Date().getTime() - lastMessage) > 345600000) {
|
||||
|
||||
showPlaybackOverlay(deferred);
|
||||
showPlaybackOverlay(resolve, reject);
|
||||
} else {
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -95,7 +95,7 @@
|
||||
return html;
|
||||
}
|
||||
|
||||
function showPlaybackOverlay(deferred) {
|
||||
function showPlaybackOverlay(resolve, reject) {
|
||||
|
||||
require(['components/paperdialoghelper', 'paper-fab', 'paper-item-body', 'paper-icon-item'], function (paperDialogHelper) {
|
||||
|
||||
@ -135,7 +135,7 @@
|
||||
dlg.addEventListener('iron-overlay-closed', function (e) {
|
||||
appStorage.setItem(supporterPlaybackKey, new Date().getTime());
|
||||
dlg.parentNode.removeChild(dlg);
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
});
|
||||
|
||||
paperDialogHelper.open(dlg);
|
||||
@ -146,12 +146,12 @@
|
||||
});
|
||||
}
|
||||
|
||||
function validateSync(deferred) {
|
||||
function validateSync(resolve, reject) {
|
||||
|
||||
Dashboard.getPluginSecurityInfo().then(function (pluginSecurityInfo) {
|
||||
|
||||
if (pluginSecurityInfo.IsMBSupporter) {
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -162,21 +162,19 @@
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
if (registrationInfo.IsRegistered) {
|
||||
deferred.resolve();
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('HeaderSyncRequiresSupporterMembership') + '<br/><p><a href="http://emby.media/premiere" target="_blank">' + Globalize.translate('ButtonLearnMore') + '</a></p>',
|
||||
title: Globalize.translate('HeaderSync'),
|
||||
callback: function () {
|
||||
deferred.reject();
|
||||
}
|
||||
callback: reject
|
||||
});
|
||||
|
||||
}, function () {
|
||||
|
||||
deferred.reject();
|
||||
reject();
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
Dashboard.alert({
|
||||
@ -279,19 +277,17 @@
|
||||
|
||||
validateFeature: function (name) {
|
||||
|
||||
var deferred = DeferredBuilder.Deferred();
|
||||
|
||||
if (name == 'playback') {
|
||||
validatePlayback(deferred);
|
||||
} else if (name == 'livetv') {
|
||||
deferred.resolve();
|
||||
} else if (name == 'sync') {
|
||||
validateSync(deferred);
|
||||
} else {
|
||||
deferred.resolve();
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (name == 'playback') {
|
||||
validatePlayback(resolve, reject);
|
||||
} else if (name == 'livetv') {
|
||||
resolve();
|
||||
} else if (name == 'sync') {
|
||||
validateSync(resolve, reject);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -167,32 +167,31 @@
|
||||
|
||||
self.getPlayerState = function () {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var apiClient = window.ApiClient;
|
||||
var apiClient = window.ApiClient;
|
||||
|
||||
if (apiClient) {
|
||||
apiClient.getSessions().then(function (sessions) {
|
||||
if (apiClient) {
|
||||
apiClient.getSessions().then(function (sessions) {
|
||||
|
||||
var currentTargetId = MediaController.getPlayerInfo().id;
|
||||
var currentTargetId = MediaController.getPlayerInfo().id;
|
||||
|
||||
// Update existing data
|
||||
//updateSessionInfo(popup, msg.Data);
|
||||
var session = sessions.filter(function (s) {
|
||||
return s.Id == currentTargetId;
|
||||
})[0];
|
||||
// Update existing data
|
||||
//updateSessionInfo(popup, msg.Data);
|
||||
var session = sessions.filter(function (s) {
|
||||
return s.Id == currentTargetId;
|
||||
})[0];
|
||||
|
||||
if (session) {
|
||||
session = getPlayerState(session);
|
||||
}
|
||||
if (session) {
|
||||
session = getPlayerState(session);
|
||||
}
|
||||
|
||||
deferred.resolveWith(null, [session]);
|
||||
});
|
||||
} else {
|
||||
deferred.resolveWith(null, [{}]);
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
resolve(session);
|
||||
});
|
||||
} else {
|
||||
resolve({});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var pollInterval;
|
||||
@ -263,53 +262,53 @@
|
||||
|
||||
self.getTargets = function () {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var sessionQuery = {
|
||||
ControllableByUserId: Dashboard.getCurrentUserId()
|
||||
};
|
||||
var sessionQuery = {
|
||||
ControllableByUserId: Dashboard.getCurrentUserId()
|
||||
};
|
||||
|
||||
var apiClient = window.ApiClient;
|
||||
var apiClient = window.ApiClient;
|
||||
|
||||
if (apiClient) {
|
||||
apiClient.getSessions(sessionQuery).then(function (sessions) {
|
||||
if (apiClient) {
|
||||
apiClient.getSessions(sessionQuery).then(function (sessions) {
|
||||
|
||||
var targets = sessions.filter(function (s) {
|
||||
var targets = sessions.filter(function (s) {
|
||||
|
||||
return s.DeviceId != apiClient.deviceId();
|
||||
return s.DeviceId != apiClient.deviceId();
|
||||
|
||||
}).map(function (s) {
|
||||
return {
|
||||
name: s.DeviceName,
|
||||
deviceName: s.DeviceName,
|
||||
id: s.Id,
|
||||
playerName: self.name,
|
||||
appName: s.Client,
|
||||
playableMediaTypes: s.PlayableMediaTypes,
|
||||
isLocalPlayer: false,
|
||||
supportedCommands: s.SupportedCommands
|
||||
};
|
||||
}).map(function (s) {
|
||||
return {
|
||||
name: s.DeviceName,
|
||||
deviceName: s.DeviceName,
|
||||
id: s.Id,
|
||||
playerName: self.name,
|
||||
appName: s.Client,
|
||||
playableMediaTypes: s.PlayableMediaTypes,
|
||||
isLocalPlayer: false,
|
||||
supportedCommands: s.SupportedCommands
|
||||
};
|
||||
});
|
||||
|
||||
resolve(targets);
|
||||
|
||||
}, function () {
|
||||
|
||||
reject();
|
||||
});
|
||||
|
||||
deferred.resolveWith(null, [targets]);
|
||||
|
||||
}, function () {
|
||||
|
||||
deferred.reject();
|
||||
});
|
||||
|
||||
} else {
|
||||
deferred.resolveWith(null, []);
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
} else {
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.tryPair = function(target) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
deferred.resolve();
|
||||
return deferred.promise();
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
function getUserViews(userId) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
ApiClient.getUserViews({}, userId).then(function (result) {
|
||||
return ApiClient.getUserViews({}, userId).then(function (result) {
|
||||
|
||||
var items = result.Items;
|
||||
|
||||
@ -44,10 +42,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
deferred.resolveWith(null, [list]);
|
||||
return list;
|
||||
});
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
function enableScrollX() {
|
||||
|
Loading…
Reference in New Issue
Block a user