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
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
return new Promise(function (resolve, reject) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
var servers = connectionManager.getSavedServers();
|
2015-09-27 08:00:57 -07:00
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
syncNext(servers, 0, options, resolve, reject);
|
|
|
|
|
});
|
2015-09-09 10:49:44 -07:00
|
|
|
|
};
|
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
function syncNext(servers, index, options, resolve, reject) {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
|
|
|
|
var length = servers.length;
|
|
|
|
|
|
|
|
|
|
if (index >= length) {
|
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
resolve();
|
2015-09-09 10:49:44 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var server = servers[index];
|
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
console.log("Creating ServerSync to server: " + server.Id);
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
|
|
|
|
require(['serversync'], function () {
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
new MediaBrowser.ServerSync(connectionManager).sync(server, options).then(function () {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
syncNext(servers, index + 1, options, resolve, reject);
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
|
2015-12-23 10:46:01 -07:00
|
|
|
|
syncNext(servers, index + 1, options, resolve, reject);
|
2015-09-09 10:49:44 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!globalScope.MediaBrowser) {
|
|
|
|
|
globalScope.MediaBrowser = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
globalScope.MediaBrowser.MultiServerSync = multiServerSync;
|
|
|
|
|
|
|
|
|
|
})(this);
|