trabajo-afectivo/public/assets/chat/chat.min.js

1 line
84 KiB
JavaScript
Raw Normal View History

var bind=function(e,t){return function(){return e.apply(t,arguments)}},slice=[].slice,extend=function(e,t){for(var n in t)hasProp.call(t,n)&&(e[n]=t[n]);function o(){this.constructor=e}return o.prototype=t.prototype,e.prototype=new o,e.__super__=t.prototype,e},hasProp={}.hasOwnProperty;!function(E,_){var n,o,t,s,e,i,a,r,l;i=(l=document.getElementsByTagName("script"))[l.length-1],r=_.location.protocol.replace(":",""),i&&i.src&&(a=i.src.match(".*://([^:/]*).*")[1],r=i.src.match("(.*)://[^:/]*.*")[1]),n=function(){function e(e){this.options=E.extend({},this.defaults,e),this.log=new t({debug:this.options.debug,logPrefix:this.options.logPrefix||this.logPrefix})}return e.prototype.defaults={debug:!1},e}(),t=function(){function e(e){this.log=bind(this.log,this),this.error=bind(this.error,this),this.notice=bind(this.notice,this),this.debug=bind(this.debug,this),this.options=E.extend({},this.defaults,e)}return e.prototype.defaults={debug:!1},e.prototype.debug=function(){var e;if(e=1<=arguments.length?slice.call(arguments,0):[],this.options.debug)return this.log("debug",e)},e.prototype.notice=function(){var e;return e=1<=arguments.length?slice.call(arguments,0):[],this.log("notice",e)},e.prototype.error=function(){var e;return e=1<=arguments.length?slice.call(arguments,0):[],this.log("error",e)},e.prototype.log=function(e,t){var n,o,s,i;if(t.unshift("||"),t.unshift(e),t.unshift(this.options.logPrefix),console.log.apply(console,t),this.options.debug){for(i="",o=0,s=t.length;o<s;o++)i+=" ","object"==typeof(n=t[o])?i+=JSON.stringify(n):n&&n.toString?i+=n.toString():i+=n;return E(".js-chatLogDisplay").prepend("<div>"+i+"</div>")}},e}(),s=function(e){function t(e){this.stop=bind(this.stop,this),this.start=bind(this.start,this),t.__super__.constructor.call(this,e)}return extend(t,n),t.prototype.timeoutStartedAt=null,t.prototype.logPrefix="timeout",t.prototype.defaults={debug:!1,timeout:4,timeoutIntervallCheck:.5},t.prototype.start=function(){var e,t,n;return this.stop(),t=new Date,e=function(){var e;if(e=new Date-new Date(t.getTime()+1e3*n.options.timeout*60),n.log.debug("Timeout check for "+n.options.timeout+" minutes (left "+e/1e3+" sec.)"),!(e<0))return n.stop(),n.options.callback()},(n=this).log.debug("Start timeout in "+this.options.timeout+" minutes"),this.intervallId=setInterval(e,1e3*this.options.timeoutIntervallCheck*60)},t.prototype.stop=function(){if(this.intervallId)return this.log.debug("Stop timeout of "+this.options.timeout+" minutes"),clearInterval(this.intervallId)},t}(),o=function(e){function t(e){this.ping=bind(this.ping,this),this.send=bind(this.send,this),this.reconnect=bind(this.reconnect,this),this.close=bind(this.close,this),this.connect=bind(this.connect,this),this.set=bind(this.set,this),t.__super__.constructor.call(this,e)}return extend(t,n),t.prototype.logPrefix="io",t.prototype.set=function(e){var t,n,o;for(t in n=[],e)o=e[t],n.push(this.options[t]=o);return n},t.prototype.connect=function(){var t,s,n,o;return this.log.debug("Connecting to "+this.options.host),this.ws=new _.WebSocket(""+this.options.host),this.ws.onopen=(t=this,function(e){return t.log.debug("onOpen",e),t.options.onOpen(e),t.ping()}),this.ws.onmessage=(s=this,function(e){var t,n,o;for(o=JSON.parse(e.data),s.log.debug("onMessage",e.data),t=0,n=o.length;t<n;t++)"pong"===o[t].event&&s.ping();if(s.options.onMessage)return s.options.onMessage(o)}),this.ws.onclose=(n=this,function(e){if(n.log.debug("close websocket connection",e),n.pingDelayId&&clearTimeout(n.pingDelayId),n.manualClose){if(n.log.debug("manual close, onClose callback"),n.manualClose=!1,n.options.onClose)return n.options.onClose(e)}else if(n.log.debug("error close, onError callback"),n.options.onError)return n.options.onError("Connection lost...")}),this.ws.onerror=(o=this,function(e){if(o.log.debug("onError",e),o.options.onError)return o.options.onError(e)})},t.prototype.close=function(){return this.log.debug("close websocket manually"),this.manualClose=!0,this.ws.close()},t.prototype.reconnect=function(){return this.log.debug("reconnect"),this.close(),this.connect()},t.prototype.