jellyfin-web/dashboard-ui/apiclient/sync/multiserversync.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-09-09 10:49:44 -07:00
(function (globalScope) {
function multiServerSync(connectionManager) {
2015-09-09 20:22:52 -07:00
var self = this;
2015-09-21 18:05:33 -07:00
self.sync = function (options) {
2015-09-09 10:49:44 -07:00
var deferred = DeferredBuilder.Deferred();
connectionManager.getAvailableServers().done(function (result) {
2015-09-21 18:05:33 -07:00
syncNext(result, 0, options, deferred);
2015-09-09 10:49:44 -07:00
});
return deferred.promise();
};
2015-09-21 18:05:33 -07:00
function syncNext(servers, index, options, deferred) {
2015-09-09 10:49:44 -07:00
var length = servers.length;
if (index >= length) {
deferred.resolve();
return;
}
var server = servers[index];
// get fresh info from connection manager
server = connectionManager.getServerInfo(server.Id) || server;
Logger.log("Creating ServerSync to server: " + server.Id);
require(['serversync'], function () {
2015-09-21 18:05:33 -07:00
new MediaBrowser.ServerSync(connectionManager).sync(server, options).done(function () {
2015-09-09 10:49:44 -07:00
2015-09-21 18:05:33 -07:00
syncNext(servers, index + 1, options, deferred);
2015-09-09 10:49:44 -07:00
}).fail(function () {
2015-09-21 18:05:33 -07:00
syncNext(servers, index + 1, options, deferred);
2015-09-09 10:49:44 -07:00
});
});
}
}
if (!globalScope.MediaBrowser) {
globalScope.MediaBrowser = {};
}
globalScope.MediaBrowser.MultiServerSync = multiServerSync;
})(this);