define([],function(){"use strict";returnfunction(connectionManager){functionperformSync(server,options){console.log("ServerSync.performSync to server: "+server.Id),options=options||{};varuploadPhotos=options.uploadPhotos!==!1;options.cameraUploadServers&&options.cameraUploadServers.indexOf(server.Id)===-1&&(uploadPhotos=!1);varpr=syncOfflineUsers(server,options);returnpr.then(function(){returnuploadPhotos?uploadContent(server,options):Promise.resolve()}).then(function(){returnsyncMedia(server,options)})}functionsyncOfflineUsers(server,options){returnoptions.syncOfflineUsers===!1?Promise.resolve():newPromise(function(resolve,reject){require(["offlineusersync"],function(OfflineUserSync){varapiClient=connectionManager.getApiClient(server.Id);(newOfflineUserSync).sync(apiClient,server).then(resolve,reject)})})}functionuploadContent(server,options){returnnewPromise(function(resolve,reject){require(["contentuploader"],function(contentuploader){uploader=newContentUploader(connectionManager),uploader.uploadImages(server).then(resolve,reject)})})}functionsyncMedia(server,options){returnnewPromise(function(resolve,reject){require(["mediasync"],function(MediaSync){varapiClient=connectionManager.getApiClient(server.Id);(newMediaSync).sync(apiClient,server,options).then(resolve,reject)})})}varself=this;self.sync=function(server,options){if(!server.AccessToken&&!server.ExchangeToken)returnconsole.log("Skipping sync to server "+server.Id+" because there is no saved authentication information."),Promise.resolve();varconnectionOptions={updateDateLastAccessed:!1,enableWebSocket:!1,reportCapabilities:!1,enableAutomaticBitrateDetection:!1};returnconnectionManager.connectToServer(server,connectionOptions).then(function(result){returnresult.State===MediaBrowser.ConnectionState.SignedIn?performSync(server,options):(console.log("Unable to connect to server id: "+server.Id),Promise.reject())},function(err){throwconsole.log("Unable to connect to server id: "+server.Id),err})}}});