1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
|
|
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.webstomp=factory()})(this,function(){"use strict";var classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}};var createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"])_i["return"]()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i)}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}}}();var toConsumableArray=function(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++)arr2[i]=arr[i];return arr2}else{return Array.from(arr)}};var VERSIONS={V1_0:"1.0",V1_1:"1.1",V1_2:"1.2",supportedVersions:function supportedVersions(){return"1.2,1.1,1.0"},supportedProtocols:function supportedProtocols(){return["v10.stomp","v11.stomp","v12.stomp"]}};var PROTOCOLS_VERSIONS={"v10.stomp":VERSIONS.V1_0,"v11.stomp":VERSIONS.V1_1,"v12.stomp":VERSIONS.V1_2};function getSupportedVersion(protocol,debug){var knownVersion=PROTOCOLS_VERSIONS[protocol];if(!knownVersion&&debug){debug("DEPRECATED: "+protocol+" is not a recognized STOMP version. In next major client version, this will close the connection.")}return knownVersion||VERSIONS.V1_2}var BYTES={LF:"\n",NULL:"\0"};var trim=function trim(str){return str.replace(/^\s+|\s+$/g,"")};function unicodeStringToTypedArray(s){var escstr=encodeURIComponent(s);var binstr=escstr.replace(/%([0-9A-F]{2})/g,function(match,p1){return String.fromCharCode("0x"+p1)});var arr=Array.prototype.map.call(binstr,function(c){return c.charCodeAt(0)});return new Uint8Array(arr)}function typedArrayToUnicodeString(ua){var binstr=String.fromCharCode.apply(String,toConsumableArray(ua));var escstr=binstr.replace(/(.)/g,function(m,p){var code=p.charCodeAt(0).toString(16).toUpperCase();if(code.length<2){code="0"+code}return"%"+code});return decodeURIComponent(escstr)}function sizeOfUTF8(s){if(!s)return 0;return encodeURIComponent(s).match(/%..|./g).length}function createId(){var ts=(new Date).getTime();var rand=Math.floor(Math.random()*1e3);return ts+"-"+rand}var Frame=function(){function Frame(command){var headers=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var body=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"";classCallCheck(this,Frame);this.command=command;this.headers=headers;this.body=body}createClass(Frame,[{key:"toString",value:function toString(){var _this=this;var lines=[this.command],skipContentLength=this.headers["content-length"]===false;if(skipContentLength)delete this.headers["content-length"];Object.keys(this.headers).forEach(function(name){var value=_this.headers[name];lines.push(name+":"+value)});if(this.body&&!skipContentLength){lines.push("content-length:"+sizeOfUTF8(this.body))}lines.push(BYTES.LF+this.body);return lines.join(BYTES.LF)}}],[{key:"unmarshallSingle",value:function unmarshallSingle(data){var divider=data.search(new RegExp(BYTES.LF+BYTES.LF)),headerLines=data.substring(0,divider).split(BYTES.LF),command=headerLines.shift(),headers={},body="",bodyIndex=divider+2;var _iteratorNormalCompletion=true;var _didIteratorError=false
|