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

1 line
66 KiB
JavaScript
Raw Normal View History

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