backendless-rt-client
Advanced tools
Comparing version
170
es/client.js
@@ -1,41 +0,34 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _config = require('./config'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _constants = require("./constants"); | ||
var _subscriptions = require('./subscriptions'); | ||
var _config = _interopRequireDefault(require("./config")); | ||
var _subscriptions2 = _interopRequireDefault(_subscriptions); | ||
var _subscriptions = _interopRequireDefault(require("./subscriptions")); | ||
var _methods = require('./methods'); | ||
var _methods = _interopRequireDefault(require("./methods")); | ||
var _methods2 = _interopRequireDefault(_methods); | ||
var _session = _interopRequireDefault(require("./session")); | ||
var _session = require('./session'); | ||
var _session2 = _interopRequireDefault(_session); | ||
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"); } } | ||
var CONNECTION_MANAGE_EVENTS = [_constants.NativeSocketEvents.CONNECTING, _constants.NativeSocketEvents.CONNECT, _constants.NativeSocketEvents.CONNECT_ERROR, _constants.NativeSocketEvents.DISCONNECT, _constants.NativeSocketEvents.RECONNECT_ATTEMPT]; | ||
var RTClient = function () { | ||
var RTClient = /*#__PURE__*/function () { | ||
function RTClient(config) { | ||
var _this = this; | ||
_classCallCheck(this, RTClient); | ||
this.onConnectError = function () { | ||
(0, _classCallCheck2["default"])(this, RTClient); | ||
(0, _defineProperty2["default"])(this, "onConnectError", function () { | ||
if (!_this.subscriptions.hasActivity() && !_this.methods.hasActivity()) { | ||
@@ -46,7 +39,6 @@ _this.disconnect('There are no active subscriptions and methods'); | ||
} | ||
}; | ||
this.connectOnMethod = function (method) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "connectOnMethod", function (method) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
@@ -65,9 +57,8 @@ } | ||
}; | ||
}; | ||
}); | ||
(0, _defineProperty2["default"])(this, "on", this.connectOnMethod('on')); | ||
(0, _defineProperty2["default"])(this, "emit", this.connectOnMethod('emit')); | ||
(0, _defineProperty2["default"])(this, "onSessionDisconnect", function () { | ||
_this.subscriptions.stop(); | ||
this.on = this.connectOnMethod('on'); | ||
this.emit = this.connectOnMethod('emit'); | ||
this.onSessionDisconnect = function () { | ||
_this.subscriptions.stop(); | ||
_this.methods.stop(); | ||
@@ -78,6 +69,5 @@ | ||
_this.provideConnection(); | ||
}; | ||
this.emitSocketEventListeners = function (event) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "emitSocketEventListeners", function (event) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
@@ -88,57 +78,43 @@ } | ||
_this.socketEvents[event].forEach(function (callback) { | ||
return callback.apply(undefined, args); | ||
return callback.apply(void 0, args); | ||
}); | ||
} | ||
}; | ||
this.addConnectingEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addConnectingEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.CONNECTING, callback); | ||
}; | ||
this.removeConnectingEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectingEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.CONNECTING, callback); | ||
}; | ||
this.addConnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addConnectEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.CONNECT, callback); | ||
}; | ||
this.removeConnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.CONNECT, callback); | ||
}; | ||
this.addConnectErrorEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addConnectErrorEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.CONNECT_ERROR, callback); | ||
}; | ||
this.removeConnectErrorEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectErrorEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.CONNECT_ERROR, callback); | ||
}; | ||
this.addDisconnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addDisconnectEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.DISCONNECT, callback); | ||
}; | ||
this.removeDisconnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeDisconnectEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.DISCONNECT, callback); | ||
}; | ||
this.addReconnectAttemptEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addReconnectAttemptEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.RECONNECT_ATTEMPT, callback); | ||
}; | ||
this.removeReconnectAttemptEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeReconnectAttemptEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.RECONNECT_ATTEMPT, callback); | ||
}; | ||
this.removeConnectionListeners = function () { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectionListeners", function () { | ||
CONNECTION_MANAGE_EVENTS.forEach(function (event) { | ||
return _this.removeSocketEventListener(event); | ||
}); | ||
}; | ||
this.config = new _config2.default(config); | ||
}); | ||
this.config = new _config["default"](config); | ||
this.resetSocketEvents(); | ||
var socketContext = { | ||
@@ -148,6 +124,4 @@ onMessage: this.on.bind(this), | ||
}; | ||
this.subscriptions = new _subscriptions2.default(socketContext); | ||
this.methods = new _methods2.default(socketContext); | ||
this.subscriptions = new _subscriptions["default"](socketContext); | ||
this.methods = new _methods["default"](socketContext); | ||
this.connectible = true; | ||
@@ -157,4 +131,4 @@ this.connected = false; | ||
_createClass(RTClient, [{ | ||
key: 'resetSocketEvents', | ||
(0, _createClass2["default"])(RTClient, [{ | ||
key: "resetSocketEvents", | ||
value: function resetSocketEvents() { | ||
@@ -165,3 +139,3 @@ this.socketEvents = {}; | ||
}, { | ||
key: 'setConfig', | ||
key: "setConfig", | ||
value: function setConfig(config) { | ||
@@ -172,3 +146,2 @@ this.config.set(config); | ||
this.disconnect('Re-config socket connection'); | ||
this.connect(); | ||
@@ -178,3 +151,3 @@ } | ||
}, { | ||
key: 'provideConnection', | ||
key: "provideConnection", | ||
value: function provideConnection() { | ||
@@ -184,3 +157,3 @@ var _this2 = this; | ||
if (!this.session) { | ||
this.session = new _session2.default(this.config, this.emitSocketEventListeners, this.onSessionDisconnect); | ||
this.session = new _session["default"](this.config, this.emitSocketEventListeners, this.onSessionDisconnect); | ||
this.session.getSocket().then(function () { | ||
@@ -190,5 +163,7 @@ _this2.connected = true; | ||
_this2.methods.initialize(); | ||
_this2.methods.restore(); | ||
_this2.subscriptions.initialize(); | ||
_this2.subscriptions.restore(); | ||
@@ -201,10 +176,9 @@ }); | ||
}, { | ||
key: 'connect', | ||
key: "connect", | ||
value: function connect() { | ||
this.connectible = true; | ||
this.provideConnection(); | ||
} | ||
}, { | ||
key: 'disconnect', | ||
key: "disconnect", | ||
value: function disconnect(reason) { | ||
@@ -214,7 +188,4 @@ if (this.session) { | ||
this.methods.stop(); | ||
this.session.terminate(); | ||
delete this.session; | ||
this.emitSocketEventListeners(_constants.NativeSocketEvents.DISCONNECT, reason || 'disconnected by client'); | ||
@@ -227,21 +198,18 @@ } | ||
}, { | ||
key: 'terminate', | ||
key: "terminate", | ||
value: function terminate(reason) { | ||
this.resetSocketEvents(); | ||
this.subscriptions.reset(); | ||
this.methods.reset(); | ||
this.disconnect(reason || 'Terminated by client'); | ||
} | ||
}, { | ||
key: 'addSocketEventListener', | ||
key: "addSocketEventListener", | ||
value: function addSocketEventListener(event, callback) { | ||
this.socketEvents[event] = this.socketEvents[event] || []; | ||
this.socketEvents[event].push(callback); | ||
return this; | ||
} | ||
}, { | ||
key: 'removeSocketEventListener', | ||
key: "removeSocketEventListener", | ||
value: function removeSocketEventListener(event, callback) { | ||
@@ -260,12 +228,6 @@ if (this.socketEvents[event]) { | ||
} | ||
/* eslint-disable max-len */ | ||
/* eslint-enable max-len */ | ||
}]); | ||
return RTClient; | ||
}(); | ||
exports.default = RTClient; | ||
exports["default"] = RTClient; |
118
es/config.js
@@ -1,30 +0,41 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _backendlessRequest = _interopRequireDefault(require("backendless-request")); | ||
var isUndefined = function isUndefined(value) { | ||
return typeof value === 'undefined'; | ||
}; | ||
var isString = function isString(value) { | ||
return typeof value === 'string'; | ||
}; | ||
var isFunction = function isFunction(value) { | ||
return typeof value === 'function'; | ||
}; | ||
var isObject = function isObject(value) { | ||
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null; | ||
return (0, _typeof2["default"])(value) === 'object' && value !== null; | ||
}; | ||
var RTConfig = function () { | ||
var RTConfig = /*#__PURE__*/function () { | ||
function RTConfig(config) { | ||
_classCallCheck(this, RTConfig); | ||
(0, _classCallCheck2["default"])(this, RTConfig); | ||
this.appId = null; | ||
@@ -35,8 +46,9 @@ this.lookupPath = null; | ||
this.connectQuery = {}; | ||
this.socketConfigTransform = null; | ||
this.socketConfig = null; | ||
this.set(config); | ||
} | ||
_createClass(RTConfig, [{ | ||
key: 'set', | ||
(0, _createClass2["default"])(RTConfig, [{ | ||
key: "set", | ||
value: function set(config) { | ||
@@ -84,13 +96,91 @@ if (!config) { | ||
} | ||
if (!isUndefined(config.socketConfigTransform)) { | ||
if (isFunction(config.socketConfigTransform)) { | ||
this.socketConfigTransform = config.socketConfigTransform; | ||
} else { | ||
throw new Error('"socketConfigTransform" must be Function.'); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'getConnectQuery', | ||
key: "getConnectQuery", | ||
value: function getConnectQuery() { | ||
return this.connectQuery; | ||
} | ||
}, { | ||
key: "prepare", | ||
value: function () { | ||
var _prepare = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var host, url, path, query, socketConfig; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (isString(this.lookupPath)) { | ||
_context.next = 2; | ||
break; | ||
} | ||
throw new Error('lookupPath must be String'); | ||
case 2: | ||
_context.next = 4; | ||
return _backendlessRequest["default"].get(this.lookupPath).set(this.lookupHeaders); | ||
case 4: | ||
host = _context.sent; | ||
url = this.appId ? "".concat(host, "/").concat(this.appId) : host; | ||
path = this.appId ? "/".concat(this.appId) : undefined; | ||
query = this.getConnectQuery(); | ||
this.socketConfig = { | ||
host: host, | ||
url: url, | ||
options: { | ||
path: path, | ||
query: query, | ||
forceNew: true, | ||
autoConnect: false, | ||
reconnection: false | ||
} | ||
}; | ||
if (!this.socketConfigTransform) { | ||
_context.next = 14; | ||
break; | ||
} | ||
_context.next = 12; | ||
return this.socketConfigTransform(this.socketConfig); | ||
case 12: | ||
socketConfig = _context.sent; | ||
if (socketConfig) { | ||
this.socketConfig = socketConfig; | ||
} | ||
case 14: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function prepare() { | ||
return _prepare.apply(this, arguments); | ||
} | ||
return prepare; | ||
}() | ||
}, { | ||
key: "getSocketConfig", | ||
value: function getSocketConfig() { | ||
return this.socketConfig; | ||
} | ||
}]); | ||
return RTConfig; | ||
}(); | ||
exports.default = RTConfig; | ||
exports["default"] = RTConfig; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,3 +6,4 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var NativeSocketEvents = exports.NativeSocketEvents = { | ||
exports.RTSubscriptionTypes = exports.RTSocketEvents = exports.RTMethodTypes = exports.NativeSocketEvents = void 0; | ||
var NativeSocketEvents = { | ||
CONNECTING: 'connecting', | ||
@@ -22,4 +23,4 @@ CONNECT: 'connect', | ||
}; | ||
var RTSocketEvents = exports.RTSocketEvents = { | ||
exports.NativeSocketEvents = NativeSocketEvents; | ||
var RTSocketEvents = { | ||
SUB_ON: 'SUB_ON', | ||
@@ -29,11 +30,9 @@ SUB_OFF: 'SUB_OFF', | ||
SUB_READY: 'SUB_READY', | ||
MET_REQ: 'MET_REQ', | ||
MET_RES: 'MET_RES' | ||
}; | ||
var RTSubscriptionTypes = exports.RTSubscriptionTypes = { | ||
exports.RTSocketEvents = RTSocketEvents; | ||
var RTSubscriptionTypes = { | ||
OBJECTS_CHANGES: 'OBJECTS_CHANGES', | ||
RELATIONS_CHANGES: 'RELATIONS_CHANGES', | ||
PUB_SUB_CONNECT: 'PUB_SUB_CONNECT', | ||
@@ -43,3 +42,2 @@ PUB_SUB_MESSAGES: 'PUB_SUB_MESSAGES', | ||
PUB_SUB_USERS: 'PUB_SUB_USERS', | ||
RSO_CONNECT: 'RSO_CONNECT', | ||
@@ -51,17 +49,13 @@ RSO_CHANGES: 'RSO_CHANGES', | ||
RSO_USERS: 'RSO_USERS', | ||
//-----------------------------------------// | ||
//----------- FOR CONSOLE ONLY ------------// | ||
LOGGING_MESSAGES: 'LOGGING_MESSAGES', | ||
CONSOLE_MESSAGES: 'CONSOLE_MESSAGES', | ||
DEVELOPER_MESSAGES: 'DEVELOPER_MESSAGES' | ||
DEVELOPER_MESSAGES: 'DEVELOPER_MESSAGES' //----------- FOR CONSOLE ONLY ------------// | ||
//-----------------------------------------// | ||
//----------- FOR CONSOLE ONLY ------------// | ||
//-----------------------------------------// | ||
}; | ||
var RTMethodTypes = exports.RTMethodTypes = { | ||
exports.RTSubscriptionTypes = RTSubscriptionTypes; | ||
var RTMethodTypes = { | ||
SET_USER_TOKEN: 'SET_USER_TOKEN', | ||
RSO_GET: 'RSO_GET', | ||
@@ -72,4 +66,4 @@ RSO_SET: 'RSO_SET', | ||
RSO_INVOKE: 'RSO_INVOKE', | ||
PUB_SUB_COMMAND: 'PUB_SUB_COMMAND' | ||
}; | ||
}; | ||
exports.RTMethodTypes = RTMethodTypes; |
@@ -1,42 +0,35 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.RTScopeConnector = exports.RTListeners = undefined; | ||
exports["default"] = exports.RTScopeConnector = exports.RTListeners = void 0; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _backendlessRequest = require('backendless-request'); | ||
var _backendlessRequest = _interopRequireDefault(require("backendless-request")); | ||
var _backendlessRequest2 = _interopRequireDefault(_backendlessRequest); | ||
var _client = _interopRequireDefault(require("./client")); | ||
var _client = require('./client'); | ||
var _listeners = _interopRequireDefault(require("./listeners")); | ||
var _client2 = _interopRequireDefault(_client); | ||
var _scopeConnector = _interopRequireDefault(require("./scope-connector")); | ||
var _listeners = require('./listeners'); | ||
var root = (typeof self === "undefined" ? "undefined" : (0, _typeof2["default"])(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : (0, _typeof2["default"])(global)) === 'object' && global.global === global && global; | ||
_client["default"].Request = _backendlessRequest["default"]; | ||
_client["default"].Listeners = _listeners["default"]; | ||
_client["default"].ScopeConnector = _scopeConnector["default"]; | ||
var _listeners2 = _interopRequireDefault(_listeners); | ||
var _scopeConnector = require('./scope-connector'); | ||
var _scopeConnector2 = _interopRequireDefault(_scopeConnector); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var root = (typeof self === 'undefined' ? 'undefined' : _typeof(self)) === 'object' && self.self === self && self || (typeof global === 'undefined' ? 'undefined' : _typeof(global)) === 'object' && global.global === global && global; | ||
_client2.default.Request = _backendlessRequest2.default; | ||
_client2.default.Listeners = _listeners2.default; | ||
_client2.default.ScopeConnector = _scopeConnector2.default; | ||
if (root) { | ||
root.BackendlessRTClient = _client2.default; | ||
root.BackendlessRTClient = _client["default"]; | ||
} | ||
module.exports = _client2.default; | ||
exports.default = _client2.default; | ||
var RTListeners = exports.RTListeners = _listeners2.default; | ||
var RTScopeConnector = exports.RTScopeConnector = _scopeConnector2.default; | ||
module.exports = _client["default"]; | ||
var _default = _client["default"]; | ||
exports["default"] = _default; | ||
var RTListeners = _listeners["default"]; | ||
exports.RTListeners = RTListeners; | ||
var RTScopeConnector = _scopeConnector["default"]; | ||
exports.RTScopeConnector = RTScopeConnector; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var RTListeners = function () { | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
var RTListeners = /*#__PURE__*/function () { | ||
function RTListeners() { | ||
_classCallCheck(this, RTListeners); | ||
(0, _classCallCheck2["default"])(this, RTListeners); | ||
this.subscriptions = {}; | ||
@@ -21,3 +27,3 @@ this.simpleListeners = {}; | ||
_createClass(RTListeners, [{ | ||
(0, _createClass2["default"])(RTListeners, [{ | ||
key: "addSubscription", | ||
@@ -32,6 +38,4 @@ value: function addSubscription(type, subscriberFn, _ref) { | ||
params = _ref.params; | ||
this.subscriptions[type] = this.subscriptions[type] || []; | ||
var subscription = subscriberFn(_extends({}, params, this.getSubscriptionOptions()), { | ||
var subscription = subscriberFn(_objectSpread(_objectSpread({}, params), this.getSubscriptionOptions()), { | ||
parser: parser, | ||
@@ -47,3 +51,2 @@ onData: callback, | ||
}); | ||
var subscriptionStore = { | ||
@@ -57,5 +60,3 @@ callback: callback, | ||
}; | ||
this.subscriptions[type].push(subscriptionStore); | ||
return subscriptionStore; | ||
@@ -73,3 +74,2 @@ } | ||
matcher = _ref2.matcher; | ||
var subscriptionsStack = this.subscriptions[type] = this.subscriptions[type] || []; | ||
@@ -95,3 +95,2 @@ | ||
var listenersStack = this.simpleListeners[type] = this.simpleListeners[type] || []; | ||
listenersStack.push(callback); | ||
@@ -111,3 +110,3 @@ } | ||
value: function runSimpleListeners(type) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
@@ -118,3 +117,3 @@ } | ||
this.simpleListeners[type].forEach(function (callback) { | ||
return callback.apply(undefined, args); | ||
return callback.apply(void 0, args); | ||
}); | ||
@@ -134,10 +133,8 @@ } | ||
}); | ||
this.simpleListeners = {}; | ||
} | ||
}]); | ||
return RTListeners; | ||
}(); | ||
exports.default = RTListeners; | ||
exports["default"] = RTListeners; |
@@ -1,20 +0,20 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _utils = require('./utils'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _utils2 = _interopRequireDefault(_utils); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _utils = _interopRequireDefault(require("./utils")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var method = function method(type) { | ||
@@ -26,3 +26,3 @@ return function (data) { | ||
var RTMethods = function () { | ||
var RTMethods = /*#__PURE__*/function () { | ||
function RTMethods(_ref) { | ||
@@ -33,12 +33,9 @@ var _this = this; | ||
emitMessage = _ref.emitMessage; | ||
_classCallCheck(this, RTMethods); | ||
this.sendRequest = function (invocationId) { | ||
(0, _classCallCheck2["default"])(this, RTMethods); | ||
(0, _defineProperty2["default"])(this, "sendRequest", function (invocationId) { | ||
if (_this.invocations[invocationId]) { | ||
_this.emitMessage(_constants.RTSocketEvents.MET_REQ, _this.invocations[invocationId].data); | ||
} | ||
}; | ||
this.onResponse = function (_ref2) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "onResponse", function (_ref2) { | ||
var id = _ref2.id, | ||
@@ -59,20 +56,17 @@ error = _ref2.error, | ||
} | ||
}; | ||
this.setUserToken = method(_constants.RTMethodTypes.SET_USER_TOKEN).bind(this); | ||
this.sendPubSubCommand = method(_constants.RTMethodTypes.PUB_SUB_COMMAND).bind(this); | ||
this.getRSO = method(_constants.RTMethodTypes.RSO_GET).bind(this); | ||
this.setRSO = method(_constants.RTMethodTypes.RSO_SET).bind(this); | ||
this.clearRSO = method(_constants.RTMethodTypes.RSO_CLEAR).bind(this); | ||
this.sendRSOCommand = method(_constants.RTMethodTypes.RSO_COMMAND).bind(this); | ||
this.invokeRSOMethod = method(_constants.RTMethodTypes.RSO_INVOKE).bind(this); | ||
}); | ||
(0, _defineProperty2["default"])(this, "setUserToken", method(_constants.RTMethodTypes.SET_USER_TOKEN).bind(this)); | ||
(0, _defineProperty2["default"])(this, "sendPubSubCommand", method(_constants.RTMethodTypes.PUB_SUB_COMMAND).bind(this)); | ||
(0, _defineProperty2["default"])(this, "getRSO", method(_constants.RTMethodTypes.RSO_GET).bind(this)); | ||
(0, _defineProperty2["default"])(this, "setRSO", method(_constants.RTMethodTypes.RSO_SET).bind(this)); | ||
(0, _defineProperty2["default"])(this, "clearRSO", method(_constants.RTMethodTypes.RSO_CLEAR).bind(this)); | ||
(0, _defineProperty2["default"])(this, "sendRSOCommand", method(_constants.RTMethodTypes.RSO_COMMAND).bind(this)); | ||
(0, _defineProperty2["default"])(this, "invokeRSOMethod", method(_constants.RTMethodTypes.RSO_INVOKE).bind(this)); | ||
this.onMessage = onMessage; | ||
this.emitMessage = emitMessage; | ||
this.invocations = {}; | ||
} | ||
_createClass(RTMethods, [{ | ||
key: 'initialize', | ||
(0, _createClass2["default"])(RTMethods, [{ | ||
key: "initialize", | ||
value: function initialize() { | ||
@@ -82,3 +76,3 @@ this.onMessage(_constants.RTSocketEvents.MET_RES, this.onResponse); | ||
}, { | ||
key: 'restore', | ||
key: "restore", | ||
value: function restore() { | ||
@@ -92,6 +86,6 @@ var _this2 = this; | ||
}, { | ||
key: 'stop', | ||
key: "stop", | ||
value: function stop() {} | ||
}, { | ||
key: 'reset', | ||
key: "reset", | ||
value: function reset() { | ||
@@ -101,3 +95,3 @@ this.invocations = {}; | ||
}, { | ||
key: 'hasActivity', | ||
key: "hasActivity", | ||
value: function hasActivity() { | ||
@@ -107,18 +101,16 @@ return !!Object.keys(this.invocations).length; | ||
}, { | ||
key: 'send', | ||
//----------- RSO METHODS ---------// | ||
//---------------------------------// | ||
key: "send", | ||
value: function send(name, options) { | ||
var _this3 = this; | ||
var invocationId = _utils2.default.generateUID(); | ||
var invocationId = _utils["default"].generateUID(); | ||
this.invocations[invocationId] = { | ||
data: { id: invocationId, name: name, options: options } | ||
data: { | ||
id: invocationId, | ||
name: name, | ||
options: options | ||
} | ||
}; | ||
this.sendRequest(invocationId); | ||
return new Promise(function (resolve, reject) { | ||
@@ -128,24 +120,9 @@ _this3.invocations[invocationId].resolve = resolve; | ||
}); | ||
} | ||
} //----------- RSO METHODS ---------// | ||
//---------------------------------// | ||
//----------- AUTH METHODS --------// | ||
//----------- AUTH METHODS --------// | ||
//---------------------------------// | ||
//---------------------------------// | ||
//-------- PUB_SUB METHODS --------// | ||
//-------- PUB_SUB METHODS --------// | ||
//---------------------------------// | ||
//---------------------------------// | ||
//----------- RSO METHODS ---------// | ||
}]); | ||
return RTMethods; | ||
}(); | ||
exports.default = RTMethods; | ||
exports["default"] = RTMethods; |
@@ -1,57 +0,38 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _dec, _dec2, _dec3, _dec4, _dec5, _desc, _value, _class, _class2, _temp; | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _listeners = require('./listeners'); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _listeners2 = _interopRequireDefault(_listeners); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor")); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var _listeners = _interopRequireDefault(require("./listeners")); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2; | ||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { | ||
var desc = {}; | ||
Object['ke' + 'ys'](descriptor).forEach(function (key) { | ||
desc[key] = descriptor[key]; | ||
}); | ||
desc.enumerable = !!desc.enumerable; | ||
desc.configurable = !!desc.configurable; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
if ('value' in desc || desc.initializer) { | ||
desc.writable = true; | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
desc = decorators.slice().reverse().reduce(function (desc, decorator) { | ||
return decorator(target, property, desc) || desc; | ||
}, desc); | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } | ||
if (context && desc.initializer !== void 0) { | ||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0; | ||
desc.initializer = undefined; | ||
} | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
if (desc.initializer === void 0) { | ||
Object['define' + 'Property'](target, property, desc); | ||
desc = null; | ||
} | ||
return desc; | ||
} | ||
var ListenerTypes = { | ||
@@ -63,27 +44,29 @@ CONNECT: 'CONNECT', | ||
}; | ||
var RTScopeConnector = (_dec = connectionRequired(), _dec2 = connectionRequired(), _dec3 = connectionRequired(), _dec4 = connectionRequired(), _dec5 = connectionRequired(true), (_class = (_class2 = /*#__PURE__*/function (_RTListeners) { | ||
(0, _inherits2["default"])(RTScopeConnector, _RTListeners); | ||
var RTScopeConnector = (_dec = connectionRequired(), _dec2 = connectionRequired(), _dec3 = connectionRequired(), _dec4 = connectionRequired(), _dec5 = connectionRequired(true), (_class = (_temp = _class2 = function (_RTListeners) { | ||
_inherits(RTScopeConnector, _RTListeners); | ||
var _super = _createSuper(RTScopeConnector); | ||
_createClass(RTScopeConnector, [{ | ||
key: 'connectSubscriber', | ||
function RTScopeConnector(options) { | ||
var _this2; | ||
(0, _classCallCheck2["default"])(this, RTScopeConnector); | ||
_this2 = _super.call(this); | ||
_this2.options = options; | ||
_this2.waitConnection = []; | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* must returns a function for adding subscriptions to CONNECT to connection scope | ||
* For ex.: RTProvider.subscriptions.connectToRSO | ||
**/ | ||
get: function get() { | ||
return null; | ||
} | ||
_this2.connect(); | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* | ||
* must returns a function for adding subscriptions to listening COMMANDS in connection scope | ||
* For ex.: RTProvider.subscriptions.onRSOCommand | ||
**/ | ||
return _this2; | ||
} | ||
/** | ||
* @public method | ||
* | ||
* connect to connection scope, if you already connected the method do nothing | ||
**/ | ||
(0, _createClass2["default"])(RTScopeConnector, [{ | ||
key: "connectSubscriber", | ||
get: | ||
/** | ||
@@ -102,8 +85,22 @@ * @static | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* must returns a function for adding subscriptions to CONNECT to connection scope | ||
* For ex.: RTProvider.subscriptions.connectToRSO | ||
**/ | ||
function get() { | ||
return null; | ||
} | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* | ||
* must returns a function for adding subscriptions to listening COMMANDS in connection scope | ||
* For ex.: RTProvider.subscriptions.onRSOCommand | ||
**/ | ||
}, { | ||
key: 'commandSubscriber', | ||
key: "commandSubscriber", | ||
get: function get() { | ||
return null; | ||
} | ||
/** | ||
@@ -117,7 +114,6 @@ * @abstract getter, must be overridden in an inherited class | ||
}, { | ||
key: 'usersSubscriber', | ||
key: "usersSubscriber", | ||
get: function get() { | ||
return null; | ||
} | ||
/** | ||
@@ -131,32 +127,10 @@ * @abstract getter, must be overridden in an inherited class | ||
}, { | ||
key: 'commandSender', | ||
key: "commandSender", | ||
get: function get() { | ||
return null; | ||
} | ||
}]); | ||
function RTScopeConnector(options) { | ||
_classCallCheck(this, RTScopeConnector); | ||
var _this = _possibleConstructorReturn(this, (RTScopeConnector.__proto__ || Object.getPrototypeOf(RTScopeConnector)).call(this)); | ||
_this.options = options; | ||
_this.waitConnection = []; | ||
_this.connect(); | ||
return _this; | ||
} | ||
/** | ||
* @public method | ||
* | ||
* connect to connection scope, if you already connected the method do nothing | ||
**/ | ||
_createClass(RTScopeConnector, [{ | ||
key: 'connect', | ||
}, { | ||
key: "connect", | ||
value: function connect() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -166,9 +140,9 @@ if (!this.isConnected()) { | ||
onError: function onError(error) { | ||
return _this2.onError(error); | ||
return _this3.onError(error); | ||
}, | ||
onReady: function onReady() { | ||
return _this2.onConnect(); | ||
return _this3.onConnect(); | ||
}, | ||
onStop: function onStop() { | ||
return _this2.onDisconnect(); | ||
return _this3.onDisconnect(); | ||
} | ||
@@ -178,3 +152,2 @@ }); | ||
} | ||
/** | ||
@@ -187,3 +160,3 @@ * @public method | ||
}, { | ||
key: 'disconnect', | ||
key: "disconnect", | ||
value: function disconnect() { | ||
@@ -194,3 +167,2 @@ if (this.isConnected()) { | ||
} | ||
/** | ||
@@ -203,7 +175,6 @@ * @public method | ||
}, { | ||
key: 'isConnected', | ||
key: "isConnected", | ||
value: function isConnected() { | ||
return !!this.connection && this.connection.isReady(); | ||
} | ||
/** | ||
@@ -214,7 +185,6 @@ * @private method | ||
}, { | ||
key: 'getSubscriptionOptions', | ||
key: "getSubscriptionOptions", | ||
value: function getSubscriptionOptions() { | ||
return this.getScopeOptions(); | ||
} | ||
/** | ||
@@ -225,7 +195,6 @@ * @private method | ||
}, { | ||
key: 'getScopeOptions', | ||
key: "getScopeOptions", | ||
value: function getScopeOptions() { | ||
return this.options; | ||
} | ||
/** | ||
@@ -236,3 +205,3 @@ * @private method | ||
}, { | ||
key: 'onConnect', | ||
key: "onConnect", | ||
value: function onConnect() { | ||
@@ -243,6 +212,4 @@ this.waitConnection.forEach(function (operation) { | ||
this.waitConnection = []; | ||
this.runSimpleListeners(ListenerTypes.CONNECT); | ||
} | ||
/** | ||
@@ -253,7 +220,6 @@ * @private method | ||
}, { | ||
key: 'onError', | ||
key: "onError", | ||
value: function onError(error) { | ||
this.runSimpleListeners(ListenerTypes.ERROR, error); | ||
} | ||
/** | ||
@@ -264,7 +230,6 @@ * @private method | ||
}, { | ||
key: 'onDisconnect', | ||
key: "onDisconnect", | ||
value: function onDisconnect() { | ||
this.connection = null; | ||
} | ||
/** | ||
@@ -275,11 +240,8 @@ * @public method | ||
}, { | ||
key: 'removeAllListeners', | ||
key: "removeAllListeners", | ||
value: function removeAllListeners() { | ||
this.waitConnection = []; | ||
_get(RTScopeConnector.prototype.__proto__ || Object.getPrototypeOf(RTScopeConnector.prototype), 'removeAllListeners', this).call(this); | ||
(0, _get2["default"])((0, _getPrototypeOf2["default"])(RTScopeConnector.prototype), "removeAllListeners", this).call(this); | ||
return this; | ||
} | ||
/** | ||
@@ -290,3 +252,3 @@ * @public method | ||
}, { | ||
key: 'addConnectListener', | ||
key: "addConnectListener", | ||
value: function addConnectListener(callback, onError) { | ||
@@ -301,3 +263,2 @@ this.addSimpleListener(ListenerTypes.CONNECT, callback); | ||
} | ||
/** | ||
@@ -308,3 +269,3 @@ * @public method | ||
}, { | ||
key: 'removeConnectListeners', | ||
key: "removeConnectListeners", | ||
value: function removeConnectListeners(callback, onError) { | ||
@@ -319,3 +280,2 @@ this.removeSimpleListener(ListenerTypes.CONNECT, callback); | ||
} | ||
/** | ||
@@ -326,9 +286,10 @@ * @public method | ||
}, { | ||
key: 'addCommandListener', | ||
key: "addCommandListener", | ||
value: function addCommandListener(callback, onError) { | ||
this.addSubscription(ListenerTypes.COMMAND, this.commandSubscriber, { callback: callback, onError: onError }); | ||
this.addSubscription(ListenerTypes.COMMAND, this.commandSubscriber, { | ||
callback: callback, | ||
onError: onError | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -339,9 +300,9 @@ * @public method | ||
}, { | ||
key: 'removeCommandListeners', | ||
key: "removeCommandListeners", | ||
value: function removeCommandListeners(callback) { | ||
this.stopSubscription(ListenerTypes.COMMAND, { callback: callback }); | ||
this.stopSubscription(ListenerTypes.COMMAND, { | ||
callback: callback | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -352,9 +313,10 @@ * @public method | ||
}, { | ||
key: 'addUserStatusListener', | ||
key: "addUserStatusListener", | ||
value: function addUserStatusListener(callback, onError) { | ||
this.addSubscription(ListenerTypes.USER_STATUS, this.usersSubscriber, { callback: callback, onError: onError }); | ||
this.addSubscription(ListenerTypes.USER_STATUS, this.usersSubscriber, { | ||
callback: callback, | ||
onError: onError | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -365,9 +327,9 @@ * @public method | ||
}, { | ||
key: 'removeUserStatusListeners', | ||
key: "removeUserStatusListeners", | ||
value: function removeUserStatusListeners(callback) { | ||
this.stopSubscription(ListenerTypes.USER_STATUS, { callback: callback }); | ||
this.stopSubscription(ListenerTypes.USER_STATUS, { | ||
callback: callback | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -378,13 +340,14 @@ * @public method | ||
}, { | ||
key: 'send', | ||
key: "send", | ||
value: function send(type, data) { | ||
return this.commandSender(_extends({}, this.getScopeOptions(), { type: type, data: data })); | ||
return this.commandSender(_objectSpread(_objectSpread({}, this.getScopeOptions()), {}, { | ||
type: type, | ||
data: data | ||
})); | ||
} | ||
}]); | ||
return RTScopeConnector; | ||
}(_listeners2.default), _class2.connectionRequired = connectionRequired, _temp), (_applyDecoratedDescriptor(_class.prototype, 'addCommandListener', [_dec], Object.getOwnPropertyDescriptor(_class.prototype, 'addCommandListener'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'removeCommandListeners', [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, 'removeCommandListeners'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'addUserStatusListener', [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, 'addUserStatusListener'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'removeUserStatusListeners', [_dec4], Object.getOwnPropertyDescriptor(_class.prototype, 'removeUserStatusListeners'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'send', [_dec5], Object.getOwnPropertyDescriptor(_class.prototype, 'send'), _class.prototype)), _class)); | ||
exports.default = RTScopeConnector; | ||
}(_listeners["default"]), (0, _defineProperty2["default"])(_class2, "connectionRequired", connectionRequired), _class2), ((0, _applyDecoratedDescriptor2["default"])(_class.prototype, "addCommandListener", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "addCommandListener"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "removeCommandListeners", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "removeCommandListeners"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "addUserStatusListener", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "addUserStatusListener"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "removeUserStatusListeners", [_dec4], Object.getOwnPropertyDescriptor(_class.prototype, "removeUserStatusListeners"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "send", [_dec5], Object.getOwnPropertyDescriptor(_class.prototype, "send"), _class.prototype)), _class)); | ||
exports["default"] = RTScopeConnector; | ||
function connectionRequired(returnPromise) { | ||
@@ -395,7 +358,7 @@ return function (target, key, descriptor) { | ||
descriptor.value = function () { | ||
var _this3 = this, | ||
_arguments = arguments; | ||
var _arguments = arguments, | ||
_this = this; | ||
var run = function run() { | ||
return decorated.apply(_this3, _arguments); | ||
return decorated.apply(_this, _arguments); | ||
}; | ||
@@ -409,3 +372,3 @@ | ||
return new Promise(function (resolve, reject) { | ||
return _this3.waitConnection.push(function () { | ||
return _this.waitConnection.push(function () { | ||
return run().then(resolve, reject); | ||
@@ -417,3 +380,2 @@ }); | ||
this.waitConnection.push(run); | ||
return this; | ||
@@ -420,0 +382,0 @@ }; |
@@ -1,20 +0,18 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _socket = require('./socket'); | ||
var _constants = require("./constants"); | ||
var _socket2 = _interopRequireDefault(_socket); | ||
var _socket = _interopRequireDefault(require("./socket")); | ||
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"); } } | ||
var INCREASE_RECONNECTION_TIMEOUT_STEP = 10; | ||
@@ -30,17 +28,14 @@ var INITIAL_RECONNECTION_TIMEOUT = 200; | ||
var RTSession = function () { | ||
var RTSession = /*#__PURE__*/function () { | ||
function RTSession(config, dispatch, onDisconnect) { | ||
_classCallCheck(this, RTSession); | ||
(0, _classCallCheck2["default"])(this, RTSession); | ||
this.config = config; | ||
this.dispatch = dispatch; | ||
this.onDisconnect = onDisconnect; | ||
this.connectAttempt = 0; | ||
this.socketPromise = this.connect(); | ||
} | ||
_createClass(RTSession, [{ | ||
key: 'terminate', | ||
(0, _createClass2["default"])(RTSession, [{ | ||
key: "terminate", | ||
value: function terminate() { | ||
@@ -50,4 +45,3 @@ if (!this.terminated) { | ||
this.dispatch = function () { | ||
//if sessions has been terminated don't need to dispatch any events | ||
this.dispatch = function () {//if sessions has been terminated don't need to dispatch any events | ||
}; | ||
@@ -63,3 +57,3 @@ | ||
}, { | ||
key: 'getSocket', | ||
key: "getSocket", | ||
value: function getSocket() { | ||
@@ -70,4 +64,3 @@ var _this = this; | ||
if (_this.terminated) { | ||
return new Promise(function () { | ||
//return unresolvable promise for preventing errors | ||
return new Promise(function () {//return unresolvable promise for preventing errors | ||
//this connection session has been terminated and a new one will be created if it necessary | ||
@@ -81,3 +74,3 @@ }); | ||
}, { | ||
key: 'connect', | ||
key: "connect", | ||
value: function connect() { | ||
@@ -91,5 +84,3 @@ var _this2 = this; | ||
this.connectAttempt = this.connectAttempt + 1; | ||
var nextReconnectionTimeout = this.getNextReconnectionTimeout(); | ||
this.onConnecting(); | ||
@@ -101,3 +92,3 @@ | ||
return _socket2.default.connect(this.config, this.onSocketDisconnect.bind(this)).then(function (rtSocket) { | ||
return _socket["default"].connect(this.config, this.onSocketDisconnect.bind(this)).then(function (rtSocket) { | ||
_this2.connectAttempt = 0; | ||
@@ -108,3 +99,3 @@ | ||
return rtSocket; | ||
}).catch(function (error) { | ||
})["catch"](function (error) { | ||
_this2.onConnectError(error); | ||
@@ -121,11 +112,10 @@ | ||
}, { | ||
key: 'getNextReconnectionTimeout', | ||
key: "getNextReconnectionTimeout", | ||
value: function getNextReconnectionTimeout() { | ||
var factor = Math.ceil(this.connectAttempt / INCREASE_RECONNECTION_TIMEOUT_STEP); | ||
var timeout = INITIAL_RECONNECTION_TIMEOUT * Math.pow(2, factor); | ||
return Math.min(timeout, MAX_RECONNECTION_TIMEOUT); | ||
} | ||
}, { | ||
key: 'onSocketDisconnect', | ||
key: "onSocketDisconnect", | ||
value: function onSocketDisconnect(reason) { | ||
@@ -136,3 +126,2 @@ this.dispatch(_constants.NativeSocketEvents.DISCONNECT, reason); | ||
this.terminate(); | ||
this.onDisconnect(); | ||
@@ -142,3 +131,3 @@ } | ||
}, { | ||
key: 'onConnecting', | ||
key: "onConnecting", | ||
value: function onConnecting() { | ||
@@ -148,3 +137,3 @@ this.dispatch(_constants.NativeSocketEvents.CONNECTING); | ||
}, { | ||
key: 'onConnect', | ||
key: "onConnect", | ||
value: function onConnect() { | ||
@@ -154,3 +143,3 @@ this.dispatch(_constants.NativeSocketEvents.CONNECT); | ||
}, { | ||
key: 'onConnectError', | ||
key: "onConnectError", | ||
value: function onConnectError(error) { | ||
@@ -160,3 +149,3 @@ this.dispatch(_constants.NativeSocketEvents.CONNECT_ERROR, error && error.message || error); | ||
}, { | ||
key: 'onReconnectAttempt', | ||
key: "onReconnectAttempt", | ||
value: function onReconnectAttempt(attempt, timeout) { | ||
@@ -166,6 +155,5 @@ this.dispatch(_constants.NativeSocketEvents.RECONNECT_ATTEMPT, attempt, timeout); | ||
}]); | ||
return RTSession; | ||
}(); | ||
exports.default = RTSession; | ||
exports["default"] = RTSession; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -13,9 +13,6 @@ /* eslint-disable */ | ||
*/ | ||
var Emitter = require('component-emitter'); | ||
exports.protocol = 4; | ||
exports.types = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'ERROR', 'BINARY_EVENT', 'BINARY_ACK']; | ||
exports.CONNECT = 0; | ||
@@ -28,3 +25,2 @@ exports.DISCONNECT = 1; | ||
exports.BINARY_ACK = 6; | ||
exports.Encoder = Encoder; | ||
@@ -34,3 +30,2 @@ exports.Decoder = Decoder; | ||
function Encoder() {} | ||
/** | ||
@@ -46,6 +41,6 @@ * Encode a packet as a single string if non-binary, or as a | ||
Encoder.prototype.encode = function (obj, callback) { | ||
callback([encodeAsString(obj)]); | ||
}; | ||
/** | ||
@@ -59,24 +54,23 @@ * Encode packet as string. | ||
function encodeAsString(obj) { | ||
// first is type | ||
var str = '' + obj.type; | ||
var str = '' + obj.type; // attachments if we have them | ||
// attachments if we have them | ||
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) { | ||
str += obj.attachments + '-'; | ||
} | ||
} // if we have a namespace other than `/` | ||
// we append it followed by a comma `,` | ||
// if we have a namespace other than `/` | ||
// we append it followed by a comma `,` | ||
if (obj.nsp && '/' !== obj.nsp) { | ||
str += obj.nsp + ','; | ||
} | ||
} // immediately followed by the id | ||
// immediately followed by the id | ||
if (null != obj.id) { | ||
str += obj.id; | ||
} | ||
} // json data | ||
// json data | ||
if (null != obj.data) { | ||
@@ -92,3 +86,2 @@ str += JSON.stringify(obj.data); | ||
Emitter(Decoder.prototype); | ||
/** | ||
@@ -109,3 +102,2 @@ * Decodes an ecoded packet string into packet JSON. | ||
}; | ||
/** | ||
@@ -119,14 +111,14 @@ * Decode a packet String (JSON data) | ||
function decodeString(str) { | ||
var i = 0; | ||
// look up type | ||
var i = 0; // look up type | ||
var p = { | ||
type: Number(str.charAt(0)) | ||
}; | ||
if (null == exports.types[p.type]) return error(); // look up attachments if type binary | ||
if (null == exports.types[p.type]) return error(); | ||
// look up attachments if type binary | ||
if (exports.BINARY_EVENT === p.type || exports.BINARY_ACK === p.type) { | ||
var buf = ''; | ||
while (str.charAt(++i) !== '-') { | ||
@@ -136,11 +128,14 @@ buf += str.charAt(i); | ||
} | ||
if (buf != Number(buf) || str.charAt(i) !== '-') { | ||
throw new Error('Illegal attachments'); | ||
} | ||
p.attachments = Number(buf); | ||
} | ||
} // look up namespace (if any) | ||
// look up namespace (if any) | ||
if ('/' === str.charAt(i + 1)) { | ||
p.nsp = ''; | ||
while (++i) { | ||
@@ -154,10 +149,13 @@ var c = str.charAt(i); | ||
p.nsp = '/'; | ||
} | ||
} // look up id | ||
// look up id | ||
var next = str.charAt(i + 1); | ||
if ('' !== next && Number(next) == next) { | ||
p.id = ''; | ||
while (++i) { | ||
var c = str.charAt(i); | ||
if (null == c || Number(c) != c) { | ||
@@ -167,9 +165,11 @@ --i; | ||
} | ||
p.id += str.charAt(i); | ||
if (i === str.length) break; | ||
} | ||
p.id = Number(p.id); | ||
} | ||
} // look up json data | ||
// look up json data | ||
if (str.charAt(++i)) { | ||
@@ -188,5 +188,5 @@ p = tryParse(p, str.substr(i)); | ||
} | ||
return p; | ||
} | ||
/** | ||
@@ -198,2 +198,3 @@ * Deallocates a parser's resources | ||
Decoder.prototype.destroy = function () {}; | ||
@@ -200,0 +201,0 @@ |
117
es/socket.js
@@ -1,55 +0,19 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _constants = require("./constants"); | ||
var RTSocket = function () { | ||
_createClass(RTSocket, null, [{ | ||
key: 'connect', | ||
value: function connect(config, onDisconnect) { | ||
var Request = require('backendless-request'); | ||
if (!config.lookupPath) { | ||
throw new Error('config.lookupPath is not configured'); | ||
} | ||
return Request.get(config.lookupPath).set(config.lookupHeaders).then(function (rtServerHost) { | ||
return new Promise(function (resolve, reject) { | ||
var rtSocket = new RTSocket(config, rtServerHost); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT, onConnect); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_ERROR, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_TIMEOUT, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.ERROR, onError); | ||
rtSocket.connect(); | ||
function onConnect() { | ||
resolve(rtSocket); | ||
} | ||
function onError(error) { | ||
rtSocket.close(); | ||
reject(error); | ||
} | ||
}); | ||
}).then(function (rtSocket) { | ||
rtSocket.on(_constants.NativeSocketEvents.DISCONNECT, onDisconnect); | ||
return rtSocket; | ||
}); | ||
} | ||
}]); | ||
var RTSocket = /*#__PURE__*/function () { | ||
function RTSocket(config, host) { | ||
_classCallCheck(this, RTSocket); | ||
(0, _classCallCheck2["default"])(this, RTSocket); | ||
@@ -59,20 +23,13 @@ var io = require('socket.io-client'); | ||
this.config = config; | ||
this.events = {}; | ||
if (!config.appId) { | ||
throw new Error('config.appId is not configured'); | ||
} | ||
var _config$getSocketConf = config.getSocketConfig(), | ||
url = _config$getSocketConf.url, | ||
options = _config$getSocketConf.options; | ||
this.ioSocket = io(host + '/' + this.config.appId, { | ||
forceNew: true, | ||
autoConnect: false, | ||
reconnection: false, | ||
path: '/' + this.config.appId, | ||
query: this.config.getConnectQuery() | ||
}); | ||
this.ioSocket = io(url, options); | ||
} | ||
_createClass(RTSocket, [{ | ||
key: 'connect', | ||
(0, _createClass2["default"])(RTSocket, [{ | ||
key: "connect", | ||
value: function connect() { | ||
@@ -82,3 +39,3 @@ this.ioSocket.connect(); | ||
}, { | ||
key: 'close', | ||
key: "close", | ||
value: function close() { | ||
@@ -90,3 +47,3 @@ this.events = {}; | ||
}, { | ||
key: 'on', | ||
key: "on", | ||
value: function on(event, callback) { | ||
@@ -105,3 +62,3 @@ var _this = this; | ||
}, { | ||
key: 'off', | ||
key: "off", | ||
value: function off(event, callback) { | ||
@@ -121,3 +78,3 @@ this.events[event] = callback ? this.events[event].filter(function (f) { | ||
}, { | ||
key: 'onEvent', | ||
key: "onEvent", | ||
value: function onEvent(event, data) { | ||
@@ -135,3 +92,3 @@ if (this.config.debugMode) { | ||
}, { | ||
key: 'emit', | ||
key: "emit", | ||
value: function emit(event, data) { | ||
@@ -144,13 +101,39 @@ if (this.config.debugMode) { | ||
} | ||
}], [{ | ||
key: "connect", | ||
value: function connect(config, onDisconnect) { | ||
return Promise.resolve().then(function () { | ||
return config.prepare(); | ||
}).then(function () { | ||
return new Promise(function (resolve, reject) { | ||
var rtSocket = new RTSocket(config); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT, onConnect); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_ERROR, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_TIMEOUT, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.ERROR, onError); | ||
rtSocket.connect(); | ||
function onConnect() { | ||
resolve(rtSocket); | ||
} | ||
function onError(error) { | ||
rtSocket.close(); | ||
reject(error); | ||
} | ||
}); | ||
}).then(function (rtSocket) { | ||
rtSocket.on(_constants.NativeSocketEvents.DISCONNECT, onDisconnect); | ||
return rtSocket; | ||
}); | ||
} | ||
}]); | ||
return RTSocket; | ||
}(); | ||
exports.default = RTSocket; | ||
exports["default"] = RTSocket; | ||
function logMessage(type, event, data) { | ||
// eslint-disable-next-line | ||
console.log('[' + type + '] - [event: ' + event + '] - arguments: ' + JSON.stringify(data) + ' '); | ||
console.log("[".concat(type, "] - [event: ").concat(event, "] - arguments: ").concat(JSON.stringify(data), " ")); | ||
} |
@@ -1,20 +0,20 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _utils = require('./utils'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _utils2 = _interopRequireDefault(_utils); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _utils = _interopRequireDefault(require("./utils")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var subscription = function subscription(type) { | ||
@@ -26,33 +26,29 @@ return function (options, callbacks) { | ||
var RTSubscriptions = function () { | ||
var RTSubscriptions = /*#__PURE__*/function () { | ||
function RTSubscriptions(_ref) { | ||
var onMessage = _ref.onMessage, | ||
emitMessage = _ref.emitMessage; | ||
_classCallCheck(this, RTSubscriptions); | ||
this.onObjectsChanges = subscription(_constants.RTSubscriptionTypes.OBJECTS_CHANGES).bind(this); | ||
this.onRelationsChanges = subscription(_constants.RTSubscriptionTypes.RELATIONS_CHANGES).bind(this); | ||
this.connectToPubSub = subscription(_constants.RTSubscriptionTypes.PUB_SUB_CONNECT).bind(this); | ||
this.onPubSubMessage = subscription(_constants.RTSubscriptionTypes.PUB_SUB_MESSAGES).bind(this); | ||
this.onPubSubCommand = subscription(_constants.RTSubscriptionTypes.PUB_SUB_COMMANDS).bind(this); | ||
this.onPubSubUserStatus = subscription(_constants.RTSubscriptionTypes.PUB_SUB_USERS).bind(this); | ||
this.connectToRSO = subscription(_constants.RTSubscriptionTypes.RSO_CONNECT).bind(this); | ||
this.onRSOChanges = subscription(_constants.RTSubscriptionTypes.RSO_CHANGES).bind(this); | ||
this.onRSOClear = subscription(_constants.RTSubscriptionTypes.RSO_CLEARED).bind(this); | ||
this.onRSOCommand = subscription(_constants.RTSubscriptionTypes.RSO_COMMANDS).bind(this); | ||
this.onRSOInvoke = subscription(_constants.RTSubscriptionTypes.RSO_INVOKE).bind(this); | ||
this.onRSOUserStatus = subscription(_constants.RTSubscriptionTypes.RSO_USERS).bind(this); | ||
this.onLoggingMessages = subscription(_constants.RTSubscriptionTypes.LOGGING_MESSAGES).bind(this); | ||
this.onConsoleMessages = subscription(_constants.RTSubscriptionTypes.CONSOLE_MESSAGES).bind(this); | ||
this.onDeveloperMessage = subscription(_constants.RTSubscriptionTypes.DEVELOPER_MESSAGES).bind(this); | ||
(0, _classCallCheck2["default"])(this, RTSubscriptions); | ||
(0, _defineProperty2["default"])(this, "onObjectsChanges", subscription(_constants.RTSubscriptionTypes.OBJECTS_CHANGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRelationsChanges", subscription(_constants.RTSubscriptionTypes.RELATIONS_CHANGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "connectToPubSub", subscription(_constants.RTSubscriptionTypes.PUB_SUB_CONNECT).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onPubSubMessage", subscription(_constants.RTSubscriptionTypes.PUB_SUB_MESSAGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onPubSubCommand", subscription(_constants.RTSubscriptionTypes.PUB_SUB_COMMANDS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onPubSubUserStatus", subscription(_constants.RTSubscriptionTypes.PUB_SUB_USERS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "connectToRSO", subscription(_constants.RTSubscriptionTypes.RSO_CONNECT).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOChanges", subscription(_constants.RTSubscriptionTypes.RSO_CHANGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOClear", subscription(_constants.RTSubscriptionTypes.RSO_CLEARED).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOCommand", subscription(_constants.RTSubscriptionTypes.RSO_COMMANDS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOInvoke", subscription(_constants.RTSubscriptionTypes.RSO_INVOKE).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOUserStatus", subscription(_constants.RTSubscriptionTypes.RSO_USERS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onLoggingMessages", subscription(_constants.RTSubscriptionTypes.LOGGING_MESSAGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onConsoleMessages", subscription(_constants.RTSubscriptionTypes.CONSOLE_MESSAGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onDeveloperMessage", subscription(_constants.RTSubscriptionTypes.DEVELOPER_MESSAGES).bind(this)); | ||
this.onMessage = onMessage; | ||
this.emitMessage = emitMessage; | ||
this.subscriptions = {}; | ||
} | ||
_createClass(RTSubscriptions, [{ | ||
key: 'initialize', | ||
(0, _createClass2["default"])(RTSubscriptions, [{ | ||
key: "initialize", | ||
value: function initialize() { | ||
@@ -69,3 +65,3 @@ var _this = this; | ||
}, { | ||
key: 'stop', | ||
key: "stop", | ||
value: function stop() { | ||
@@ -79,3 +75,3 @@ var _this2 = this; | ||
}, { | ||
key: 'reset', | ||
key: "reset", | ||
value: function reset() { | ||
@@ -89,3 +85,3 @@ var _this3 = this; | ||
}, { | ||
key: 'restore', | ||
key: "restore", | ||
value: function restore() { | ||
@@ -99,3 +95,3 @@ var _this4 = this; | ||
}, { | ||
key: 'hasActivity', | ||
key: "hasActivity", | ||
value: function hasActivity() { | ||
@@ -105,3 +101,3 @@ return !!Object.keys(this.subscriptions).length; | ||
}, { | ||
key: 'subscribe', | ||
key: "subscribe", | ||
value: function subscribe(name, options, _ref2) { | ||
@@ -116,6 +112,10 @@ var _this5 = this; | ||
var subscriptionId = _utils2.default.generateUID(); | ||
var subscriptionId = _utils["default"].generateUID(); | ||
this.subscriptions[subscriptionId] = { | ||
data: { id: subscriptionId, name: name, options: options }, | ||
data: { | ||
id: subscriptionId, | ||
name: name, | ||
options: options | ||
}, | ||
ready: false, | ||
@@ -128,5 +128,3 @@ parser: parser, | ||
}; | ||
this.startSubscription(subscriptionId); | ||
return { | ||
@@ -136,3 +134,2 @@ isReady: function isReady() { | ||
}, | ||
stop: function stop() { | ||
@@ -146,10 +143,9 @@ if (_this5.subscriptions[subscriptionId]) { | ||
}, { | ||
key: 'startSubscription', | ||
key: "startSubscription", | ||
value: function startSubscription(subscriptionId) { | ||
var subscription = this.subscriptions[subscriptionId]; | ||
this.emitMessage(_constants.RTSocketEvents.SUB_ON, subscription.data); | ||
} | ||
}, { | ||
key: 'stopSubscription', | ||
key: "stopSubscription", | ||
value: function stopSubscription(subscriptionId) { | ||
@@ -167,3 +163,3 @@ var subscription = this.subscriptions[subscriptionId]; | ||
}, { | ||
key: 'offSubscription', | ||
key: "offSubscription", | ||
value: function offSubscription(subscriptionId) { | ||
@@ -173,4 +169,5 @@ var subscription = this.subscriptions[subscriptionId]; | ||
if (subscription) { | ||
this.emitMessage(_constants.RTSocketEvents.SUB_OFF, { id: subscriptionId }); | ||
this.emitMessage(_constants.RTSocketEvents.SUB_OFF, { | ||
id: subscriptionId | ||
}); | ||
this.stopSubscription(subscriptionId); | ||
@@ -180,6 +177,5 @@ } | ||
}, { | ||
key: 'onSubscriptionReady', | ||
key: "onSubscriptionReady", | ||
value: function onSubscriptionReady(_ref3) { | ||
var id = _ref3.id; | ||
var subscription = this.subscriptions[id]; | ||
@@ -196,10 +192,3 @@ | ||
}, { | ||
key: 'onSubscriptionResponse', | ||
/***** CONSOLE SUBSCRIPTIONS ****** **/ | ||
/***************************************** **/ | ||
/** CONSOLE's SUBSCRIPTIONS **************************************************** **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
key: "onSubscriptionResponse", | ||
value: function onSubscriptionResponse(_ref4) { | ||
@@ -209,3 +198,2 @@ var id = _ref4.id, | ||
error = _ref4.error; | ||
var subscription = this.subscriptions[id]; | ||
@@ -215,3 +203,2 @@ | ||
if (error) { | ||
if (subscription.onError) { | ||
@@ -241,57 +228,28 @@ subscription.onError(error); | ||
} | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/** COMMON SUBSCRIPTIONS ******************************************************** **/ | ||
/***************************************** **/ | ||
/***** DATA SUBSCRIPTIONS **************** **/ | ||
/** */ | ||
/** */ | ||
/***** DATA SUBSCRIPTIONS **************** **/ | ||
/***************************************** **/ | ||
/***************************************** **/ | ||
/***** PUB_SUB SUBSCRIPTIONS ************* **/ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/***** PUB_SUB SUBSCRIPTIONS ************* **/ | ||
/***************************************** **/ | ||
/***** CONSOLE SUBSCRIPTIONS ****** **/ | ||
/***************************************** **/ | ||
/***** RSO SUBSCRIPTIONS ***************** **/ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/***** RSO SUBSCRIPTIONS ***************** **/ | ||
/***************************************** **/ | ||
/** COMMON SUBSCRIPTIONS ******************************************************** **/ | ||
/** CONSOLE's SUBSCRIPTIONS **************************************************** **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/** CONSOLE's SUBSCRIPTIONS **************************************************** **/ | ||
/***************************************** **/ | ||
/***** LOGGING SUBSCRIPTIONS ****** **/ | ||
/** */ | ||
/***** LOGGING SUBSCRIPTIONS ****** **/ | ||
/***************************************** **/ | ||
/***************************************** **/ | ||
/***** CONSOLE SUBSCRIPTIONS ****** **/ | ||
/** */ | ||
/** */ | ||
}]); | ||
return RTSubscriptions; | ||
}(); | ||
exports.default = RTSubscriptions; | ||
exports["default"] = RTSubscriptions; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,4 +6,4 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports["default"] = void 0; | ||
var CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
var Utils = { | ||
@@ -21,3 +21,3 @@ generateUID: function generateUID() { | ||
}; | ||
exports.default = Utils; | ||
var _default = Utils; | ||
exports["default"] = _default; |
@@ -1,41 +0,34 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _config = require('./config'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _constants = require("./constants"); | ||
var _subscriptions = require('./subscriptions'); | ||
var _config = _interopRequireDefault(require("./config")); | ||
var _subscriptions2 = _interopRequireDefault(_subscriptions); | ||
var _subscriptions = _interopRequireDefault(require("./subscriptions")); | ||
var _methods = require('./methods'); | ||
var _methods = _interopRequireDefault(require("./methods")); | ||
var _methods2 = _interopRequireDefault(_methods); | ||
var _session = _interopRequireDefault(require("./session")); | ||
var _session = require('./session'); | ||
var _session2 = _interopRequireDefault(_session); | ||
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"); } } | ||
var CONNECTION_MANAGE_EVENTS = [_constants.NativeSocketEvents.CONNECTING, _constants.NativeSocketEvents.CONNECT, _constants.NativeSocketEvents.CONNECT_ERROR, _constants.NativeSocketEvents.DISCONNECT, _constants.NativeSocketEvents.RECONNECT_ATTEMPT]; | ||
var RTClient = function () { | ||
var RTClient = /*#__PURE__*/function () { | ||
function RTClient(config) { | ||
var _this = this; | ||
_classCallCheck(this, RTClient); | ||
this.onConnectError = function () { | ||
(0, _classCallCheck2["default"])(this, RTClient); | ||
(0, _defineProperty2["default"])(this, "onConnectError", function () { | ||
if (!_this.subscriptions.hasActivity() && !_this.methods.hasActivity()) { | ||
@@ -46,7 +39,6 @@ _this.disconnect('There are no active subscriptions and methods'); | ||
} | ||
}; | ||
this.connectOnMethod = function (method) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "connectOnMethod", function (method) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
@@ -65,9 +57,8 @@ } | ||
}; | ||
}; | ||
}); | ||
(0, _defineProperty2["default"])(this, "on", this.connectOnMethod('on')); | ||
(0, _defineProperty2["default"])(this, "emit", this.connectOnMethod('emit')); | ||
(0, _defineProperty2["default"])(this, "onSessionDisconnect", function () { | ||
_this.subscriptions.stop(); | ||
this.on = this.connectOnMethod('on'); | ||
this.emit = this.connectOnMethod('emit'); | ||
this.onSessionDisconnect = function () { | ||
_this.subscriptions.stop(); | ||
_this.methods.stop(); | ||
@@ -78,6 +69,5 @@ | ||
_this.provideConnection(); | ||
}; | ||
this.emitSocketEventListeners = function (event) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "emitSocketEventListeners", function (event) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
@@ -88,57 +78,43 @@ } | ||
_this.socketEvents[event].forEach(function (callback) { | ||
return callback.apply(undefined, args); | ||
return callback.apply(void 0, args); | ||
}); | ||
} | ||
}; | ||
this.addConnectingEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addConnectingEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.CONNECTING, callback); | ||
}; | ||
this.removeConnectingEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectingEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.CONNECTING, callback); | ||
}; | ||
this.addConnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addConnectEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.CONNECT, callback); | ||
}; | ||
this.removeConnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.CONNECT, callback); | ||
}; | ||
this.addConnectErrorEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addConnectErrorEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.CONNECT_ERROR, callback); | ||
}; | ||
this.removeConnectErrorEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectErrorEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.CONNECT_ERROR, callback); | ||
}; | ||
this.addDisconnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addDisconnectEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.DISCONNECT, callback); | ||
}; | ||
this.removeDisconnectEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeDisconnectEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.DISCONNECT, callback); | ||
}; | ||
this.addReconnectAttemptEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "addReconnectAttemptEventListener", function (callback) { | ||
return _this.addSocketEventListener(_constants.NativeSocketEvents.RECONNECT_ATTEMPT, callback); | ||
}; | ||
this.removeReconnectAttemptEventListener = function (callback) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeReconnectAttemptEventListener", function (callback) { | ||
return _this.removeSocketEventListener(_constants.NativeSocketEvents.RECONNECT_ATTEMPT, callback); | ||
}; | ||
this.removeConnectionListeners = function () { | ||
}); | ||
(0, _defineProperty2["default"])(this, "removeConnectionListeners", function () { | ||
CONNECTION_MANAGE_EVENTS.forEach(function (event) { | ||
return _this.removeSocketEventListener(event); | ||
}); | ||
}; | ||
this.config = new _config2.default(config); | ||
}); | ||
this.config = new _config["default"](config); | ||
this.resetSocketEvents(); | ||
var socketContext = { | ||
@@ -148,6 +124,4 @@ onMessage: this.on.bind(this), | ||
}; | ||
this.subscriptions = new _subscriptions2.default(socketContext); | ||
this.methods = new _methods2.default(socketContext); | ||
this.subscriptions = new _subscriptions["default"](socketContext); | ||
this.methods = new _methods["default"](socketContext); | ||
this.connectible = true; | ||
@@ -157,4 +131,4 @@ this.connected = false; | ||
_createClass(RTClient, [{ | ||
key: 'resetSocketEvents', | ||
(0, _createClass2["default"])(RTClient, [{ | ||
key: "resetSocketEvents", | ||
value: function resetSocketEvents() { | ||
@@ -165,3 +139,3 @@ this.socketEvents = {}; | ||
}, { | ||
key: 'setConfig', | ||
key: "setConfig", | ||
value: function setConfig(config) { | ||
@@ -172,3 +146,2 @@ this.config.set(config); | ||
this.disconnect('Re-config socket connection'); | ||
this.connect(); | ||
@@ -178,3 +151,3 @@ } | ||
}, { | ||
key: 'provideConnection', | ||
key: "provideConnection", | ||
value: function provideConnection() { | ||
@@ -184,3 +157,3 @@ var _this2 = this; | ||
if (!this.session) { | ||
this.session = new _session2.default(this.config, this.emitSocketEventListeners, this.onSessionDisconnect); | ||
this.session = new _session["default"](this.config, this.emitSocketEventListeners, this.onSessionDisconnect); | ||
this.session.getSocket().then(function () { | ||
@@ -190,5 +163,7 @@ _this2.connected = true; | ||
_this2.methods.initialize(); | ||
_this2.methods.restore(); | ||
_this2.subscriptions.initialize(); | ||
_this2.subscriptions.restore(); | ||
@@ -201,10 +176,9 @@ }); | ||
}, { | ||
key: 'connect', | ||
key: "connect", | ||
value: function connect() { | ||
this.connectible = true; | ||
this.provideConnection(); | ||
} | ||
}, { | ||
key: 'disconnect', | ||
key: "disconnect", | ||
value: function disconnect(reason) { | ||
@@ -214,7 +188,4 @@ if (this.session) { | ||
this.methods.stop(); | ||
this.session.terminate(); | ||
delete this.session; | ||
this.emitSocketEventListeners(_constants.NativeSocketEvents.DISCONNECT, reason || 'disconnected by client'); | ||
@@ -227,21 +198,18 @@ } | ||
}, { | ||
key: 'terminate', | ||
key: "terminate", | ||
value: function terminate(reason) { | ||
this.resetSocketEvents(); | ||
this.subscriptions.reset(); | ||
this.methods.reset(); | ||
this.disconnect(reason || 'Terminated by client'); | ||
} | ||
}, { | ||
key: 'addSocketEventListener', | ||
key: "addSocketEventListener", | ||
value: function addSocketEventListener(event, callback) { | ||
this.socketEvents[event] = this.socketEvents[event] || []; | ||
this.socketEvents[event].push(callback); | ||
return this; | ||
} | ||
}, { | ||
key: 'removeSocketEventListener', | ||
key: "removeSocketEventListener", | ||
value: function removeSocketEventListener(event, callback) { | ||
@@ -260,12 +228,6 @@ if (this.socketEvents[event]) { | ||
} | ||
/* eslint-disable max-len */ | ||
/* eslint-enable max-len */ | ||
}]); | ||
return RTClient; | ||
}(); | ||
exports.default = RTClient; | ||
exports["default"] = RTClient; |
@@ -1,30 +0,41 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _backendlessRequest = _interopRequireDefault(require("backendless-request")); | ||
var isUndefined = function isUndefined(value) { | ||
return typeof value === 'undefined'; | ||
}; | ||
var isString = function isString(value) { | ||
return typeof value === 'string'; | ||
}; | ||
var isFunction = function isFunction(value) { | ||
return typeof value === 'function'; | ||
}; | ||
var isObject = function isObject(value) { | ||
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null; | ||
return (0, _typeof2["default"])(value) === 'object' && value !== null; | ||
}; | ||
var RTConfig = function () { | ||
var RTConfig = /*#__PURE__*/function () { | ||
function RTConfig(config) { | ||
_classCallCheck(this, RTConfig); | ||
(0, _classCallCheck2["default"])(this, RTConfig); | ||
this.appId = null; | ||
@@ -35,8 +46,9 @@ this.lookupPath = null; | ||
this.connectQuery = {}; | ||
this.socketConfigTransform = null; | ||
this.socketConfig = null; | ||
this.set(config); | ||
} | ||
_createClass(RTConfig, [{ | ||
key: 'set', | ||
(0, _createClass2["default"])(RTConfig, [{ | ||
key: "set", | ||
value: function set(config) { | ||
@@ -84,13 +96,91 @@ if (!config) { | ||
} | ||
if (!isUndefined(config.socketConfigTransform)) { | ||
if (isFunction(config.socketConfigTransform)) { | ||
this.socketConfigTransform = config.socketConfigTransform; | ||
} else { | ||
throw new Error('"socketConfigTransform" must be Function.'); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'getConnectQuery', | ||
key: "getConnectQuery", | ||
value: function getConnectQuery() { | ||
return this.connectQuery; | ||
} | ||
}, { | ||
key: "prepare", | ||
value: function () { | ||
var _prepare = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var host, url, path, query, socketConfig; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (isString(this.lookupPath)) { | ||
_context.next = 2; | ||
break; | ||
} | ||
throw new Error('lookupPath must be String'); | ||
case 2: | ||
_context.next = 4; | ||
return _backendlessRequest["default"].get(this.lookupPath).set(this.lookupHeaders); | ||
case 4: | ||
host = _context.sent; | ||
url = this.appId ? "".concat(host, "/").concat(this.appId) : host; | ||
path = this.appId ? "/".concat(this.appId) : undefined; | ||
query = this.getConnectQuery(); | ||
this.socketConfig = { | ||
host: host, | ||
url: url, | ||
options: { | ||
path: path, | ||
query: query, | ||
forceNew: true, | ||
autoConnect: false, | ||
reconnection: false | ||
} | ||
}; | ||
if (!this.socketConfigTransform) { | ||
_context.next = 14; | ||
break; | ||
} | ||
_context.next = 12; | ||
return this.socketConfigTransform(this.socketConfig); | ||
case 12: | ||
socketConfig = _context.sent; | ||
if (socketConfig) { | ||
this.socketConfig = socketConfig; | ||
} | ||
case 14: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function prepare() { | ||
return _prepare.apply(this, arguments); | ||
} | ||
return prepare; | ||
}() | ||
}, { | ||
key: "getSocketConfig", | ||
value: function getSocketConfig() { | ||
return this.socketConfig; | ||
} | ||
}]); | ||
return RTConfig; | ||
}(); | ||
exports.default = RTConfig; | ||
exports["default"] = RTConfig; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,3 +6,4 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var NativeSocketEvents = exports.NativeSocketEvents = { | ||
exports.RTSubscriptionTypes = exports.RTSocketEvents = exports.RTMethodTypes = exports.NativeSocketEvents = void 0; | ||
var NativeSocketEvents = { | ||
CONNECTING: 'connecting', | ||
@@ -22,4 +23,4 @@ CONNECT: 'connect', | ||
}; | ||
var RTSocketEvents = exports.RTSocketEvents = { | ||
exports.NativeSocketEvents = NativeSocketEvents; | ||
var RTSocketEvents = { | ||
SUB_ON: 'SUB_ON', | ||
@@ -29,11 +30,9 @@ SUB_OFF: 'SUB_OFF', | ||
SUB_READY: 'SUB_READY', | ||
MET_REQ: 'MET_REQ', | ||
MET_RES: 'MET_RES' | ||
}; | ||
var RTSubscriptionTypes = exports.RTSubscriptionTypes = { | ||
exports.RTSocketEvents = RTSocketEvents; | ||
var RTSubscriptionTypes = { | ||
OBJECTS_CHANGES: 'OBJECTS_CHANGES', | ||
RELATIONS_CHANGES: 'RELATIONS_CHANGES', | ||
PUB_SUB_CONNECT: 'PUB_SUB_CONNECT', | ||
@@ -43,3 +42,2 @@ PUB_SUB_MESSAGES: 'PUB_SUB_MESSAGES', | ||
PUB_SUB_USERS: 'PUB_SUB_USERS', | ||
RSO_CONNECT: 'RSO_CONNECT', | ||
@@ -51,17 +49,13 @@ RSO_CHANGES: 'RSO_CHANGES', | ||
RSO_USERS: 'RSO_USERS', | ||
//-----------------------------------------// | ||
//----------- FOR CONSOLE ONLY ------------// | ||
LOGGING_MESSAGES: 'LOGGING_MESSAGES', | ||
CONSOLE_MESSAGES: 'CONSOLE_MESSAGES', | ||
DEVELOPER_MESSAGES: 'DEVELOPER_MESSAGES' | ||
DEVELOPER_MESSAGES: 'DEVELOPER_MESSAGES' //----------- FOR CONSOLE ONLY ------------// | ||
//-----------------------------------------// | ||
//----------- FOR CONSOLE ONLY ------------// | ||
//-----------------------------------------// | ||
}; | ||
var RTMethodTypes = exports.RTMethodTypes = { | ||
exports.RTSubscriptionTypes = RTSubscriptionTypes; | ||
var RTMethodTypes = { | ||
SET_USER_TOKEN: 'SET_USER_TOKEN', | ||
RSO_GET: 'RSO_GET', | ||
@@ -72,4 +66,4 @@ RSO_SET: 'RSO_SET', | ||
RSO_INVOKE: 'RSO_INVOKE', | ||
PUB_SUB_COMMAND: 'PUB_SUB_COMMAND' | ||
}; | ||
}; | ||
exports.RTMethodTypes = RTMethodTypes; |
@@ -1,42 +0,35 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.RTScopeConnector = exports.RTListeners = undefined; | ||
exports["default"] = exports.RTScopeConnector = exports.RTListeners = void 0; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _backendlessRequest = require('backendless-request'); | ||
var _backendlessRequest = _interopRequireDefault(require("backendless-request")); | ||
var _backendlessRequest2 = _interopRequireDefault(_backendlessRequest); | ||
var _client = _interopRequireDefault(require("./client")); | ||
var _client = require('./client'); | ||
var _listeners = _interopRequireDefault(require("./listeners")); | ||
var _client2 = _interopRequireDefault(_client); | ||
var _scopeConnector = _interopRequireDefault(require("./scope-connector")); | ||
var _listeners = require('./listeners'); | ||
var root = (typeof self === "undefined" ? "undefined" : (0, _typeof2["default"])(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : (0, _typeof2["default"])(global)) === 'object' && global.global === global && global; | ||
_client["default"].Request = _backendlessRequest["default"]; | ||
_client["default"].Listeners = _listeners["default"]; | ||
_client["default"].ScopeConnector = _scopeConnector["default"]; | ||
var _listeners2 = _interopRequireDefault(_listeners); | ||
var _scopeConnector = require('./scope-connector'); | ||
var _scopeConnector2 = _interopRequireDefault(_scopeConnector); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var root = (typeof self === 'undefined' ? 'undefined' : _typeof(self)) === 'object' && self.self === self && self || (typeof global === 'undefined' ? 'undefined' : _typeof(global)) === 'object' && global.global === global && global; | ||
_client2.default.Request = _backendlessRequest2.default; | ||
_client2.default.Listeners = _listeners2.default; | ||
_client2.default.ScopeConnector = _scopeConnector2.default; | ||
if (root) { | ||
root.BackendlessRTClient = _client2.default; | ||
root.BackendlessRTClient = _client["default"]; | ||
} | ||
module.exports = _client2.default; | ||
exports.default = _client2.default; | ||
var RTListeners = exports.RTListeners = _listeners2.default; | ||
var RTScopeConnector = exports.RTScopeConnector = _scopeConnector2.default; | ||
module.exports = _client["default"]; | ||
var _default = _client["default"]; | ||
exports["default"] = _default; | ||
var RTListeners = _listeners["default"]; | ||
exports.RTListeners = RTListeners; | ||
var RTScopeConnector = _scopeConnector["default"]; | ||
exports.RTScopeConnector = RTScopeConnector; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var RTListeners = function () { | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
var RTListeners = /*#__PURE__*/function () { | ||
function RTListeners() { | ||
_classCallCheck(this, RTListeners); | ||
(0, _classCallCheck2["default"])(this, RTListeners); | ||
this.subscriptions = {}; | ||
@@ -21,3 +27,3 @@ this.simpleListeners = {}; | ||
_createClass(RTListeners, [{ | ||
(0, _createClass2["default"])(RTListeners, [{ | ||
key: "addSubscription", | ||
@@ -32,6 +38,4 @@ value: function addSubscription(type, subscriberFn, _ref) { | ||
params = _ref.params; | ||
this.subscriptions[type] = this.subscriptions[type] || []; | ||
var subscription = subscriberFn(_extends({}, params, this.getSubscriptionOptions()), { | ||
var subscription = subscriberFn(_objectSpread(_objectSpread({}, params), this.getSubscriptionOptions()), { | ||
parser: parser, | ||
@@ -47,3 +51,2 @@ onData: callback, | ||
}); | ||
var subscriptionStore = { | ||
@@ -57,5 +60,3 @@ callback: callback, | ||
}; | ||
this.subscriptions[type].push(subscriptionStore); | ||
return subscriptionStore; | ||
@@ -73,3 +74,2 @@ } | ||
matcher = _ref2.matcher; | ||
var subscriptionsStack = this.subscriptions[type] = this.subscriptions[type] || []; | ||
@@ -95,3 +95,2 @@ | ||
var listenersStack = this.simpleListeners[type] = this.simpleListeners[type] || []; | ||
listenersStack.push(callback); | ||
@@ -111,3 +110,3 @@ } | ||
value: function runSimpleListeners(type) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
@@ -118,3 +117,3 @@ } | ||
this.simpleListeners[type].forEach(function (callback) { | ||
return callback.apply(undefined, args); | ||
return callback.apply(void 0, args); | ||
}); | ||
@@ -134,10 +133,8 @@ } | ||
}); | ||
this.simpleListeners = {}; | ||
} | ||
}]); | ||
return RTListeners; | ||
}(); | ||
exports.default = RTListeners; | ||
exports["default"] = RTListeners; |
@@ -1,20 +0,20 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _utils = require('./utils'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _utils2 = _interopRequireDefault(_utils); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _utils = _interopRequireDefault(require("./utils")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var method = function method(type) { | ||
@@ -26,3 +26,3 @@ return function (data) { | ||
var RTMethods = function () { | ||
var RTMethods = /*#__PURE__*/function () { | ||
function RTMethods(_ref) { | ||
@@ -33,12 +33,9 @@ var _this = this; | ||
emitMessage = _ref.emitMessage; | ||
_classCallCheck(this, RTMethods); | ||
this.sendRequest = function (invocationId) { | ||
(0, _classCallCheck2["default"])(this, RTMethods); | ||
(0, _defineProperty2["default"])(this, "sendRequest", function (invocationId) { | ||
if (_this.invocations[invocationId]) { | ||
_this.emitMessage(_constants.RTSocketEvents.MET_REQ, _this.invocations[invocationId].data); | ||
} | ||
}; | ||
this.onResponse = function (_ref2) { | ||
}); | ||
(0, _defineProperty2["default"])(this, "onResponse", function (_ref2) { | ||
var id = _ref2.id, | ||
@@ -59,20 +56,17 @@ error = _ref2.error, | ||
} | ||
}; | ||
this.setUserToken = method(_constants.RTMethodTypes.SET_USER_TOKEN).bind(this); | ||
this.sendPubSubCommand = method(_constants.RTMethodTypes.PUB_SUB_COMMAND).bind(this); | ||
this.getRSO = method(_constants.RTMethodTypes.RSO_GET).bind(this); | ||
this.setRSO = method(_constants.RTMethodTypes.RSO_SET).bind(this); | ||
this.clearRSO = method(_constants.RTMethodTypes.RSO_CLEAR).bind(this); | ||
this.sendRSOCommand = method(_constants.RTMethodTypes.RSO_COMMAND).bind(this); | ||
this.invokeRSOMethod = method(_constants.RTMethodTypes.RSO_INVOKE).bind(this); | ||
}); | ||
(0, _defineProperty2["default"])(this, "setUserToken", method(_constants.RTMethodTypes.SET_USER_TOKEN).bind(this)); | ||
(0, _defineProperty2["default"])(this, "sendPubSubCommand", method(_constants.RTMethodTypes.PUB_SUB_COMMAND).bind(this)); | ||
(0, _defineProperty2["default"])(this, "getRSO", method(_constants.RTMethodTypes.RSO_GET).bind(this)); | ||
(0, _defineProperty2["default"])(this, "setRSO", method(_constants.RTMethodTypes.RSO_SET).bind(this)); | ||
(0, _defineProperty2["default"])(this, "clearRSO", method(_constants.RTMethodTypes.RSO_CLEAR).bind(this)); | ||
(0, _defineProperty2["default"])(this, "sendRSOCommand", method(_constants.RTMethodTypes.RSO_COMMAND).bind(this)); | ||
(0, _defineProperty2["default"])(this, "invokeRSOMethod", method(_constants.RTMethodTypes.RSO_INVOKE).bind(this)); | ||
this.onMessage = onMessage; | ||
this.emitMessage = emitMessage; | ||
this.invocations = {}; | ||
} | ||
_createClass(RTMethods, [{ | ||
key: 'initialize', | ||
(0, _createClass2["default"])(RTMethods, [{ | ||
key: "initialize", | ||
value: function initialize() { | ||
@@ -82,3 +76,3 @@ this.onMessage(_constants.RTSocketEvents.MET_RES, this.onResponse); | ||
}, { | ||
key: 'restore', | ||
key: "restore", | ||
value: function restore() { | ||
@@ -92,6 +86,6 @@ var _this2 = this; | ||
}, { | ||
key: 'stop', | ||
key: "stop", | ||
value: function stop() {} | ||
}, { | ||
key: 'reset', | ||
key: "reset", | ||
value: function reset() { | ||
@@ -101,3 +95,3 @@ this.invocations = {}; | ||
}, { | ||
key: 'hasActivity', | ||
key: "hasActivity", | ||
value: function hasActivity() { | ||
@@ -107,18 +101,16 @@ return !!Object.keys(this.invocations).length; | ||
}, { | ||
key: 'send', | ||
//----------- RSO METHODS ---------// | ||
//---------------------------------// | ||
key: "send", | ||
value: function send(name, options) { | ||
var _this3 = this; | ||
var invocationId = _utils2.default.generateUID(); | ||
var invocationId = _utils["default"].generateUID(); | ||
this.invocations[invocationId] = { | ||
data: { id: invocationId, name: name, options: options } | ||
data: { | ||
id: invocationId, | ||
name: name, | ||
options: options | ||
} | ||
}; | ||
this.sendRequest(invocationId); | ||
return new Promise(function (resolve, reject) { | ||
@@ -128,24 +120,9 @@ _this3.invocations[invocationId].resolve = resolve; | ||
}); | ||
} | ||
} //----------- RSO METHODS ---------// | ||
//---------------------------------// | ||
//----------- AUTH METHODS --------// | ||
//----------- AUTH METHODS --------// | ||
//---------------------------------// | ||
//---------------------------------// | ||
//-------- PUB_SUB METHODS --------// | ||
//-------- PUB_SUB METHODS --------// | ||
//---------------------------------// | ||
//---------------------------------// | ||
//----------- RSO METHODS ---------// | ||
}]); | ||
return RTMethods; | ||
}(); | ||
exports.default = RTMethods; | ||
exports["default"] = RTMethods; |
@@ -1,57 +0,38 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get")); | ||
var _dec, _dec2, _dec3, _dec4, _dec5, _desc, _value, _class, _class2, _temp; | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
var _listeners = require('./listeners'); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _listeners2 = _interopRequireDefault(_listeners); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor")); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var _listeners = _interopRequireDefault(require("./listeners")); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2; | ||
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { | ||
var desc = {}; | ||
Object['ke' + 'ys'](descriptor).forEach(function (key) { | ||
desc[key] = descriptor[key]; | ||
}); | ||
desc.enumerable = !!desc.enumerable; | ||
desc.configurable = !!desc.configurable; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
if ('value' in desc || desc.initializer) { | ||
desc.writable = true; | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
desc = decorators.slice().reverse().reduce(function (desc, decorator) { | ||
return decorator(target, property, desc) || desc; | ||
}, desc); | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } | ||
if (context && desc.initializer !== void 0) { | ||
desc.value = desc.initializer ? desc.initializer.call(context) : void 0; | ||
desc.initializer = undefined; | ||
} | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
if (desc.initializer === void 0) { | ||
Object['define' + 'Property'](target, property, desc); | ||
desc = null; | ||
} | ||
return desc; | ||
} | ||
var ListenerTypes = { | ||
@@ -63,27 +44,29 @@ CONNECT: 'CONNECT', | ||
}; | ||
var RTScopeConnector = (_dec = connectionRequired(), _dec2 = connectionRequired(), _dec3 = connectionRequired(), _dec4 = connectionRequired(), _dec5 = connectionRequired(true), (_class = (_class2 = /*#__PURE__*/function (_RTListeners) { | ||
(0, _inherits2["default"])(RTScopeConnector, _RTListeners); | ||
var RTScopeConnector = (_dec = connectionRequired(), _dec2 = connectionRequired(), _dec3 = connectionRequired(), _dec4 = connectionRequired(), _dec5 = connectionRequired(true), (_class = (_temp = _class2 = function (_RTListeners) { | ||
_inherits(RTScopeConnector, _RTListeners); | ||
var _super = _createSuper(RTScopeConnector); | ||
_createClass(RTScopeConnector, [{ | ||
key: 'connectSubscriber', | ||
function RTScopeConnector(options) { | ||
var _this2; | ||
(0, _classCallCheck2["default"])(this, RTScopeConnector); | ||
_this2 = _super.call(this); | ||
_this2.options = options; | ||
_this2.waitConnection = []; | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* must returns a function for adding subscriptions to CONNECT to connection scope | ||
* For ex.: RTProvider.subscriptions.connectToRSO | ||
**/ | ||
get: function get() { | ||
return null; | ||
} | ||
_this2.connect(); | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* | ||
* must returns a function for adding subscriptions to listening COMMANDS in connection scope | ||
* For ex.: RTProvider.subscriptions.onRSOCommand | ||
**/ | ||
return _this2; | ||
} | ||
/** | ||
* @public method | ||
* | ||
* connect to connection scope, if you already connected the method do nothing | ||
**/ | ||
(0, _createClass2["default"])(RTScopeConnector, [{ | ||
key: "connectSubscriber", | ||
get: | ||
/** | ||
@@ -102,8 +85,22 @@ * @static | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* must returns a function for adding subscriptions to CONNECT to connection scope | ||
* For ex.: RTProvider.subscriptions.connectToRSO | ||
**/ | ||
function get() { | ||
return null; | ||
} | ||
/** | ||
* @abstract getter, must be overridden in an inherited class | ||
* | ||
* must returns a function for adding subscriptions to listening COMMANDS in connection scope | ||
* For ex.: RTProvider.subscriptions.onRSOCommand | ||
**/ | ||
}, { | ||
key: 'commandSubscriber', | ||
key: "commandSubscriber", | ||
get: function get() { | ||
return null; | ||
} | ||
/** | ||
@@ -117,7 +114,6 @@ * @abstract getter, must be overridden in an inherited class | ||
}, { | ||
key: 'usersSubscriber', | ||
key: "usersSubscriber", | ||
get: function get() { | ||
return null; | ||
} | ||
/** | ||
@@ -131,32 +127,10 @@ * @abstract getter, must be overridden in an inherited class | ||
}, { | ||
key: 'commandSender', | ||
key: "commandSender", | ||
get: function get() { | ||
return null; | ||
} | ||
}]); | ||
function RTScopeConnector(options) { | ||
_classCallCheck(this, RTScopeConnector); | ||
var _this = _possibleConstructorReturn(this, (RTScopeConnector.__proto__ || Object.getPrototypeOf(RTScopeConnector)).call(this)); | ||
_this.options = options; | ||
_this.waitConnection = []; | ||
_this.connect(); | ||
return _this; | ||
} | ||
/** | ||
* @public method | ||
* | ||
* connect to connection scope, if you already connected the method do nothing | ||
**/ | ||
_createClass(RTScopeConnector, [{ | ||
key: 'connect', | ||
}, { | ||
key: "connect", | ||
value: function connect() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -166,9 +140,9 @@ if (!this.isConnected()) { | ||
onError: function onError(error) { | ||
return _this2.onError(error); | ||
return _this3.onError(error); | ||
}, | ||
onReady: function onReady() { | ||
return _this2.onConnect(); | ||
return _this3.onConnect(); | ||
}, | ||
onStop: function onStop() { | ||
return _this2.onDisconnect(); | ||
return _this3.onDisconnect(); | ||
} | ||
@@ -178,3 +152,2 @@ }); | ||
} | ||
/** | ||
@@ -187,3 +160,3 @@ * @public method | ||
}, { | ||
key: 'disconnect', | ||
key: "disconnect", | ||
value: function disconnect() { | ||
@@ -194,3 +167,2 @@ if (this.isConnected()) { | ||
} | ||
/** | ||
@@ -203,7 +175,6 @@ * @public method | ||
}, { | ||
key: 'isConnected', | ||
key: "isConnected", | ||
value: function isConnected() { | ||
return !!this.connection && this.connection.isReady(); | ||
} | ||
/** | ||
@@ -214,7 +185,6 @@ * @private method | ||
}, { | ||
key: 'getSubscriptionOptions', | ||
key: "getSubscriptionOptions", | ||
value: function getSubscriptionOptions() { | ||
return this.getScopeOptions(); | ||
} | ||
/** | ||
@@ -225,7 +195,6 @@ * @private method | ||
}, { | ||
key: 'getScopeOptions', | ||
key: "getScopeOptions", | ||
value: function getScopeOptions() { | ||
return this.options; | ||
} | ||
/** | ||
@@ -236,3 +205,3 @@ * @private method | ||
}, { | ||
key: 'onConnect', | ||
key: "onConnect", | ||
value: function onConnect() { | ||
@@ -243,6 +212,4 @@ this.waitConnection.forEach(function (operation) { | ||
this.waitConnection = []; | ||
this.runSimpleListeners(ListenerTypes.CONNECT); | ||
} | ||
/** | ||
@@ -253,7 +220,6 @@ * @private method | ||
}, { | ||
key: 'onError', | ||
key: "onError", | ||
value: function onError(error) { | ||
this.runSimpleListeners(ListenerTypes.ERROR, error); | ||
} | ||
/** | ||
@@ -264,7 +230,6 @@ * @private method | ||
}, { | ||
key: 'onDisconnect', | ||
key: "onDisconnect", | ||
value: function onDisconnect() { | ||
this.connection = null; | ||
} | ||
/** | ||
@@ -275,11 +240,8 @@ * @public method | ||
}, { | ||
key: 'removeAllListeners', | ||
key: "removeAllListeners", | ||
value: function removeAllListeners() { | ||
this.waitConnection = []; | ||
_get(RTScopeConnector.prototype.__proto__ || Object.getPrototypeOf(RTScopeConnector.prototype), 'removeAllListeners', this).call(this); | ||
(0, _get2["default"])((0, _getPrototypeOf2["default"])(RTScopeConnector.prototype), "removeAllListeners", this).call(this); | ||
return this; | ||
} | ||
/** | ||
@@ -290,3 +252,3 @@ * @public method | ||
}, { | ||
key: 'addConnectListener', | ||
key: "addConnectListener", | ||
value: function addConnectListener(callback, onError) { | ||
@@ -301,3 +263,2 @@ this.addSimpleListener(ListenerTypes.CONNECT, callback); | ||
} | ||
/** | ||
@@ -308,3 +269,3 @@ * @public method | ||
}, { | ||
key: 'removeConnectListeners', | ||
key: "removeConnectListeners", | ||
value: function removeConnectListeners(callback, onError) { | ||
@@ -319,3 +280,2 @@ this.removeSimpleListener(ListenerTypes.CONNECT, callback); | ||
} | ||
/** | ||
@@ -326,9 +286,10 @@ * @public method | ||
}, { | ||
key: 'addCommandListener', | ||
key: "addCommandListener", | ||
value: function addCommandListener(callback, onError) { | ||
this.addSubscription(ListenerTypes.COMMAND, this.commandSubscriber, { callback: callback, onError: onError }); | ||
this.addSubscription(ListenerTypes.COMMAND, this.commandSubscriber, { | ||
callback: callback, | ||
onError: onError | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -339,9 +300,9 @@ * @public method | ||
}, { | ||
key: 'removeCommandListeners', | ||
key: "removeCommandListeners", | ||
value: function removeCommandListeners(callback) { | ||
this.stopSubscription(ListenerTypes.COMMAND, { callback: callback }); | ||
this.stopSubscription(ListenerTypes.COMMAND, { | ||
callback: callback | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -352,9 +313,10 @@ * @public method | ||
}, { | ||
key: 'addUserStatusListener', | ||
key: "addUserStatusListener", | ||
value: function addUserStatusListener(callback, onError) { | ||
this.addSubscription(ListenerTypes.USER_STATUS, this.usersSubscriber, { callback: callback, onError: onError }); | ||
this.addSubscription(ListenerTypes.USER_STATUS, this.usersSubscriber, { | ||
callback: callback, | ||
onError: onError | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -365,9 +327,9 @@ * @public method | ||
}, { | ||
key: 'removeUserStatusListeners', | ||
key: "removeUserStatusListeners", | ||
value: function removeUserStatusListeners(callback) { | ||
this.stopSubscription(ListenerTypes.USER_STATUS, { callback: callback }); | ||
this.stopSubscription(ListenerTypes.USER_STATUS, { | ||
callback: callback | ||
}); | ||
return this; | ||
} | ||
/** | ||
@@ -378,13 +340,14 @@ * @public method | ||
}, { | ||
key: 'send', | ||
key: "send", | ||
value: function send(type, data) { | ||
return this.commandSender(_extends({}, this.getScopeOptions(), { type: type, data: data })); | ||
return this.commandSender(_objectSpread(_objectSpread({}, this.getScopeOptions()), {}, { | ||
type: type, | ||
data: data | ||
})); | ||
} | ||
}]); | ||
return RTScopeConnector; | ||
}(_listeners2.default), _class2.connectionRequired = connectionRequired, _temp), (_applyDecoratedDescriptor(_class.prototype, 'addCommandListener', [_dec], Object.getOwnPropertyDescriptor(_class.prototype, 'addCommandListener'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'removeCommandListeners', [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, 'removeCommandListeners'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'addUserStatusListener', [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, 'addUserStatusListener'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'removeUserStatusListeners', [_dec4], Object.getOwnPropertyDescriptor(_class.prototype, 'removeUserStatusListeners'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'send', [_dec5], Object.getOwnPropertyDescriptor(_class.prototype, 'send'), _class.prototype)), _class)); | ||
exports.default = RTScopeConnector; | ||
}(_listeners["default"]), (0, _defineProperty2["default"])(_class2, "connectionRequired", connectionRequired), _class2), ((0, _applyDecoratedDescriptor2["default"])(_class.prototype, "addCommandListener", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "addCommandListener"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "removeCommandListeners", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "removeCommandListeners"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "addUserStatusListener", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "addUserStatusListener"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "removeUserStatusListeners", [_dec4], Object.getOwnPropertyDescriptor(_class.prototype, "removeUserStatusListeners"), _class.prototype), (0, _applyDecoratedDescriptor2["default"])(_class.prototype, "send", [_dec5], Object.getOwnPropertyDescriptor(_class.prototype, "send"), _class.prototype)), _class)); | ||
exports["default"] = RTScopeConnector; | ||
function connectionRequired(returnPromise) { | ||
@@ -395,7 +358,7 @@ return function (target, key, descriptor) { | ||
descriptor.value = function () { | ||
var _this3 = this, | ||
_arguments = arguments; | ||
var _arguments = arguments, | ||
_this = this; | ||
var run = function run() { | ||
return decorated.apply(_this3, _arguments); | ||
return decorated.apply(_this, _arguments); | ||
}; | ||
@@ -409,3 +372,3 @@ | ||
return new Promise(function (resolve, reject) { | ||
return _this3.waitConnection.push(function () { | ||
return _this.waitConnection.push(function () { | ||
return run().then(resolve, reject); | ||
@@ -417,3 +380,2 @@ }); | ||
this.waitConnection.push(run); | ||
return this; | ||
@@ -420,0 +382,0 @@ }; |
@@ -1,20 +0,18 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _socket = require('./socket'); | ||
var _constants = require("./constants"); | ||
var _socket2 = _interopRequireDefault(_socket); | ||
var _socket = _interopRequireDefault(require("./socket")); | ||
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"); } } | ||
var INCREASE_RECONNECTION_TIMEOUT_STEP = 10; | ||
@@ -30,17 +28,14 @@ var INITIAL_RECONNECTION_TIMEOUT = 200; | ||
var RTSession = function () { | ||
var RTSession = /*#__PURE__*/function () { | ||
function RTSession(config, dispatch, onDisconnect) { | ||
_classCallCheck(this, RTSession); | ||
(0, _classCallCheck2["default"])(this, RTSession); | ||
this.config = config; | ||
this.dispatch = dispatch; | ||
this.onDisconnect = onDisconnect; | ||
this.connectAttempt = 0; | ||
this.socketPromise = this.connect(); | ||
} | ||
_createClass(RTSession, [{ | ||
key: 'terminate', | ||
(0, _createClass2["default"])(RTSession, [{ | ||
key: "terminate", | ||
value: function terminate() { | ||
@@ -50,4 +45,3 @@ if (!this.terminated) { | ||
this.dispatch = function () { | ||
//if sessions has been terminated don't need to dispatch any events | ||
this.dispatch = function () {//if sessions has been terminated don't need to dispatch any events | ||
}; | ||
@@ -63,3 +57,3 @@ | ||
}, { | ||
key: 'getSocket', | ||
key: "getSocket", | ||
value: function getSocket() { | ||
@@ -70,4 +64,3 @@ var _this = this; | ||
if (_this.terminated) { | ||
return new Promise(function () { | ||
//return unresolvable promise for preventing errors | ||
return new Promise(function () {//return unresolvable promise for preventing errors | ||
//this connection session has been terminated and a new one will be created if it necessary | ||
@@ -81,3 +74,3 @@ }); | ||
}, { | ||
key: 'connect', | ||
key: "connect", | ||
value: function connect() { | ||
@@ -91,5 +84,3 @@ var _this2 = this; | ||
this.connectAttempt = this.connectAttempt + 1; | ||
var nextReconnectionTimeout = this.getNextReconnectionTimeout(); | ||
this.onConnecting(); | ||
@@ -101,3 +92,3 @@ | ||
return _socket2.default.connect(this.config, this.onSocketDisconnect.bind(this)).then(function (rtSocket) { | ||
return _socket["default"].connect(this.config, this.onSocketDisconnect.bind(this)).then(function (rtSocket) { | ||
_this2.connectAttempt = 0; | ||
@@ -108,3 +99,3 @@ | ||
return rtSocket; | ||
}).catch(function (error) { | ||
})["catch"](function (error) { | ||
_this2.onConnectError(error); | ||
@@ -121,11 +112,10 @@ | ||
}, { | ||
key: 'getNextReconnectionTimeout', | ||
key: "getNextReconnectionTimeout", | ||
value: function getNextReconnectionTimeout() { | ||
var factor = Math.ceil(this.connectAttempt / INCREASE_RECONNECTION_TIMEOUT_STEP); | ||
var timeout = INITIAL_RECONNECTION_TIMEOUT * Math.pow(2, factor); | ||
return Math.min(timeout, MAX_RECONNECTION_TIMEOUT); | ||
} | ||
}, { | ||
key: 'onSocketDisconnect', | ||
key: "onSocketDisconnect", | ||
value: function onSocketDisconnect(reason) { | ||
@@ -136,3 +126,2 @@ this.dispatch(_constants.NativeSocketEvents.DISCONNECT, reason); | ||
this.terminate(); | ||
this.onDisconnect(); | ||
@@ -142,3 +131,3 @@ } | ||
}, { | ||
key: 'onConnecting', | ||
key: "onConnecting", | ||
value: function onConnecting() { | ||
@@ -148,3 +137,3 @@ this.dispatch(_constants.NativeSocketEvents.CONNECTING); | ||
}, { | ||
key: 'onConnect', | ||
key: "onConnect", | ||
value: function onConnect() { | ||
@@ -154,3 +143,3 @@ this.dispatch(_constants.NativeSocketEvents.CONNECT); | ||
}, { | ||
key: 'onConnectError', | ||
key: "onConnectError", | ||
value: function onConnectError(error) { | ||
@@ -160,3 +149,3 @@ this.dispatch(_constants.NativeSocketEvents.CONNECT_ERROR, error && error.message || error); | ||
}, { | ||
key: 'onReconnectAttempt', | ||
key: "onReconnectAttempt", | ||
value: function onReconnectAttempt(attempt, timeout) { | ||
@@ -166,6 +155,5 @@ this.dispatch(_constants.NativeSocketEvents.RECONNECT_ATTEMPT, attempt, timeout); | ||
}]); | ||
return RTSession; | ||
}(); | ||
exports.default = RTSession; | ||
exports["default"] = RTSession; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -13,9 +13,6 @@ /* eslint-disable */ | ||
*/ | ||
var Emitter = require('component-emitter'); | ||
exports.protocol = 4; | ||
exports.types = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'ERROR', 'BINARY_EVENT', 'BINARY_ACK']; | ||
exports.CONNECT = 0; | ||
@@ -28,3 +25,2 @@ exports.DISCONNECT = 1; | ||
exports.BINARY_ACK = 6; | ||
exports.Encoder = Encoder; | ||
@@ -34,3 +30,2 @@ exports.Decoder = Decoder; | ||
function Encoder() {} | ||
/** | ||
@@ -46,6 +41,6 @@ * Encode a packet as a single string if non-binary, or as a | ||
Encoder.prototype.encode = function (obj, callback) { | ||
callback([encodeAsString(obj)]); | ||
}; | ||
/** | ||
@@ -59,24 +54,23 @@ * Encode packet as string. | ||
function encodeAsString(obj) { | ||
// first is type | ||
var str = '' + obj.type; | ||
var str = '' + obj.type; // attachments if we have them | ||
// attachments if we have them | ||
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) { | ||
str += obj.attachments + '-'; | ||
} | ||
} // if we have a namespace other than `/` | ||
// we append it followed by a comma `,` | ||
// if we have a namespace other than `/` | ||
// we append it followed by a comma `,` | ||
if (obj.nsp && '/' !== obj.nsp) { | ||
str += obj.nsp + ','; | ||
} | ||
} // immediately followed by the id | ||
// immediately followed by the id | ||
if (null != obj.id) { | ||
str += obj.id; | ||
} | ||
} // json data | ||
// json data | ||
if (null != obj.data) { | ||
@@ -92,3 +86,2 @@ str += JSON.stringify(obj.data); | ||
Emitter(Decoder.prototype); | ||
/** | ||
@@ -109,3 +102,2 @@ * Decodes an ecoded packet string into packet JSON. | ||
}; | ||
/** | ||
@@ -119,14 +111,14 @@ * Decode a packet String (JSON data) | ||
function decodeString(str) { | ||
var i = 0; | ||
// look up type | ||
var i = 0; // look up type | ||
var p = { | ||
type: Number(str.charAt(0)) | ||
}; | ||
if (null == exports.types[p.type]) return error(); // look up attachments if type binary | ||
if (null == exports.types[p.type]) return error(); | ||
// look up attachments if type binary | ||
if (exports.BINARY_EVENT === p.type || exports.BINARY_ACK === p.type) { | ||
var buf = ''; | ||
while (str.charAt(++i) !== '-') { | ||
@@ -136,11 +128,14 @@ buf += str.charAt(i); | ||
} | ||
if (buf != Number(buf) || str.charAt(i) !== '-') { | ||
throw new Error('Illegal attachments'); | ||
} | ||
p.attachments = Number(buf); | ||
} | ||
} // look up namespace (if any) | ||
// look up namespace (if any) | ||
if ('/' === str.charAt(i + 1)) { | ||
p.nsp = ''; | ||
while (++i) { | ||
@@ -154,10 +149,13 @@ var c = str.charAt(i); | ||
p.nsp = '/'; | ||
} | ||
} // look up id | ||
// look up id | ||
var next = str.charAt(i + 1); | ||
if ('' !== next && Number(next) == next) { | ||
p.id = ''; | ||
while (++i) { | ||
var c = str.charAt(i); | ||
if (null == c || Number(c) != c) { | ||
@@ -167,9 +165,11 @@ --i; | ||
} | ||
p.id += str.charAt(i); | ||
if (i === str.length) break; | ||
} | ||
p.id = Number(p.id); | ||
} | ||
} // look up json data | ||
// look up json data | ||
if (str.charAt(++i)) { | ||
@@ -188,5 +188,5 @@ p = tryParse(p, str.substr(i)); | ||
} | ||
return p; | ||
} | ||
/** | ||
@@ -198,2 +198,3 @@ * Deallocates a parser's resources | ||
Decoder.prototype.destroy = function () {}; | ||
@@ -200,0 +201,0 @@ |
@@ -1,55 +0,19 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _constants = require("./constants"); | ||
var RTSocket = function () { | ||
_createClass(RTSocket, null, [{ | ||
key: 'connect', | ||
value: function connect(config, onDisconnect) { | ||
var Request = require('backendless-request'); | ||
if (!config.lookupPath) { | ||
throw new Error('config.lookupPath is not configured'); | ||
} | ||
return Request.get(config.lookupPath).set(config.lookupHeaders).then(function (rtServerHost) { | ||
return new Promise(function (resolve, reject) { | ||
var rtSocket = new RTSocket(config, rtServerHost); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT, onConnect); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_ERROR, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_TIMEOUT, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.ERROR, onError); | ||
rtSocket.connect(); | ||
function onConnect() { | ||
resolve(rtSocket); | ||
} | ||
function onError(error) { | ||
rtSocket.close(); | ||
reject(error); | ||
} | ||
}); | ||
}).then(function (rtSocket) { | ||
rtSocket.on(_constants.NativeSocketEvents.DISCONNECT, onDisconnect); | ||
return rtSocket; | ||
}); | ||
} | ||
}]); | ||
var RTSocket = /*#__PURE__*/function () { | ||
function RTSocket(config, host) { | ||
_classCallCheck(this, RTSocket); | ||
(0, _classCallCheck2["default"])(this, RTSocket); | ||
@@ -59,20 +23,13 @@ var io = require('socket.io-client'); | ||
this.config = config; | ||
this.events = {}; | ||
if (!config.appId) { | ||
throw new Error('config.appId is not configured'); | ||
} | ||
var _config$getSocketConf = config.getSocketConfig(), | ||
url = _config$getSocketConf.url, | ||
options = _config$getSocketConf.options; | ||
this.ioSocket = io(host + '/' + this.config.appId, { | ||
forceNew: true, | ||
autoConnect: false, | ||
reconnection: false, | ||
path: '/' + this.config.appId, | ||
query: this.config.getConnectQuery() | ||
}); | ||
this.ioSocket = io(url, options); | ||
} | ||
_createClass(RTSocket, [{ | ||
key: 'connect', | ||
(0, _createClass2["default"])(RTSocket, [{ | ||
key: "connect", | ||
value: function connect() { | ||
@@ -82,3 +39,3 @@ this.ioSocket.connect(); | ||
}, { | ||
key: 'close', | ||
key: "close", | ||
value: function close() { | ||
@@ -90,3 +47,3 @@ this.events = {}; | ||
}, { | ||
key: 'on', | ||
key: "on", | ||
value: function on(event, callback) { | ||
@@ -105,3 +62,3 @@ var _this = this; | ||
}, { | ||
key: 'off', | ||
key: "off", | ||
value: function off(event, callback) { | ||
@@ -121,3 +78,3 @@ this.events[event] = callback ? this.events[event].filter(function (f) { | ||
}, { | ||
key: 'onEvent', | ||
key: "onEvent", | ||
value: function onEvent(event, data) { | ||
@@ -135,3 +92,3 @@ if (this.config.debugMode) { | ||
}, { | ||
key: 'emit', | ||
key: "emit", | ||
value: function emit(event, data) { | ||
@@ -144,13 +101,39 @@ if (this.config.debugMode) { | ||
} | ||
}], [{ | ||
key: "connect", | ||
value: function connect(config, onDisconnect) { | ||
return Promise.resolve().then(function () { | ||
return config.prepare(); | ||
}).then(function () { | ||
return new Promise(function (resolve, reject) { | ||
var rtSocket = new RTSocket(config); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT, onConnect); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_ERROR, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.CONNECT_TIMEOUT, onError); | ||
rtSocket.on(_constants.NativeSocketEvents.ERROR, onError); | ||
rtSocket.connect(); | ||
function onConnect() { | ||
resolve(rtSocket); | ||
} | ||
function onError(error) { | ||
rtSocket.close(); | ||
reject(error); | ||
} | ||
}); | ||
}).then(function (rtSocket) { | ||
rtSocket.on(_constants.NativeSocketEvents.DISCONNECT, onDisconnect); | ||
return rtSocket; | ||
}); | ||
} | ||
}]); | ||
return RTSocket; | ||
}(); | ||
exports.default = RTSocket; | ||
exports["default"] = RTSocket; | ||
function logMessage(type, event, data) { | ||
// eslint-disable-next-line | ||
console.log('[' + type + '] - [event: ' + event + '] - arguments: ' + JSON.stringify(data) + ' '); | ||
console.log("[".concat(type, "] - [event: ").concat(event, "] - arguments: ").concat(JSON.stringify(data), " ")); | ||
} |
@@ -1,20 +0,20 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
exports["default"] = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _constants = require('./constants'); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _utils = require('./utils'); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _utils2 = _interopRequireDefault(_utils); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _utils = _interopRequireDefault(require("./utils")); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var subscription = function subscription(type) { | ||
@@ -26,33 +26,29 @@ return function (options, callbacks) { | ||
var RTSubscriptions = function () { | ||
var RTSubscriptions = /*#__PURE__*/function () { | ||
function RTSubscriptions(_ref) { | ||
var onMessage = _ref.onMessage, | ||
emitMessage = _ref.emitMessage; | ||
_classCallCheck(this, RTSubscriptions); | ||
this.onObjectsChanges = subscription(_constants.RTSubscriptionTypes.OBJECTS_CHANGES).bind(this); | ||
this.onRelationsChanges = subscription(_constants.RTSubscriptionTypes.RELATIONS_CHANGES).bind(this); | ||
this.connectToPubSub = subscription(_constants.RTSubscriptionTypes.PUB_SUB_CONNECT).bind(this); | ||
this.onPubSubMessage = subscription(_constants.RTSubscriptionTypes.PUB_SUB_MESSAGES).bind(this); | ||
this.onPubSubCommand = subscription(_constants.RTSubscriptionTypes.PUB_SUB_COMMANDS).bind(this); | ||
this.onPubSubUserStatus = subscription(_constants.RTSubscriptionTypes.PUB_SUB_USERS).bind(this); | ||
this.connectToRSO = subscription(_constants.RTSubscriptionTypes.RSO_CONNECT).bind(this); | ||
this.onRSOChanges = subscription(_constants.RTSubscriptionTypes.RSO_CHANGES).bind(this); | ||
this.onRSOClear = subscription(_constants.RTSubscriptionTypes.RSO_CLEARED).bind(this); | ||
this.onRSOCommand = subscription(_constants.RTSubscriptionTypes.RSO_COMMANDS).bind(this); | ||
this.onRSOInvoke = subscription(_constants.RTSubscriptionTypes.RSO_INVOKE).bind(this); | ||
this.onRSOUserStatus = subscription(_constants.RTSubscriptionTypes.RSO_USERS).bind(this); | ||
this.onLoggingMessages = subscription(_constants.RTSubscriptionTypes.LOGGING_MESSAGES).bind(this); | ||
this.onConsoleMessages = subscription(_constants.RTSubscriptionTypes.CONSOLE_MESSAGES).bind(this); | ||
this.onDeveloperMessage = subscription(_constants.RTSubscriptionTypes.DEVELOPER_MESSAGES).bind(this); | ||
(0, _classCallCheck2["default"])(this, RTSubscriptions); | ||
(0, _defineProperty2["default"])(this, "onObjectsChanges", subscription(_constants.RTSubscriptionTypes.OBJECTS_CHANGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRelationsChanges", subscription(_constants.RTSubscriptionTypes.RELATIONS_CHANGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "connectToPubSub", subscription(_constants.RTSubscriptionTypes.PUB_SUB_CONNECT).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onPubSubMessage", subscription(_constants.RTSubscriptionTypes.PUB_SUB_MESSAGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onPubSubCommand", subscription(_constants.RTSubscriptionTypes.PUB_SUB_COMMANDS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onPubSubUserStatus", subscription(_constants.RTSubscriptionTypes.PUB_SUB_USERS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "connectToRSO", subscription(_constants.RTSubscriptionTypes.RSO_CONNECT).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOChanges", subscription(_constants.RTSubscriptionTypes.RSO_CHANGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOClear", subscription(_constants.RTSubscriptionTypes.RSO_CLEARED).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOCommand", subscription(_constants.RTSubscriptionTypes.RSO_COMMANDS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOInvoke", subscription(_constants.RTSubscriptionTypes.RSO_INVOKE).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onRSOUserStatus", subscription(_constants.RTSubscriptionTypes.RSO_USERS).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onLoggingMessages", subscription(_constants.RTSubscriptionTypes.LOGGING_MESSAGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onConsoleMessages", subscription(_constants.RTSubscriptionTypes.CONSOLE_MESSAGES).bind(this)); | ||
(0, _defineProperty2["default"])(this, "onDeveloperMessage", subscription(_constants.RTSubscriptionTypes.DEVELOPER_MESSAGES).bind(this)); | ||
this.onMessage = onMessage; | ||
this.emitMessage = emitMessage; | ||
this.subscriptions = {}; | ||
} | ||
_createClass(RTSubscriptions, [{ | ||
key: 'initialize', | ||
(0, _createClass2["default"])(RTSubscriptions, [{ | ||
key: "initialize", | ||
value: function initialize() { | ||
@@ -69,3 +65,3 @@ var _this = this; | ||
}, { | ||
key: 'stop', | ||
key: "stop", | ||
value: function stop() { | ||
@@ -79,3 +75,3 @@ var _this2 = this; | ||
}, { | ||
key: 'reset', | ||
key: "reset", | ||
value: function reset() { | ||
@@ -89,3 +85,3 @@ var _this3 = this; | ||
}, { | ||
key: 'restore', | ||
key: "restore", | ||
value: function restore() { | ||
@@ -99,3 +95,3 @@ var _this4 = this; | ||
}, { | ||
key: 'hasActivity', | ||
key: "hasActivity", | ||
value: function hasActivity() { | ||
@@ -105,3 +101,3 @@ return !!Object.keys(this.subscriptions).length; | ||
}, { | ||
key: 'subscribe', | ||
key: "subscribe", | ||
value: function subscribe(name, options, _ref2) { | ||
@@ -116,6 +112,10 @@ var _this5 = this; | ||
var subscriptionId = _utils2.default.generateUID(); | ||
var subscriptionId = _utils["default"].generateUID(); | ||
this.subscriptions[subscriptionId] = { | ||
data: { id: subscriptionId, name: name, options: options }, | ||
data: { | ||
id: subscriptionId, | ||
name: name, | ||
options: options | ||
}, | ||
ready: false, | ||
@@ -128,5 +128,3 @@ parser: parser, | ||
}; | ||
this.startSubscription(subscriptionId); | ||
return { | ||
@@ -136,3 +134,2 @@ isReady: function isReady() { | ||
}, | ||
stop: function stop() { | ||
@@ -146,10 +143,9 @@ if (_this5.subscriptions[subscriptionId]) { | ||
}, { | ||
key: 'startSubscription', | ||
key: "startSubscription", | ||
value: function startSubscription(subscriptionId) { | ||
var subscription = this.subscriptions[subscriptionId]; | ||
this.emitMessage(_constants.RTSocketEvents.SUB_ON, subscription.data); | ||
} | ||
}, { | ||
key: 'stopSubscription', | ||
key: "stopSubscription", | ||
value: function stopSubscription(subscriptionId) { | ||
@@ -167,3 +163,3 @@ var subscription = this.subscriptions[subscriptionId]; | ||
}, { | ||
key: 'offSubscription', | ||
key: "offSubscription", | ||
value: function offSubscription(subscriptionId) { | ||
@@ -173,4 +169,5 @@ var subscription = this.subscriptions[subscriptionId]; | ||
if (subscription) { | ||
this.emitMessage(_constants.RTSocketEvents.SUB_OFF, { id: subscriptionId }); | ||
this.emitMessage(_constants.RTSocketEvents.SUB_OFF, { | ||
id: subscriptionId | ||
}); | ||
this.stopSubscription(subscriptionId); | ||
@@ -180,6 +177,5 @@ } | ||
}, { | ||
key: 'onSubscriptionReady', | ||
key: "onSubscriptionReady", | ||
value: function onSubscriptionReady(_ref3) { | ||
var id = _ref3.id; | ||
var subscription = this.subscriptions[id]; | ||
@@ -196,10 +192,3 @@ | ||
}, { | ||
key: 'onSubscriptionResponse', | ||
/***** CONSOLE SUBSCRIPTIONS ****** **/ | ||
/***************************************** **/ | ||
/** CONSOLE's SUBSCRIPTIONS **************************************************** **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
key: "onSubscriptionResponse", | ||
value: function onSubscriptionResponse(_ref4) { | ||
@@ -209,3 +198,2 @@ var id = _ref4.id, | ||
error = _ref4.error; | ||
var subscription = this.subscriptions[id]; | ||
@@ -215,3 +203,2 @@ | ||
if (error) { | ||
if (subscription.onError) { | ||
@@ -241,57 +228,28 @@ subscription.onError(error); | ||
} | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/** COMMON SUBSCRIPTIONS ******************************************************** **/ | ||
/***************************************** **/ | ||
/***** DATA SUBSCRIPTIONS **************** **/ | ||
/** */ | ||
/** */ | ||
/***** DATA SUBSCRIPTIONS **************** **/ | ||
/***************************************** **/ | ||
/***************************************** **/ | ||
/***** PUB_SUB SUBSCRIPTIONS ************* **/ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/***** PUB_SUB SUBSCRIPTIONS ************* **/ | ||
/***************************************** **/ | ||
/***** CONSOLE SUBSCRIPTIONS ****** **/ | ||
/***************************************** **/ | ||
/***** RSO SUBSCRIPTIONS ***************** **/ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/** */ | ||
/***** RSO SUBSCRIPTIONS ***************** **/ | ||
/***************************************** **/ | ||
/** COMMON SUBSCRIPTIONS ******************************************************** **/ | ||
/** CONSOLE's SUBSCRIPTIONS **************************************************** **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/******************************************************************************* **/ | ||
/** CONSOLE's SUBSCRIPTIONS **************************************************** **/ | ||
/***************************************** **/ | ||
/***** LOGGING SUBSCRIPTIONS ****** **/ | ||
/** */ | ||
/***** LOGGING SUBSCRIPTIONS ****** **/ | ||
/***************************************** **/ | ||
/***************************************** **/ | ||
/***** CONSOLE SUBSCRIPTIONS ****** **/ | ||
/** */ | ||
/** */ | ||
}]); | ||
return RTSubscriptions; | ||
}(); | ||
exports.default = RTSubscriptions; | ||
exports["default"] = RTSubscriptions; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,4 +6,4 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports["default"] = void 0; | ||
var CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
var Utils = { | ||
@@ -21,3 +21,3 @@ generateUID: function generateUID() { | ||
}; | ||
exports.default = Utils; | ||
var _default = Utils; | ||
exports["default"] = _default; |
{ | ||
"name": "backendless-rt-client", | ||
"version": "0.0.24", | ||
"version": "0.0.25-test.1", | ||
"description": "Backendless RT Client for connect to Backendless RT Server", | ||
@@ -23,4 +23,4 @@ "browser": "dist/backendless-rt-client.js", | ||
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es", | ||
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js dist/backendless-rt-client.js", | ||
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack src/index.js dist/backendless-rt-client.min.js", | ||
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack", | ||
"build:umd:min": "cross-env BABEL_ENV=commonjs NODE_ENV=production webpack", | ||
"bannerize": "bannerize ./dist/*.js --banner=./banner.ejs", | ||
@@ -50,28 +50,27 @@ "prepare": "npm run clean && npm run build && npm run bannerize" | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^8.0.3", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-polyfill": "^6.20.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-stage-1": "^6.24.1", | ||
"babel-preset-stage-3": "^6.17.0", | ||
"babelify": "^8.0.0", | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.18.2", | ||
"@babel/plugin-proposal-class-properties": "^7.17.12", | ||
"@babel/plugin-proposal-decorators": "^7.18.2", | ||
"@babel/plugin-transform-object-assign": "^7.16.7", | ||
"@babel/plugin-transform-runtime": "^7.18.2", | ||
"@babel/polyfill": "^7.12.1", | ||
"@babel/preset-env": "^7.18.2", | ||
"@babel/register": "^7.17.7", | ||
"babel-eslint": "^10.1.0", | ||
"babel-loader": "^8.2.5", | ||
"bannerize": "^1.1.4", | ||
"browserify": "^14.5.0", | ||
"copyfiles": "^1.1.0", | ||
"cross-env": "^5.1.0", | ||
"eslint": "~4.13.0", | ||
"rimraf": "^2.6.2", | ||
"uglify-js": "^3.2.2", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.16.0", | ||
"rimraf": "^3.0.2", | ||
"watch": "^1.0.2", | ||
"watchify": "^3.11.1", | ||
"webpack": "^3.10.0" | ||
"terser-webpack-plugin": "^5.3.1", | ||
"webpack": "^5.72.1", | ||
"webpack-cli": "^4.9.2" | ||
}, | ||
"dependencies": { | ||
"backendless-request": "^0.1.1", | ||
"@babel/runtime": "^7.18.2", | ||
"backendless-request": "^0.2.0", | ||
"socket.io-client": "^2.0.3" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
import Request from 'backendless-request' | ||
const isUndefined = value => typeof value === 'undefined' | ||
@@ -14,3 +16,6 @@ const isString = value => typeof value === 'string' | ||
this.connectQuery = {} | ||
this.socketConfigTransform = null | ||
this.socketConfig = null | ||
this.set(config) | ||
@@ -63,2 +68,11 @@ } | ||
} | ||
if (!isUndefined(config.socketConfigTransform)) { | ||
if (isFunction(config.socketConfigTransform)) { | ||
this.socketConfigTransform = config.socketConfigTransform | ||
} else { | ||
throw new Error('"socketConfigTransform" must be Function.') | ||
} | ||
} | ||
} | ||
@@ -70,3 +84,39 @@ | ||
async prepare() { | ||
if (!isString(this.lookupPath)) { | ||
throw new Error('lookupPath must be String') | ||
} | ||
const host = await Request.get(this.lookupPath).set(this.lookupHeaders) | ||
const url = this.appId ? `${ host }/${ this.appId }` : host | ||
const path = this.appId ? `/${ this.appId }` : undefined | ||
const query = this.getConnectQuery() | ||
this.socketConfig = { | ||
host, | ||
url, | ||
options: { | ||
path, | ||
query, | ||
forceNew : true, | ||
autoConnect : false, | ||
reconnection: false, | ||
} | ||
} | ||
if (this.socketConfigTransform) { | ||
const socketConfig = await this.socketConfigTransform(this.socketConfig) | ||
if (socketConfig) { | ||
this.socketConfig = socketConfig | ||
} | ||
} | ||
} | ||
getSocketConfig() { | ||
return this.socketConfig | ||
} | ||
} | ||
@@ -6,13 +6,7 @@ import { NativeSocketEvents } from './constants' | ||
static connect(config, onDisconnect) { | ||
const Request = require('backendless-request') | ||
if (!config.lookupPath) { | ||
throw new Error('config.lookupPath is not configured') | ||
} | ||
return Request.get(config.lookupPath) | ||
.set(config.lookupHeaders) | ||
.then(rtServerHost => { | ||
return Promise.resolve() | ||
.then(() => config.prepare()) | ||
.then(() => { | ||
return new Promise((resolve, reject) => { | ||
const rtSocket = new RTSocket(config, rtServerHost) | ||
const rtSocket = new RTSocket(config) | ||
@@ -51,13 +45,5 @@ rtSocket.on(NativeSocketEvents.CONNECT, onConnect) | ||
if (!config.appId) { | ||
throw new Error('config.appId is not configured') | ||
} | ||
const { url, options } = config.getSocketConfig() | ||
this.ioSocket = io(`${host}/${this.config.appId}`, { | ||
forceNew : true, | ||
autoConnect : false, | ||
reconnection: false, | ||
path : `/${this.config.appId}`, | ||
query : this.config.getConnectQuery() | ||
}) | ||
this.ioSocket = io(url, options) | ||
} | ||
@@ -64,0 +50,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
19
-9.52%43
2.38%12658
5.25%1179400
-11.43%3
50%1
Infinity%80
-20%+ Added
+ Added
+ Added
+ Added
- Removed
Updated