@webex/calling 3.12.0-next.5 → 3.12.0-next.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CallingClient/CallingClient.js +506 -223
- package/dist/CallingClient/CallingClient.js.map +1 -1
- package/dist/CallingClient/CallingClient.test.js +236 -77
- package/dist/CallingClient/CallingClient.test.js.map +1 -1
- package/dist/CallingClient/calling/call.js +589 -445
- package/dist/CallingClient/calling/call.js.map +1 -1
- package/dist/CallingClient/calling/call.test.js +695 -445
- package/dist/CallingClient/calling/call.test.js.map +1 -1
- package/dist/CallingClient/calling/callManager.js +53 -30
- package/dist/CallingClient/calling/callManager.js.map +1 -1
- package/dist/CallingClient/calling/callManager.test.js +35 -0
- package/dist/CallingClient/calling/callManager.test.js.map +1 -1
- package/dist/CallingClient/calling/types.js +2 -0
- package/dist/CallingClient/calling/types.js.map +1 -1
- package/dist/CallingClient/constants.js +27 -3
- package/dist/CallingClient/constants.js.map +1 -1
- package/dist/CallingClient/line/index.js +4 -1
- package/dist/CallingClient/line/index.js.map +1 -1
- package/dist/CallingClient/line/line.test.js +16 -1
- package/dist/CallingClient/line/line.test.js.map +1 -1
- package/dist/CallingClient/registration/register.js +714 -407
- package/dist/CallingClient/registration/register.js.map +1 -1
- package/dist/CallingClient/registration/register.test.js +311 -58
- package/dist/CallingClient/registration/register.test.js.map +1 -1
- package/dist/CallingClient/registration/types.js.map +1 -1
- package/dist/CallingClient/registration/webWorker.js +41 -104
- package/dist/CallingClient/registration/webWorker.js.map +1 -1
- package/dist/CallingClient/registration/webWorker.test.js +39 -153
- package/dist/CallingClient/registration/webWorker.test.js.map +1 -1
- package/dist/CallingClient/registration/webWorkerStr.js +1 -1
- package/dist/CallingClient/registration/webWorkerStr.js.map +1 -1
- package/dist/CallingClient/types.js.map +1 -1
- package/dist/CallingClient/utils/constants.js +58 -0
- package/dist/CallingClient/utils/constants.js.map +1 -0
- package/dist/CallingClient/utils/index.js +63 -0
- package/dist/CallingClient/utils/index.js.map +1 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.js +122 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.js.map +1 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.test.js +221 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.test.js.map +1 -0
- package/dist/CallingClient/utils/request.js +415 -0
- package/dist/CallingClient/utils/request.js.map +1 -0
- package/dist/CallingClient/utils/request.test.js +968 -0
- package/dist/CallingClient/utils/request.test.js.map +1 -0
- package/dist/CallingClient/utils/types.js +7 -0
- package/dist/CallingClient/utils/types.js.map +1 -0
- package/dist/CallingClient/utils/wsFeatureFlag.js +70 -0
- package/dist/CallingClient/utils/wsFeatureFlag.js.map +1 -0
- package/dist/CallingClient/utils/wsFeatureFlag.test.js +139 -0
- package/dist/CallingClient/utils/wsFeatureFlag.test.js.map +1 -0
- package/dist/Contacts/ContactsClient.js +13 -11
- package/dist/Contacts/ContactsClient.js.map +1 -1
- package/dist/Contacts/ContactsClient.test.js +3 -8
- package/dist/Contacts/ContactsClient.test.js.map +1 -1
- package/dist/Events/types.js +11 -11
- package/dist/Events/types.js.map +1 -1
- package/dist/Metrics/index.js +63 -2
- package/dist/Metrics/index.js.map +1 -1
- package/dist/Metrics/index.test.js +357 -1
- package/dist/Metrics/index.test.js.map +1 -1
- package/dist/Metrics/types.js +19 -1
- package/dist/Metrics/types.js.map +1 -1
- package/dist/SDKConnector/types.js.map +1 -1
- package/dist/common/Utils.js +138 -44
- package/dist/common/Utils.js.map +1 -1
- package/dist/common/testUtil.js +8 -4
- package/dist/common/testUtil.js.map +1 -1
- package/dist/common/types.js +2 -0
- package/dist/common/types.js.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/mobius-socket/config.js +24 -0
- package/dist/mobius-socket/config.js.map +1 -0
- package/dist/mobius-socket/errors.js +143 -0
- package/dist/mobius-socket/errors.js.map +1 -0
- package/dist/mobius-socket/errors.test.js +20 -0
- package/dist/mobius-socket/errors.test.js.map +1 -0
- package/dist/mobius-socket/index.js +57 -0
- package/dist/mobius-socket/index.js.map +1 -0
- package/dist/mobius-socket/mobius-socket-events.test.js +492 -0
- package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -0
- package/dist/mobius-socket/mobius-socket.js +849 -0
- package/dist/mobius-socket/mobius-socket.js.map +1 -0
- package/dist/mobius-socket/mobius-socket.test.js +1898 -0
- package/dist/mobius-socket/mobius-socket.test.js.map +1 -0
- package/dist/mobius-socket/socket/constants.js +55 -0
- package/dist/mobius-socket/socket/constants.js.map +1 -0
- package/dist/mobius-socket/socket/index.js +15 -0
- package/dist/mobius-socket/socket/index.js.map +1 -0
- package/dist/mobius-socket/socket/socket-base.js +604 -0
- package/dist/mobius-socket/socket/socket-base.js.map +1 -0
- package/dist/mobius-socket/socket/socket.js +19 -0
- package/dist/mobius-socket/socket/socket.js.map +1 -0
- package/dist/mobius-socket/socket/socket.shim.js +26 -0
- package/dist/mobius-socket/socket/socket.shim.js.map +1 -0
- package/dist/mobius-socket/socket/types.js +7 -0
- package/dist/mobius-socket/socket/types.js.map +1 -0
- package/dist/mobius-socket/socket.test.js +727 -0
- package/dist/mobius-socket/socket.test.js.map +1 -0
- package/dist/mobius-socket/test/mocha-helpers.js +23 -0
- package/dist/mobius-socket/test/mocha-helpers.js.map +1 -0
- package/dist/mobius-socket/test/promise-tick.js +28 -0
- package/dist/mobius-socket/test/promise-tick.js.map +1 -0
- package/dist/mobius-socket/types.js +7 -0
- package/dist/mobius-socket/types.js.map +1 -0
- package/dist/module/CallingClient/CallingClient.js +148 -10
- package/dist/module/CallingClient/calling/call.js +177 -61
- package/dist/module/CallingClient/calling/callManager.js +27 -7
- package/dist/module/CallingClient/calling/types.js +2 -0
- package/dist/module/CallingClient/constants.js +23 -0
- package/dist/module/CallingClient/line/index.js +2 -2
- package/dist/module/CallingClient/registration/register.js +236 -63
- package/dist/module/CallingClient/registration/webWorker.js +42 -61
- package/dist/module/CallingClient/registration/webWorkerStr.js +47 -82
- package/dist/module/CallingClient/utils/constants.js +36 -0
- package/dist/module/CallingClient/utils/index.js +5 -0
- package/dist/module/CallingClient/utils/mobiusSocketMapper.js +72 -0
- package/dist/module/CallingClient/utils/request.js +204 -0
- package/dist/module/CallingClient/utils/types.js +1 -0
- package/dist/module/CallingClient/utils/wsFeatureFlag.js +41 -0
- package/dist/module/Contacts/ContactsClient.js +1 -1
- package/dist/module/Events/types.js +4 -10
- package/dist/module/Metrics/index.js +48 -1
- package/dist/module/Metrics/types.js +18 -0
- package/dist/module/common/Utils.js +52 -12
- package/dist/module/common/testUtil.js +5 -1
- package/dist/module/common/types.js +2 -0
- package/dist/module/index.js +1 -1
- package/dist/module/mobius-socket/config.js +15 -0
- package/dist/module/mobius-socket/errors.js +58 -0
- package/dist/module/mobius-socket/index.js +24 -0
- package/dist/module/mobius-socket/mobius-socket.js +593 -0
- package/dist/module/mobius-socket/socket/constants.js +26 -0
- package/dist/module/mobius-socket/socket/index.js +4 -0
- package/dist/module/mobius-socket/socket/socket-base.js +368 -0
- package/dist/module/mobius-socket/socket/socket.js +9 -0
- package/dist/module/mobius-socket/socket/socket.shim.js +12 -0
- package/dist/module/mobius-socket/socket/types.js +1 -0
- package/dist/module/mobius-socket/types.js +1 -0
- package/dist/types/CallingClient/CallingClient.d.ts +8 -0
- package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/call.d.ts +12 -0
- package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/callManager.d.ts +3 -2
- package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/types.d.ts +34 -9
- package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
- package/dist/types/CallingClient/constants.d.ts +23 -0
- package/dist/types/CallingClient/constants.d.ts.map +1 -1
- package/dist/types/CallingClient/line/index.d.ts +1 -1
- package/dist/types/CallingClient/line/index.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/register.d.ts +7 -1
- package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/types.d.ts +4 -2
- package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
- package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
- package/dist/types/CallingClient/types.d.ts +1 -0
- package/dist/types/CallingClient/types.d.ts.map +1 -1
- package/dist/types/CallingClient/utils/constants.d.ts +35 -0
- package/dist/types/CallingClient/utils/constants.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/index.d.ts +6 -0
- package/dist/types/CallingClient/utils/index.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts +5 -0
- package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/request.d.ts +27 -0
- package/dist/types/CallingClient/utils/request.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/types.d.ts +34 -0
- package/dist/types/CallingClient/utils/types.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts +4 -0
- package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts.map +1 -0
- package/dist/types/Events/types.d.ts +14 -13
- package/dist/types/Events/types.d.ts.map +1 -1
- package/dist/types/Metrics/index.d.ts.map +1 -1
- package/dist/types/Metrics/types.d.ts +19 -2
- package/dist/types/Metrics/types.d.ts.map +1 -1
- package/dist/types/SDKConnector/types.d.ts +24 -0
- package/dist/types/SDKConnector/types.d.ts.map +1 -1
- package/dist/types/common/Utils.d.ts +9 -2
- package/dist/types/common/Utils.d.ts.map +1 -1
- package/dist/types/common/testUtil.d.ts +4 -1
- package/dist/types/common/testUtil.d.ts.map +1 -1
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/common/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mobius-socket/config.d.ts +17 -0
- package/dist/types/mobius-socket/config.d.ts.map +1 -0
- package/dist/types/mobius-socket/errors.d.ts +32 -0
- package/dist/types/mobius-socket/errors.d.ts.map +1 -0
- package/dist/types/mobius-socket/index.d.ts +14 -0
- package/dist/types/mobius-socket/index.d.ts.map +1 -0
- package/dist/types/mobius-socket/mobius-socket.d.ts +48 -0
- package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/constants.d.ts +27 -0
- package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/index.d.ts +5 -0
- package/dist/types/mobius-socket/socket/index.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/socket-base.d.ts +43 -0
- package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/socket.d.ts +6 -0
- package/dist/types/mobius-socket/socket/socket.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/socket.shim.d.ts +6 -0
- package/dist/types/mobius-socket/socket/socket.shim.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/types.d.ts +61 -0
- package/dist/types/mobius-socket/socket/types.d.ts.map +1 -0
- package/dist/types/mobius-socket/types.d.ts +21 -0
- package/dist/types/mobius-socket/types.d.ts.map +1 -0
- package/package.json +20 -5
- package/src/mobius-socket/socket/socket.shim.ts +22 -0
- package/src/mobius-socket/socket/socket.ts +14 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _errors = require("./errors");
|
|
4
|
+
describe('Mobius socket errors', function () {
|
|
5
|
+
it('preserves close-event details assigned after super(event)', function () {
|
|
6
|
+
var error = new _errors.ConnectionError({
|
|
7
|
+
code: 3050,
|
|
8
|
+
reason: 'done (permanent)'
|
|
9
|
+
});
|
|
10
|
+
expect(error.code).toBe(3050);
|
|
11
|
+
expect(error.reason).toBe('done (permanent)');
|
|
12
|
+
expect(error.parse({
|
|
13
|
+
code: 3051,
|
|
14
|
+
reason: 'retry'
|
|
15
|
+
})).toBe('retry');
|
|
16
|
+
expect(error.code).toBe(3050);
|
|
17
|
+
expect(error.reason).toBe('done (permanent)');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=errors.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","describe","it","error","ConnectionError","code","reason","expect","toBe","parse"],"sources":["errors.test.ts"],"sourcesContent":["import {ConnectionError} from './errors';\n\ndescribe('Mobius socket errors', () => {\n it('preserves close-event details assigned after super(event)', () => {\n const error = new ConnectionError({code: 3050, reason: 'done (permanent)'});\n\n expect(error.code).toBe(3050);\n expect(error.reason).toBe('done (permanent)');\n expect(error.parse({code: 3051, reason: 'retry'})).toBe('retry');\n expect(error.code).toBe(3050);\n expect(error.reason).toBe('done (permanent)');\n });\n});\n"],"mappings":";;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEAC,QAAQ,CAAC,sBAAsB,EAAE,YAAM;EACrCC,EAAE,CAAC,2DAA2D,EAAE,YAAM;IACpE,IAAMC,KAAK,GAAG,IAAIC,uBAAe,CAAC;MAACC,IAAI,EAAE,IAAI;MAAEC,MAAM,EAAE;IAAkB,CAAC,CAAC;IAE3EC,MAAM,CAACJ,KAAK,CAACE,IAAI,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC;IAC7BD,MAAM,CAACJ,KAAK,CAACG,MAAM,CAAC,CAACE,IAAI,CAAC,kBAAkB,CAAC;IAC7CD,MAAM,CAACJ,KAAK,CAACM,KAAK,CAAC;MAACJ,IAAI,EAAE,IAAI;MAAEC,MAAM,EAAE;IAAO,CAAC,CAAC,CAAC,CAACE,IAAI,CAAC,OAAO,CAAC;IAChED,MAAM,CAACJ,KAAK,CAACE,IAAI,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC;IAC7BD,MAAM,CAACJ,KAAK,CAACG,MAAM,CAAC,CAACE,IAAI,CAAC,kBAAkB,CAAC;EAC/C,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
5
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
6
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
7
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
8
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
9
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
10
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
11
|
+
value: true
|
|
12
|
+
});
|
|
13
|
+
_Object$defineProperty(exports, "MobiusSocket", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _mobiusSocket.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.default = void 0;
|
|
20
|
+
exports.getMobiusSocketInstance = getMobiusSocketInstance;
|
|
21
|
+
exports.resetMobiusSocketInstance = resetMobiusSocketInstance;
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
23
|
+
require("@webex/internal-plugin-device");
|
|
24
|
+
require("@webex/internal-plugin-feature");
|
|
25
|
+
require("@webex/internal-plugin-metrics");
|
|
26
|
+
var _mobiusSocket = _interopRequireDefault(require("./mobius-socket"));
|
|
27
|
+
var _config = _interopRequireDefault(require("./config"));
|
|
28
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
29
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; } /*!
|
|
30
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
31
|
+
*/
|
|
32
|
+
// Singleton instance - keeping just one instance of MobiusSocket since there won't be multiple connections
|
|
33
|
+
var mobiusSocketInstance;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates or returns the singleton Mobius socket client for the provided Webex instance.
|
|
37
|
+
*
|
|
38
|
+
* @param webex - The Webex SDK instance
|
|
39
|
+
* @param mobiusSocketConfig - Optional configuration overrides
|
|
40
|
+
* @returns The singleton MobiusSocket instance
|
|
41
|
+
*/
|
|
42
|
+
function getMobiusSocketInstance(webex, mobiusSocketConfig) {
|
|
43
|
+
if (mobiusSocketInstance) {
|
|
44
|
+
return mobiusSocketInstance;
|
|
45
|
+
}
|
|
46
|
+
mobiusSocketInstance = new _mobiusSocket.default(webex, _objectSpread(_objectSpread({}, _config.default.mobiusSocket), mobiusSocketConfig));
|
|
47
|
+
return mobiusSocketInstance;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Resets the singleton MobiusSocket instance, allowing a new one to be created.
|
|
52
|
+
*/
|
|
53
|
+
function resetMobiusSocketInstance() {
|
|
54
|
+
mobiusSocketInstance = undefined;
|
|
55
|
+
}
|
|
56
|
+
var _default = exports.default = _mobiusSocket.default;
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["require","_mobiusSocket","_interopRequireDefault","_config","ownKeys","e","r","t","_Object$keys","_Object$getOwnPropertySymbols","o","filter","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","Object","forEach","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","mobiusSocketInstance","getMobiusSocketInstance","webex","mobiusSocketConfig","MobiusSocket","config","mobiusSocket","resetMobiusSocketInstance","undefined","_default","exports"],"sources":["index.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\nimport '@webex/internal-plugin-feature';\nimport '@webex/internal-plugin-metrics';\n\nimport type {WebexSDK} from '../SDKConnector/types';\nimport MobiusSocket from './mobius-socket';\nimport config, {MobiusSocketConfig} from './config';\n\n// Singleton instance - keeping just one instance of MobiusSocket since there won't be multiple connections\nlet mobiusSocketInstance: MobiusSocket | undefined;\n\n/**\n * Creates or returns the singleton Mobius socket client for the provided Webex instance.\n *\n * @param webex - The Webex SDK instance\n * @param mobiusSocketConfig - Optional configuration overrides\n * @returns The singleton MobiusSocket instance\n */\nexport function getMobiusSocketInstance(\n webex: WebexSDK,\n mobiusSocketConfig?: Partial<MobiusSocketConfig>\n): MobiusSocket {\n if (mobiusSocketInstance) {\n return mobiusSocketInstance;\n }\n\n mobiusSocketInstance = new MobiusSocket(webex, {\n ...config.mobiusSocket,\n ...mobiusSocketConfig,\n });\n\n return mobiusSocketInstance;\n}\n\n/**\n * Resets the singleton MobiusSocket instance, allowing a new one to be created.\n */\nexport function resetMobiusSocketInstance() {\n mobiusSocketInstance = undefined;\n}\n\nexport default MobiusSocket;\nexport {MobiusSocket};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIAA,OAAA;AACAA,OAAA;AACAA,OAAA;AAGA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAoD,SAAAI,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAH,CAAA,OAAAI,6BAAA,QAAAC,CAAA,GAAAD,6BAAA,CAAAJ,CAAA,GAAAC,CAAA,KAAAI,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAL,CAAA,WAAAM,gCAAA,CAAAP,CAAA,EAAAC,CAAA,EAAAO,UAAA,OAAAN,CAAA,CAAAO,IAAA,CAAAC,KAAA,CAAAR,CAAA,EAAAG,CAAA,YAAAH,CAAA;AAAA,SAAAS,cAAAX,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAW,SAAA,CAAAC,MAAA,EAAAZ,CAAA,UAAAC,CAAA,WAAAU,SAAA,CAAAX,CAAA,IAAAW,SAAA,CAAAX,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAe,MAAA,CAAAZ,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,CAAAC,OAAA,EAAAjB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAiB,iCAAA,GAAAC,wBAAA,CAAAnB,CAAA,EAAAkB,iCAAA,CAAAhB,CAAA,KAAAH,OAAA,CAAAe,MAAA,CAAAZ,CAAA,GAAAa,OAAA,WAAAd,CAAA,IAAAmB,sBAAA,CAAApB,CAAA,EAAAC,CAAA,EAAAM,gCAAA,CAAAL,CAAA,EAAAD,CAAA,iBAAAD,CAAA,IAVpD;AACA;AACA;AAUA;AACA,IAAIqB,oBAA8C;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,uBAAuBA,CACrCC,KAAe,EACfC,kBAAgD,EAClC;EACd,IAAIH,oBAAoB,EAAE;IACxB,OAAOA,oBAAoB;EAC7B;EAEAA,oBAAoB,GAAG,IAAII,qBAAY,CAACF,KAAK,EAAAZ,aAAA,CAAAA,aAAA,KACxCe,eAAM,CAACC,YAAY,GACnBH,kBAAkB,CACtB,CAAC;EAEF,OAAOH,oBAAoB;AAC7B;;AAEA;AACA;AACA;AACO,SAASO,yBAAyBA,CAAA,EAAG;EAC1CP,oBAAoB,GAAGQ,SAAS;AAClC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAd,OAAA,GAEcQ,qBAAY","ignoreList":[]}
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
5
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
6
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
7
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
8
|
+
var _Object$defineProperty2 = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
9
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/define-property"));
|
|
12
|
+
var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
|
|
13
|
+
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
14
|
+
var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
|
|
15
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
16
|
+
var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
17
|
+
var _construct2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/construct"));
|
|
18
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
|
19
|
+
var _wrap2 = _interopRequireDefault(require("lodash/wrap"));
|
|
20
|
+
var _crypto = require("crypto");
|
|
21
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
22
|
+
var _testHelperChai = require("@webex/test-helper-chai");
|
|
23
|
+
var _testHelperMockWebex = _interopRequireDefault(require("@webex/test-helper-mock-webex"));
|
|
24
|
+
var _testHelperMockWebSocket = _interopRequireDefault(require("@webex/test-helper-mock-web-socket"));
|
|
25
|
+
var _index = _interopRequireDefault(require("./index"));
|
|
26
|
+
var _config = _interopRequireDefault(require("./config"));
|
|
27
|
+
var _socket = _interopRequireDefault(require("./socket"));
|
|
28
|
+
var _constants = require("./socket/constants");
|
|
29
|
+
var _promiseTick = _interopRequireDefault(require("./test/promise-tick"));
|
|
30
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
31
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty2(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; } /*!
|
|
32
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
33
|
+
*/
|
|
34
|
+
if (!crypto.randomUUID) {
|
|
35
|
+
(0, _defineProperty2.default)(crypto, 'randomUUID', {
|
|
36
|
+
value: _crypto.randomUUID,
|
|
37
|
+
configurable: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
describe('plugin-mobiusSocket', function () {
|
|
41
|
+
var createUuid = function createUuid() {
|
|
42
|
+
return crypto.randomUUID();
|
|
43
|
+
};
|
|
44
|
+
describe('MobiusSocket', function () {
|
|
45
|
+
describe('Events', function () {
|
|
46
|
+
var mobiusSocket;
|
|
47
|
+
var mockWebSocket;
|
|
48
|
+
var originalSendSpy;
|
|
49
|
+
var socketOpenStub;
|
|
50
|
+
var usingFakeTimers;
|
|
51
|
+
var webex;
|
|
52
|
+
var fakeTestMessage = {
|
|
53
|
+
id: createUuid(),
|
|
54
|
+
data: {
|
|
55
|
+
eventType: 'fake.test'
|
|
56
|
+
},
|
|
57
|
+
timestamp: (0, _now.default)(),
|
|
58
|
+
trackingId: "suffix_".concat(createUuid(), "_").concat((0, _now.default)())
|
|
59
|
+
};
|
|
60
|
+
var statusStartTypingMessage = {
|
|
61
|
+
id: createUuid(),
|
|
62
|
+
data: {
|
|
63
|
+
eventType: 'status.start_typing',
|
|
64
|
+
actor: {
|
|
65
|
+
id: 'actorId'
|
|
66
|
+
},
|
|
67
|
+
conversationId: createUuid()
|
|
68
|
+
},
|
|
69
|
+
timestamp: (0, _now.default)(),
|
|
70
|
+
trackingId: "suffix_".concat(createUuid(), "_").concat((0, _now.default)())
|
|
71
|
+
};
|
|
72
|
+
var emitAuthResponse = function emitAuthResponse() {
|
|
73
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
74
|
+
_ref$statusCode = _ref.statusCode,
|
|
75
|
+
statusCode = _ref$statusCode === void 0 ? 200 : _ref$statusCode,
|
|
76
|
+
_ref$statusMessage = _ref.statusMessage,
|
|
77
|
+
statusMessage = _ref$statusMessage === void 0 ? 'OK' : _ref$statusMessage;
|
|
78
|
+
var sendSpy = mockWebSocket.send.lastCall ? mockWebSocket.send : originalSendSpy;
|
|
79
|
+
var authRequest = JSON.parse(sendSpy.lastCall.args[0]);
|
|
80
|
+
mockWebSocket.emit('message', {
|
|
81
|
+
data: (0, _stringify.default)({
|
|
82
|
+
type: 'response_event',
|
|
83
|
+
subtype: _constants.MESSAGE_TYPES.AUTH,
|
|
84
|
+
trackingId: authRequest.trackingId,
|
|
85
|
+
statusCode: statusCode,
|
|
86
|
+
statusMessage: statusMessage
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
beforeEach(function () {
|
|
91
|
+
jest.useFakeTimers({
|
|
92
|
+
doNotFake: ['nextTick']
|
|
93
|
+
});
|
|
94
|
+
usingFakeTimers = true;
|
|
95
|
+
});
|
|
96
|
+
afterEach(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
97
|
+
var _t;
|
|
98
|
+
return _regenerator.default.wrap(function (_context) {
|
|
99
|
+
while (1) switch (_context.prev = _context.next) {
|
|
100
|
+
case 0:
|
|
101
|
+
if (usingFakeTimers) {
|
|
102
|
+
jest.useRealTimers();
|
|
103
|
+
usingFakeTimers = false;
|
|
104
|
+
}
|
|
105
|
+
if (!mobiusSocket) {
|
|
106
|
+
_context.next = 4;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
_context.prev = 1;
|
|
110
|
+
_context.next = 2;
|
|
111
|
+
return mobiusSocket.disconnect();
|
|
112
|
+
case 2:
|
|
113
|
+
_context.next = 4;
|
|
114
|
+
break;
|
|
115
|
+
case 3:
|
|
116
|
+
_context.prev = 3;
|
|
117
|
+
_t = _context["catch"](1);
|
|
118
|
+
case 4:
|
|
119
|
+
if (mockWebSocket && typeof mockWebSocket.close === 'function') {
|
|
120
|
+
try {
|
|
121
|
+
mockWebSocket.close();
|
|
122
|
+
} catch (e) {
|
|
123
|
+
// Ignore cleanup errors in tests.
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Restore stubs
|
|
127
|
+
if (_socket.default.getWebSocketConstructor.restore) {
|
|
128
|
+
_socket.default.getWebSocketConstructor.restore();
|
|
129
|
+
}
|
|
130
|
+
if (socketOpenStub && socketOpenStub.restore) {
|
|
131
|
+
socketOpenStub.restore();
|
|
132
|
+
}
|
|
133
|
+
case 5:
|
|
134
|
+
case "end":
|
|
135
|
+
return _context.stop();
|
|
136
|
+
}
|
|
137
|
+
}, _callee, null, [[1, 3]]);
|
|
138
|
+
})));
|
|
139
|
+
beforeEach(function () {
|
|
140
|
+
webex = new _testHelperMockWebex.default();
|
|
141
|
+
webex.internal.device.registered = true;
|
|
142
|
+
webex.internal.metrics.submitClientMetrics = _sinon.default.stub();
|
|
143
|
+
webex.trackingId = 'fakeTrackingId';
|
|
144
|
+
webex.logger = console;
|
|
145
|
+
_sinon.default.stub(_socket.default, 'getWebSocketConstructor').callsFake(function () {
|
|
146
|
+
return function () {
|
|
147
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
148
|
+
args[_key] = arguments[_key];
|
|
149
|
+
}
|
|
150
|
+
mockWebSocket = (0, _construct2.default)(_testHelperMockWebSocket.default, args);
|
|
151
|
+
originalSendSpy = mockWebSocket.send;
|
|
152
|
+
return mockWebSocket;
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
var origOpen = _socket.default.prototype.open;
|
|
156
|
+
socketOpenStub = _sinon.default.stub(_socket.default.prototype, 'open').callsFake(function () {
|
|
157
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
158
|
+
args[_key2] = arguments[_key2];
|
|
159
|
+
}
|
|
160
|
+
var promise = (0, _apply.default)(origOpen, this, args);
|
|
161
|
+
process.nextTick(function () {
|
|
162
|
+
mockWebSocket.open();
|
|
163
|
+
// Simulate Mobius auth response after socket open
|
|
164
|
+
process.nextTick(function () {
|
|
165
|
+
emitAuthResponse();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return promise;
|
|
169
|
+
});
|
|
170
|
+
mobiusSocket = new _index.default(webex, _objectSpread({}, _config.default.mobiusSocket));
|
|
171
|
+
mobiusSocket.logger = {
|
|
172
|
+
debug: jest.fn(),
|
|
173
|
+
error: jest.fn(),
|
|
174
|
+
info: jest.fn(),
|
|
175
|
+
log: jest.fn(),
|
|
176
|
+
warn: jest.fn()
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
it('removes all listeners for an event when off() is called without a listener', function () {
|
|
180
|
+
var firstListener = _sinon.default.stub();
|
|
181
|
+
var secondListener = _sinon.default.stub();
|
|
182
|
+
mobiusSocket.on('event:fake.test', firstListener);
|
|
183
|
+
mobiusSocket.on('event:fake.test', secondListener);
|
|
184
|
+
mobiusSocket.off('event:fake.test');
|
|
185
|
+
mobiusSocket.emit('event:fake.test', fakeTestMessage);
|
|
186
|
+
_testHelperChai.assert.notCalled(firstListener);
|
|
187
|
+
_testHelperChai.assert.notCalled(secondListener);
|
|
188
|
+
});
|
|
189
|
+
afterEach(function () {
|
|
190
|
+
if (socketOpenStub) {
|
|
191
|
+
socketOpenStub.restore();
|
|
192
|
+
}
|
|
193
|
+
if (_socket.default.getWebSocketConstructor.restore) {
|
|
194
|
+
_socket.default.getWebSocketConstructor.restore();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
describe('when connected', function () {
|
|
198
|
+
it('emits the `online` event', function () {
|
|
199
|
+
var spy = _sinon.default.spy();
|
|
200
|
+
mobiusSocket.on('online', spy);
|
|
201
|
+
var promise = mobiusSocket.connect();
|
|
202
|
+
return promise.then(function () {
|
|
203
|
+
return _testHelperChai.assert.called(spy);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe('when disconnected', function () {
|
|
208
|
+
it('emits the `offline` event', function () {
|
|
209
|
+
var spy = _sinon.default.spy();
|
|
210
|
+
mobiusSocket.on('offline', spy);
|
|
211
|
+
var promise = mobiusSocket.connect();
|
|
212
|
+
mockWebSocket.open();
|
|
213
|
+
return promise.then(function () {
|
|
214
|
+
var disconnectPromise = mobiusSocket.disconnect();
|
|
215
|
+
mockWebSocket.emit('close', {
|
|
216
|
+
code: 1000,
|
|
217
|
+
reason: 'Done'
|
|
218
|
+
});
|
|
219
|
+
return disconnectPromise;
|
|
220
|
+
}).then(function () {
|
|
221
|
+
return _testHelperChai.assert.calledOnce(spy);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
describe('when reconnected', function () {
|
|
225
|
+
it('emits the `online` event', function () {
|
|
226
|
+
var spy = _sinon.default.spy();
|
|
227
|
+
mobiusSocket.on('online', spy);
|
|
228
|
+
var promise = mobiusSocket.connect();
|
|
229
|
+
mockWebSocket.open();
|
|
230
|
+
return promise.then(function () {
|
|
231
|
+
return _testHelperChai.assert.calledOnce(spy);
|
|
232
|
+
}).then(function () {
|
|
233
|
+
return mockWebSocket.emit('close', {
|
|
234
|
+
code: 1000,
|
|
235
|
+
reason: 'Idle'
|
|
236
|
+
});
|
|
237
|
+
}).then(function () {
|
|
238
|
+
return mobiusSocket.connect();
|
|
239
|
+
}).then(function () {
|
|
240
|
+
return _testHelperChai.assert.calledTwice(spy);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
describe('when `mercury.buffer_state` is received', function () {
|
|
246
|
+
// This test is here because the buffer states message may arrive before
|
|
247
|
+
// the mobiusSocket Promise resolves.
|
|
248
|
+
it('gets emitted', function () {
|
|
249
|
+
var sendSpy;
|
|
250
|
+
var resolveTest;
|
|
251
|
+
var rejectTest;
|
|
252
|
+
var bufferStateSpy = _sinon.default.spy();
|
|
253
|
+
var onlineSpy = _sinon.default.spy();
|
|
254
|
+
mobiusSocket.on('event:mercury.buffer_state', bufferStateSpy);
|
|
255
|
+
mobiusSocket.on('online', onlineSpy);
|
|
256
|
+
_socket.default.getWebSocketConstructor.callsFake(function () {
|
|
257
|
+
return function () {
|
|
258
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
259
|
+
args[_key3] = arguments[_key3];
|
|
260
|
+
}
|
|
261
|
+
mockWebSocket = (0, _construct2.default)(_testHelperMockWebSocket.default, args);
|
|
262
|
+
sendSpy = mockWebSocket.send;
|
|
263
|
+
mockWebSocket.send = (0, _wrap2.default)(mockWebSocket.send, function (fn) {
|
|
264
|
+
var _this = this;
|
|
265
|
+
for (var _len4 = arguments.length, sendArgs = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
266
|
+
sendArgs[_key4 - 1] = arguments[_key4];
|
|
267
|
+
}
|
|
268
|
+
process.nextTick(function () {
|
|
269
|
+
(0, _apply.default)(fn, _this, sendArgs);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
process.nextTick(function () {
|
|
273
|
+
_testHelperChai.assert.isTrue(mobiusSocket.connecting, 'MobiusSocket is still connecting');
|
|
274
|
+
_testHelperChai.assert.isFalse(mobiusSocket.connected, 'MobiusSocket has not yet connected');
|
|
275
|
+
_testHelperChai.assert.notCalled(onlineSpy);
|
|
276
|
+
_testHelperChai.assert.lengthOf(sendSpy.args, 0, 'The client has not yet sent the auth message');
|
|
277
|
+
// set websocket readystate to 1 to allow a successful send message
|
|
278
|
+
mockWebSocket.readyState = 1;
|
|
279
|
+
mockWebSocket.emit('open');
|
|
280
|
+
mockWebSocket.emit('message', {
|
|
281
|
+
data: (0, _stringify.default)({
|
|
282
|
+
id: createUuid(),
|
|
283
|
+
data: {
|
|
284
|
+
eventType: 'mercury.buffer_state'
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
// using lengthOf because notCalled doesn't allow the helpful
|
|
289
|
+
// string assertion
|
|
290
|
+
_testHelperChai.assert.lengthOf(sendSpy.args, 0, 'The client has not acked the buffer_state message');
|
|
291
|
+
(0, _promiseTick.default)(1).then(function () {
|
|
292
|
+
_testHelperChai.assert.called(bufferStateSpy);
|
|
293
|
+
resolveTest();
|
|
294
|
+
}).catch(rejectTest);
|
|
295
|
+
});
|
|
296
|
+
return mockWebSocket;
|
|
297
|
+
};
|
|
298
|
+
});
|
|
299
|
+
return new _promise.default(function (resolve, reject) {
|
|
300
|
+
resolveTest = resolve;
|
|
301
|
+
rejectTest = reject;
|
|
302
|
+
mobiusSocket.connect().catch(function () {});
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
describe('when a CloseEvent is received', function () {
|
|
307
|
+
var events = [{
|
|
308
|
+
code: 1000,
|
|
309
|
+
reason: 'idle',
|
|
310
|
+
action: 'close'
|
|
311
|
+
}, {
|
|
312
|
+
code: 1000,
|
|
313
|
+
reason: 'done (forced)',
|
|
314
|
+
action: 'close'
|
|
315
|
+
}, {
|
|
316
|
+
code: 1000,
|
|
317
|
+
reason: 'pong not received',
|
|
318
|
+
action: 'close'
|
|
319
|
+
}, {
|
|
320
|
+
code: 1000,
|
|
321
|
+
reason: 'pong mismatch',
|
|
322
|
+
action: 'close'
|
|
323
|
+
}, {
|
|
324
|
+
code: 1000,
|
|
325
|
+
action: 'close'
|
|
326
|
+
}, {
|
|
327
|
+
code: 1003,
|
|
328
|
+
action: 'close'
|
|
329
|
+
}, {
|
|
330
|
+
code: 1001,
|
|
331
|
+
action: 'close'
|
|
332
|
+
}, {
|
|
333
|
+
code: 1005,
|
|
334
|
+
action: 'reconnect'
|
|
335
|
+
}, {
|
|
336
|
+
code: 1006,
|
|
337
|
+
action: 'reconnect'
|
|
338
|
+
}, {
|
|
339
|
+
code: 1011,
|
|
340
|
+
action: 'reconnect'
|
|
341
|
+
}, {
|
|
342
|
+
code: 4000,
|
|
343
|
+
action: 'replace'
|
|
344
|
+
}, {
|
|
345
|
+
action: 'close'
|
|
346
|
+
}];
|
|
347
|
+
events.forEach(function (def) {
|
|
348
|
+
var action = def.action,
|
|
349
|
+
reason = def.reason,
|
|
350
|
+
code = def.code;
|
|
351
|
+
var description;
|
|
352
|
+
if (code && reason) {
|
|
353
|
+
description = "with code `".concat(code, "` and reason `").concat(reason, "`");
|
|
354
|
+
} else if (code) {
|
|
355
|
+
description = "with code `".concat(code, "`");
|
|
356
|
+
} else if (reason) {
|
|
357
|
+
description = "with reason `".concat(reason, "`");
|
|
358
|
+
}
|
|
359
|
+
describe("when an event ".concat(description, " is received"), function () {
|
|
360
|
+
it("takes the ".concat(action, " action"), function () {
|
|
361
|
+
if (mobiusSocket.reconnect.restore) {
|
|
362
|
+
mobiusSocket.reconnect.restore();
|
|
363
|
+
}
|
|
364
|
+
_sinon.default.spy(mobiusSocket, 'connect');
|
|
365
|
+
var offlineSpy = _sinon.default.spy();
|
|
366
|
+
var permanentSpy = _sinon.default.spy();
|
|
367
|
+
var transientSpy = _sinon.default.spy();
|
|
368
|
+
var replacedSpy = _sinon.default.spy();
|
|
369
|
+
mobiusSocket.on('offline', offlineSpy);
|
|
370
|
+
mobiusSocket.on('offline.permanent', permanentSpy);
|
|
371
|
+
mobiusSocket.on('offline.transient', transientSpy);
|
|
372
|
+
mobiusSocket.on('offline.replaced', replacedSpy);
|
|
373
|
+
var promise = mobiusSocket.connect();
|
|
374
|
+
mockWebSocket.open();
|
|
375
|
+
return promise.then(function () {
|
|
376
|
+
// Make sure mobiusSocket.connect has a call count of zero
|
|
377
|
+
mobiusSocket.connect.resetHistory();
|
|
378
|
+
mockWebSocket.emit('close', {
|
|
379
|
+
code: code,
|
|
380
|
+
reason: reason
|
|
381
|
+
});
|
|
382
|
+
return (0, _promiseTick.default)(1);
|
|
383
|
+
}).then(function () {
|
|
384
|
+
_testHelperChai.assert.called(offlineSpy);
|
|
385
|
+
_testHelperChai.assert.calledWith(offlineSpy, {
|
|
386
|
+
code: code,
|
|
387
|
+
reason: reason
|
|
388
|
+
});
|
|
389
|
+
switch (action) {
|
|
390
|
+
case 'close':
|
|
391
|
+
_testHelperChai.assert.called(permanentSpy);
|
|
392
|
+
_testHelperChai.assert.notCalled(transientSpy);
|
|
393
|
+
_testHelperChai.assert.notCalled(replacedSpy);
|
|
394
|
+
break;
|
|
395
|
+
case 'reconnect':
|
|
396
|
+
_testHelperChai.assert.notCalled(permanentSpy);
|
|
397
|
+
_testHelperChai.assert.called(transientSpy);
|
|
398
|
+
_testHelperChai.assert.notCalled(replacedSpy);
|
|
399
|
+
break;
|
|
400
|
+
case 'replace':
|
|
401
|
+
_testHelperChai.assert.notCalled(permanentSpy);
|
|
402
|
+
_testHelperChai.assert.notCalled(transientSpy);
|
|
403
|
+
_testHelperChai.assert.called(replacedSpy);
|
|
404
|
+
break;
|
|
405
|
+
default:
|
|
406
|
+
(0, _testHelperChai.assert)(false, 'unreachable code reached');
|
|
407
|
+
}
|
|
408
|
+
_testHelperChai.assert.isFalse(mobiusSocket.connected, 'MobiusSocket is not connected');
|
|
409
|
+
if (action === 'reconnect') {
|
|
410
|
+
_testHelperChai.assert.called(mobiusSocket.connect);
|
|
411
|
+
_testHelperChai.assert.calledWith(mobiusSocket.connect, mockWebSocket.url);
|
|
412
|
+
_testHelperChai.assert.isTrue(mobiusSocket.connecting, 'MobiusSocket is connecting');
|
|
413
|
+
|
|
414
|
+
// Block until reconnect completes so logs don't overlap
|
|
415
|
+
return mobiusSocket.connect();
|
|
416
|
+
}
|
|
417
|
+
_testHelperChai.assert.notCalled(mobiusSocket.connect);
|
|
418
|
+
_testHelperChai.assert.isFalse(mobiusSocket.connecting, 'MobiusSocket is not connecting');
|
|
419
|
+
return _promise.default.resolve();
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
describe('when a MessageEvent is received', function () {
|
|
426
|
+
it('emits the MobiusSocket envelope', function () {
|
|
427
|
+
var startSpy = _sinon.default.spy();
|
|
428
|
+
var stopSpy = _sinon.default.spy();
|
|
429
|
+
mobiusSocket.on('event:status.start_typing', startSpy);
|
|
430
|
+
mobiusSocket.on('event:status.stop_typing', stopSpy);
|
|
431
|
+
var promise = mobiusSocket.connect();
|
|
432
|
+
mockWebSocket.open();
|
|
433
|
+
return promise.then(function () {
|
|
434
|
+
mockWebSocket.emit('message', {
|
|
435
|
+
data: (0, _stringify.default)(statusStartTypingMessage)
|
|
436
|
+
});
|
|
437
|
+
return (0, _promiseTick.default)(1);
|
|
438
|
+
}).then(function () {
|
|
439
|
+
_testHelperChai.assert.calledOnce(startSpy);
|
|
440
|
+
_testHelperChai.assert.notCalled(stopSpy);
|
|
441
|
+
_testHelperChai.assert.calledWith(startSpy, statusStartTypingMessage);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
it("emits the MobiusSocket envelope named by the MobiusSocket event's eventType", function () {
|
|
445
|
+
var startSpy = _sinon.default.spy();
|
|
446
|
+
var stopSpy = _sinon.default.spy();
|
|
447
|
+
mobiusSocket.on('event:status.start_typing', startSpy);
|
|
448
|
+
mobiusSocket.on('event:status.stop_typing', stopSpy);
|
|
449
|
+
var promise = mobiusSocket.connect();
|
|
450
|
+
mockWebSocket.open();
|
|
451
|
+
return promise.then(function () {
|
|
452
|
+
mockWebSocket.emit('message', {
|
|
453
|
+
data: (0, _stringify.default)(statusStartTypingMessage)
|
|
454
|
+
});
|
|
455
|
+
return (0, _promiseTick.default)(1);
|
|
456
|
+
}).then(function () {
|
|
457
|
+
_testHelperChai.assert.calledOnce(startSpy);
|
|
458
|
+
_testHelperChai.assert.notCalled(stopSpy);
|
|
459
|
+
_testHelperChai.assert.calledWith(startSpy, statusStartTypingMessage);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// Mobius does not use sequence numbers, so sequence-mismatch tests are not applicable
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
/*
|
|
469
|
+
// On mobiusSocket:
|
|
470
|
+
online
|
|
471
|
+
offline
|
|
472
|
+
offline.transient
|
|
473
|
+
offline.permanent
|
|
474
|
+
offline.replaced
|
|
475
|
+
event
|
|
476
|
+
event:locus.participant_joined
|
|
477
|
+
mockWebSocket.connection-failed
|
|
478
|
+
mockWebSocket.sequence-mismatch
|
|
479
|
+
// On webex:
|
|
480
|
+
mobiusSocket.online
|
|
481
|
+
mobiusSocket.offline
|
|
482
|
+
mobiusSocket.offline.transient
|
|
483
|
+
mobiusSocket.offline.permanent
|
|
484
|
+
mobiusSocket.offline.replaced
|
|
485
|
+
mobiusSocket.event
|
|
486
|
+
mobiusSocket.event:locus.participant_joined
|
|
487
|
+
mobiusSocket.mockWebSocket.connection-failed
|
|
488
|
+
mobiusSocket.mockWebSocket.sequence-mismatch
|
|
489
|
+
// TODO go through all it(`emits...`) and make sure corresponding tests are here
|
|
490
|
+
*/
|
|
491
|
+
});
|
|
492
|
+
//# sourceMappingURL=mobius-socket-events.test.js.map
|