From eedb613aef19bd78980e5d83efc45b37fd5aaea1 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Tue, 14 May 2019 12:23:44 +0300 Subject: [PATCH] Created prod build --- dist/serializers/MsgpackSerializer.js | 4 +- dist/serializers/MsgpackSerializer.js.map | 2 +- dist/wampy.js | 93 ++++++++++++++++++----- dist/wampy.js.map | 2 +- 4 files changed, 79 insertions(+), 22 deletions(-) diff --git a/dist/serializers/MsgpackSerializer.js b/dist/serializers/MsgpackSerializer.js index 93619d8..78c399f 100644 --- a/dist/serializers/MsgpackSerializer.js +++ b/dist/serializers/MsgpackSerializer.js @@ -7,7 +7,7 @@ exports.MsgpackSerializer = void 0; var _msgpack = _interopRequireDefault(require("msgpack5")); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -15,7 +15,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var msgpack = (0, _msgpack.default)(); +var msgpack = (0, _msgpack["default"])(); var MsgpackSerializer = /*#__PURE__*/ diff --git a/dist/serializers/MsgpackSerializer.js.map b/dist/serializers/MsgpackSerializer.js.map index 7609588..2362fef 100644 --- a/dist/serializers/MsgpackSerializer.js.map +++ b/dist/serializers/MsgpackSerializer.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/serializers/MsgpackSerializer.js"],"names":["msgpack","MsgpackSerializer","protocol","isBinary","data","encode","Promise","resolve","type","constructor","name","decode","Uint8Array","reader","FileReader","onload","result","readAsArrayBuffer"],"mappings":";;;;;;;AAAA;;;;;;;;;;AAEA,IAAMA,OAAO,GAAG,uBAAhB;;IAEaC,iB;;;AACT,+BAAe;AAAA;;AACX,SAAKC,QAAL,GAAgB,SAAhB;AACA,SAAKC,QAAL,GAAgB,IAAhB;AACH;;;;2BAEOC,I,EAAM;AACV,aAAOJ,OAAO,CAACK,MAAR,CAAeD,IAAf,CAAP;AACH;;;2BAEOA,I,EAAM;AACV,aAAO,IAAIE,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAE1B,YAAMC,IAAI,GAAGJ,IAAI,CAACK,WAAL,CAAiBC,IAA9B;;AAEA,YAAIF,IAAI,KAAK,aAAT,IAA0BA,IAAI,KAAK,QAAvC,EAAiD;AAC7CD,UAAAA,OAAO,CAACP,OAAO,CAACW,MAAR,CAAe,IAAIC,UAAJ,CAAeR,IAAf,CAAf,CAAD,CAAP;AACH,SAFD,MAEO;AACH,cAAMS,MAAM,GAAG,IAAIC,UAAJ,EAAf;;AAEAD,UAAAA,MAAM,CAACE,MAAP,GAAgB,YAAY;AACxBR,YAAAA,OAAO,CAACP,OAAO,CAACW,MAAR,CAAe,IAAIC,UAAJ,CAAe,KAAKI,MAApB,CAAf,CAAD,CAAP;AACH,WAFD;;AAIAH,UAAAA,MAAM,CAACI,iBAAP,CAAyBb,IAAzB;AACH;AAEJ,OAhBM,CAAP;AAiBH","sourcesContent":["import msgpack5 from 'msgpack5';\n\nconst msgpack = msgpack5();\n\nexport class MsgpackSerializer {\n constructor () {\n this.protocol = 'msgpack';\n this.isBinary = true;\n }\n\n encode (data) {\n return msgpack.encode(data);\n }\n\n decode (data) {\n return new Promise(resolve => {\n\n const type = data.constructor.name;\n\n if (type === 'ArrayBuffer' || type === 'Buffer') {\n resolve(msgpack.decode(new Uint8Array(data)));\n } else {\n const reader = new FileReader();\n\n reader.onload = function () {\n resolve(msgpack.decode(new Uint8Array(this.result)));\n };\n\n reader.readAsArrayBuffer(data);\n }\n\n });\n }\n}\n"],"file":"MsgpackSerializer.js"} \ No newline at end of file +{"version":3,"sources":["../../src/serializers/MsgpackSerializer.js"],"names":["msgpack","MsgpackSerializer","protocol","isBinary","data","encode","Promise","resolve","type","constructor","name","decode","Uint8Array","reader","FileReader","onload","result","readAsArrayBuffer"],"mappings":";;;;;;;AAAA;;;;;;;;;;AAEA,IAAMA,OAAO,GAAG,0BAAhB;;IAEaC,iB;;;AACT,+BAAe;AAAA;;AACX,SAAKC,QAAL,GAAgB,SAAhB;AACA,SAAKC,QAAL,GAAgB,IAAhB;AACH;;;;2BAEOC,I,EAAM;AACV,aAAOJ,OAAO,CAACK,MAAR,CAAeD,IAAf,CAAP;AACH;;;2BAEOA,I,EAAM;AACV,aAAO,IAAIE,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAE1B,YAAMC,IAAI,GAAGJ,IAAI,CAACK,WAAL,CAAiBC,IAA9B;;AAEA,YAAIF,IAAI,KAAK,aAAT,IAA0BA,IAAI,KAAK,QAAvC,EAAiD;AAC7CD,UAAAA,OAAO,CAACP,OAAO,CAACW,MAAR,CAAe,IAAIC,UAAJ,CAAeR,IAAf,CAAf,CAAD,CAAP;AACH,SAFD,MAEO;AACH,cAAMS,MAAM,GAAG,IAAIC,UAAJ,EAAf;;AAEAD,UAAAA,MAAM,CAACE,MAAP,GAAgB,YAAY;AACxBR,YAAAA,OAAO,CAACP,OAAO,CAACW,MAAR,CAAe,IAAIC,UAAJ,CAAe,KAAKI,MAApB,CAAf,CAAD,CAAP;AACH,WAFD;;AAIAH,UAAAA,MAAM,CAACI,iBAAP,CAAyBb,IAAzB;AACH;AAEJ,OAhBM,CAAP;AAiBH","sourcesContent":["import msgpack5 from 'msgpack5';\n\nconst msgpack = msgpack5();\n\nexport class MsgpackSerializer {\n constructor () {\n this.protocol = 'msgpack';\n this.isBinary = true;\n }\n\n encode (data) {\n return msgpack.encode(data);\n }\n\n decode (data) {\n return new Promise(resolve => {\n\n const type = data.constructor.name;\n\n if (type === 'ArrayBuffer' || type === 'Buffer') {\n resolve(msgpack.decode(new Uint8Array(data)));\n } else {\n const reader = new FileReader();\n\n reader.onload = function () {\n resolve(msgpack.decode(new Uint8Array(this.result)));\n };\n\n reader.readAsArrayBuffer(data);\n }\n\n });\n }\n}\n"],"file":"MsgpackSerializer.js"} \ No newline at end of file diff --git a/dist/wampy.js b/dist/wampy.js index 04c1d2a..3230903 100644 --- a/dist/wampy.js +++ b/dist/wampy.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.Wampy = exports.default = void 0; +exports.Wampy = exports["default"] = void 0; var _constants = require("./constants"); @@ -38,7 +38,7 @@ function () { * @type {string} * @private */ - this.version = 'v6.2.1'; + this.version = 'v6.2.2'; /** * WS Url * @type {string} @@ -245,6 +245,12 @@ function () { */ helloCustomDetails: null, + /** + * Validation of the topic URI structure + * @type {string} - strict or loose + */ + uriValidation: 'strict', + /** * Authentication id to use in challenge * @type {string} @@ -405,7 +411,42 @@ function () { }, { key: "_isPlainObject", value: function _isPlainObject(obj) { - return !!obj && obj.constructor === Object; + if (!this._isObject(obj)) { + return false; + } // If has modified constructor + + + var ctor = obj.constructor; + + if (typeof ctor !== 'function') { + return false; + } // If has modified prototype + + + var prot = ctor.prototype; + + if (this._isObject(prot) === false) { + return false; + } // If constructor does not have an Object-specific method + + + if (prot.hasOwnProperty('isPrototypeOf') === false) { + return false; + } + + return true; + } + /** + * Check if value is an object + * @param obj + * @returns {boolean} + * @private + */ + + }, { + key: "_isObject", + value: function _isObject(obj) { + return obj !== null && _typeof(obj) === 'object' && Array.isArray(obj) === false && Object.prototype.toString.call(obj) === '[object Object]'; } /** * Fix websocket protocols based on options @@ -467,8 +508,19 @@ function () { }, { key: "_validateURI", value: function _validateURI(uri, patternBased, allowWAMP) { - var reBase = /^([0-9a-zA-Z_]+\.)*([0-9a-zA-Z_]+)$/; - var rePattern = /^([0-9a-zA-Z_]+\.{1,2})*([0-9a-zA-Z_]+)$/; + var reBase; + var rePattern; + + if (this._options.uriValidation === 'strict') { + reBase = /^([0-9a-zA-Z_]+\.)*([0-9a-zA-Z_]+)$/; + rePattern = /^([0-9a-zA-Z_]+\.{1,2})*([0-9a-zA-Z_]+)$/; + } else if (this._options.uriValidation === 'loose') { + reBase = /^([^\s.#]+\.)*([^\s.#]+)$/; + rePattern = /^([^\s.#]+\.{1,2})*([^\s.#]+)$/; + } else { + return false; + } + var re = patternBased ? rePattern : reBase; if (allowWAMP) { @@ -622,7 +674,10 @@ function () { if (this._options.serializer.protocol !== serverProtocol) { // Server have chosen not our preferred protocol // Falling back to json if possible - if (serverProtocol === 'json') { + //FIXME Temp hack for React Native Environment. + // Due to bug (facebook/react-native#24796), it doesn't provide selected subprotocol. + // Remove when ^^^ bug will be fixed. + if (serverProtocol === 'json' || typeof navigator != 'undefined' && navigator.product === 'ReactNative' && typeof this._ws.protocol === 'undefined') { this._options.serializer = new _JsonSerializer.JsonSerializer(); } else { this._cache.opStatus = _constants.WAMP_ERROR_MSG.NO_SERIALIZER_AVAILABLE; @@ -746,7 +801,7 @@ function () { p.then(function (key) { // Sending directly 'cause it's a challenge msg and no sessionId check is needed _this3._ws.send(_this3._encode([_constants.WAMP_MSG_SPEC.AUTHENTICATE, key, {}])); - }).catch(function (e) { + })["catch"](function (e) { _this3._ws.send(_this3._encode([_constants.WAMP_MSG_SPEC.ABORT, { message: 'Exception in onChallenge handler raised!' }, 'wamp.error.cannot_authenticate'])); @@ -851,7 +906,8 @@ function () { if (_this3._requests[data[1]]) { _this3._subscriptions[_this3._requests[data[1]].topic] = _this3._subscriptions[data[2]] = { id: data[2], - callbacks: [_this3._requests[data[1]].callbacks.onEvent] + callbacks: [_this3._requests[data[1]].callbacks.onEvent], + advancedOptions: _this3._requests[data[1]].advancedOptions }; _this3._subsTopics.add(_this3._requests[data[1]].topic); @@ -877,7 +933,7 @@ function () { delete _this3._subscriptions[id]; if (_this3._subsTopics.has(_this3._requests[data[1]].topic)) { - _this3._subsTopics.delete(_this3._requests[data[1]].topic); + _this3._subsTopics["delete"](_this3._requests[data[1]].topic); } if (_this3._requests[data[1]].callbacks.onSuccess) { @@ -989,7 +1045,7 @@ function () { delete _this3._rpcRegs[id]; if (_this3._rpcNames.has(_this3._requests[data[1]].topic)) { - _this3._rpcNames.delete(_this3._requests[data[1]].topic); + _this3._rpcNames["delete"](_this3._requests[data[1]].topic); } if (_this3._requests[data[1]].callbacks && _this3._requests[data[1]].callbacks.onSuccess) { @@ -1071,7 +1127,7 @@ function () { }); p.then(function (results) { invoke_result_handler(results); - }).catch(function (e) { + })["catch"](function (e) { invoke_error_handler(e); }); } else { @@ -1158,7 +1214,7 @@ function () { i = subs[topic].callbacks.length; while (i--) { - this.subscribe(topic, subs[topic].callbacks[i]); + this.subscribe(topic, subs[topic].callbacks[i], subs[topic].advancedOptions); } } } catch (err) { @@ -1166,8 +1222,8 @@ function () { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); } } finally { if (_didIteratorError) { @@ -1204,8 +1260,8 @@ function () { _iteratorError2 = err; } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); } } finally { if (_didIteratorError2) { @@ -1397,7 +1453,8 @@ function () { reqId = this._getReqId(); this._requests[reqId] = { topic: topicURI, - callbacks: callbacks + callbacks: callbacks, + advancedOptions: advancedOptions }; // WAMP SPEC: [SUBSCRIBE, Request|id, Options|dict, Topic|uri] this._send([_constants.WAMP_MSG_SPEC.SUBSCRIBE, reqId, options, topicURI]); @@ -2015,5 +2072,5 @@ function () { exports.Wampy = Wampy; var _default = Wampy; -exports.default = _default; +exports["default"] = _default; //# sourceMappingURL=wampy.js.map diff --git a/dist/wampy.js.map b/dist/wampy.js.map index 7195a5d..0cf5b8c 100644 --- a/dist/wampy.js.map +++ b/dist/wampy.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/wampy.js"],"names":["Wampy","url","options","version","_url","_protocols","_wamp_features","agent","roles","publisher","features","subscriber_blackwhite_listing","publisher_exclusion","publisher_identification","subscriber","pattern_based_subscription","publication_trustlevels","caller","caller_identification","progressive_call_results","call_canceling","call_timeout","callee","call_trustlevels","pattern_based_registration","shared_registration","_cache","sessionId","reqId","server_wamp_features","isSayingGoodbye","opStatus","code","description","timer","reconnectingAttempts","_ws","_wsQueue","_requests","_calls","_subscriptions","_subsTopics","Set","_rpcRegs","_rpcNames","_options","debug","autoReconnect","reconnectInterval","maxRetries","realm","helloCustomDetails","authid","authmethods","onChallenge","onConnect","onClose","onError","onReconnect","onReconnectSuccess","ws","additionalHeaders","wsRequestOptions","serializer","JsonSerializer","_isPlainObject","_merge","connect","args","console","log","obj","l","length","i","attr","Array","isArray","constructor","Object","unshift","protocol","topicType","role","callbacks","flag","WAMP_ERROR_MSG","toUpperCase","_validateURI","topic","patternBased","allowWAMP","URI_ERROR","error","uri","reBase","rePattern","re","test","indexOf","msg","encode","e","_hardClose","decode","errorUri","details","_log","_send","WAMP_MSG_SPEC","ABORT","message","close","push","_encode","readyState","send","shift","onopen","_wsOnOpen","onclose","event","_wsOnClose","onmessage","_wsOnMessage","onerror","_wsOnError","serverProtocol","split","NO_SERIALIZER_AVAILABLE","isBinary","binaryType","HELLO","setTimeout","_wsReconnect","_resetState","_decode","data","then","id","p","self","WELCOME","_renewSubscriptions","_renewRegistrations","CHALLENGE","Promise","resolve","reject","key","AUTHENTICATE","catch","CRA_EXCEPTION","NO_CRA_CB_OR_ID","GOODBYE","ERROR","SUBSCRIBE","UNSUBSCRIBE","PUBLISH","REGISTER","UNREGISTER","argsList","argsDict","CALL","SUBSCRIBED","onEvent","add","onSuccess","UNSUBSCRIBED","has","delete","PUBLISHED","EVENT","RESULT","progress","REGISTERED","rpc","UNREGISTERED","INVOCATION","invoke_result_handler","results","YIELD","_isArray","invoke_error_handler","result_handler","error_handler","NON_EXIST_RPC_INVOCATION","err","_initWsCallbacks","subs","st","subscribe","rpcs","rn","rpcName","register","opts","authp","_setWsProtocols","NO_WS_OR_URL","NO_REALM","SUCCESS","topicURI","advancedOptions","hasOwnProperty","match","_preReqChecks","NO_CALLBACK_SPEC","_getReqId","splice","NON_EXIST_UNSUBSCRIBE","payload","hasPayload","_optionsConvertHelper","option","sourceType","acknowledge","exclude_me","disclose_me","INVALID_PARAM","arguments","receive_progress","timeout","NON_EXIST_RPC_REQ_ID","mode","CANCEL","invoke","RPC_ALREADY_REGISTERED","NON_EXIST_RPC_UNREG"],"mappings":";;;;;;;AAgBA;;AACA;;AACA;;;;;;;;;;AAEA;;;IAGMA,K;;;AAEF;;;;;AAKA,iBAAaC,GAAb,EAAkBC,OAAlB,EAA2B;AAAA;;AAEvB;;;;;AAKA,SAAKC,OAAL,GAAe,QAAf;AAEA;;;;;;AAKA,SAAKC,IAAL,GAAa,OAAOH,GAAP,KAAe,QAAhB,GAA4BA,GAA5B,GAAkC,IAA9C;AAEA;;;;;;AAKA,SAAKI,UAAL,GAAkB,CAAC,aAAD,CAAlB;AAEA;;;;;;AAKA,SAAKC,cAAL,GAAsB;AAClBC,MAAAA,KAAK,EAAE,cAAc,KAAKJ,OADR;AAElBK,MAAAA,KAAK,EAAE;AACHC,QAAAA,SAAS,EAAE;AACPC,UAAAA,QAAQ,EAAE;AACNC,YAAAA,6BAA6B,EAAE,IADzB;AAENC,YAAAA,mBAAmB,EAAE,IAFf;AAGNC,YAAAA,wBAAwB,EAAE;AAHpB;AADH,SADR;AAQHC,QAAAA,UAAU,EAAE;AACRJ,UAAAA,QAAQ,EAAE;AACNK,YAAAA,0BAA0B,EAAE,IADtB;AAENC,YAAAA,uBAAuB,EAAE;AAFnB;AADF,SART;AAcHC,QAAAA,MAAM,EAAE;AACJP,UAAAA,QAAQ,EAAE;AACNQ,YAAAA,qBAAqB,EAAE,IADjB;AAENC,YAAAA,wBAAwB,EAAE,IAFpB;AAGNC,YAAAA,cAAc,EAAE,IAHV;AAINC,YAAAA,YAAY,EAAE;AAJR;AADN,SAdL;AAsBHC,QAAAA,MAAM,EAAE;AACJZ,UAAAA,QAAQ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K,EAAEiH,QADa;AAEpBtH,UAAAA,SAAS,EAATA;AAFoB,SAAxB,CAJyB,CASzB;;AACA,aAAKwB,KAAL,CAAW,CAACC,yBAAcmD,UAAf,EAA2BpI,KAA3B,EAAkC,KAAKe,QAAL,CAAc+J,QAAd,EAAwB/D,EAA1D,CAAX;;AACA,aAAKjH,MAAL,CAAYK,QAAZ,GAAuBuD,0BAAemH,OAAtC;AACA,aAAK/K,MAAL,CAAYK,QAAZ,CAAqBH,KAArB,GAA6BA,KAA7B;AACH,OAbD,MAaO;AAAK;AACR,aAAKF,MAAL,CAAYK,QAAZ,GAAuBuD,0BAAe8I,mBAAtC;;AAEA,YAAI,KAAKnK,cAAL,CAAoBmB,SAApB,KAAkCA,SAAS,CAAC3B,OAAhD,EAAyD;AACrD2B,UAAAA,SAAS,CAAC3B,OAAV,CAAkB;AAAEoC,YAAAA,KAAK,EAAE,KAAKnE,MAAL,CAAYK,QAAZ,CAAqBE;AAA9B,WAAlB;AACH;AAEJ;;AAED,aAAO,IAAP;AACH;;;;;;;eAGUjC,K","sourcesContent":["/**\n * Project: wampy.js\n *\n * https://github.com/KSDaemon/wampy.js\n *\n * A lightweight client-side implementation of\n * WAMP (The WebSocket Application Messaging Protocol v2)\n * http://wamp.ws\n *\n * Provides asynchronous RPC/PubSub over WebSocket.\n *\n * Copyright 2014 KSDaemon. Licensed under the MIT License.\n * See @license text at http://www.opensource.org/licenses/mit-license.php\n *\n */\n\nimport { WAMP_MSG_SPEC, WAMP_ERROR_MSG } from './constants';\nimport { getWebSocket } from './utils';\nimport { JsonSerializer } from './serializers/JsonSerializer';\n\n/**\n * WAMP Client Class\n */\nclass Wampy {\n\n /**\n * Wampy constructor\n * @param {string} [url]\n * @param {Object} [options]\n */\n constructor (url, options) {\n\n /**\n * Wampy version\n * @type {string}\n * @private\n */\n this.version = 'v6.2.1';\n\n /**\n * WS Url\n * @type {string}\n * @private\n */\n this._url = (typeof url === 'string') ? url : null;\n\n /**\n * WS protocols\n * @type {Array}\n * @private\n */\n this._protocols = ['wamp.2.json'];\n\n /**\n * WAMP features, supported by Wampy\n * @type {object}\n * @private\n */\n this._wamp_features = {\n agent: 'Wampy.js ' + this.version,\n roles: {\n publisher: {\n features: {\n subscriber_blackwhite_listing: true,\n publisher_exclusion: true,\n publisher_identification: true\n }\n },\n subscriber: {\n features: {\n pattern_based_subscription: true,\n publication_trustlevels: true\n }\n },\n caller: {\n features: {\n caller_identification: true,\n progressive_call_results: true,\n call_canceling: true,\n call_timeout: true\n }\n },\n callee: {\n features: {\n caller_identification: true,\n call_trustlevels: true,\n pattern_based_registration: true,\n shared_registration: true\n }\n }\n }\n };\n\n /**\n * Internal cache for object lifetime\n * @type {Object}\n * @private\n */\n this._cache = {\n /**\n * WAMP Session ID\n * @type {string}\n */\n sessionId: null,\n\n /**\n * WAMP Session scope requests ID\n * @type {int}\n */\n reqId: 0,\n\n /**\n * Server WAMP roles and features\n */\n server_wamp_features: { roles: {} },\n\n /**\n * Are we in state of saying goodbye\n * @type {boolean}\n */\n isSayingGoodbye: false,\n\n /**\n * Status of last operation\n */\n opStatus: { code: 0, description: 'Success!', reqId: 0 },\n\n /**\n * Timer for reconnection\n * @type {null}\n */\n timer: null,\n\n /**\n * Reconnection attempts\n * @type {number}\n */\n reconnectingAttempts: 0\n };\n\n /**\n * WebSocket object\n * @type {Object}\n * @private\n */\n this._ws = null;\n\n /**\n * Internal queue for websocket requests, for case of disconnect\n * @type {Array}\n * @private\n */\n this._wsQueue = [];\n\n /**\n * Internal queue for wamp requests\n * @type {object}\n * @private\n */\n this._requests = {};\n\n /**\n * Stored RPC\n * @type {object}\n * @private\n */\n this._calls = {};\n\n /**\n * Stored Pub/Sub\n * @type {object}\n * @private\n */\n this._subscriptions = {};\n\n /**\n * Stored Pub/Sub topics\n * @type {Array}\n * @private\n */\n this._subsTopics = new Set();\n\n /**\n * Stored RPC Registrations\n * @type {object}\n * @private\n */\n this._rpcRegs = {};\n\n /**\n * Stored RPC names\n * @type {Array}\n * @private\n */\n this._rpcNames = new Set();\n\n /**\n * Options hash-table\n * @type {Object}\n * @private\n */\n this._options = {\n /**\n * Logging\n * @type {boolean}\n */\n debug: false,\n\n /**\n * Reconnecting flag\n * @type {boolean}\n */\n autoReconnect: true,\n\n /**\n * Reconnecting interval (in ms)\n * @type {number}\n */\n reconnectInterval: 2 * 1000,\n\n /**\n * Maximum reconnection retries\n * @type {number}\n */\n maxRetries: 25,\n\n /**\n * WAMP Realm to join\n * @type {string}\n */\n realm: null,\n\n /**\n * Custom attributes to send to router on hello\n * @type {object}\n */\n helloCustomDetails: null,\n\n /**\n * Authentication id to use in challenge\n * @type {string}\n */\n authid: null,\n\n /**\n * Supported authentication methods\n * @type {array}\n */\n authmethods: [],\n\n /**\n * onChallenge callback\n * @type {function}\n */\n onChallenge: null,\n\n /**\n * onConnect callback\n * @type {function}\n */\n onConnect: null,\n\n /**\n * onClose callback\n * @type {function}\n */\n onClose: null,\n\n /**\n * onError callback\n * @type {function}\n */\n onError: null,\n\n /**\n * onReconnect callback\n * @type {function}\n */\n onReconnect: null,\n\n /**\n * onReconnectSuccess callback\n * @type {function}\n */\n onReconnectSuccess: null,\n\n /**\n * User provided WebSocket class\n * @type {function}\n */\n ws: null,\n\n /**\n * User provided additional HTTP headers (for use in Node.js enviroment)\n * @type {object}\n */\n additionalHeaders: null,\n\n /**\n * User provided WS Client Config Options (for use in Node.js enviroment)\n * @type {object}\n */\n wsRequestOptions: null,\n\n /**\n * User provided msgpack class\n * @type {object}\n */\n serializer: new JsonSerializer()\n };\n\n if (this._isPlainObject(options)) {\n this._options = this._merge(this._options, options);\n } else if (this._isPlainObject(url)) {\n this._options = this._merge(this._options, url);\n }\n\n if (this._url) {\n this.connect();\n }\n\n }\n\n /* Internal utils methods */\n /**\n * Internal logger\n * @private\n */\n _log (...args) {\n if (this._options.debug) {\n console.log(args);\n }\n }\n\n /**\n * Get the new unique request id\n * @returns {number}\n * @private\n */\n _getReqId () {\n return ++this._cache.reqId;\n }\n\n /**\n * Merge argument objects into one\n * @returns {Object}\n * @private\n */\n _merge (...args) {\n const obj = {}, l = args.length;\n let i, attr;\n\n for (i = 0; i < l; i++) {\n for (attr in args[i]) {\n obj[attr] = args[i][attr];\n }\n }\n\n return obj;\n }\n\n /**\n * Check if value is array\n * @param obj\n * @returns {boolean}\n * @private\n */\n _isArray (obj) {\n return (!!obj) && (Array.isArray(obj));\n }\n\n /**\n * Check if value is object literal\n * @param obj\n * @returns {boolean}\n * @private\n */\n _isPlainObject (obj) {\n return (!!obj) && (obj.constructor === Object);\n }\n\n /**\n * Fix websocket protocols based on options\n * @private\n */\n _setWsProtocols () {\n if (!(this._options.serializer instanceof JsonSerializer)) {\n this._protocols.unshift('wamp.2.' + this._options.serializer.protocol);\n }\n }\n\n /**\n * Prerequisite checks for any wampy api call\n * @param {object} topicType { topic: URI, patternBased: true|false, allowWAMP: true|false }\n * @param {string} role\n * @param {object} callbacks\n * @returns {boolean}\n * @private\n */\n _preReqChecks (topicType, role, callbacks) {\n let flag = true;\n\n if (this._cache.sessionId && !this._cache.server_wamp_features.roles[role]) {\n this._cache.opStatus = WAMP_ERROR_MSG['NO_' + role.toUpperCase()];\n flag = false;\n }\n\n if (topicType && !this._validateURI(topicType.topic, topicType.patternBased, topicType.allowWAMP)) {\n this._cache.opStatus = WAMP_ERROR_MSG.URI_ERROR;\n flag = false;\n }\n\n if (flag) {\n return true;\n }\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return false;\n }\n\n /**\n * Validate uri\n * @param {string} uri\n * @param {boolean} patternBased\n * @param {boolean} allowWAMP\n * @returns {boolean}\n * @private\n */\n _validateURI (uri, patternBased, allowWAMP) {\n const reBase = /^([0-9a-zA-Z_]+\\.)*([0-9a-zA-Z_]+)$/;\n const rePattern = /^([0-9a-zA-Z_]+\\.{1,2})*([0-9a-zA-Z_]+)$/;\n const re = patternBased ? rePattern : reBase;\n\n if (allowWAMP) {\n return re.test(uri);\n } else {\n return !(!re.test(uri) || uri.indexOf('wamp.') === 0);\n }\n }\n\n /**\n * Encode WAMP message\n * @param {Array} msg\n * @returns {*}\n * @private\n */\n _encode (msg) {\n try {\n return this._options.serializer.encode(msg);\n } catch (e) {\n this._hardClose('wamp.error.protocol_violation', 'Can not encode message');\n }\n }\n\n /**\n * Decode WAMP message\n * @param msg\n * @returns {Promise}\n * @private\n */\n _decode (msg) {\n return this._options.serializer.decode(msg);\n }\n\n /**\n * Hard close of connection due to protocol violations\n * @param {string} errorUri\n * @param {string} details\n * @private\n */\n _hardClose (errorUri, details) {\n this._log('[wampy] ' + details);\n // Cleanup outgoing message queue\n this._wsQueue = [];\n this._send([WAMP_MSG_SPEC.ABORT, { message: details }, errorUri]);\n\n if (this._options.onError) {\n this._options.onError({ error: errorUri, details: details });\n }\n this._ws.close();\n }\n\n /**\n * Send encoded message to server\n * @param {Array} msg\n * @private\n */\n _send (msg) {\n if (msg) {\n this._wsQueue.push(this._encode(msg));\n }\n\n if (this._ws && this._ws.readyState === 1 && this._cache.sessionId) {\n while (this._wsQueue.length) {\n this._ws.send(this._wsQueue.shift());\n }\n }\n }\n\n /**\n * Reset internal state and cache\n * @private\n */\n _resetState () {\n this._wsQueue = [];\n this._subscriptions = {};\n this._subsTopics = new Set();\n this._requests = {};\n this._calls = {};\n this._rpcRegs = {};\n this._rpcNames = new Set();\n\n // Just keep attrs that are have to be present\n this._cache = {\n reqId: 0,\n reconnectingAttempts: 0\n };\n }\n\n /**\n * Initialize internal websocket callbacks\n * @private\n */\n _initWsCallbacks () {\n if (this._ws) {\n this._ws.onopen = () => {\n this._wsOnOpen();\n };\n this._ws.onclose = event => {\n this._wsOnClose(event);\n };\n this._ws.onmessage = event => {\n this._wsOnMessage(event);\n };\n this._ws.onerror = error => {\n this._wsOnError(error);\n };\n }\n }\n\n /**\n * Internal websocket on open callback\n * @private\n */\n _wsOnOpen () {\n const options = this._merge(this._options.helloCustomDetails, this._wamp_features),\n serverProtocol = this._ws.protocol ? this._ws.protocol.split('.')[2] : '';\n\n if (this._options.authid) {\n options.authmethods = this._options.authmethods;\n options.authid = this._options.authid;\n }\n\n this._log('[wampy] websocket connected');\n\n if (this._options.serializer.protocol !== serverProtocol) {\n // Server have chosen not our preferred protocol\n\n // Falling back to json if possible\n if (serverProtocol === 'json') {\n this._options.serializer = new JsonSerializer();\n } else {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_SERIALIZER_AVAILABLE;\n return this;\n }\n\n }\n\n if (this._options.serializer.isBinary) {\n this._ws.binaryType = 'arraybuffer';\n }\n\n // WAMP SPEC: [HELLO, Realm|uri, Details|dict]\n // Sending directly 'cause it's a hello msg and no sessionId check is needed\n this._ws.send(this._encode([WAMP_MSG_SPEC.HELLO, this._options.realm, options]));\n }\n\n /**\n * Internal websocket on close callback\n * @param {object} event\n * @private\n */\n _wsOnClose (event) {\n this._log('[wampy] websocket disconnected. Info: ', event);\n\n // Automatic reconnection\n if ((this._cache.sessionId || this._cache.reconnectingAttempts) &&\n this._options.autoReconnect && this._cache.reconnectingAttempts < this._options.maxRetries && !this._cache.isSayingGoodbye) {\n this._cache.sessionId = null;\n this._cache.timer = setTimeout(() => { this._wsReconnect(); }, this._options.reconnectInterval);\n } else {\n // No reconnection needed or reached max retries count\n if (this._options.onClose) {\n this._options.onClose();\n }\n\n this._resetState();\n this._ws = null;\n }\n }\n\n /**\n * Internal websocket on event callback\n * @param {object} event\n * @private\n */\n _wsOnMessage (event) {\n this._decode(event.data).then(data => {\n\n this._log('[wampy] websocket message received: ', data);\n\n let id, i, p, self = this;\n\n switch (data[0]) {\n case WAMP_MSG_SPEC.WELCOME:\n // WAMP SPEC: [WELCOME, Session|id, Details|dict]\n if (this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received WELCOME message after session was established');\n } else {\n this._cache.sessionId = data[1];\n this._cache.server_wamp_features = data[2];\n\n if (this._cache.reconnectingAttempts) {\n // There was reconnection\n\n this._cache.reconnectingAttempts = 0;\n\n if (this._options.onReconnectSuccess) {\n this._options.onReconnectSuccess(data[2]);\n }\n\n // Let's renew all previous state\n this._renewSubscriptions();\n this._renewRegistrations();\n\n } else {\n // Firing onConnect event on real connection to WAMP server\n if (this._options.onConnect) {\n this._options.onConnect(data[2]);\n }\n }\n\n // Send local queue if there is something out there\n this._send();\n }\n break;\n case WAMP_MSG_SPEC.ABORT:\n // WAMP SPEC: [ABORT, Details|dict, Reason|uri]\n if (this._options.onError) {\n this._options.onError({ error: data[2], details: data[1] });\n }\n this._ws.close();\n break;\n case WAMP_MSG_SPEC.CHALLENGE:\n // WAMP SPEC: [CHALLENGE, AuthMethod|string, Extra|dict]\n if (this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received CHALLENGE message after session was established');\n } else {\n if (this._options.authid && typeof this._options.onChallenge === 'function') {\n\n p = new Promise((resolve, reject) => {\n resolve(this._options.onChallenge(data[1], data[2]));\n });\n\n p.then((key) => {\n\n // Sending directly 'cause it's a challenge msg and no sessionId check is needed\n this._ws.send(this._encode([WAMP_MSG_SPEC.AUTHENTICATE, key, {}]));\n\n }).catch(e => {\n this._ws.send(this._encode([\n WAMP_MSG_SPEC.ABORT,\n { message: 'Exception in onChallenge handler raised!' },\n 'wamp.error.cannot_authenticate'\n ]));\n if (this._options.onError) {\n this._options.onError({ error: WAMP_ERROR_MSG.CRA_EXCEPTION.description });\n }\n this._ws.close();\n this._cache.opStatus = WAMP_ERROR_MSG.CRA_EXCEPTION;\n });\n\n } else {\n\n this._ws.send(this._encode([\n WAMP_MSG_SPEC.ABORT,\n { message: WAMP_ERROR_MSG.NO_CRA_CB_OR_ID.description },\n 'wamp.error.cannot_authenticate'\n ]));\n if (this._options.onError) {\n this._options.onError({ error: WAMP_ERROR_MSG.NO_CRA_CB_OR_ID.description });\n }\n this._ws.close();\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CRA_CB_OR_ID;\n\n }\n }\n break;\n case WAMP_MSG_SPEC.GOODBYE:\n // WAMP SPEC: [GOODBYE, Details|dict, Reason|uri]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received GOODBYE message before session was established');\n } else {\n if (!this._cache.isSayingGoodbye) { // get goodbye, initiated by server\n this._cache.isSayingGoodbye = true;\n this._send([WAMP_MSG_SPEC.GOODBYE, {}, 'wamp.close.goodbye_and_out']);\n }\n this._cache.sessionId = null;\n this._ws.close();\n }\n break;\n case WAMP_MSG_SPEC.ERROR:\n // WAMP SPEC: [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict,\n // Error|uri, (Arguments|list, ArgumentsKw|dict)]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received ERROR message before session was established');\n } else {\n switch (data[1]) {\n case WAMP_MSG_SPEC.SUBSCRIBE:\n case WAMP_MSG_SPEC.UNSUBSCRIBE:\n case WAMP_MSG_SPEC.PUBLISH:\n case WAMP_MSG_SPEC.REGISTER:\n case WAMP_MSG_SPEC.UNREGISTER:\n\n this._requests[data[2]] && this._requests[data[2]].callbacks.onError &&\n this._requests[data[2]].callbacks.onError({\n error: data[4],\n details: data[3],\n argsList: data[5],\n argsDict: data[6]\n });\n delete this._requests[data[2]];\n\n break;\n // case WAMP_MSG_SPEC.INVOCATION:\n // break;\n case WAMP_MSG_SPEC.CALL:\n\n // WAMP SPEC: [ERROR, CALL, CALL.Request|id, Details|dict,\n // Error|uri, Arguments|list, ArgumentsKw|dict]\n this._calls[data[2]] && this._calls[data[2]].onError &&\n this._calls[data[2]].onError({\n error: data[4],\n details: data[3],\n argsList: data[5],\n argsDict: data[6]\n });\n delete this._calls[data[2]];\n\n break;\n default:\n this._hardClose('wamp.error.protocol_violation', 'Received invalid ERROR message');\n break;\n }\n }\n break;\n case WAMP_MSG_SPEC.SUBSCRIBED:\n // WAMP SPEC: [SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received SUBSCRIBED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n this._subscriptions[this._requests[data[1]].topic] = this._subscriptions[data[2]] = {\n id: data[2],\n callbacks: [this._requests[data[1]].callbacks.onEvent]\n };\n\n this._subsTopics.add(this._requests[data[1]].topic);\n\n if (this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n\n }\n }\n break;\n case WAMP_MSG_SPEC.UNSUBSCRIBED:\n // WAMP SPEC: [UNSUBSCRIBED, UNSUBSCRIBE.Request|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received UNSUBSCRIBED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n id = this._subscriptions[this._requests[data[1]].topic].id;\n delete this._subscriptions[this._requests[data[1]].topic];\n delete this._subscriptions[id];\n\n if (this._subsTopics.has(this._requests[data[1]].topic)) {\n this._subsTopics.delete(this._requests[data[1]].topic);\n }\n\n if (this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n case WAMP_MSG_SPEC.PUBLISHED:\n // WAMP SPEC: [PUBLISHED, PUBLISH.Request|id, Publication|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received PUBLISHED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n if (this._requests[data[1]].callbacks && this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n case WAMP_MSG_SPEC.EVENT:\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received EVENT message before session was established');\n } else {\n if (this._subscriptions[data[1]]) {\n\n // WAMP SPEC: [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id,\n // Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentKw|dict]\n\n i = this._subscriptions[data[1]].callbacks.length;\n while (i--) {\n this._subscriptions[data[1]].callbacks[i]({\n details: data[3],\n argsList: data[4],\n argsDict: data[5]\n });\n }\n }\n }\n break;\n case WAMP_MSG_SPEC.RESULT:\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received RESULT message before session was established');\n } else {\n if (this._calls[data[1]]) {\n\n // WAMP SPEC: [RESULT, CALL.Request|id, Details|dict,\n // YIELD.Arguments|list, YIELD.ArgumentsKw|dict]\n\n this._calls[data[1]].onSuccess({\n details: data[2],\n argsList: data[3],\n argsDict: data[4]\n });\n if (!(data[2].progress && data[2].progress === true)) {\n // We receive final result (progressive or not)\n delete this._calls[data[1]];\n }\n }\n }\n break;\n // case WAMP_MSG_SPEC.REGISTER:\n // // WAMP SPEC:\n // break;\n case WAMP_MSG_SPEC.REGISTERED:\n // WAMP SPEC: [REGISTERED, REGISTER.Request|id, Registration|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received REGISTERED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n this._rpcRegs[this._requests[data[1]].topic] = this._rpcRegs[data[2]] = {\n id: data[2],\n callbacks: [this._requests[data[1]].callbacks.rpc]\n };\n\n this._rpcNames.add(this._requests[data[1]].topic);\n\n if (this._requests[data[1]].callbacks && this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n // case WAMP_MSG_SPEC.UNREGISTER:\n // // WAMP SPEC:\n // break;\n case WAMP_MSG_SPEC.UNREGISTERED:\n // WAMP SPEC: [UNREGISTERED, UNREGISTER.Request|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received UNREGISTERED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n id = this._rpcRegs[this._requests[data[1]].topic].id;\n delete this._rpcRegs[this._requests[data[1]].topic];\n delete this._rpcRegs[id];\n\n if (this._rpcNames.has(this._requests[data[1]].topic)) {\n this._rpcNames.delete(this._requests[data[1]].topic);\n }\n\n if (this._requests[data[1]].callbacks && this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n case WAMP_MSG_SPEC.INVOCATION:\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received INVOCATION message before session was established');\n } else {\n if (this._rpcRegs[data[2]]) {\n\n // WAMP SPEC: [INVOCATION, Request|id, REGISTERED.Registration|id,\n // Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict]\n\n let invoke_result_handler = results => {\n // WAMP SPEC: [YIELD, INVOCATION.Request|id, Options|dict, (Arguments|list,\n // ArgumentsKw|dict)]\n let msg = [WAMP_MSG_SPEC.YIELD, data[1], {}];\n\n if (self._isPlainObject(results)) {\n\n if (self._isPlainObject(results.options)) {\n msg[2] = results.options;\n }\n\n if (self._isArray(results.argsList)) {\n msg.push(results.argsList);\n } else if (typeof (results.argsList) !== 'undefined') {\n msg.push([results.argsList]);\n }\n\n if (self._isPlainObject(results.argsDict)) {\n if (msg.length === 3) {\n msg.push([]);\n }\n msg.push(results.argsDict);\n }\n } else {\n msg = [WAMP_MSG_SPEC.YIELD, data[1], {}];\n }\n self._send(msg);\n },\n invoke_error_handler = ({ details, error, argsList, argsDict }) => {\n let msg = [WAMP_MSG_SPEC.ERROR, WAMP_MSG_SPEC.INVOCATION,\n data[1], details || {}, error || 'wamp.error.invocation_exception'];\n\n if (argsList && self._isArray(argsList)) {\n msg.push(argsList);\n }\n\n if (argsDict && self._isPlainObject(argsDict)) {\n if (msg.length === 5) {\n msg.push([]);\n }\n msg.push(argsDict);\n }\n self._send(msg);\n };\n\n p = new Promise((resolve, reject) => {\n resolve(this._rpcRegs[data[2]].callbacks[0]({\n details : data[3],\n argsList : data[4],\n argsDict : data[5],\n result_handler: invoke_result_handler,\n error_handler : invoke_error_handler\n }));\n });\n\n p.then((results) => {\n invoke_result_handler(results);\n }).catch(e => {\n invoke_error_handler(e);\n });\n\n } else {\n // WAMP SPEC: [ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri]\n this._send([WAMP_MSG_SPEC.ERROR, WAMP_MSG_SPEC.INVOCATION,\n data[1], {}, 'wamp.error.no_such_procedure']);\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_RPC_INVOCATION;\n }\n }\n break;\n // case WAMP_MSG_SPEC.INTERRUPT:\n // // WAMP SPEC:\n // break;\n // case WAMP_MSG_SPEC.YIELD:\n // // WAMP SPEC:\n // break;\n default:\n this._hardClose('wamp.error.protocol_violation', 'Received non-compliant WAMP message');\n break;\n }\n }, err => {\n this._hardClose('wamp.error.protocol_violation', 'Can not decode received message');\n });\n }\n\n /**\n * Internal websocket on error callback\n * @param {object} error\n * @private\n */\n _wsOnError (error) {\n this._log('[wampy] websocket error');\n\n if (this._options.onError) {\n this._options.onError({ error });\n }\n }\n\n /**\n * Reconnect to server in case of websocket error\n * @private\n */\n _wsReconnect () {\n this._log('[wampy] websocket reconnecting...');\n\n if (this._options.onReconnect) {\n this._options.onReconnect();\n }\n\n this._cache.reconnectingAttempts++;\n this._ws = getWebSocket(this._url, this._protocols, this._options.ws,\n this._options.additionalHeaders, this._options.wsRequestOptions);\n this._initWsCallbacks();\n }\n\n /**\n * Resubscribe to topics in case of communication error\n * @private\n */\n _renewSubscriptions () {\n let i;\n const subs = this._subscriptions,\n st = this._subsTopics;\n\n this._subscriptions = {};\n this._subsTopics = new Set();\n\n for (let topic of st) {\n i = subs[topic].callbacks.length;\n while (i--) {\n this.subscribe(topic, subs[topic].callbacks[i]);\n }\n }\n }\n\n /**\n * Reregister RPCs in case of communication error\n * @private\n */\n _renewRegistrations () {\n const rpcs = this._rpcRegs,\n rn = this._rpcNames;\n\n this._rpcRegs = {};\n this._rpcNames = new Set();\n\n for (let rpcName of rn) {\n this.register(rpcName, { rpc: rpcs[rpcName].callbacks[0] });\n }\n }\n\n /* Wampy public API */\n\n /**\n * Get or set Wampy options\n *\n * To get options - call without parameters\n * To set options - pass hash-table with options values\n *\n * @param {object} [opts]\n * @returns {*}\n */\n options (opts) {\n if (typeof (opts) === 'undefined') {\n return this._options;\n } else if (this._isPlainObject(opts)) {\n this._options = this._merge(this._options, opts);\n return this;\n }\n }\n\n /**\n * Get the status of last operation\n *\n * @returns {object} with 2 fields: code, description\n * code: 0 - if operation was successful\n * code > 0 - if error occurred\n * description contains details about error\n * reqId: last send request ID\n */\n getOpStatus () {\n return this._cache.opStatus;\n }\n\n /**\n * Get the WAMP Session ID\n *\n * @returns {string} Session ID\n */\n getSessionId () {\n return this._cache.sessionId;\n }\n\n /**\n * Connect to server\n * @param {string} [url] New url (optional)\n * @returns {Wampy}\n */\n connect (url) {\n if (url) {\n this._url = url;\n }\n\n if (this._options.realm) {\n\n const authp = (this._options.authid ? 1 : 0) +\n ((this._isArray(this._options.authmethods) && this._options.authmethods.length) ? 1 : 0) +\n (typeof this._options.onChallenge === 'function' ? 1 : 0);\n\n if (authp > 0 && authp < 3) {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CRA_CB_OR_ID;\n return this;\n }\n\n this._setWsProtocols();\n this._ws = getWebSocket(this._url, this._protocols, this._options.ws,\n this._options.additionalHeaders, this._options.wsRequestOptions);\n if (!this._ws) {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_WS_OR_URL;\n return this;\n }\n this._initWsCallbacks();\n\n } else {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_REALM;\n }\n\n return this;\n }\n\n /**\n * Disconnect from server\n * @returns {Wampy}\n */\n disconnect () {\n if (this._cache.sessionId) {\n // need to send goodbye message to server\n this._cache.isSayingGoodbye = true;\n this._send([WAMP_MSG_SPEC.GOODBYE, {}, 'wamp.close.system_shutdown']);\n } else if (this._ws) {\n this._ws.close();\n }\n\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n\n return this;\n }\n\n /**\n * Abort WAMP session establishment\n *\n * @returns {Wampy}\n */\n abort () {\n\n if (!this._cache.sessionId && this._ws.readyState === 1) {\n this._send([WAMP_MSG_SPEC.ABORT, {}, 'wamp.error.abort']);\n this._cache.sessionId = null;\n }\n\n this._ws.close();\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n\n return this;\n }\n\n /**\n * Subscribe to a topic on a broker\n *\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function - it will be treated as published event callback\n * or it can be hash table of callbacks:\n * { onSuccess: will be called when subscribe would be confirmed\n * onError: will be called if subscribe would be aborted\n * onEvent: will be called on receiving published event }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { match: string matching policy (\"prefix\"|\"wildcard\") }\n *\n * @returns {Wampy}\n */\n subscribe (topicURI, callbacks, advancedOptions) {\n let reqId, patternBased = false;\n const options = {};\n\n if ((typeof (advancedOptions) !== 'undefined') &&\n (this._isPlainObject(advancedOptions)) &&\n (advancedOptions.hasOwnProperty('match'))) {\n\n if (/prefix|wildcard/.test(advancedOptions.match)) {\n options.match = advancedOptions.match;\n patternBased = true;\n }\n }\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: patternBased, allowWAMP: true }, 'broker', callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { onEvent: callbacks };\n } else if (!this._isPlainObject(callbacks) || typeof (callbacks.onEvent) === 'undefined') {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (!this._subscriptions[topicURI] || !this._subscriptions[topicURI].callbacks.length) {\n // no such subscription or processing unsubscribing\n\n reqId = this._getReqId();\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP SPEC: [SUBSCRIBE, Request|id, Options|dict, Topic|uri]\n this._send([WAMP_MSG_SPEC.SUBSCRIBE, reqId, options, topicURI]);\n\n } else { // already have subscription to this topic\n // There is no such callback yet\n if (this._subscriptions[topicURI].callbacks.indexOf(callbacks.onEvent) < 0) {\n this._subscriptions[topicURI].callbacks.push(callbacks.onEvent);\n }\n\n if (callbacks.onSuccess) {\n callbacks.onSuccess();\n }\n }\n\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * Unsubscribe from topic\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function - it will be treated as\n * published event callback to remove or it can be hash table of callbacks:\n * { onSuccess: will be called when unsubscribe would be confirmed\n * onError: will be called if unsubscribe would be aborted\n * onEvent: published event callback to remove }\n * @returns {Wampy}\n */\n unsubscribe (topicURI, callbacks) {\n let reqId, i = -1;\n\n if (!this._preReqChecks(null, 'broker', callbacks)) {\n return this;\n }\n\n if (this._subscriptions[topicURI]) {\n\n reqId = this._getReqId();\n\n if (typeof (callbacks) === 'undefined') {\n this._subscriptions[topicURI].callbacks = [];\n callbacks = {};\n } else if (typeof callbacks === 'function') {\n i = this._subscriptions[topicURI].callbacks.indexOf(callbacks);\n callbacks = {};\n } else if (callbacks.onEvent && typeof callbacks.onEvent === 'function') {\n i = this._subscriptions[topicURI].callbacks.indexOf(callbacks.onEvent);\n } else {\n this._subscriptions[topicURI].callbacks = [];\n }\n\n if (i >= 0) {\n this._subscriptions[topicURI].callbacks.splice(i, 1);\n }\n\n if (this._subscriptions[topicURI].callbacks.length) {\n // There are another callbacks for this topic\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n return this;\n }\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP_SPEC: [UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]\n this._send([WAMP_MSG_SPEC.UNSUBSCRIBE, reqId, this._subscriptions[topicURI].id]);\n\n } else {\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_UNSUBSCRIBE;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * Publish a event to topic\n * @param {string} topicURI\n * @param {string|number|Array|object} payload - can be either a value of any type or null. Also it\n * is possible to pass array and object-like data simultaneously.\n * In this case pass a hash-table with next attributes:\n * {\n * argsList: array payload (may be omitted)\n * argsDict: object payload (may be omitted)\n * }\n * @param {object} [callbacks] - optional hash table of callbacks:\n * { onSuccess: will be called when publishing would be confirmed\n * onError: will be called if publishing would be aborted }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { exclude: integer|array WAMP session id(s) that won't receive a published event,\n * even though they may be subscribed\n * exclude_authid: string|array Authentication id(s) that won't receive\n * a published event, even though they may be subscribed\n * exclude_authrole: string|array Authentication role(s) that won't receive\n * a published event, even though they may be subscribed\n * eligible: integer|array WAMP session id(s) that are allowed\n * to receive a published event\n * eligible_authid: string|array Authentication id(s) that are allowed\n * to receive a published event\n * eligible_authrole: string|array Authentication role(s) that are allowed\n * to receive a published event\n * exclude_me: bool flag of receiving publishing event by initiator\n * disclose_me: bool flag of disclosure of publisher identity (its WAMP session ID)\n * to receivers of a published event }\n * @returns {Wampy}\n */\n publish (topicURI, payload, callbacks, advancedOptions) {\n let reqId, msg, err = false, hasPayload = false;\n const options = {},\n _optionsConvertHelper = (option, sourceType) => {\n if (advancedOptions[option]) {\n if (this._isArray(advancedOptions[option]) && advancedOptions[option].length) {\n options[option] = advancedOptions[option];\n } else if (typeof advancedOptions[option] === sourceType) {\n options[option] = [advancedOptions[option]];\n } else {\n err = true;\n }\n }\n };\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: false }, 'broker', callbacks)) {\n return this;\n }\n\n if (this._isPlainObject(callbacks)) {\n options.acknowledge = true;\n }\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n _optionsConvertHelper('exclude', 'number');\n _optionsConvertHelper('exclude_authid', 'string');\n _optionsConvertHelper('exclude_authrole', 'string');\n _optionsConvertHelper('eligible', 'number');\n _optionsConvertHelper('eligible_authid', 'string');\n _optionsConvertHelper('eligible_authrole', 'string');\n\n if (advancedOptions.hasOwnProperty('exclude_me')) {\n options.exclude_me = advancedOptions.exclude_me !== false;\n }\n\n if (advancedOptions.hasOwnProperty('disclose_me')) {\n options.disclose_me = advancedOptions.disclose_me === true;\n }\n\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n reqId = this._getReqId();\n\n switch (arguments.length) {\n case 1:\n break;\n case 2:\n hasPayload = true;\n break;\n default:\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n hasPayload = true;\n break;\n }\n\n // WAMP_SPEC: [PUBLISH, Request|id, Options|dict, Topic|uri]\n msg = [WAMP_MSG_SPEC.PUBLISH, reqId, options, topicURI];\n\n if (hasPayload) {\n // WAMP_SPEC: [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list (, ArgumentsKw|dict)]\n if (this._isArray(payload)) {\n msg.push(payload);\n } else if (this._isPlainObject(payload)) {\n // It's a wampy unified form of payload passing\n if (payload.argsList || payload.argsDict) {\n if (payload.argsList) {\n msg.push(payload.argsList);\n }\n\n if (payload.argsDict) {\n if (msg.length === 4) {\n msg.push([]);\n }\n msg.push(payload.argsDict);\n }\n } else {\n msg.push([], payload);\n }\n } else { // assume it's a single value\n msg.push([payload]);\n }\n }\n\n this._send(msg);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * Remote Procedure Call\n * @param {string} topicURI\n * @param {string|number|Array|object} payload - can be either a value of any type or null. Also it\n * is possible to pass array and object-like data simultaneously.\n * In this case pass a hash-table with next attributes:\n * {\n * argsList: array payload (may be omitted)\n * argsDict: object payload (may be omitted)\n * }\n * @param {function|object} callbacks - if it is a function - it will be treated as result callback function\n * or it can be hash table of callbacks:\n * { onSuccess: will be called with result on successful call\n * onError: will be called if invocation would be aborted }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { disclose_me: bool flag of disclosure of Caller identity (WAMP session ID)\n * to endpoints of a routed call\n * receive_progress: bool flag for receiving progressive results. In this case\n * onSuccess function will be called every time on receiving result\n * timeout: integer timeout (in ms) for the call to finish }\n * @returns {Wampy}\n */\n call (topicURI, payload, callbacks, advancedOptions) {\n let reqId, msg, err = false;\n const options = {};\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: true }, 'dealer', callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { onSuccess: callbacks };\n } else if (!this._isPlainObject(callbacks) || typeof (callbacks.onSuccess) === 'undefined') {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n if (advancedOptions.hasOwnProperty('disclose_me')) {\n options.disclose_me = advancedOptions.disclose_me === true;\n }\n\n if (advancedOptions.hasOwnProperty('receive_progress')) {\n options.receive_progress = advancedOptions.receive_progress === true;\n }\n\n if (advancedOptions.hasOwnProperty('timeout')) {\n if (typeof advancedOptions.timeout === 'number') {\n options.timeout = advancedOptions.timeout;\n } else {\n err = true;\n }\n }\n\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n do {\n reqId = this._getReqId();\n } while (reqId in this._calls);\n\n this._calls[reqId] = callbacks;\n\n // WAMP SPEC: [CALL, Request|id, Options|dict, Procedure|uri, (Arguments|list, ArgumentsKw|dict)]\n msg = [WAMP_MSG_SPEC.CALL, reqId, options, topicURI];\n\n if (payload !== null && typeof (payload) !== 'undefined') {\n if (this._isArray(payload)) {\n msg.push(payload);\n } else if (this._isPlainObject(payload)) {\n // It's a wampy unified form of payload passing\n if (payload.argsList || payload.argsDict) {\n if (payload.argsList) {\n msg.push(payload.argsList);\n }\n\n if (payload.argsDict) {\n if (msg.length === 4) {\n msg.push([]);\n }\n msg.push(payload.argsDict);\n }\n } else {\n msg.push([], payload);\n }\n } else { // assume it's a single value\n msg.push([payload]);\n }\n }\n\n this._send(msg);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * RPC invocation cancelling\n *\n * @param {int} reqId RPC call request ID\n * @param {function|object} callbacks - if it is a function - it will be called if successfully\n * sent canceling message or it can be hash table of callbacks:\n * { onSuccess: will be called if successfully sent canceling message\n * onError: will be called if some error occurred }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { mode: string|one of the possible modes:\n * \"skip\" | \"kill\" | \"killnowait\". Skip is default.\n * }\n *\n * @returns {Wampy}\n */\n cancel (reqId, callbacks, advancedOptions) {\n let err = false;\n const options = {};\n\n if (!this._preReqChecks(null, 'dealer', callbacks)) {\n return this;\n }\n\n if (!reqId || !this._calls[reqId]) {\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_RPC_REQ_ID;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n\n if (advancedOptions.hasOwnProperty('mode')) {\n if (/skip|kill|killnowait/.test(advancedOptions.mode)) {\n options.mode = advancedOptions.mode;\n } else {\n err = true;\n }\n\n }\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n // WAMP SPEC: [CANCEL, CALL.Request|id, Options|dict]\n this._send([WAMP_MSG_SPEC.CANCEL, reqId, options]);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n\n callbacks.onSuccess && callbacks.onSuccess();\n\n return this;\n }\n\n /**\n * RPC registration for invocation\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function - it will be treated as rpc itself\n * or it can be hash table of callbacks:\n * { rpc: registered procedure\n * onSuccess: will be called on successful registration\n * onError: will be called if registration would be aborted }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * {\n * match: string matching policy (\"prefix\"|\"wildcard\")\n * invoke: string invocation policy (\"single\"|\"roundrobin\"|\"random\"|\"first\"|\"last\")\n * }\n * @returns {Wampy}\n */\n register (topicURI, callbacks, advancedOptions) {\n let reqId, patternBased = false, err = false;\n const options = {};\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n\n if (advancedOptions.hasOwnProperty('match')) {\n if (/prefix|wildcard/.test(advancedOptions.match)) {\n options.match = advancedOptions.match;\n patternBased = true;\n } else {\n err = true;\n }\n }\n\n if (advancedOptions.hasOwnProperty('invoke')) {\n if (/single|roundrobin|random|first|last/.test(advancedOptions.invoke)) {\n options.invoke = advancedOptions.invoke;\n } else {\n err = true;\n }\n }\n\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: patternBased, allowWAMP: false }, 'dealer', callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { rpc: callbacks };\n } else if (!this._isPlainObject(callbacks) || typeof (callbacks.rpc) === 'undefined') {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (!this._rpcRegs[topicURI] || !this._rpcRegs[topicURI].callbacks.length) {\n // no such registration or processing unregistering\n\n reqId = this._getReqId();\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP SPEC: [REGISTER, Request|id, Options|dict, Procedure|uri]\n this._send([WAMP_MSG_SPEC.REGISTER, reqId, options, topicURI]);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n } else { // already have registration with such topicURI\n this._cache.opStatus = WAMP_ERROR_MSG.RPC_ALREADY_REGISTERED;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n }\n\n return this;\n\n }\n\n /**\n * RPC unregistration for invocation\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function, it will be called on successful unregistration\n * or it can be hash table of callbacks:\n * { onSuccess: will be called on successful unregistration\n * onError: will be called if unregistration would be aborted }\n * @returns {Wampy}\n */\n unregister (topicURI, callbacks) {\n let reqId;\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: false }, 'dealer', callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { onSuccess: callbacks };\n }\n\n if (this._rpcRegs[topicURI]) { // there is such registration\n\n reqId = this._getReqId();\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP SPEC: [UNREGISTER, Request|id, REGISTERED.Registration|id]\n this._send([WAMP_MSG_SPEC.UNREGISTER, reqId, this._rpcRegs[topicURI].id]);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n } else { // there is no registration with such topicURI\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_RPC_UNREG;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n }\n\n return this;\n }\n}\n\nexport default Wampy;\nexport { Wampy };\n"],"file":"wampy.js"} \ No newline at end of file +{"version":3,"sources":["../src/wampy.js"],"names":["Wampy","url","options","version","_url","_protocols","_wamp_features","agent","roles","publisher","features","subscriber_blackwhite_listing","publisher_exclusion","publisher_identification","subscriber","pattern_based_subscription","publication_trustlevels","caller","caller_identification","progressive_call_results","call_canceling","call_timeout","callee","call_trustlevels","pattern_based_registration","shared_registration","_cache","sessionId","reqId","server_wamp_features","isSayingGoodbye","opStatus","code","description","timer","reconnectingAttempts","_ws","_wsQueue","_requests","_calls","_subscriptions","_subsTopics","Set","_rpcRegs","_rpcNames","_options","debug","autoReconnect","reconnectInterval","maxRetries","realm","helloCustomDetails","uriValidation","authid","authmethods","onChallenge","onConnect","onClose","onError","onReconnect","onReconnectSuccess","ws","additionalHeaders","wsRequestOptions","serializer","JsonSerializer","_isPlainObject","_merge","connect","args","console","log","obj","l","length","i","attr","Array","isArray","_isObject","ctor","constructor","prot","prototype","hasOwnProperty","Object","toString","call","unshift","protocol","topicType","role","callbacks","flag","WAMP_ERROR_MSG","toUpperCase","_validateURI","topic","patternBased","allowWAMP","URI_ERROR","error","uri","reBase","rePattern","re","test","indexOf","msg","encode","e","_hardClose","decode","errorUri","details","_log","_send","WAMP_MSG_SPEC","ABORT","message","close","push","_encode","readyState","send","shift","onopen","_wsOnOpen","onclose","event","_wsOnClose","onmessage","_wsOnMessage","onerror","_wsOnError","serverProtocol","split","navigator","product","NO_SERIALIZER_AVAILABLE","isBinary","binaryType","HELLO","setTimeout","_wsReconnect","_resetState","_decode","data","then","id","p","self","WELCOME","_renewSubscriptions","_renewRegistrations","CHALLENGE","Promise","resolve","reject","key","AUTHENTICATE","CRA_EXCEPTION","NO_CRA_CB_OR_ID","GOODBYE","ERROR","SUBSCRIBE","UNSUBSCRIBE","PUBLISH","REGISTER","UNREGISTER","argsList","argsDict","CALL","SUBSCRIBED","onEvent","advancedOptions","add","onSuccess","UNSUBSCRIBED","has","PUBLISHED","EVENT","RESULT","progress","REGISTERED","rpc","UNREGISTERED","INVOCATION","invoke_result_handler","results","YIELD","_isArray","invoke_error_handler","result_handler","error_handler","NON_EXIST_RPC_INVOCATION","err","_initWsCallbacks","subs","st","subscribe","rpcs","rn","rpcName","register","opts","authp","_setWsProtocols","NO_WS_OR_URL","NO_REALM","SUCCESS","topicURI","match","_preReqChecks","NO_CALLBACK_SPEC","_getReqId","splice","NON_EXIST_UNSUBSCRIBE","payload","hasPayload","_optionsConvertHelper","option","sourceType","acknowledge","exclude_me","disclose_me","INVALID_PARAM","arguments","receive_progress","timeout","NON_EXIST_RPC_REQ_ID","mode","CANCEL","invoke","RPC_ALREADY_REGISTERED","NON_EXIST_RPC_UNREG"],"mappings":";;;;;;;AAgBA;;AACA;;AACA;;;;;;;;;;AAEA;;;IAGMA,K;;;AAEF;;;;;AAKA,iBAAaC,GAAb,EAAkBC,OAAlB,EAA2B;AAAA;;AAEvB;;;;;AAKA,SAAKC,OAAL,GAAe,QAAf;AAEA;;;;;;AAKA,SAAKC,IAAL,GAAa,OAAOH,GAAP,KAAe,QAAhB,GAA4BA,GAA5B,GAAkC,IAA9C;AAEA;;;;;;AAKA,SAAKI,UAAL,GAAkB,CAAC,aAAD,CAAlB;AAEA;;;;;;AAKA,SAAKC,cAAL,GAAsB;AAClBC,MAAAA,KAAK,EAAE,cAAc,KAAKJ,OADR;AAElBK,MAAAA,KAAK,EAAE;AACHC,QAAAA,SAAS,EAAG;AACRC,UAAAA,QAAQ,EAAE;AACNC,YAAAA,6BAA6B,EAAE,IADzB;AAENC,YAAAA,mBAAmB,EAAY,IAFzB;AAGNC,YAAAA,wBAAwB,EAAO;AAHzB;AADF,SADT;AAQHC,QAAAA,U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H,QAAAA,KAAK,EAAEkH,QAAT;AAAmBjH,QAAAA,YAAY,EAAE,KAAjC;AAAwCC,QAAAA,SAAS,EAAE;AAAnD,OAAnB,EAA+E,QAA/E,EAAyFP,SAAzF,CAAL,EAA0G;AACtG,eAAO,IAAP;AACH;;AAED,UAAI,OAAOA,SAAP,KAAqB,UAAzB,EAAqC;AACjCA,QAAAA,SAAS,GAAG;AAAEqF,UAAAA,SAAS,EAAErF;AAAb,SAAZ;AACH;;AAED,UAAI,KAAKjD,QAAL,CAAcwK,QAAd,CAAJ,EAA6B;AAAI;AAE7BvL,QAAAA,KAAK,GAAG,KAAK2L,SAAL,EAAR;AAEA,aAAKjL,SAAL,CAAeV,KAAf,IAAwB;AACpBqE,UAAAA,KAAK,EAAEkH,QADa;AAEpBvH,UAAAA,SAAS,EAATA;AAFoB,SAAxB,CAJyB,CASzB;;AACA,aAAKwB,KAAL,CAAW,CAACC,yBAAcoD,UAAf,EAA2B7I,KAA3B,EAAkC,KAAKe,QAAL,CAAcwK,QAAd,EAAwB9D,EAA1D,CAAX;;AACA,aAAK3H,MAAL,CAAYK,QAAZ,GAAuB+D,0BAAeoH,OAAtC;AACA,aAAKxL,MAAL,CAAYK,QAAZ,CAAqBH,KAArB,GAA6BA,KAA7B;AACH,OAbD,MAaO;AAAK;AACR,aAAKF,MAAL,CAAYK,QAAZ,GAAuB+D,0BAAe6I,mBAAtC;;AAEA,YAAI,KAAKzK,cAAL,CAAoB0B,SAApB,KAAkCA,SAAS,CAAClC,OAAhD,EAAyD;AACrDkC,UAAAA,SAAS,CAAClC,OAAV,CAAkB;AAAE2C,YAAAA,KAAK,EAAE,KAAK3E,MAAL,CAAYK,QAAZ,CAAqBE;AAA9B,WAAlB;AACH;AAEJ;;AAED,aAAO,IAAP;AACH;;;;;;;eAGUjC,K","sourcesContent":["/**\n * Project: wampy.js\n *\n * https://github.com/KSDaemon/wampy.js\n *\n * A lightweight client-side implementation of\n * WAMP (The WebSocket Application Messaging Protocol v2)\n * http://wamp.ws\n *\n * Provides asynchronous RPC/PubSub over WebSocket.\n *\n * Copyright 2014 KSDaemon. Licensed under the MIT License.\n * See @license text at http://www.opensource.org/licenses/mit-license.php\n *\n */\n\nimport { WAMP_MSG_SPEC, WAMP_ERROR_MSG } from './constants';\nimport { getWebSocket } from './utils';\nimport { JsonSerializer } from './serializers/JsonSerializer';\n\n/**\n * WAMP Client Class\n */\nclass Wampy {\n\n /**\n * Wampy constructor\n * @param {string} [url]\n * @param {Object} [options]\n */\n constructor (url, options) {\n\n /**\n * Wampy version\n * @type {string}\n * @private\n */\n this.version = 'v6.2.2';\n\n /**\n * WS Url\n * @type {string}\n * @private\n */\n this._url = (typeof url === 'string') ? url : null;\n\n /**\n * WS protocols\n * @type {Array}\n * @private\n */\n this._protocols = ['wamp.2.json'];\n\n /**\n * WAMP features, supported by Wampy\n * @type {object}\n * @private\n */\n this._wamp_features = {\n agent: 'Wampy.js ' + this.version,\n roles: {\n publisher : {\n features: {\n subscriber_blackwhite_listing: true,\n publisher_exclusion : true,\n publisher_identification : true\n }\n },\n subscriber: {\n features: {\n pattern_based_subscription: true,\n publication_trustlevels : true\n }\n },\n caller : {\n features: {\n caller_identification : true,\n progressive_call_results: true,\n call_canceling : true,\n call_timeout : true\n }\n },\n callee : {\n features: {\n caller_identification : true,\n call_trustlevels : true,\n pattern_based_registration: true,\n shared_registration : true\n }\n }\n }\n };\n\n /**\n * Internal cache for object lifetime\n * @type {Object}\n * @private\n */\n this._cache = {\n /**\n * WAMP Session ID\n * @type {string}\n */\n sessionId: null,\n\n /**\n * WAMP Session scope requests ID\n * @type {int}\n */\n reqId: 0,\n\n /**\n * Server WAMP roles and features\n */\n server_wamp_features: { roles: {} },\n\n /**\n * Are we in state of saying goodbye\n * @type {boolean}\n */\n isSayingGoodbye: false,\n\n /**\n * Status of last operation\n */\n opStatus: { code: 0, description: 'Success!', reqId: 0 },\n\n /**\n * Timer for reconnection\n * @type {null}\n */\n timer: null,\n\n /**\n * Reconnection attempts\n * @type {number}\n */\n reconnectingAttempts: 0\n };\n\n /**\n * WebSocket object\n * @type {Object}\n * @private\n */\n this._ws = null;\n\n /**\n * Internal queue for websocket requests, for case of disconnect\n * @type {Array}\n * @private\n */\n this._wsQueue = [];\n\n /**\n * Internal queue for wamp requests\n * @type {object}\n * @private\n */\n this._requests = {};\n\n /**\n * Stored RPC\n * @type {object}\n * @private\n */\n this._calls = {};\n\n /**\n * Stored Pub/Sub\n * @type {object}\n * @private\n */\n this._subscriptions = {};\n\n /**\n * Stored Pub/Sub topics\n * @type {Array}\n * @private\n */\n this._subsTopics = new Set();\n\n /**\n * Stored RPC Registrations\n * @type {object}\n * @private\n */\n this._rpcRegs = {};\n\n /**\n * Stored RPC names\n * @type {Array}\n * @private\n */\n this._rpcNames = new Set();\n\n /**\n * Options hash-table\n * @type {Object}\n * @private\n */\n this._options = {\n /**\n * Logging\n * @type {boolean}\n */\n debug: false,\n\n /**\n * Reconnecting flag\n * @type {boolean}\n */\n autoReconnect: true,\n\n /**\n * Reconnecting interval (in ms)\n * @type {number}\n */\n reconnectInterval: 2 * 1000,\n\n /**\n * Maximum reconnection retries\n * @type {number}\n */\n maxRetries: 25,\n\n /**\n * WAMP Realm to join\n * @type {string}\n */\n realm: null,\n\n /**\n * Custom attributes to send to router on hello\n * @type {object}\n */\n helloCustomDetails: null,\n\n /**\n * Validation of the topic URI structure\n * @type {string} - strict or loose\n */\n uriValidation: 'strict',\n\n /**\n * Authentication id to use in challenge\n * @type {string}\n */\n authid: null,\n\n /**\n * Supported authentication methods\n * @type {array}\n */\n authmethods: [],\n\n /**\n * onChallenge callback\n * @type {function}\n */\n onChallenge: null,\n\n /**\n * onConnect callback\n * @type {function}\n */\n onConnect: null,\n\n /**\n * onClose callback\n * @type {function}\n */\n onClose: null,\n\n /**\n * onError callback\n * @type {function}\n */\n onError: null,\n\n /**\n * onReconnect callback\n * @type {function}\n */\n onReconnect: null,\n\n /**\n * onReconnectSuccess callback\n * @type {function}\n */\n onReconnectSuccess: null,\n\n /**\n * User provided WebSocket class\n * @type {function}\n */\n ws: null,\n\n /**\n * User provided additional HTTP headers (for use in Node.js enviroment)\n * @type {object}\n */\n additionalHeaders: null,\n\n /**\n * User provided WS Client Config Options (for use in Node.js enviroment)\n * @type {object}\n */\n wsRequestOptions: null,\n\n /**\n * User provided msgpack class\n * @type {object}\n */\n serializer: new JsonSerializer()\n };\n\n if (this._isPlainObject(options)) {\n this._options = this._merge(this._options, options);\n } else if (this._isPlainObject(url)) {\n this._options = this._merge(this._options, url);\n }\n\n if (this._url) {\n this.connect();\n }\n\n }\n\n /* Internal utils methods */\n /**\n * Internal logger\n * @private\n */\n _log (...args) {\n if (this._options.debug) {\n console.log(args);\n }\n }\n\n /**\n * Get the new unique request id\n * @returns {number}\n * @private\n */\n _getReqId () {\n return ++this._cache.reqId;\n }\n\n /**\n * Merge argument objects into one\n * @returns {Object}\n * @private\n */\n _merge (...args) {\n const obj = {}, l = args.length;\n let i, attr;\n\n for (i = 0; i < l; i++) {\n for (attr in args[i]) {\n obj[attr] = args[i][attr];\n }\n }\n\n return obj;\n }\n\n /**\n * Check if value is array\n * @param obj\n * @returns {boolean}\n * @private\n */\n _isArray (obj) {\n return (!!obj) && (Array.isArray(obj));\n }\n\n /**\n * Check if value is object literal\n * @param obj\n * @returns {boolean}\n * @private\n */\n _isPlainObject (obj) {\n if (!this._isObject(obj)) {\n return false;\n }\n\n // If has modified constructor\n const ctor = obj.constructor;\n if (typeof ctor !== 'function') {\n return false;\n }\n\n // If has modified prototype\n const prot = ctor.prototype;\n if (this._isObject(prot) === false) {\n return false;\n }\n\n // If constructor does not have an Object-specific method\n if (prot.hasOwnProperty('isPrototypeOf') === false) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Check if value is an object\n * @param obj\n * @returns {boolean}\n * @private\n */\n _isObject (obj) {\n return obj !== null\n && typeof obj === 'object'\n && Array.isArray(obj) === false\n && Object.prototype.toString.call(obj) === '[object Object]';\n }\n\n /**\n * Fix websocket protocols based on options\n * @private\n */\n _setWsProtocols () {\n if (!(this._options.serializer instanceof JsonSerializer)) {\n this._protocols.unshift('wamp.2.' + this._options.serializer.protocol);\n }\n }\n\n /**\n * Prerequisite checks for any wampy api call\n * @param {object} topicType { topic: URI, patternBased: true|false, allowWAMP: true|false }\n * @param {string} role\n * @param {object} callbacks\n * @returns {boolean}\n * @private\n */\n _preReqChecks (topicType, role, callbacks) {\n let flag = true;\n\n if (this._cache.sessionId && !this._cache.server_wamp_features.roles[role]) {\n this._cache.opStatus = WAMP_ERROR_MSG['NO_' + role.toUpperCase()];\n flag = false;\n }\n\n if (topicType && !this._validateURI(topicType.topic, topicType.patternBased, topicType.allowWAMP)) {\n this._cache.opStatus = WAMP_ERROR_MSG.URI_ERROR;\n flag = false;\n }\n\n if (flag) {\n return true;\n }\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return false;\n }\n\n /**\n * Validate uri\n * @param {string} uri\n * @param {boolean} patternBased\n * @param {boolean} allowWAMP\n * @returns {boolean}\n * @private\n */\n _validateURI (uri, patternBased, allowWAMP) {\n let reBase;\n let rePattern;\n\n if (this._options.uriValidation === 'strict') {\n reBase = /^([0-9a-zA-Z_]+\\.)*([0-9a-zA-Z_]+)$/;\n rePattern = /^([0-9a-zA-Z_]+\\.{1,2})*([0-9a-zA-Z_]+)$/;\n } else if (this._options.uriValidation === 'loose') {\n reBase = /^([^\\s.#]+\\.)*([^\\s.#]+)$/;\n rePattern = /^([^\\s.#]+\\.{1,2})*([^\\s.#]+)$/;\n } else {\n return false;\n }\n const re = patternBased ? rePattern : reBase;\n\n if (allowWAMP) {\n return re.test(uri);\n } else {\n return !(!re.test(uri) || uri.indexOf('wamp.') === 0);\n }\n }\n\n /**\n * Encode WAMP message\n * @param {Array} msg\n * @returns {*}\n * @private\n */\n _encode (msg) {\n try {\n return this._options.serializer.encode(msg);\n } catch (e) {\n this._hardClose('wamp.error.protocol_violation', 'Can not encode message');\n }\n }\n\n /**\n * Decode WAMP message\n * @param msg\n * @returns {Promise}\n * @private\n */\n _decode (msg) {\n return this._options.serializer.decode(msg);\n }\n\n /**\n * Hard close of connection due to protocol violations\n * @param {string} errorUri\n * @param {string} details\n * @private\n */\n _hardClose (errorUri, details) {\n this._log('[wampy] ' + details);\n // Cleanup outgoing message queue\n this._wsQueue = [];\n this._send([WAMP_MSG_SPEC.ABORT, { message: details }, errorUri]);\n\n if (this._options.onError) {\n this._options.onError({ error: errorUri, details: details });\n }\n this._ws.close();\n }\n\n /**\n * Send encoded message to server\n * @param {Array} msg\n * @private\n */\n _send (msg) {\n if (msg) {\n this._wsQueue.push(this._encode(msg));\n }\n\n if (this._ws && this._ws.readyState === 1 && this._cache.sessionId) {\n while (this._wsQueue.length) {\n this._ws.send(this._wsQueue.shift());\n }\n }\n }\n\n /**\n * Reset internal state and cache\n * @private\n */\n _resetState () {\n this._wsQueue = [];\n this._subscriptions = {};\n this._subsTopics = new Set();\n this._requests = {};\n this._calls = {};\n this._rpcRegs = {};\n this._rpcNames = new Set();\n\n // Just keep attrs that are have to be present\n this._cache = {\n reqId : 0,\n reconnectingAttempts: 0\n };\n }\n\n /**\n * Initialize internal websocket callbacks\n * @private\n */\n _initWsCallbacks () {\n if (this._ws) {\n this._ws.onopen = () => {\n this._wsOnOpen();\n };\n this._ws.onclose = event => {\n this._wsOnClose(event);\n };\n this._ws.onmessage = event => {\n this._wsOnMessage(event);\n };\n this._ws.onerror = error => {\n this._wsOnError(error);\n };\n }\n }\n\n /**\n * Internal websocket on open callback\n * @private\n */\n _wsOnOpen () {\n const options = this._merge(this._options.helloCustomDetails, this._wamp_features),\n serverProtocol = this._ws.protocol ? this._ws.protocol.split('.')[2] : '';\n\n if (this._options.authid) {\n options.authmethods = this._options.authmethods;\n options.authid = this._options.authid;\n }\n\n this._log('[wampy] websocket connected');\n\n if (this._options.serializer.protocol !== serverProtocol) {\n // Server have chosen not our preferred protocol\n\n // Falling back to json if possible\n //FIXME Temp hack for React Native Environment.\n // Due to bug (facebook/react-native#24796), it doesn't provide selected subprotocol.\n // Remove when ^^^ bug will be fixed.\n if (serverProtocol === 'json' ||\n (typeof navigator != 'undefined' &&\n navigator.product === 'ReactNative' &&\n typeof this._ws.protocol === 'undefined')) {\n this._options.serializer = new JsonSerializer();\n } else {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_SERIALIZER_AVAILABLE;\n return this;\n }\n\n }\n\n if (this._options.serializer.isBinary) {\n this._ws.binaryType = 'arraybuffer';\n }\n\n // WAMP SPEC: [HELLO, Realm|uri, Details|dict]\n // Sending directly 'cause it's a hello msg and no sessionId check is needed\n this._ws.send(this._encode([WAMP_MSG_SPEC.HELLO, this._options.realm, options]));\n }\n\n /**\n * Internal websocket on close callback\n * @param {object} event\n * @private\n */\n _wsOnClose (event) {\n this._log('[wampy] websocket disconnected. Info: ', event);\n\n // Automatic reconnection\n if ((this._cache.sessionId || this._cache.reconnectingAttempts) &&\n this._options.autoReconnect && this._cache.reconnectingAttempts < this._options.maxRetries && !this._cache.isSayingGoodbye) {\n this._cache.sessionId = null;\n this._cache.timer = setTimeout(() => {\n this._wsReconnect();\n }, this._options.reconnectInterval);\n } else {\n // No reconnection needed or reached max retries count\n if (this._options.onClose) {\n this._options.onClose();\n }\n\n this._resetState();\n this._ws = null;\n }\n }\n\n /**\n * Internal websocket on event callback\n * @param {object} event\n * @private\n */\n _wsOnMessage (event) {\n this._decode(event.data).then(data => {\n\n this._log('[wampy] websocket message received: ', data);\n\n let id, i, p, self = this;\n\n switch (data[0]) {\n case WAMP_MSG_SPEC.WELCOME:\n // WAMP SPEC: [WELCOME, Session|id, Details|dict]\n if (this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received WELCOME message after session was established');\n } else {\n this._cache.sessionId = data[1];\n this._cache.server_wamp_features = data[2];\n\n if (this._cache.reconnectingAttempts) {\n // There was reconnection\n\n this._cache.reconnectingAttempts = 0;\n\n if (this._options.onReconnectSuccess) {\n this._options.onReconnectSuccess(data[2]);\n }\n\n // Let's renew all previous state\n this._renewSubscriptions();\n this._renewRegistrations();\n\n } else {\n // Firing onConnect event on real connection to WAMP server\n if (this._options.onConnect) {\n this._options.onConnect(data[2]);\n }\n }\n\n // Send local queue if there is something out there\n this._send();\n }\n break;\n case WAMP_MSG_SPEC.ABORT:\n // WAMP SPEC: [ABORT, Details|dict, Reason|uri]\n if (this._options.onError) {\n this._options.onError({ error: data[2], details: data[1] });\n }\n this._ws.close();\n break;\n case WAMP_MSG_SPEC.CHALLENGE:\n // WAMP SPEC: [CHALLENGE, AuthMethod|string, Extra|dict]\n if (this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received CHALLENGE message after session was established');\n } else {\n if (this._options.authid && typeof this._options.onChallenge === 'function') {\n\n p = new Promise((resolve, reject) => {\n resolve(this._options.onChallenge(data[1], data[2]));\n });\n\n p.then((key) => {\n\n // Sending directly 'cause it's a challenge msg and no sessionId check is needed\n this._ws.send(this._encode([WAMP_MSG_SPEC.AUTHENTICATE, key, {}]));\n\n }).catch(e => {\n this._ws.send(this._encode([\n WAMP_MSG_SPEC.ABORT,\n { message: 'Exception in onChallenge handler raised!' },\n 'wamp.error.cannot_authenticate'\n ]));\n if (this._options.onError) {\n this._options.onError({ error: WAMP_ERROR_MSG.CRA_EXCEPTION.description });\n }\n this._ws.close();\n this._cache.opStatus = WAMP_ERROR_MSG.CRA_EXCEPTION;\n });\n\n } else {\n\n this._ws.send(this._encode([\n WAMP_MSG_SPEC.ABORT,\n { message: WAMP_ERROR_MSG.NO_CRA_CB_OR_ID.description },\n 'wamp.error.cannot_authenticate'\n ]));\n if (this._options.onError) {\n this._options.onError({ error: WAMP_ERROR_MSG.NO_CRA_CB_OR_ID.description });\n }\n this._ws.close();\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CRA_CB_OR_ID;\n\n }\n }\n break;\n case WAMP_MSG_SPEC.GOODBYE:\n // WAMP SPEC: [GOODBYE, Details|dict, Reason|uri]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received GOODBYE message before session was established');\n } else {\n if (!this._cache.isSayingGoodbye) { // get goodbye, initiated by server\n this._cache.isSayingGoodbye = true;\n this._send([WAMP_MSG_SPEC.GOODBYE, {}, 'wamp.close.goodbye_and_out']);\n }\n this._cache.sessionId = null;\n this._ws.close();\n }\n break;\n case WAMP_MSG_SPEC.ERROR:\n // WAMP SPEC: [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict,\n // Error|uri, (Arguments|list, ArgumentsKw|dict)]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received ERROR message before session was established');\n } else {\n switch (data[1]) {\n case WAMP_MSG_SPEC.SUBSCRIBE:\n case WAMP_MSG_SPEC.UNSUBSCRIBE:\n case WAMP_MSG_SPEC.PUBLISH:\n case WAMP_MSG_SPEC.REGISTER:\n case WAMP_MSG_SPEC.UNREGISTER:\n\n this._requests[data[2]] && this._requests[data[2]].callbacks.onError &&\n this._requests[data[2]].callbacks.onError({\n error : data[4],\n details : data[3],\n argsList: data[5],\n argsDict: data[6]\n });\n delete this._requests[data[2]];\n\n break;\n // case WAMP_MSG_SPEC.INVOCATION:\n // break;\n case WAMP_MSG_SPEC.CALL:\n\n // WAMP SPEC: [ERROR, CALL, CALL.Request|id, Details|dict,\n // Error|uri, Arguments|list, ArgumentsKw|dict]\n this._calls[data[2]] && this._calls[data[2]].onError &&\n this._calls[data[2]].onError({\n error : data[4],\n details : data[3],\n argsList: data[5],\n argsDict: data[6]\n });\n delete this._calls[data[2]];\n\n break;\n default:\n this._hardClose('wamp.error.protocol_violation', 'Received invalid ERROR message');\n break;\n }\n }\n break;\n case WAMP_MSG_SPEC.SUBSCRIBED:\n // WAMP SPEC: [SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received SUBSCRIBED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n this._subscriptions[this._requests[data[1]].topic] = this._subscriptions[data[2]] = {\n id : data[2],\n callbacks : [this._requests[data[1]].callbacks.onEvent],\n advancedOptions: this._requests[data[1]].advancedOptions\n };\n\n this._subsTopics.add(this._requests[data[1]].topic);\n\n if (this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n\n }\n }\n break;\n case WAMP_MSG_SPEC.UNSUBSCRIBED:\n // WAMP SPEC: [UNSUBSCRIBED, UNSUBSCRIBE.Request|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received UNSUBSCRIBED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n id = this._subscriptions[this._requests[data[1]].topic].id;\n delete this._subscriptions[this._requests[data[1]].topic];\n delete this._subscriptions[id];\n\n if (this._subsTopics.has(this._requests[data[1]].topic)) {\n this._subsTopics.delete(this._requests[data[1]].topic);\n }\n\n if (this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n case WAMP_MSG_SPEC.PUBLISHED:\n // WAMP SPEC: [PUBLISHED, PUBLISH.Request|id, Publication|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received PUBLISHED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n if (this._requests[data[1]].callbacks && this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n case WAMP_MSG_SPEC.EVENT:\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received EVENT message before session was established');\n } else {\n if (this._subscriptions[data[1]]) {\n\n // WAMP SPEC: [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id,\n // Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentKw|dict]\n\n i = this._subscriptions[data[1]].callbacks.length;\n while (i--) {\n this._subscriptions[data[1]].callbacks[i]({\n details : data[3],\n argsList: data[4],\n argsDict: data[5]\n });\n }\n }\n }\n break;\n case WAMP_MSG_SPEC.RESULT:\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received RESULT message before session was established');\n } else {\n if (this._calls[data[1]]) {\n\n // WAMP SPEC: [RESULT, CALL.Request|id, Details|dict,\n // YIELD.Arguments|list, YIELD.ArgumentsKw|dict]\n\n this._calls[data[1]].onSuccess({\n details : data[2],\n argsList: data[3],\n argsDict: data[4]\n });\n if (!(data[2].progress && data[2].progress === true)) {\n // We receive final result (progressive or not)\n delete this._calls[data[1]];\n }\n }\n }\n break;\n // case WAMP_MSG_SPEC.REGISTER:\n // // WAMP SPEC:\n // break;\n case WAMP_MSG_SPEC.REGISTERED:\n // WAMP SPEC: [REGISTERED, REGISTER.Request|id, Registration|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received REGISTERED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n this._rpcRegs[this._requests[data[1]].topic] = this._rpcRegs[data[2]] = {\n id : data[2],\n callbacks: [this._requests[data[1]].callbacks.rpc]\n };\n\n this._rpcNames.add(this._requests[data[1]].topic);\n\n if (this._requests[data[1]].callbacks && this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n // case WAMP_MSG_SPEC.UNREGISTER:\n // // WAMP SPEC:\n // break;\n case WAMP_MSG_SPEC.UNREGISTERED:\n // WAMP SPEC: [UNREGISTERED, UNREGISTER.Request|id]\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received UNREGISTERED message before session was established');\n } else {\n if (this._requests[data[1]]) {\n id = this._rpcRegs[this._requests[data[1]].topic].id;\n delete this._rpcRegs[this._requests[data[1]].topic];\n delete this._rpcRegs[id];\n\n if (this._rpcNames.has(this._requests[data[1]].topic)) {\n this._rpcNames.delete(this._requests[data[1]].topic);\n }\n\n if (this._requests[data[1]].callbacks && this._requests[data[1]].callbacks.onSuccess) {\n this._requests[data[1]].callbacks.onSuccess();\n }\n\n delete this._requests[data[1]];\n }\n }\n break;\n case WAMP_MSG_SPEC.INVOCATION:\n if (!this._cache.sessionId) {\n this._hardClose('wamp.error.protocol_violation',\n 'Received INVOCATION message before session was established');\n } else {\n if (this._rpcRegs[data[2]]) {\n\n // WAMP SPEC: [INVOCATION, Request|id, REGISTERED.Registration|id,\n // Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict]\n\n let invoke_result_handler = results => {\n // WAMP SPEC: [YIELD, INVOCATION.Request|id, Options|dict, (Arguments|list,\n // ArgumentsKw|dict)]\n let msg = [WAMP_MSG_SPEC.YIELD, data[1], {}];\n\n if (self._isPlainObject(results)) {\n\n if (self._isPlainObject(results.options)) {\n msg[2] = results.options;\n }\n\n if (self._isArray(results.argsList)) {\n msg.push(results.argsList);\n } else if (typeof (results.argsList) !== 'undefined') {\n msg.push([results.argsList]);\n }\n\n if (self._isPlainObject(results.argsDict)) {\n if (msg.length === 3) {\n msg.push([]);\n }\n msg.push(results.argsDict);\n }\n } else {\n msg = [WAMP_MSG_SPEC.YIELD, data[1], {}];\n }\n self._send(msg);\n },\n invoke_error_handler = ({ details, error, argsList, argsDict }) => {\n let msg = [WAMP_MSG_SPEC.ERROR, WAMP_MSG_SPEC.INVOCATION,\n data[1], details || {}, error || 'wamp.error.invocation_exception'];\n\n if (argsList && self._isArray(argsList)) {\n msg.push(argsList);\n }\n\n if (argsDict && self._isPlainObject(argsDict)) {\n if (msg.length === 5) {\n msg.push([]);\n }\n msg.push(argsDict);\n }\n self._send(msg);\n };\n\n p = new Promise((resolve, reject) => {\n resolve(this._rpcRegs[data[2]].callbacks[0]({\n details : data[3],\n argsList : data[4],\n argsDict : data[5],\n result_handler: invoke_result_handler,\n error_handler : invoke_error_handler\n }));\n });\n\n p.then((results) => {\n invoke_result_handler(results);\n }).catch(e => {\n invoke_error_handler(e);\n });\n\n } else {\n // WAMP SPEC: [ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri]\n this._send([WAMP_MSG_SPEC.ERROR, WAMP_MSG_SPEC.INVOCATION,\n data[1], {}, 'wamp.error.no_such_procedure']);\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_RPC_INVOCATION;\n }\n }\n break;\n // case WAMP_MSG_SPEC.INTERRUPT:\n // // WAMP SPEC:\n // break;\n // case WAMP_MSG_SPEC.YIELD:\n // // WAMP SPEC:\n // break;\n default:\n this._hardClose('wamp.error.protocol_violation', 'Received non-compliant WAMP message');\n break;\n }\n }, err => {\n this._hardClose('wamp.error.protocol_violation', 'Can not decode received message');\n });\n }\n\n /**\n * Internal websocket on error callback\n * @param {object} error\n * @private\n */\n _wsOnError (error) {\n this._log('[wampy] websocket error');\n\n if (this._options.onError) {\n this._options.onError({ error });\n }\n }\n\n /**\n * Reconnect to server in case of websocket error\n * @private\n */\n _wsReconnect () {\n this._log('[wampy] websocket reconnecting...');\n\n if (this._options.onReconnect) {\n this._options.onReconnect();\n }\n\n this._cache.reconnectingAttempts++;\n this._ws = getWebSocket(this._url, this._protocols, this._options.ws,\n this._options.additionalHeaders, this._options.wsRequestOptions);\n this._initWsCallbacks();\n }\n\n /**\n * Resubscribe to topics in case of communication error\n * @private\n */\n _renewSubscriptions () {\n let i;\n const subs = this._subscriptions,\n st = this._subsTopics;\n\n this._subscriptions = {};\n this._subsTopics = new Set();\n\n for (let topic of st) {\n i = subs[topic].callbacks.length;\n while (i--) {\n this.subscribe(topic, subs[topic].callbacks[i], subs[topic].advancedOptions);\n }\n }\n }\n\n /**\n * Reregister RPCs in case of communication error\n * @private\n */\n _renewRegistrations () {\n const rpcs = this._rpcRegs,\n rn = this._rpcNames;\n\n this._rpcRegs = {};\n this._rpcNames = new Set();\n\n for (let rpcName of rn) {\n this.register(rpcName, { rpc: rpcs[rpcName].callbacks[0] });\n }\n }\n\n /* Wampy public API */\n\n /**\n * Get or set Wampy options\n *\n * To get options - call without parameters\n * To set options - pass hash-table with options values\n *\n * @param {object} [opts]\n * @returns {*}\n */\n options (opts) {\n if (typeof (opts) === 'undefined') {\n return this._options;\n } else if (this._isPlainObject(opts)) {\n this._options = this._merge(this._options, opts);\n return this;\n }\n }\n\n /**\n * Get the status of last operation\n *\n * @returns {object} with 2 fields: code, description\n * code: 0 - if operation was successful\n * code > 0 - if error occurred\n * description contains details about error\n * reqId: last send request ID\n */\n getOpStatus () {\n return this._cache.opStatus;\n }\n\n /**\n * Get the WAMP Session ID\n *\n * @returns {string} Session ID\n */\n getSessionId () {\n return this._cache.sessionId;\n }\n\n /**\n * Connect to server\n * @param {string} [url] New url (optional)\n * @returns {Wampy}\n */\n connect (url) {\n if (url) {\n this._url = url;\n }\n\n if (this._options.realm) {\n\n const authp = (this._options.authid ? 1 : 0) +\n ((this._isArray(this._options.authmethods) && this._options.authmethods.length) ? 1 : 0) +\n (typeof this._options.onChallenge === 'function' ? 1 : 0);\n\n if (authp > 0 && authp < 3) {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CRA_CB_OR_ID;\n return this;\n }\n\n this._setWsProtocols();\n this._ws = getWebSocket(this._url, this._protocols, this._options.ws,\n this._options.additionalHeaders, this._options.wsRequestOptions);\n if (!this._ws) {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_WS_OR_URL;\n return this;\n }\n this._initWsCallbacks();\n\n } else {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_REALM;\n }\n\n return this;\n }\n\n /**\n * Disconnect from server\n * @returns {Wampy}\n */\n disconnect () {\n if (this._cache.sessionId) {\n // need to send goodbye message to server\n this._cache.isSayingGoodbye = true;\n this._send([WAMP_MSG_SPEC.GOODBYE, {}, 'wamp.close.system_shutdown']);\n } else if (this._ws) {\n this._ws.close();\n }\n\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n\n return this;\n }\n\n /**\n * Abort WAMP session establishment\n *\n * @returns {Wampy}\n */\n abort () {\n\n if (!this._cache.sessionId && this._ws.readyState === 1) {\n this._send([WAMP_MSG_SPEC.ABORT, {}, 'wamp.error.abort']);\n this._cache.sessionId = null;\n }\n\n this._ws.close();\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n\n return this;\n }\n\n /**\n * Subscribe to a topic on a broker\n *\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function - it will be treated as published event callback\n * or it can be hash table of callbacks:\n * { onSuccess: will be called when subscribe would be confirmed\n * onError: will be called if subscribe would be aborted\n * onEvent: will be called on receiving published event }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { match: string matching policy (\"prefix\"|\"wildcard\") }\n *\n * @returns {Wampy}\n */\n subscribe (topicURI, callbacks, advancedOptions) {\n let reqId, patternBased = false;\n const options = {};\n\n if ((typeof (advancedOptions) !== 'undefined') &&\n (this._isPlainObject(advancedOptions)) &&\n (advancedOptions.hasOwnProperty('match'))) {\n\n if (/prefix|wildcard/.test(advancedOptions.match)) {\n options.match = advancedOptions.match;\n patternBased = true;\n }\n }\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: patternBased, allowWAMP: true },\n 'broker',\n callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { onEvent: callbacks };\n } else if (!this._isPlainObject(callbacks) || typeof (callbacks.onEvent) === 'undefined') {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (!this._subscriptions[topicURI] || !this._subscriptions[topicURI].callbacks.length) {\n // no such subscription or processing unsubscribing\n\n reqId = this._getReqId();\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks,\n advancedOptions\n };\n\n // WAMP SPEC: [SUBSCRIBE, Request|id, Options|dict, Topic|uri]\n this._send([WAMP_MSG_SPEC.SUBSCRIBE, reqId, options, topicURI]);\n\n } else { // already have subscription to this topic\n // There is no such callback yet\n if (this._subscriptions[topicURI].callbacks.indexOf(callbacks.onEvent) < 0) {\n this._subscriptions[topicURI].callbacks.push(callbacks.onEvent);\n }\n\n if (callbacks.onSuccess) {\n callbacks.onSuccess();\n }\n }\n\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * Unsubscribe from topic\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function - it will be treated as\n * published event callback to remove or it can be hash table of callbacks:\n * { onSuccess: will be called when unsubscribe would be confirmed\n * onError: will be called if unsubscribe would be aborted\n * onEvent: published event callback to remove }\n * @returns {Wampy}\n */\n unsubscribe (topicURI, callbacks) {\n let reqId, i = -1;\n\n if (!this._preReqChecks(null, 'broker', callbacks)) {\n return this;\n }\n\n if (this._subscriptions[topicURI]) {\n\n reqId = this._getReqId();\n\n if (typeof (callbacks) === 'undefined') {\n this._subscriptions[topicURI].callbacks = [];\n callbacks = {};\n } else if (typeof callbacks === 'function') {\n i = this._subscriptions[topicURI].callbacks.indexOf(callbacks);\n callbacks = {};\n } else if (callbacks.onEvent && typeof callbacks.onEvent === 'function') {\n i = this._subscriptions[topicURI].callbacks.indexOf(callbacks.onEvent);\n } else {\n this._subscriptions[topicURI].callbacks = [];\n }\n\n if (i >= 0) {\n this._subscriptions[topicURI].callbacks.splice(i, 1);\n }\n\n if (this._subscriptions[topicURI].callbacks.length) {\n // There are another callbacks for this topic\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n return this;\n }\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP_SPEC: [UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]\n this._send([WAMP_MSG_SPEC.UNSUBSCRIBE, reqId, this._subscriptions[topicURI].id]);\n\n } else {\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_UNSUBSCRIBE;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * Publish a event to topic\n * @param {string} topicURI\n * @param {string|number|Array|object} payload - can be either a value of any type or null. Also it\n * is possible to pass array and object-like data simultaneously.\n * In this case pass a hash-table with next attributes:\n * {\n * argsList: array payload (may be omitted)\n * argsDict: object payload (may be omitted)\n * }\n * @param {object} [callbacks] - optional hash table of callbacks:\n * { onSuccess: will be called when publishing would be confirmed\n * onError: will be called if publishing would be aborted }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { exclude: integer|array WAMP session id(s) that won't receive a published event,\n * even though they may be subscribed\n * exclude_authid: string|array Authentication id(s) that won't receive\n * a published event, even though they may be subscribed\n * exclude_authrole: string|array Authentication role(s) that won't receive\n * a published event, even though they may be subscribed\n * eligible: integer|array WAMP session id(s) that are allowed\n * to receive a published event\n * eligible_authid: string|array Authentication id(s) that are allowed\n * to receive a published event\n * eligible_authrole: string|array Authentication role(s) that are allowed\n * to receive a published event\n * exclude_me: bool flag of receiving publishing event by initiator\n * disclose_me: bool flag of disclosure of publisher identity (its WAMP session ID)\n * to receivers of a published event }\n * @returns {Wampy}\n */\n publish (topicURI, payload, callbacks, advancedOptions) {\n let reqId, msg, err = false, hasPayload = false;\n const options = {},\n _optionsConvertHelper = (option, sourceType) => {\n if (advancedOptions[option]) {\n if (this._isArray(advancedOptions[option]) && advancedOptions[option].length) {\n options[option] = advancedOptions[option];\n } else if (typeof advancedOptions[option] === sourceType) {\n options[option] = [advancedOptions[option]];\n } else {\n err = true;\n }\n }\n };\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: false }, 'broker', callbacks)) {\n return this;\n }\n\n if (this._isPlainObject(callbacks)) {\n options.acknowledge = true;\n }\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n _optionsConvertHelper('exclude', 'number');\n _optionsConvertHelper('exclude_authid', 'string');\n _optionsConvertHelper('exclude_authrole', 'string');\n _optionsConvertHelper('eligible', 'number');\n _optionsConvertHelper('eligible_authid', 'string');\n _optionsConvertHelper('eligible_authrole', 'string');\n\n if (advancedOptions.hasOwnProperty('exclude_me')) {\n options.exclude_me = advancedOptions.exclude_me !== false;\n }\n\n if (advancedOptions.hasOwnProperty('disclose_me')) {\n options.disclose_me = advancedOptions.disclose_me === true;\n }\n\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n reqId = this._getReqId();\n\n switch (arguments.length) {\n case 1:\n break;\n case 2:\n hasPayload = true;\n break;\n default:\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n hasPayload = true;\n break;\n }\n\n // WAMP_SPEC: [PUBLISH, Request|id, Options|dict, Topic|uri]\n msg = [WAMP_MSG_SPEC.PUBLISH, reqId, options, topicURI];\n\n if (hasPayload) {\n // WAMP_SPEC: [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list (, ArgumentsKw|dict)]\n if (this._isArray(payload)) {\n msg.push(payload);\n } else if (this._isPlainObject(payload)) {\n // It's a wampy unified form of payload passing\n if (payload.argsList || payload.argsDict) {\n if (payload.argsList) {\n msg.push(payload.argsList);\n }\n\n if (payload.argsDict) {\n if (msg.length === 4) {\n msg.push([]);\n }\n msg.push(payload.argsDict);\n }\n } else {\n msg.push([], payload);\n }\n } else { // assume it's a single value\n msg.push([payload]);\n }\n }\n\n this._send(msg);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * Remote Procedure Call\n * @param {string} topicURI\n * @param {string|number|Array|object} payload - can be either a value of any type or null. Also it\n * is possible to pass array and object-like data simultaneously.\n * In this case pass a hash-table with next attributes:\n * {\n * argsList: array payload (may be omitted)\n * argsDict: object payload (may be omitted)\n * }\n * @param {function|object} callbacks - if it is a function - it will be treated as result callback function\n * or it can be hash table of callbacks:\n * { onSuccess: will be called with result on successful call\n * onError: will be called if invocation would be aborted }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { disclose_me: bool flag of disclosure of Caller identity (WAMP session ID)\n * to endpoints of a routed call\n * receive_progress: bool flag for receiving progressive results. In this case\n * onSuccess function will be called every time on receiving result\n * timeout: integer timeout (in ms) for the call to finish }\n * @returns {Wampy}\n */\n call (topicURI, payload, callbacks, advancedOptions) {\n let reqId, msg, err = false;\n const options = {};\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: true }, 'dealer', callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { onSuccess: callbacks };\n } else if (!this._isPlainObject(callbacks) || typeof (callbacks.onSuccess) === 'undefined') {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n if (advancedOptions.hasOwnProperty('disclose_me')) {\n options.disclose_me = advancedOptions.disclose_me === true;\n }\n\n if (advancedOptions.hasOwnProperty('receive_progress')) {\n options.receive_progress = advancedOptions.receive_progress === true;\n }\n\n if (advancedOptions.hasOwnProperty('timeout')) {\n if (typeof advancedOptions.timeout === 'number') {\n options.timeout = advancedOptions.timeout;\n } else {\n err = true;\n }\n }\n\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n do {\n reqId = this._getReqId();\n } while (reqId in this._calls);\n\n this._calls[reqId] = callbacks;\n\n // WAMP SPEC: [CALL, Request|id, Options|dict, Procedure|uri, (Arguments|list, ArgumentsKw|dict)]\n msg = [WAMP_MSG_SPEC.CALL, reqId, options, topicURI];\n\n if (payload !== null && typeof (payload) !== 'undefined') {\n if (this._isArray(payload)) {\n msg.push(payload);\n } else if (this._isPlainObject(payload)) {\n // It's a wampy unified form of payload passing\n if (payload.argsList || payload.argsDict) {\n if (payload.argsList) {\n msg.push(payload.argsList);\n }\n\n if (payload.argsDict) {\n if (msg.length === 4) {\n msg.push([]);\n }\n msg.push(payload.argsDict);\n }\n } else {\n msg.push([], payload);\n }\n } else { // assume it's a single value\n msg.push([payload]);\n }\n }\n\n this._send(msg);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n return this;\n }\n\n /**\n * RPC invocation cancelling\n *\n * @param {int} reqId RPC call request ID\n * @param {function|object} callbacks - if it is a function - it will be called if successfully\n * sent canceling message or it can be hash table of callbacks:\n * { onSuccess: will be called if successfully sent canceling message\n * onError: will be called if some error occurred }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * { mode: string|one of the possible modes:\n * \"skip\" | \"kill\" | \"killnowait\". Skip is default.\n * }\n *\n * @returns {Wampy}\n */\n cancel (reqId, callbacks, advancedOptions) {\n let err = false;\n const options = {};\n\n if (!this._preReqChecks(null, 'dealer', callbacks)) {\n return this;\n }\n\n if (!reqId || !this._calls[reqId]) {\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_RPC_REQ_ID;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n\n if (advancedOptions.hasOwnProperty('mode')) {\n if (/skip|kill|killnowait/.test(advancedOptions.mode)) {\n options.mode = advancedOptions.mode;\n } else {\n err = true;\n }\n\n }\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n // WAMP SPEC: [CANCEL, CALL.Request|id, Options|dict]\n this._send([WAMP_MSG_SPEC.CANCEL, reqId, options]);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n\n callbacks.onSuccess && callbacks.onSuccess();\n\n return this;\n }\n\n /**\n * RPC registration for invocation\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function - it will be treated as rpc itself\n * or it can be hash table of callbacks:\n * { rpc: registered procedure\n * onSuccess: will be called on successful registration\n * onError: will be called if registration would be aborted }\n * @param {object} advancedOptions - optional parameter. Must include any or all of the options:\n * {\n * match: string matching policy (\"prefix\"|\"wildcard\")\n * invoke: string invocation policy (\"single\"|\"roundrobin\"|\"random\"|\"first\"|\"last\")\n * }\n * @returns {Wampy}\n */\n register (topicURI, callbacks, advancedOptions) {\n let reqId, patternBased = false, err = false;\n const options = {};\n\n if (typeof (advancedOptions) !== 'undefined') {\n\n if (this._isPlainObject(advancedOptions)) {\n\n if (advancedOptions.hasOwnProperty('match')) {\n if (/prefix|wildcard/.test(advancedOptions.match)) {\n options.match = advancedOptions.match;\n patternBased = true;\n } else {\n err = true;\n }\n }\n\n if (advancedOptions.hasOwnProperty('invoke')) {\n if (/single|roundrobin|random|first|last/.test(advancedOptions.invoke)) {\n options.invoke = advancedOptions.invoke;\n } else {\n err = true;\n }\n }\n\n } else {\n err = true;\n }\n\n if (err) {\n this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n }\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: patternBased, allowWAMP: false },\n 'dealer',\n callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { rpc: callbacks };\n } else if (!this._isPlainObject(callbacks) || typeof (callbacks.rpc) === 'undefined') {\n this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n return this;\n }\n\n if (!this._rpcRegs[topicURI] || !this._rpcRegs[topicURI].callbacks.length) {\n // no such registration or processing unregistering\n\n reqId = this._getReqId();\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP SPEC: [REGISTER, Request|id, Options|dict, Procedure|uri]\n this._send([WAMP_MSG_SPEC.REGISTER, reqId, options, topicURI]);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n } else { // already have registration with such topicURI\n this._cache.opStatus = WAMP_ERROR_MSG.RPC_ALREADY_REGISTERED;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n }\n\n return this;\n\n }\n\n /**\n * RPC unregistration for invocation\n * @param {string} topicURI\n * @param {function|object} callbacks - if it is a function, it will be called on successful unregistration\n * or it can be hash table of callbacks:\n * { onSuccess: will be called on successful unregistration\n * onError: will be called if unregistration would be aborted }\n * @returns {Wampy}\n */\n unregister (topicURI, callbacks) {\n let reqId;\n\n if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: false }, 'dealer', callbacks)) {\n return this;\n }\n\n if (typeof callbacks === 'function') {\n callbacks = { onSuccess: callbacks };\n }\n\n if (this._rpcRegs[topicURI]) { // there is such registration\n\n reqId = this._getReqId();\n\n this._requests[reqId] = {\n topic: topicURI,\n callbacks\n };\n\n // WAMP SPEC: [UNREGISTER, Request|id, REGISTERED.Registration|id]\n this._send([WAMP_MSG_SPEC.UNREGISTER, reqId, this._rpcRegs[topicURI].id]);\n this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;\n this._cache.opStatus.reqId = reqId;\n } else { // there is no registration with such topicURI\n this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_RPC_UNREG;\n\n if (this._isPlainObject(callbacks) && callbacks.onError) {\n callbacks.onError({ error: this._cache.opStatus.description });\n }\n\n }\n\n return this;\n }\n}\n\nexport default Wampy;\nexport { Wampy };\n"],"file":"wampy.js"} \ No newline at end of file