@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 22.5 kB
JavaScript
DrawioFileSync=function(t){mxEventSource.call(this),this.lastActivity=new Date,this.clientId=Editor.guid(),this.ui=t.ui,this.file=t,this.onlineListener=mxUtils.bind(this,(function(){this.updateOnlineState(),this.isConnected()&&this.fileChangedNotify()})),mxEvent.addListener(window,"online",this.onlineListener),this.visibleListener=mxUtils.bind(this,(function(){"hidden"==document.visibilityState?this.isConnected()&&this.stop():this.start()})),mxEvent.addListener(document,"visibilitychange",this.visibleListener),this.activityListener=mxUtils.bind(this,(function(t){this.lastActivity=new Date,this.start()})),mxEvent.addListener(document,mxClient.IS_POINTER?"pointermove":"mousemove",this.activityListener),mxEvent.addListener(document,"keypress",this.activityListener),mxEvent.addListener(window,"focus",this.activityListener),!mxClient.IS_POINTER&&mxClient.IS_TOUCH&&(mxEvent.addListener(document,"touchstart",this.activityListener),mxEvent.addListener(document,"touchmove",this.activityListener)),this.pusherErrorListener=mxUtils.bind(this,(function(t){null!=t.error&&null!=t.error.data&&4004===t.error.data.code&&EditorUi.logError("Error: Pusher Limit",null,this.file.getId())})),this.connectionListener=mxUtils.bind(this,(function(){if(this.updateOnlineState(),this.updateStatus(),this.isConnected())if(this.announced)this.fileChangedNotify();else{var t=this.file.getCurrentUser(),e={a:"join"};null!=t&&(e.name=encodeURIComponent(t.displayName),e.uid=t.id),mxUtils.post(EditorUi.cacheUrl,this.getIdParameters()+"&msg="+encodeURIComponent(this.objectToString(this.createMessage(e)))),this.file.stats.msgSent++,this.announced=!0}})),this.changeListener=mxUtils.bind(this,(function(t){if(this.file.stats.msgReceived++,this.lastActivity=new Date,this.enabled&&!this.file.inConflictState&&!this.file.redirectDialogShowing)try{var e=this.stringToObject(t);null!=e&&(EditorUi.debug("Sync.message",[this],e,t.length,"bytes"),e.v>DrawioFileSync.PROTOCOL?this.file.redirectToNewApp(mxUtils.bind(this,(function(){}))):e.v===DrawioFileSync.PROTOCOL&&null!=e.d&&this.handleMessageData(e.d))}catch(t){this.isConnected()&&this.fileChangedNotify()}}))},DrawioFileSync.PROTOCOL=6,mxUtils.extend(DrawioFileSync,mxEventSource),DrawioFileSync.prototype.maxCacheEntrySize=1e6,DrawioFileSync.prototype.enabled=!0,DrawioFileSync.prototype.updateStatusInterval=1e4,DrawioFileSync.prototype.channelId=null,DrawioFileSync.prototype.channel=null,DrawioFileSync.prototype.catchupRetryCount=0,DrawioFileSync.prototype.maxCatchupRetries=15,DrawioFileSync.prototype.maxCacheReadyRetries=1,DrawioFileSync.prototype.cacheReadyDelay=700,DrawioFileSync.prototype.maxOptimisticReloadRetries=6,DrawioFileSync.prototype.inactivityTimeoutSeconds=1800,DrawioFileSync.prototype.lastActivity=null,DrawioFileSync.prototype.start=function(){if(null==this.channelId&&(this.channelId=this.file.getChannelId()),null==this.key&&(this.key=this.file.getChannelKey()),null==this.pusher&&null!=this.channelId&&"hidden"!=document.visibilityState){if(this.pusher=this.ui.getPusher(),null!=this.pusher){try{null!=this.pusher.connection&&this.pusher.connection.bind("error",this.pusherErrorListener)}catch(t){}try{this.pusher.connect(),this.channel=this.pusher.subscribe(this.channelId),EditorUi.debug("Sync.start",[this,"v"+DrawioFileSync.PROTOCOL],"rev",this.file.getCurrentRevisionId())}catch(t){}this.installListeners()}window.setTimeout(mxUtils.bind(this,(function(){this.lastModified=this.file.getLastModifiedDate(),this.lastActivity=new Date,this.resetUpdateStatusThread(),this.updateOnlineState(),this.updateStatus()}),0))}},DrawioFileSync.prototype.isConnected=function(){return null!=this.pusher&&null!=this.pusher.connection&&"connected"==this.pusher.connection.state},DrawioFileSync.prototype.updateOnlineState=function(){if("1"!=urlParams.embedRT){var t=mxUtils.bind(this,(function(t){mxEvent.addListener(t,"click",mxUtils.bind(this,(function(t){this.enabled=!this.enabled,this.ui.updateButtonContainer(),this.resetUpdateStatusThread(),this.updateOnlineState(),this.updateStatus(),!this.file.inConflictState&&this.enabled&&this.fileChangedNotify()})))}));if("min"==uiTheme&&null!=this.ui.buttonContainer&&"1"!=urlParams.sketch)null==this.collaboratorsElement&&((e=document.createElement("a")).className="geToolbarButton",e.style.cssText="display:inline-block;position:relative;box-sizing:border-box;margin-right:4px;cursor:pointer;float:left;",e.style.backgroundPosition="center center",e.style.backgroundRepeat="no-repeat",e.style.backgroundSize="24px 24px",e.style.height="24px",e.style.width="24px",t(e),this.ui.buttonContainer.appendChild(e),this.collaboratorsElement=e);else if(null!=this.ui.toolbarContainer){var e;null==this.collaboratorsElement&&((e=document.createElement("a")).className="geButton",e.style.position="absolute",e.style.display="inline-block",e.style.verticalAlign="bottom",e.style.color="#666",e.style.top="6px",e.style.right="atlas"!=uiTheme?"70px":"50px",e.style.padding="2px",e.style.fontSize="8pt",e.style.verticalAlign="middle",e.style.textDecoration="none",e.style.backgroundPosition="center center",e.style.backgroundRepeat="no-repeat",e.style.backgroundSize="16px 16px",e.style.width="16px",e.style.height="16px",mxUtils.setOpacity(e,60),"dark"==uiTheme&&(e.style.filter="invert(100%)"),mxEvent.addListener(e,mxClient.IS_POINTER?"pointerdown":"mousedown",mxUtils.bind(this,(function(t){t.preventDefault()}))),t(e),this.ui.toolbarContainer.appendChild(e),this.collaboratorsElement=e)}if(null!=this.collaboratorsElement){var i;i=this.enabled?this.file.invalidChecksum?mxResources.get("error")+": "+mxResources.get("checksum"):this.ui.isOffline(!0)||!this.isConnected()?mxResources.get("offline"):mxResources.get("online"):mxResources.get("disconnected"),this.collaboratorsElement.setAttribute("title",i),this.collaboratorsElement.style.backgroundImage="url("+(this.enabled?this.ui.isOffline(!0)||!this.isConnected()||this.file.invalidChecksum?Editor.syncProblemImage:Editor.syncImage:Editor.syncDisabledImage)+")"}}},DrawioFileSync.prototype.updateStatus=function(){if(this.isConnected()&&null!=this.lastActivity&&((new Date).getTime()-this.lastActivity.getTime())/1e3>this.inactivityTimeoutSeconds&&this.stop(),!(this.file.isModified()||this.file.inConflictState||null!=this.file.autosaveThread||this.file.savingFile||this.file.redirectDialogShowing))if(this.enabled&&null!=this.ui.statusContainer){var t=this.ui.timeSince(new Date(this.lastModified));null==t&&(t=mxResources.get("lessThanAMinute"));var e=this.file.isRevisionHistorySupported(),i=this.lastMessage;this.lastMessage=null,null!=i&&i.length>40&&(i=i.substring(0,40)+"...");var s=mxResources.get("lastChange",[t]);this.ui.editor.setStatus('<div title="'+mxUtils.htmlEntities(s)+'">'+mxUtils.htmlEntities(s)+"</div>"+(this.file.isEditable()?"":'<div class="geStatusAlert">'+mxUtils.htmlEntities(mxResources.get("readOnly"))+"</div>")+(this.isConnected()?"":'<div class="geStatusAlert">'+mxUtils.htmlEntities(mxResources.get("disconnected"))+"</div>")+(null!=i?' <span title="'+mxUtils.htmlEntities(i)+'">('+mxUtils.htmlEntities(i)+")</span>":""));var n=this.ui.statusContainer.getElementsByTagName("div");n.length>0&&e&&(n[0].style.display="inline-block",e&&(n[0].style.cursor="pointer",n[0].style.textDecoration="underline",mxEvent.addListener(n[0],"click",mxUtils.bind(this,(function(){this.ui.actions.get("revisionHistory").funct()})))));var l=this.ui.statusContainer.getElementsByTagName("span");if(l.length>0){var o=l[0];o.style.opacity="0",mxUtils.setPrefixedStyle(o.style,"transition","all 0.2s ease"),window.setTimeout(mxUtils.bind(this,(function(){mxUtils.setOpacity(o,100),mxUtils.setPrefixedStyle(o.style,"transition","all 1s ease"),window.setTimeout(mxUtils.bind(this,(function(){mxUtils.setOpacity(o,0)})),this.updateStatusInterval/2)})),0)}this.resetUpdateStatusThread()}else this.file.addAllSavedStatus()},DrawioFileSync.prototype.resetUpdateStatusThread=function(){null!=this.updateStatusThread&&window.clearInterval(this.updateStatusThread),null!=this.channel&&(this.updateStatusThread=window.setInterval(mxUtils.bind(this,(function(){this.updateStatus()})),this.updateStatusInterval))},DrawioFileSync.prototype.installListeners=function(){null!=this.pusher&&null!=this.pusher.connection&&this.pusher.connection.bind("state_change",this.connectionListener),null!=this.channel&&this.channel.bind("changed",this.changeListener)},DrawioFileSync.prototype.handleMessageData=function(t){if("desc"==t.a)this.file.savingFile||this.reloadDescriptor();else if("join"==t.a||"leave"==t.a)"join"==t.a&&this.file.stats.joined++,null!=t.name&&(this.lastMessage=mxResources.get("join"==t.a?"userJoined":"userLeft",[decodeURIComponent(t.name)]),this.resetUpdateStatusThread(),this.updateStatus());else if(null!=t.m){var e=new Date(t.m);(null==this.lastMessageModified||this.lastMessageModified<e)&&(this.lastMessageModified=e,this.fileChangedNotify(t))}},DrawioFileSync.prototype.isValidState=function(){return this.ui.getCurrentFile()==this.file&&this.file.sync==this&&!this.file.invalidChecksum&&!this.file.redirectDialogShowing},DrawioFileSync.prototype.optimisticSync=function(t){null==this.reloadThread&&((t=null!=t?t:0)<this.maxOptimisticReloadRetries&&(this.reloadThread=window.setTimeout(mxUtils.bind(this,(function(){this.file.getLatestVersion(mxUtils.bind(this,(function(e){if(this.reloadThread=null,null!=e){var i=e.getCurrentRevisionId();this.file.getCurrentRevisionId()==i?this.optimisticSync(t+1):this.file.mergeFile(e,mxUtils.bind(this,(function(){this.lastModified=this.file.getLastModifiedDate(),this.updateStatus()})))}})),mxUtils.bind(this,(function(){this.reloadThread=null})))})),(t+1)*this.file.optimisticSyncDelay)),"1"==urlParams.test&&EditorUi.debug("Sync.optimisticSync",[this],"retryCount",t))},DrawioFileSync.prototype.fileChangedNotify=function(t){if(this.isValidState())if(this.file.savingFile)this.remoteFileChanged=!0;else if(null!=t&&"optimistic"==t.type)this.optimisticSync();else var e=this.fileChanged(mxUtils.bind(this,(function(t){this.updateStatus()})),mxUtils.bind(this,(function(t){this.file.handleFileError(t)})),mxUtils.bind(this,(function(){return!this.file.savingFile&&this.notifyThread!=e})),!0)},DrawioFileSync.prototype.fileChanged=function(t,e,i,s){var n=window.setTimeout(mxUtils.bind(this,(function(){null!=i&&i()||(this.isValidState()?this.file.loadPatchDescriptor(mxUtils.bind(this,(function(s){null!=i&&i()||(this.isValidState()?this.catchup(s,t,e,i):null!=e&&e())})),e):null!=e&&e())})),s?this.cacheReadyDelay:0);return this.notifyThread=n,n},DrawioFileSync.prototype.reloadDescriptor=function(){this.file.loadDescriptor(mxUtils.bind(this,(function(t){null!=t?(this.file.setDescriptorRevisionId(t,this.file.getCurrentRevisionId()),this.updateDescriptor(t),this.fileChangedNotify()):(this.file.inConflictState=!0,this.file.handleFileError())})),mxUtils.bind(this,(function(t){this.file.inConflictState=!0,this.file.handleFileError(t)})))},DrawioFileSync.prototype.updateDescriptor=function(t){this.file.setDescriptor(t),this.file.descriptorChanged(),this.start()},DrawioFileSync.prototype.p2pCatchup=function(t,e,i,s,n,l,o,a){if(null!=n&&(null==a||!a()))if(this.file.getDescriptorRevisionId(n),this.file.getCurrentRevisionId(),this.isValidState()){if(this.file.getDescriptorSecret(n),null==a||!a()){this.file.stats.bytesReceived+=t.length;var r=null,h=[];try{var c=[t];if(null!=c&&c.length>0)for(var u=0;u<c.length;u++){var d=this.stringToObject(c[u]);if(d.v>DrawioFileSync.PROTOCOL){failed=!0,h=[];break}if(d.v!==DrawioFileSync.PROTOCOL||null==d.d){failed=!0,h=[];break}r=d.d.checksum,h.push(d.d.patch)}}catch(t){h=[],null!=window.console&&"1"==urlParams.test&&console.log(t)}try{h.length>0?(this.file.stats.cacheHits++,this.merge(h,r,n,l,o,a)):(this.file.stats.cacheFail++,this.reload(l,o,a))}catch(t){null!=o&&o(t)}}}else null!=o&&o()},DrawioFileSync.prototype.catchup=function(t,e,i,s){if(null!=t&&(null==s||!s())){var n=this.file.getDescriptorRevisionId(t),l=this.file.getCurrentRevisionId();if(l==n)this.file.patchDescriptor(this.file.getDescriptor(),t),null!=e&&e();else if(this.isValidState()){var o=this.file.getDescriptorSecret(t);if(null==o||"1"==urlParams.lockdown)this.reload(e,i,s);else{var a=0,r=!1,h=mxUtils.bind(this,(function(){if(null==s||!s())if(l!=this.file.getCurrentRevisionId())null!=e&&e();else if(this.isValidState()){var c=!0,u=window.setTimeout(mxUtils.bind(this,(function(){c=!1,this.reload(e,i,s)})),this.ui.timeout);mxUtils.get(EditorUi.cacheUrl+"?id="+encodeURIComponent(this.channelId)+"&from="+encodeURIComponent(l)+"&to="+encodeURIComponent(n)+(null!=o?"&secret="+encodeURIComponent(o):""),mxUtils.bind(this,(function(n){if(this.file.stats.bytesReceived+=n.getText().length,window.clearTimeout(u),c&&(null==s||!s()))if(l!=this.file.getCurrentRevisionId())null!=e&&e();else if(this.isValidState()){var o=null,d=[];if(n.getStatus()>=200&&n.getStatus()<=299&&n.getText().length>0)try{var f=JSON.parse(n.getText());if(null!=f&&f.length>0)for(var m=0;m<f.length;m++){var p=this.stringToObject(f[m]);if(p.v>DrawioFileSync.PROTOCOL){r=!0,d=[];break}if(p.v!==DrawioFileSync.PROTOCOL||null==p.d){r=!0,d=[];break}o=p.d.checksum,d.push(p.d.patch)}}catch(t){d=[],null!=window.console&&"1"==urlParams.test&&console.log(t)}try{d.length>0?(this.file.stats.cacheHits++,this.merge(d,o,t,e,i,s)):a<=this.maxCacheReadyRetries-1&&!r&&401!=n.getStatus()&&503!=n.getStatus()?(a++,this.file.stats.cacheMiss++,window.setTimeout(h,(a+1)*this.cacheReadyDelay)):(this.file.stats.cacheFail++,this.reload(e,i,s))}catch(t){null!=i&&i(t)}}else null!=i&&i()})))}else null!=i&&i()}));window.setTimeout(h,this.cacheReadyDelay)}}else null!=i&&i()}},DrawioFileSync.prototype.reload=function(t,e,i,s){this.file.updateFile(mxUtils.bind(this,(function(){this.lastModified=this.file.getLastModifiedDate(),this.updateStatus(),this.start(),null!=t&&t()})),mxUtils.bind(this,(function(t){null!=e&&e(t)})),i,s)},DrawioFileSync.prototype.merge=function(t,e,i,s,n,l){try{this.file.stats.merged++,this.lastModified=new Date,this.file.shadowPages=null!=this.file.shadowPages?this.file.shadowPages:this.ui.getPagesForNode(mxUtils.parseXml(this.file.shadowData).documentElement),this.file.backupPatch=this.file.isModified()?this.ui.diffPages(this.file.shadowPages,this.ui.pages):null;var o=this.file.ignorePatches(t),a=this.file.getDescriptorRevisionId(i);if(!o){for(var r=0;r<t.length;r++)this.file.shadowPages=this.ui.patchPages(this.file.shadowPages,t[r]);var h=null!=e?this.ui.getHashValueForPages(this.file.shadowPages):null;if("1"==urlParams.test&&EditorUi.debug("Sync.merge",[this],"from",this.file.getCurrentRevisionId(),"to",a,"etag",this.file.getDescriptorEtag(i),"backup",this.file.backupPatch,"attempt",this.catchupRetryCount,"patches",t,"checksum",e==h,e),null!=e&&e!=h){var c=this.ui.hashValue(this.file.getCurrentRevisionId()),u=this.ui.hashValue(a);return void this.file.checksumError(n,t,"From: "+c+"\nTo: "+u+"\nChecksum: "+e+"\nCurrent: "+h,a,"merge")}this.file.patch(t,DrawioFile.LAST_WRITE_WINS?this.file.backupPatch:null)}this.file.invalidChecksum=!1,this.file.inConflictState=!1,this.file.patchDescriptor(this.file.getDescriptor(),i),this.file.backupPatch=null,null!=s&&s()}catch(i){this.file.inConflictState=!0,this.file.invalidChecksum=!0,this.file.descriptorChanged(),null!=n&&n(i);try{if(this.file.errorReportsEnabled)c=this.ui.hashValue(this.file.getCurrentRevisionId()),u=this.ui.hashValue(a),this.file.sendErrorReport("Error in merge","From: "+c+"\nTo: "+u+"\nChecksum: "+e+"\nPatches:\n"+this.file.compressReportData(JSON.stringify(t,null,2)),i);else{var d=this.file.getCurrentUser(),f=null!=d?d.id:"unknown";EditorUi.logError("Error in merge",null,this.file.getMode()+"."+this.file.getId(),f,i)}}catch(t){}}},DrawioFileSync.prototype.descriptorChanged=function(t){if(this.lastModified=this.file.getLastModifiedDate(),null!=this.channelId){var e=this.objectToString(this.createMessage({a:"desc",m:this.lastModified.getTime()})),i=this.file.getCurrentRevisionId(),s=this.objectToString({});mxUtils.post(EditorUi.cacheUrl,this.getIdParameters()+"&from="+encodeURIComponent(t)+"&to="+encodeURIComponent(i)+"&msg="+encodeURIComponent(e)+"&data="+encodeURIComponent(s)),this.file.stats.bytesSent+=s.length,this.file.stats.msgSent++}this.updateStatus()},DrawioFileSync.prototype.objectToString=function(t){var e=Graph.compress(JSON.stringify(t));return null!=this.key&&"undefined"!=typeof CryptoJS&&(e=CryptoJS.AES.encrypt(e,this.key).toString()),e},DrawioFileSync.prototype.stringToObject=function(t){return null!=this.key&&"undefined"!=typeof CryptoJS&&(t=CryptoJS.AES.decrypt(t,this.key).toString(CryptoJS.enc.Utf8)),JSON.parse(Graph.decompress(t))},DrawioFileSync.prototype.createToken=function(t,e,i){var s=!0,n=window.setTimeout(mxUtils.bind(this,(function(){s=!1,i({code:App.ERROR_TIMEOUT,message:mxResources.get("timeout")})})),this.ui.timeout);mxUtils.get(EditorUi.cacheUrl+"?id="+encodeURIComponent(this.channelId)+"&secret="+encodeURIComponent(t),mxUtils.bind(this,(function(t){window.clearTimeout(n),s&&(t.getStatus()>=200&&t.getStatus()<=299?e(t.getText()):i({code:t.getStatus(),message:"Token Error "+t.getStatus()}))})))},DrawioFileSync.prototype.fileSaving=function(){var t=this.objectToString(this.createMessage({m:(new Date).getTime(),type:"optimistic"}));mxUtils.post(EditorUi.cacheUrl,this.getIdParameters()+"&msg="+encodeURIComponent(t),(function(){}))},DrawioFileSync.prototype.sendFileChanges=function(t,e){this.lastModified=this.file.getLastModifiedDate();var i=this.objectToString(this.createMessage({m:this.lastModified.getTime()})),s=this.file.getDescriptorSecret(this.file.getDescriptor()),n=this.file.getDescriptorRevisionId(e),l=this.file.getCurrentRevisionId(),o=null!=this.file.shadowPages?this.file.shadowPages:this.ui.getPagesForNode(mxUtils.parseXml(this.file.shadowData).documentElement),a=this.file.getDescriptorSecret(e),r=this.ui.getHashValueForPages(t),h=this.ui.diffPages(o,t),c=this.objectToString(this.createMessage({patch:h,checksum:r}));this.file.p2pCollab.sendMessage("diff",{id:this.channelId,from:n,to:l,msg:i,secret:s,lastSecret:a,data:c})},DrawioFileSync.prototype.fileSaved=function(t,e,i,s,n){if(this.lastModified=this.file.getLastModifiedDate(),this.resetUpdateStatusThread(),this.catchupRetryCount=0,!this.ui.isOffline(!0)&&!this.file.inConflictState&&!this.file.redirectDialogShowing&&(this.start(),null!=this.channelId)){var l=this.objectToString(this.createMessage({m:this.lastModified.getTime()})),o=this.file.getDescriptorSecret(this.file.getDescriptor()),a=this.file.getDescriptorRevisionId(e),r=this.file.getCurrentRevisionId();if(null==o||"1"==urlParams.lockdown)this.file.stats.msgSent++,mxUtils.post(EditorUi.cacheUrl,this.getIdParameters()+"&msg="+encodeURIComponent(l),(function(){})),null!=i&&i(),"1"==urlParams.test&&EditorUi.debug("Sync.fileSaved",[this],"from",a,"to",r,"etag",this.file.getCurrentEtag(),"notify");else{var h=null!=this.file.shadowPages?this.file.shadowPages:this.ui.getPagesForNode(mxUtils.parseXml(this.file.shadowData).documentElement),c=this.file.getDescriptorSecret(e),u=this.ui.getHashValueForPages(t),d=this.ui.diffPages(h,t),f=this.objectToString(this.createMessage({patch:d,checksum:u}));this.file.stats.bytesSent+=f.length,this.file.stats.msgSent++;var m=!0,p=window.setTimeout(mxUtils.bind(this,(function(){m=!1,s({code:App.ERROR_TIMEOUT,message:mxResources.get("timeout")})})),this.ui.timeout);mxUtils.post(EditorUi.cacheUrl,this.getIdParameters()+"&from="+encodeURIComponent(a)+"&to="+encodeURIComponent(r)+"&msg="+encodeURIComponent(l)+(null!=o?"&secret="+encodeURIComponent(o):"")+(null!=c?"&last-secret="+encodeURIComponent(c):"")+(f.length<this.maxCacheEntrySize?"&data="+encodeURIComponent(f):"")+(null!=n?"&token="+encodeURIComponent(n):""),mxUtils.bind(this,(function(t){window.clearTimeout(p),m&&(t.getStatus()>=200&&t.getStatus()<=299?null!=i&&i():s({code:t.getStatus(),message:t.getStatus()}))}))),"1"==urlParams.test&&EditorUi.debug("Sync.fileSaved",[this],"from",a,"to",r,"etag",this.file.getCurrentEtag(),f.length,"bytes","diff",d,"checksum",u)}}this.file.shadowPages=t},DrawioFileSync.prototype.getIdParameters=function(){var t="id="+this.channelId;return null!=this.pusher&&null!=this.pusher.connection&&null!=this.pusher.connection.socket_id&&(t+="&sid="+this.pusher.connection.socket_id),t},DrawioFileSync.prototype.createMessage=function(t){return{v:DrawioFileSync.PROTOCOL,d:t,c:this.clientId}},DrawioFileSync.prototype.fileConflict=function(t,e,i){this.catchupRetryCount++,this.catchupRetryCount<this.maxCatchupRetries?(this.file.stats.conflicts++,null!=t?this.catchup(t,e,i):this.fileChanged(e,i)):(this.file.stats.timeouts++,this.catchupRetryCount=0,null!=i&&i({code:App.ERROR_TIMEOUT,message:mxResources.get("timeout")}))},DrawioFileSync.prototype.stop=function(){null!=this.pusher&&(EditorUi.debug("Sync.stop",[this]),null!=this.pusher.connection&&(this.pusher.connection.unbind("state_change",this.connectionListener),this.pusher.connection.unbind("error",this.pusherErrorListener)),null!=this.channel&&(this.channel.unbind("changed",this.changeListener),this.channel=null),this.pusher.disconnect(),this.pusher=null),this.updateOnlineState(),this.updateStatus()},DrawioFileSync.prototype.destroy=function(){if(null!=this.channelId){var t=this.file.getCurrentUser(),e={a:"leave"};null!=t&&(e.name=encodeURIComponent(t.displayName),e.uid=t.id),mxUtils.post(EditorUi.cacheUrl,this.getIdParameters()+"&msg="+encodeURIComponent(this.objectToString(this.createMessage(e)))),this.file.stats.msgSent++}this.stop(),null!=this.updateStatusThread&&(window.clearInterval(this.updateStatusThread),this.updateStatusThread=null),null!=this.onlineListener&&(mxEvent.removeListener(window,"online",this.onlineListener),this.onlineListener=null),null!=this.visibleListener&&(mxEvent.removeListener(document,"visibilitychange",this.visibleListener),this.visibleListener=null),null!=this.activityListener&&(mxEvent.removeListener(document,mxClient.IS_POINTER?"pointermove":"mousemove",this.activityListener),mxEvent.removeListener(document,"keypress",this.activityListener),mxEvent.removeListener(window,"focus",this.activityListener),!mxClient.IS_POINTER&&mxClient.IS_TOUCH&&(mxEvent.removeListener(document,"touchstart",this.activityListener),mxEvent.removeListener(document,"touchmove",this.activityListener)),this.activityListener=null),null!=this.collaboratorsElement&&(this.collaboratorsElement.parentNode.removeChild(this.collaboratorsElement),this.collaboratorsElement=null)};