@monterosa/sdk-enmasse-kit 2.0.0-rc.1 → 2.0.0-rc.2
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/{index.esm.js → index.js} +244 -301
- package/dist/index.js.map +1 -0
- package/package.json +19 -18
- package/dist/index.cjs.js +0 -2180
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
|
@@ -1,10 +1,77 @@
|
|
|
1
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
3
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
4
1
|
import { checkAvailability, getItem, Emitter, getGlobal, getErrorMessage } from '@monterosa/sdk-util';
|
|
5
|
-
import {
|
|
2
|
+
import { storageRead, storageWrite, storageRemove } from '@monterosa/sdk-storage-kit';
|
|
6
3
|
import { getParentApplication } from '@monterosa/sdk-launcher-kit';
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(r, a) {
|
|
6
|
+
(null == a || a > r.length) && (a = r.length);
|
|
7
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
function _arrayWithHoles(r) {
|
|
11
|
+
if (Array.isArray(r)) return r;
|
|
12
|
+
}
|
|
13
|
+
function _defineProperty(e, r, t) {
|
|
14
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
15
|
+
value: t,
|
|
16
|
+
enumerable: !0,
|
|
17
|
+
configurable: !0,
|
|
18
|
+
writable: !0
|
|
19
|
+
}) : e[r] = t, e;
|
|
20
|
+
}
|
|
21
|
+
function _iterableToArrayLimit(r, l) {
|
|
22
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
23
|
+
if (null != t) {
|
|
24
|
+
var e,
|
|
25
|
+
n,
|
|
26
|
+
i,
|
|
27
|
+
u,
|
|
28
|
+
a = [],
|
|
29
|
+
f = !0,
|
|
30
|
+
o = !1;
|
|
31
|
+
try {
|
|
32
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
33
|
+
if (Object(t) !== t) return;
|
|
34
|
+
f = !1;
|
|
35
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
36
|
+
} catch (r) {
|
|
37
|
+
o = !0, n = r;
|
|
38
|
+
} finally {
|
|
39
|
+
try {
|
|
40
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
41
|
+
} finally {
|
|
42
|
+
if (o) throw n;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return a;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _nonIterableRest() {
|
|
49
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
50
|
+
}
|
|
51
|
+
function _slicedToArray(r, e) {
|
|
52
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
53
|
+
}
|
|
54
|
+
function _toPrimitive(t, r) {
|
|
55
|
+
if ("object" != typeof t || !t) return t;
|
|
56
|
+
var e = t[Symbol.toPrimitive];
|
|
57
|
+
if (void 0 !== e) {
|
|
58
|
+
var i = e.call(t, r || "default");
|
|
59
|
+
if ("object" != typeof i) return i;
|
|
60
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
61
|
+
}
|
|
62
|
+
return ("string" === r ? String : Number)(t);
|
|
63
|
+
}
|
|
64
|
+
function _toPropertyKey(t) {
|
|
65
|
+
var i = _toPrimitive(t, "string");
|
|
66
|
+
return "symbol" == typeof i ? i : i + "";
|
|
67
|
+
}
|
|
68
|
+
function _unsupportedIterableToArray(r, a) {
|
|
69
|
+
if (r) {
|
|
70
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
71
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
72
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
8
75
|
|
|
9
76
|
var ARG_OVERRIDE_METHODS = 'enmasse_override_methods';
|
|
10
77
|
var ARG_DEBUG = 'enmasse_debug';
|
|
@@ -52,7 +119,7 @@ var ENMASSE_OVERRIDE_METHODS = getSettingForMethods();
|
|
|
52
119
|
var ENMASSE_DEBUG = getSettingFor(ARG_DEBUG);
|
|
53
120
|
var ENMASSE_CONFIG = getSettingFor(ARG_CONFIG);
|
|
54
121
|
|
|
55
|
-
var version = "2.0.0-rc.
|
|
122
|
+
var version = "2.0.0-rc.2";
|
|
56
123
|
|
|
57
124
|
/* eslint no-bitwise: "off" */
|
|
58
125
|
var TYPE_PROTOCOL = 1; // 0000 0000 0001
|
|
@@ -1252,127 +1319,58 @@ var Enmasse = (() => {
|
|
|
1252
1319
|
* Private methods
|
|
1253
1320
|
*/
|
|
1254
1321
|
|
|
1255
|
-
var storeSession =
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
case 12:
|
|
1308
|
-
if (!(getParentApplication() === null)) {
|
|
1309
|
-
_context2.next = 14;
|
|
1310
|
-
break;
|
|
1311
|
-
}
|
|
1312
|
-
return _context2.abrupt("return", null);
|
|
1313
|
-
case 14:
|
|
1314
|
-
try {
|
|
1315
|
-
restoredId = getItem(PARAM_SESSION_ID);
|
|
1316
|
-
} catch (err) {
|
|
1317
|
-
console.error("Failed to read local session during migration: ".concat(getErrorMessage(err)));
|
|
1318
|
-
}
|
|
1319
|
-
if (!(restoredId === null)) {
|
|
1320
|
-
_context2.next = 17;
|
|
1321
|
-
break;
|
|
1322
|
-
}
|
|
1323
|
-
return _context2.abrupt("return", null);
|
|
1324
|
-
case 17:
|
|
1325
|
-
_context2.prev = 17;
|
|
1326
|
-
_context2.next = 20;
|
|
1327
|
-
return storageWrite(PARAM_SESSION_ID, restoredId);
|
|
1328
|
-
case 20:
|
|
1329
|
-
_context2.next = 25;
|
|
1330
|
-
break;
|
|
1331
|
-
case 22:
|
|
1332
|
-
_context2.prev = 22;
|
|
1333
|
-
_context2.t1 = _context2["catch"](17);
|
|
1334
|
-
console.error("Failed to persist session to shared storage during migration: ".concat(getErrorMessage(_context2.t1)));
|
|
1335
|
-
case 25:
|
|
1336
|
-
return _context2.abrupt("return", restoredId);
|
|
1337
|
-
case 26:
|
|
1338
|
-
case "end":
|
|
1339
|
-
return _context2.stop();
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
}, _callee2, null, [[1, 7], [17, 22]]);
|
|
1343
|
-
}));
|
|
1344
|
-
return function restoreSession() {
|
|
1345
|
-
return _ref2.apply(this, arguments);
|
|
1346
|
-
};
|
|
1347
|
-
}();
|
|
1348
|
-
var resetSession = /*#__PURE__*/function () {
|
|
1349
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
1350
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
1351
|
-
while (1) {
|
|
1352
|
-
switch (_context3.prev = _context3.next) {
|
|
1353
|
-
case 0:
|
|
1354
|
-
sessionId = null;
|
|
1355
|
-
_context3.prev = 1;
|
|
1356
|
-
_context3.next = 4;
|
|
1357
|
-
return storageRemove(PARAM_SESSION_ID);
|
|
1358
|
-
case 4:
|
|
1359
|
-
_context3.next = 9;
|
|
1360
|
-
break;
|
|
1361
|
-
case 6:
|
|
1362
|
-
_context3.prev = 6;
|
|
1363
|
-
_context3.t0 = _context3["catch"](1);
|
|
1364
|
-
console.error("Failed to remove session from shared storage: ".concat(getErrorMessage(_context3.t0)));
|
|
1365
|
-
case 9:
|
|
1366
|
-
case "end":
|
|
1367
|
-
return _context3.stop();
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}, _callee3, null, [[1, 6]]);
|
|
1371
|
-
}));
|
|
1372
|
-
return function resetSession() {
|
|
1373
|
-
return _ref3.apply(this, arguments);
|
|
1374
|
-
};
|
|
1375
|
-
}();
|
|
1322
|
+
var storeSession = async id => {
|
|
1323
|
+
try {
|
|
1324
|
+
await storageWrite(PARAM_SESSION_ID, id);
|
|
1325
|
+
} catch (err) {
|
|
1326
|
+
console.error("Failed to persist session to shared storage: ".concat(getErrorMessage(err)));
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
var restoreSession = async () => {
|
|
1330
|
+
var restoredId = null;
|
|
1331
|
+
|
|
1332
|
+
// Read session from shared storage
|
|
1333
|
+
try {
|
|
1334
|
+
restoredId = await storageRead(PARAM_SESSION_ID);
|
|
1335
|
+
} catch (err) {
|
|
1336
|
+
console.error("Failed to read session from shared storage: ".concat(getErrorMessage(err)));
|
|
1337
|
+
}
|
|
1338
|
+
if (restoredId !== null) {
|
|
1339
|
+
return restoredId;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* Further down is a special case when we try to restore session id from the
|
|
1344
|
+
* local storage and save it to the shared storage. This could happen in
|
|
1345
|
+
* previous versions of the SDK when we didn't have a shared storage.
|
|
1346
|
+
*/
|
|
1347
|
+
|
|
1348
|
+
if (getParentApplication() === null) {
|
|
1349
|
+
return null;
|
|
1350
|
+
}
|
|
1351
|
+
try {
|
|
1352
|
+
restoredId = getItem(PARAM_SESSION_ID);
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
console.error("Failed to read local session during migration: ".concat(getErrorMessage(err)));
|
|
1355
|
+
}
|
|
1356
|
+
if (restoredId === null) {
|
|
1357
|
+
return null;
|
|
1358
|
+
}
|
|
1359
|
+
try {
|
|
1360
|
+
await storageWrite(PARAM_SESSION_ID, restoredId);
|
|
1361
|
+
} catch (err) {
|
|
1362
|
+
console.error("Failed to persist session to shared storage during migration: ".concat(getErrorMessage(err)));
|
|
1363
|
+
}
|
|
1364
|
+
return restoredId;
|
|
1365
|
+
};
|
|
1366
|
+
var resetSession = async () => {
|
|
1367
|
+
sessionId = null;
|
|
1368
|
+
try {
|
|
1369
|
+
await storageRemove(PARAM_SESSION_ID);
|
|
1370
|
+
} catch (err) {
|
|
1371
|
+
console.error("Failed to remove session from shared storage: ".concat(getErrorMessage(err)));
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1376
1374
|
var validateSession = id =>
|
|
1377
1375
|
// eslint-disable-next-line
|
|
1378
1376
|
/^[a-f\d]{8}\-[a-f\d]{4}\-[a-f\d]{4}-[a-f\d]{4}\-[a-f\d]{12}$/i.test(id);
|
|
@@ -1472,85 +1470,71 @@ var Enmasse = (() => {
|
|
|
1472
1470
|
break;
|
|
1473
1471
|
}
|
|
1474
1472
|
};
|
|
1475
|
-
var handleConnectionManagerMessage =
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
});
|
|
1496
|
-
if (!(sessionId === null)) {
|
|
1497
|
-
_context4.next = 14;
|
|
1498
|
-
break;
|
|
1499
|
-
}
|
|
1500
|
-
_data$body = _slicedToArray(data.body, 1);
|
|
1501
|
-
sessionId = _data$body[0];
|
|
1502
|
-
_context4.next = 14;
|
|
1503
|
-
return storeSession(sessionId);
|
|
1504
|
-
case 14:
|
|
1505
|
-
setTime(time);
|
|
1506
|
-
queue.stash();
|
|
1507
|
-
queue.push({
|
|
1508
|
-
channel: sysChannel,
|
|
1509
|
-
klass: SSCP_KLASS_AUTHR,
|
|
1510
|
-
body: [sessionId, self.PROTOCOL_VERSION, clientInfo.join(',')]
|
|
1511
|
-
}, true);
|
|
1512
|
-
queue.run();
|
|
1513
|
-
return _context4.abrupt("break", 34);
|
|
1514
|
-
case 19:
|
|
1515
|
-
// We have to resubscribe to the previously
|
|
1516
|
-
// subscribed channels after the reconnect.
|
|
1517
|
-
subscriptions = queue.getSubscriptions();
|
|
1518
|
-
subscriptions.forEach(channel => {
|
|
1519
|
-
queue.push({
|
|
1520
|
-
channel,
|
|
1521
|
-
klass: SSCP_KLASS_SUB,
|
|
1522
|
-
body: []
|
|
1523
|
-
}, true);
|
|
1524
|
-
});
|
|
1525
|
-
queue.unstash();
|
|
1526
|
-
queue.run();
|
|
1527
|
-
setStateToConnected();
|
|
1528
|
-
return _context4.abrupt("break", 34);
|
|
1529
|
-
case 25:
|
|
1530
|
-
resolveLogin();
|
|
1531
|
-
return _context4.abrupt("break", 34);
|
|
1532
|
-
case 27:
|
|
1533
|
-
rejectLogin();
|
|
1534
|
-
return _context4.abrupt("break", 34);
|
|
1535
|
-
case 29:
|
|
1536
|
-
return _context4.abrupt("break", 34);
|
|
1537
|
-
case 30:
|
|
1538
|
-
self.trigger(self.ON_EOC, data.channel);
|
|
1539
|
-
return _context4.abrupt("break", 34);
|
|
1540
|
-
case 32:
|
|
1541
|
-
self.trigger(self.ON_MESSAGE, data);
|
|
1542
|
-
return _context4.abrupt("break", 34);
|
|
1543
|
-
case 34:
|
|
1544
|
-
case "end":
|
|
1545
|
-
return _context4.stop();
|
|
1473
|
+
var handleConnectionManagerMessage = async message => {
|
|
1474
|
+
log(TYPE_PROTOCOL, 'Enmasse::handleConnectionManagerMessage', message);
|
|
1475
|
+
var data = parseSSCP(message);
|
|
1476
|
+
switch (data.klass) {
|
|
1477
|
+
case SSCP_KLASS_AUTH:
|
|
1478
|
+
{
|
|
1479
|
+
var time = data.sent_at;
|
|
1480
|
+
var clientInfo = ["enmassejs-".concat(self.VERSION), navigator.userAgent].concat(info);
|
|
1481
|
+
|
|
1482
|
+
// store system channel
|
|
1483
|
+
sysChannel = data.channel;
|
|
1484
|
+
|
|
1485
|
+
// url encode each client info item
|
|
1486
|
+
clientInfo.forEach((item, idx) => {
|
|
1487
|
+
clientInfo[idx] = encodeURIComponent(item);
|
|
1488
|
+
});
|
|
1489
|
+
if (sessionId === null) {
|
|
1490
|
+
var _data$body = _slicedToArray(data.body, 1);
|
|
1491
|
+
sessionId = _data$body[0];
|
|
1492
|
+
await storeSession(sessionId);
|
|
1546
1493
|
}
|
|
1494
|
+
setTime(time);
|
|
1495
|
+
queue.stash();
|
|
1496
|
+
queue.push({
|
|
1497
|
+
channel: sysChannel,
|
|
1498
|
+
klass: SSCP_KLASS_AUTHR,
|
|
1499
|
+
body: [sessionId, self.PROTOCOL_VERSION, clientInfo.join(',')]
|
|
1500
|
+
}, true);
|
|
1501
|
+
queue.run();
|
|
1502
|
+
break;
|
|
1547
1503
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1504
|
+
case SSCP_KLASS_AUTHOK:
|
|
1505
|
+
{
|
|
1506
|
+
// We have to resubscribe to the previously
|
|
1507
|
+
// subscribed channels after the reconnect.
|
|
1508
|
+
var subscriptions = queue.getSubscriptions();
|
|
1509
|
+
subscriptions.forEach(channel => {
|
|
1510
|
+
queue.push({
|
|
1511
|
+
channel,
|
|
1512
|
+
klass: SSCP_KLASS_SUB,
|
|
1513
|
+
body: []
|
|
1514
|
+
}, true);
|
|
1515
|
+
});
|
|
1516
|
+
queue.unstash();
|
|
1517
|
+
queue.run();
|
|
1518
|
+
setStateToConnected();
|
|
1519
|
+
break;
|
|
1520
|
+
}
|
|
1521
|
+
case SSCP_KLASS_LOGIN_OK:
|
|
1522
|
+
resolveLogin();
|
|
1523
|
+
break;
|
|
1524
|
+
case SSCP_KLASS_LOGIN_FAIL:
|
|
1525
|
+
rejectLogin();
|
|
1526
|
+
break;
|
|
1527
|
+
case SSCP_KLASS_PING:
|
|
1528
|
+
// ignoring ping message handling
|
|
1529
|
+
break;
|
|
1530
|
+
case SSCP_KLASS_EOC:
|
|
1531
|
+
self.trigger(self.ON_EOC, data.channel);
|
|
1532
|
+
break;
|
|
1533
|
+
default:
|
|
1534
|
+
self.trigger(self.ON_MESSAGE, data);
|
|
1535
|
+
break;
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1554
1538
|
var handleDemographicsCounter = (channel, data) => {
|
|
1555
1539
|
self.send(channel, 'avgcounter', data);
|
|
1556
1540
|
};
|
|
@@ -1623,105 +1607,64 @@ var Enmasse = (() => {
|
|
|
1623
1607
|
}
|
|
1624
1608
|
self.send(sysChannel, SSCP_KLASS_LOGOUT);
|
|
1625
1609
|
};
|
|
1626
|
-
self.init =
|
|
1627
|
-
var
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
_context5.next = 5;
|
|
1644
|
-
return restoreSession();
|
|
1645
|
-
case 5:
|
|
1646
|
-
sessionId = _context5.sent;
|
|
1647
|
-
if (typeof config.forceSecure === 'boolean') {
|
|
1648
|
-
forceSecure = config.forceSecure;
|
|
1649
|
-
}
|
|
1650
|
-
if (!(configFile === null)) {
|
|
1651
|
-
_context5.next = 9;
|
|
1652
|
-
break;
|
|
1653
|
-
}
|
|
1654
|
-
throw 'EnMasse config file is not set';
|
|
1655
|
-
case 9:
|
|
1656
|
-
if (!(sessionId !== null && !validateSession(sessionId))) {
|
|
1657
|
-
_context5.next = 12;
|
|
1658
|
-
break;
|
|
1659
|
-
}
|
|
1660
|
-
_context5.next = 12;
|
|
1661
|
-
return resetSession();
|
|
1662
|
-
case 12:
|
|
1663
|
-
queue = new Queue({
|
|
1664
|
-
runner
|
|
1665
|
-
});
|
|
1666
|
-
TransportManager$1.bind(TransportManager$1.ON_READY, handleTransportManagerReady);
|
|
1667
|
-
ConnectionManager.bind(ConnectionManager.ON_STATE, handleConnectionManagerState);
|
|
1668
|
-
ConnectionManager.bind(ConnectionManager.ON_MESSAGE, handleConnectionManagerMessage);
|
|
1669
|
-
Demographics$1.bind(Demographics$1.ON_ADD_COUNTER, handleDemographicsCounter);
|
|
1670
|
-
_context5.prev = 17;
|
|
1671
|
-
_context5.next = 20;
|
|
1672
|
-
return fetch(configFile);
|
|
1673
|
-
case 20:
|
|
1674
|
-
response = _context5.sent;
|
|
1675
|
-
status = response.status, text = response.statusText;
|
|
1676
|
-
_context5.prev = 22;
|
|
1677
|
-
_context5.next = 25;
|
|
1678
|
-
return response.json();
|
|
1679
|
-
case 25:
|
|
1680
|
-
data = _context5.sent;
|
|
1681
|
-
_context5.next = 32;
|
|
1682
|
-
break;
|
|
1683
|
-
case 28:
|
|
1684
|
-
_context5.prev = 28;
|
|
1685
|
-
_context5.t0 = _context5["catch"](22);
|
|
1686
|
-
self.trigger(self.ON_ERROR, "Invalid JSON from config ".concat(configFile));
|
|
1687
|
-
return _context5.abrupt("return");
|
|
1688
|
-
case 32:
|
|
1689
|
-
isSuccess = status >= 200 && status <= 300 ||
|
|
1690
|
-
// If you conclude with an XMLHttpRequest receiving status=0 and
|
|
1691
|
-
// statusText=null, this means the request was not allowed to be
|
|
1692
|
-
// performed.
|
|
1693
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#xmlhttprequests_being_stopped
|
|
1694
|
-
status === 0 && !!text || status === '';
|
|
1695
|
-
data.forceSecure = forceSecure;
|
|
1696
|
-
if (data.background_timeout === undefined) {
|
|
1697
|
-
data.background_timeout = 0;
|
|
1698
|
-
}
|
|
1699
|
-
if (isSuccess) {
|
|
1700
|
-
ConnectionManager.init(data);
|
|
1701
|
-
TransportManager$1.init(data);
|
|
1702
|
-
} else {
|
|
1703
|
-
self.trigger(self.ON_ERROR, "Failed to load config ".concat(configFile));
|
|
1704
|
-
}
|
|
1705
|
-
_context5.next = 41;
|
|
1706
|
-
break;
|
|
1707
|
-
case 38:
|
|
1708
|
-
_context5.prev = 38;
|
|
1709
|
-
_context5.t1 = _context5["catch"](17);
|
|
1710
|
-
self.trigger(self.ON_ERROR, "Error loading config: ".concat(_context5.t1.message));
|
|
1711
|
-
case 41:
|
|
1712
|
-
case "end":
|
|
1713
|
-
return _context5.stop();
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
}, _callee5, null, [[17, 38], [22, 28]]);
|
|
1717
|
-
}));
|
|
1718
|
-
function init() {
|
|
1719
|
-
return _init.apply(this, arguments);
|
|
1610
|
+
self.init = async function init() {
|
|
1611
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {};
|
|
1612
|
+
// config file is passed either as GET parameter or via constructor
|
|
1613
|
+
configFile = !ENMASSE_CONFIG ? config.config || null : ENMASSE_CONFIG;
|
|
1614
|
+
info = config.info || [];
|
|
1615
|
+
sessionId = await restoreSession();
|
|
1616
|
+
if (typeof config.forceSecure === 'boolean') {
|
|
1617
|
+
forceSecure = config.forceSecure;
|
|
1618
|
+
}
|
|
1619
|
+
if (configFile === null) {
|
|
1620
|
+
// eslint-disable-next-line
|
|
1621
|
+
throw 'EnMasse config file is not set';
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
// If session id has invalid format
|
|
1625
|
+
if (sessionId !== null && !validateSession(sessionId)) {
|
|
1626
|
+
await resetSession();
|
|
1720
1627
|
}
|
|
1721
|
-
|
|
1722
|
-
|
|
1628
|
+
queue = new Queue({
|
|
1629
|
+
runner
|
|
1630
|
+
});
|
|
1631
|
+
TransportManager$1.bind(TransportManager$1.ON_READY, handleTransportManagerReady);
|
|
1632
|
+
ConnectionManager.bind(ConnectionManager.ON_STATE, handleConnectionManagerState);
|
|
1633
|
+
ConnectionManager.bind(ConnectionManager.ON_MESSAGE, handleConnectionManagerMessage);
|
|
1634
|
+
Demographics$1.bind(Demographics$1.ON_ADD_COUNTER, handleDemographicsCounter);
|
|
1635
|
+
try {
|
|
1636
|
+
var response = await fetch(configFile);
|
|
1637
|
+
var status = response.status,
|
|
1638
|
+
text = response.statusText;
|
|
1639
|
+
var data;
|
|
1640
|
+
try {
|
|
1641
|
+
data = await response.json();
|
|
1642
|
+
} catch (jsonErr) {
|
|
1643
|
+
self.trigger(self.ON_ERROR, "Invalid JSON from config ".concat(configFile));
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
var isSuccess = status >= 200 && status <= 300 ||
|
|
1647
|
+
// If you conclude with an XMLHttpRequest receiving status=0 and
|
|
1648
|
+
// statusText=null, this means the request was not allowed to be
|
|
1649
|
+
// performed.
|
|
1650
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#xmlhttprequests_being_stopped
|
|
1651
|
+
status === 0 && !!text || status === '';
|
|
1652
|
+
data.forceSecure = forceSecure;
|
|
1653
|
+
if (data.background_timeout === undefined) {
|
|
1654
|
+
data.background_timeout = 0;
|
|
1655
|
+
}
|
|
1656
|
+
if (isSuccess) {
|
|
1657
|
+
ConnectionManager.init(data);
|
|
1658
|
+
TransportManager$1.init(data);
|
|
1659
|
+
} else {
|
|
1660
|
+
self.trigger(self.ON_ERROR, "Failed to load config ".concat(configFile));
|
|
1661
|
+
}
|
|
1662
|
+
} catch (err) {
|
|
1663
|
+
self.trigger(self.ON_ERROR, "Error loading config: ".concat(err.message));
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1723
1666
|
return self;
|
|
1724
1667
|
})();
|
|
1725
1668
|
|
|
1726
1669
|
export { Enmasse as default };
|
|
1727
|
-
//# sourceMappingURL=index.
|
|
1670
|
+
//# sourceMappingURL=index.js.map
|