Clear interval

This commit is contained in:
Jiiks 2016-01-07 08:53:03 +02:00
parent c2b491c0f4
commit dcff0a3a51
2 changed files with 2 additions and 1 deletions

View File

@ -1602,6 +1602,7 @@ BdWSocket.prototype.onError = function(e) {
BdWSocket.prototype.onClose = function(e) {
utils.log("Socket Closed - " + e.code + " : " + e.reason);
clearInterval(bdSocket.interval);
bdws.start();
};

2
js/main.min.js vendored
View File

@ -65,7 +65,7 @@ ThemeModule.prototype.loadThemes=function(){this.loadThemeData();$.each(bdthemes
if(enabled){$("head").append('<style id="'+name+'">'+unescape(bdthemes[name]["css"])+'</style>');}});};ThemeModule.prototype.handleTheme=function(checkbox){var cb=$(checkbox).children().find('input[type="checkbox"]');var enabled=!cb.is(":checked");var id=cb.attr("id").substring(2);cb.prop("checked",enabled);if(enabled){$("head").append('<style id="'+id+'">'+unescape(bdthemes[id]["css"])+'</style>');themeCookie[id]=true;}else{$("#"+id).remove();themeCookie[id]=false;}
this.saveThemeData();};ThemeModule.prototype.loadThemeData=function(){var cookie=$.cookie("bd-themes");if(cookie!=undefined){themeCookie=JSON.parse($.cookie("bd-themes"));}};ThemeModule.prototype.saveThemeData=function(){$.cookie("bd-themes",JSON.stringify(themeCookie),{expires:365,path:'/'});};var bdSocket;var bdws;function BdWSocket(){bdws=this;}
BdWSocket.prototype.start=function(){var self=this;$.ajax({method:"GET",url:"https://discordapp.com/api/gateway",headers:{authorization:localStorage.token.match(/\"(.+)\"/)[1]},success:function(data){self.open(data.url);}});};BdWSocket.prototype.open=function(host){utils.log("Socket Host: "+host);try{bdSocket=new WebSocket(host);bdSocket.onopen=this.onOpen;bdSocket.onmessage=this.onMessage;bdSocket.onerror=this.onError;bdSocket.onclose=this.onClose;}catch(err){utils.log(err);}};BdWSocket.prototype.onOpen=function(){utils.log("Socket Open");var data={op:2,d:{token:JSON.parse(localStorage.getItem('token')),properties:JSON.parse(localStorage.getItem('superProperties')),v:3}};bdws.send(data);};BdWSocket.prototype.onMessage=function(e){var packet,data,type;try{packet=JSON.parse(e.data);data=packet.d;type=packet.t;}catch(err){utils.err(err);return;}
switch(type){case"READY":bdSocket.interval=setInterval(()=>bdws.send({op:1,d:Date.now()}),data.heartbeat_interval);utils.log("Socket Ready");break;case"PRESENCE_UPDATE":pluginModule.socketEvent("PRESENCE_UPDATE",data);break;case"TYPING_START":pluginModule.socketEvent("TYPING_START",data);break;case"MESSAGE_CREATE":pluginModule.socketEvent("MESSAGE_CREATE",data);break;case"MESSAGE_UPDATE":pluginModule.socketEvent("MESSAGE_UPDATE",data);break;default:break;}};BdWSocket.prototype.onError=function(e){utils.log("Socket Error - "+e.message);};BdWSocket.prototype.onClose=function(e){utils.log("Socket Closed - "+e.code+" : "+e.reason);bdws.start();};BdWSocket.prototype.send=function(data){bdSocket.send(JSON.stringify(data));};BdWSocket.prototype.getSocket=function(){return bdSocket;};function BdApi(){}
switch(type){case"READY":bdSocket.interval=setInterval(()=>bdws.send({op:1,d:Date.now()}),data.heartbeat_interval);utils.log("Socket Ready");break;case"PRESENCE_UPDATE":pluginModule.socketEvent("PRESENCE_UPDATE",data);break;case"TYPING_START":pluginModule.socketEvent("TYPING_START",data);break;case"MESSAGE_CREATE":pluginModule.socketEvent("MESSAGE_CREATE",data);break;case"MESSAGE_UPDATE":pluginModule.socketEvent("MESSAGE_UPDATE",data);break;default:break;}};BdWSocket.prototype.onError=function(e){utils.log("Socket Error - "+e.message);};BdWSocket.prototype.onClose=function(e){utils.log("Socket Closed - "+e.code+" : "+e.reason);clearInterval(bdSocket.interval);bdws.start();};BdWSocket.prototype.send=function(data){bdSocket.send(JSON.stringify(data));};BdWSocket.prototype.getSocket=function(){return bdSocket;};function BdApi(){}
BdApi.joinServer=function(code){opublicServers.joinServer(code);};BdApi.injectCSS=function(id,css){$("head").append('<style id="'+id+'"></style>')
$("#"+id).html(css);};BdApi.clearCSS=function(id){$("#"+id).remove();};BdApi.getPlugin=function(name){if(bdplugins.hasOwnProperty(name)){return bdplugins[name]["plugin"];}
return null;};BdApi.getIpc=function(){return betterDiscordIPC;};BdApi.getCore=function(){return mainCore;};BdApi.getUserIdByName=function(name){var users=$(".member-username");for(var i=0;i<users.length;i++){var user=$(users[i]);if(user.text()==name){var avatarUrl=user.closest(".member").find(".avatar-small").css("background-image");return avatarUrl.match(/\d+/);}}