2015-08-12 17:39:02 -04:00
|
|
|
|
(function () {
|
|
|
|
|
|
2015-09-10 14:28:22 -04:00
|
|
|
|
var syncPromise;
|
2015-09-19 22:06:56 -04:00
|
|
|
|
var lastStart = 0;
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-08-12 17:39:02 -04:00
|
|
|
|
window.LocalSync = {
|
|
|
|
|
|
|
|
|
|
isSupported: function () {
|
2015-09-10 14:28:22 -04:00
|
|
|
|
return AppInfo.isNativeApp;
|
2015-08-12 17:39:02 -04:00
|
|
|
|
},
|
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
sync: function (options) {
|
2015-08-12 17:39:02 -04:00
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
if (syncPromise) {
|
|
|
|
|
return syncPromise.promise();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deferred = DeferredBuilder.Deferred();
|
|
|
|
|
|
|
|
|
|
require(['multiserversync'], function () {
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
lastStart = new Date().getTime();
|
|
|
|
|
syncPromise = new MediaBrowser.MultiServerSync(ConnectionManager).sync(options).done(function () {
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
syncPromise = null;
|
|
|
|
|
deferred.resolve();
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
}).fail(function () {
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
syncPromise = null;
|
2015-09-10 14:28:22 -04:00
|
|
|
|
});
|
2015-09-21 21:05:33 -04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
2015-08-12 17:39:02 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getSyncStatus: function () {
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
|
|
|
|
if (syncPromise != null) {
|
|
|
|
|
return 'Syncing';
|
|
|
|
|
}
|
2015-08-12 17:39:02 -04:00
|
|
|
|
return 'Idle';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-19 22:06:56 -04:00
|
|
|
|
var syncInterval = 1800000;
|
|
|
|
|
|
|
|
|
|
function restartInterval() {
|
2015-09-10 14:28:22 -04:00
|
|
|
|
if (LocalSync.isSupported) {
|
|
|
|
|
setInterval(function () {
|
|
|
|
|
|
2015-09-21 21:05:33 -04:00
|
|
|
|
//LocalSync.startSync();
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-09-19 22:06:56 -04:00
|
|
|
|
}, syncInterval);
|
|
|
|
|
|
|
|
|
|
if (lastStart > 0 && (now - lastStart) >= syncInterval) {
|
2015-09-21 21:05:33 -04:00
|
|
|
|
//LocalSync.startSync();
|
2015-09-19 22:06:56 -04:00
|
|
|
|
}
|
2015-09-10 14:28:22 -04:00
|
|
|
|
}
|
2015-09-14 17:24:54 -04:00
|
|
|
|
//LocalSync.startSync();
|
2015-09-19 22:06:56 -04:00
|
|
|
|
}
|
2015-09-10 14:28:22 -04:00
|
|
|
|
|
2015-09-19 22:06:56 -04:00
|
|
|
|
Dashboard.ready(restartInterval);
|
|
|
|
|
document.addEventListener("resume", restartInterval, false);
|
2015-08-12 17:39:02 -04:00
|
|
|
|
})();
|