// Generated by CoffeeScript 1.12.6 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 Copyright (C) 2010-2013 [Jeff Mesnil](http://jmesnil.net/) Copyright (C) 2012 [FuseSource, Inc.](http://fusesource.com) Copyright (C) 2017 [Deepak Kumar](https://www.kreatio.com) */ (function(){var e,t,n,i,r={}.hasOwnProperty,s=[].slice;e={LF:"\n",NULL:"\0"};n=function(){var t;function n(e,t,n,i){this.command=e;this.headers=t!=null?t:{};this.body=n!=null?n:"";this.escapeHeaderValues=i!=null?i:false}n.prototype.toString=function(){var t,i,s,o,c;t=[this.command];o=this.headers["content-length"]===false?true:false;if(o){delete this.headers["content-length"]}s=this.headers;for(i in s){if(!r.call(s,i))continue;c=s[i];if(this.escapeHeaderValues&&this.command!=="CONNECT"&&this.command!=="CONNECTED"){t.push(i+":"+n.frEscape(c))}else{t.push(i+":"+c)}}if(this.body&&!o){t.push("content-length:"+n.sizeOfUTF8(this.body))}t.push(e.LF+this.body);return t.join(e.LF)};n.sizeOfUTF8=function(e){if(e){return encodeURI(e).match(/%..|./g).length}else{return 0}};t=function(t,i){var r,s,o,c,a,u,f,l,h,p,d,g,b,m,v,y,_,S;if(i==null){i=false}c=t.search(RegExp(""+e.LF+e.LF));a=t.substring(0,c).split(e.LF);o=a.shift();u={};S=function(e){return e.replace(/^\s+|\s+$/g,"")};m=a.reverse();for(h=0,g=m.length;hy;f=v<=y?++p:--p){s=t.charAt(f);if(s===e.NULL){break}r+=s}}return new n(o,u,r,i)};n.unmarshall=function(n,i){var r,s,o,c;if(i==null){i=false}s=n.split(RegExp(""+e.NULL+e.LF+"*"));c={frames:[],partial:""};c.frames=function(){var e,n,o,c;o=s.slice(0,-1);c=[];for(e=0,n=o.length;e>> "+r)}while(true){if(r.length>this.maxWebSocketFrameSize){this.ws.send(r.substring(0,this.maxWebSocketFrameSize));r=r.substring(this.maxWebSocketFrameSize);if(typeof this.debug==="function"){this.debug("remaining = "+r.length)}}else{return this.ws.send(r)}}};r.prototype._setupHeartbeat=function(n){var r,s,o,c,a,u;if((r=n.version)!==i.VERSIONS.V1_1&&r!==i.VERSIONS.V1_2){return}s=function(){var e,t,i,r;i=n["heart-beat"].split(",");r=[];for(e=0,t=i.length;e>> PING"):void 0}}(this))}if(!(this.heartbeat.incoming===0||c===0)){a=Math.max(this.heartbeat.incoming,c);if(typeof this.debug==="function"){this.debug("check PONG every "+a+"ms")}return this.ponger=i.setInterval(a,function(e){return function(){var n;n=t()-e.serverActivity;if(n>a*2){if(typeof e.debug==="function"){e.debug("did not receive server activity for the last "+n+"ms")}return e.ws.close()}}}(this))}};r.prototype._parseConnect=function(){var e,t,n,i,r;e=1<=arguments.length?s.call(arguments,0):[];r={};if(e.length<2){throw"Connect requires at least 2 arguments"}if(typeof e[1]==="function"){r=e[0],n=e[1],i=e[2],t=e[3]}else{switch(e.length){case 6:r.login=e[0],r.passcode=e[1],n=e[2],i=e[3],t=e[4],r.host=e[5];break;default:r.login=e[0],r.passcode=e[1],n=e[2],i=e[3],t=e[4]}}return[r,n,i,t]};r.prototype.connect=function(){var e,t;e=1<=arguments.length?s.call(arguments,0):[];this.escapeHeaderValues=false;t=this._parseConnect.apply(this,e);this.headers=t[0],this.connectCallback=t[1],this.errorCallback=t[2],this.closeEventCallback=t[3];this._active=true;return this._connect()};r.prototype._connect=function(){var r,s,o,c;c=this.headers;o=this.errorCallback;s=this.closeEventCallback;if(!this._active){this.debug("Client has been marked inactive, will not attempt to connect");return}if(typeof this.debug==="function"){this.debug("Opening Web Socket...")}this.ws=this.ws_fn();r=function(e){return function(e){var t,n,i,r,s,o;o="";s=e.length;r=0;while(r>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:o+=String.fromCharCode(t);break;case 12:case 13:n=e[r++];o+=String.fromCharCode((t&31)<<6|n&63);break;case 14:n=e[r++];i=e[r++];o+=String.fromCharCode((t&15)<<12|(n&63)<<6|(i&63)<<0)}}return o}}(this);this.ws.onmessage=function(s){return function(c){var a,u,f,l,h,p,d,g,b,m,v;f=typeof ArrayBuffer!=="undefined"&&c.data instanceof ArrayBuffer?(a=new Uint8Array(c.data),typeof s.debug==="function"?s.debug("--- got data length: "+a.length):void 0,r(a)):c.data;s.serverActivity=t();if(f===e.LF){if(typeof s.debug==="function"){s.debug("<<< PONG")}return}if(typeof s.debug==="function"){s.debug("<<< "+f)}v=n.unmarshall(s.partialData+f,s.escapeHeaderValues);s.partialData=v.partial;b=v.frames;for(h=0,p=b.length;h0){if(typeof this.debug==="function"){this.debug("STOMP: scheduling reconnection in "+this.reconnect_delay+"ms")}return this._reconnector=setTimeout(function(e){return function(){if(e.connected){return typeof e.debug==="function"?e.debug("STOMP: already connected"):void 0}else{if(typeof e.debug==="function"){e.debug("STOMP: attempting to reconnect")}return e._connect()}}}(this),this.reconnect_delay)}};r.prototype.disconnect=function(e,t){var n;if(t==null){t={}}this._disconnectCallback=e;this._active=false;if(this.connected){if(!t.receipt){t.receipt="close-"+this.counter++}this.closeReceipt=t.receipt;try{return this._transmit("DISCONNECT",t)}catch(e){n=e;return typeof this.debug==="function"?this.debug("Ignoring error during disconnect",n):void 0}}};r.prototype._cleanUp=function(){if(this._reconnector){clearTimeout(this._reconnector)}this.connected=false;this.subscriptions={};this.partial="";if(this.pinger){i.clearInterval(this.pinger)}if(this.ponger){return i.clearInterval(this.ponger)}};r.prototype.send=function(e,t,n){if(t==null){t={}}if(n==null){n=""}t.destination=e;return this._transmit("SEND",t,n)};r.prototype.subscribe=function(e,t,n){var i;if(n==null){n={}}if(!n.id){n.id="sub-"+this.counter++}n.destination=e;this.subscriptions[n.id]=t;this._transmit("SUBSCRIBE",n);i=this;return{id:n.id,unsubscribe:function(e){return i.unsubscribe(n.id,e)}}};r.prototype.unsubscribe=function(e,t){if(t==null){t={}}delete this.subscriptions[e];t.id=e;return this._transmit("UNSUBSCRIBE",t)};r.prototype.begin=function(e){var t,n;n=e||"tx-"+this.counter++;this._transmit("BEGIN",{transaction:n});t=this;return{id:n,commit:function(){return t.commit(n)},abort:function(){return t.abort(n)}}};r.prototype.commit=function(e){return this._transmit("COMMIT",{transaction:e})};r.prototype.abort=function(e){return this._transmit("ABORT",{transaction:e})};r.prototype.ack=function(e,t,n){if(n==null){n={}}if(this.version===i.VERSIONS.V1_2){n["id"]=e}else{n["message-id"]=e}n.subscription=t;return this._transmit("ACK",n)};r.prototype.nack=function(e,t,n){if(n==null){n={}}if(this.version===i.VERSIONS.V1_2){n["id"]=e}else{n["message-id"]=e}n.subscription=t;return this._transmit("NACK",n)};return r}();i={VERSIONS:{V1_0:"1.0",V1_1:"1.1",V1_2:"1.2",supportedVersions:function(){return"1.2,1.1,1.0"}},client:function(e,n){var r;if(n==null){n=["v10.stomp","v11.stomp","v12.stomp"]}r=function(){var t;t=i.WebSocketClass||WebSocket;return new t(e,n)};return new t(r)},over:function(e){var n;n=typeof e==="function"?e:function(){return e};return new t(n)},Frame:n};i.setInterval=function(e,t){return setInterval(t,e)};i.clearInterval=function(e){return clearInterval(e)};if(typeof exports!=="undefined"&&exports!==null){exports.Stomp=i}if(typeof window!=="undefined"&&window!==null){window.Stomp=i}else if(!exports){self.Stomp=i}}).call(this);