qiscus-sdk-core 2.15.0 → 2.16.0
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/qiscus-sdk-core.js +5740 -6693
- package/dist/qiscus-sdk-core.js.map +1 -1
- package/dist/qiscus-sdk-core.min.js +3 -7
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +570 -637
- package/lib/lib/adapters/custom-event.js +11 -11
- package/lib/lib/adapters/mqtt.js +13 -42
- package/lib/lib/is.js +51 -0
- package/package.json +3 -5
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = CustomEventAdapter;
|
|
8
|
-
var
|
|
8
|
+
var _is = _interopRequireDefault(require("../is"));
|
|
9
9
|
var _mitt = _interopRequireDefault(require("mitt"));
|
|
10
10
|
function CustomEventAdapter(mqttAdapter, userId) {
|
|
11
11
|
var events = (0, _mitt["default"])();
|
|
@@ -19,10 +19,10 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
19
19
|
};
|
|
20
20
|
return {
|
|
21
21
|
publishEvent: function publishEvent(roomId, payload) {
|
|
22
|
-
if (
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
25
|
-
if (
|
|
22
|
+
if (_is["default"].undefined(roomId)) throw new Error('`roomId` required');
|
|
23
|
+
if (_is["default"].not.string(roomId)) throw new TypeError('`roomId` must have type of string');
|
|
24
|
+
if (_is["default"].undefined(payload)) throw new Error('`payload` required');
|
|
25
|
+
if (_is["default"].not.object(payload)) throw new TypeError('`payload` must have type of object');
|
|
26
26
|
var _payload = JSON.stringify({
|
|
27
27
|
sender: userId,
|
|
28
28
|
// ?
|
|
@@ -31,10 +31,10 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
31
31
|
mqttAdapter.publish(getTopic(roomId), _payload);
|
|
32
32
|
},
|
|
33
33
|
subscribeEvent: function subscribeEvent(roomId, callback) {
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
if (
|
|
37
|
-
if (
|
|
34
|
+
if (_is["default"].undefined(roomId)) throw new Error('`roomId` required');
|
|
35
|
+
if (_is["default"].not.string(roomId)) throw new TypeError('`roomId` must have type of string');
|
|
36
|
+
if (_is["default"].undefined(callback)) throw new Error('`callback` required');
|
|
37
|
+
if (_is["default"].not["function"](callback)) throw new TypeError('`callback` must have type of function');
|
|
38
38
|
var topic = getTopic(roomId);
|
|
39
39
|
// Only allow 1 subcription for now
|
|
40
40
|
if (subscribedTopics[topic]) return;
|
|
@@ -47,8 +47,8 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
47
47
|
subscribedTopics[topic] = cb;
|
|
48
48
|
},
|
|
49
49
|
unsubscribeEvent: function unsubscribeEvent(roomId) {
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
50
|
+
if (_is["default"].undefined(roomId)) throw new Error('`roomId` required');
|
|
51
|
+
if (_is["default"].not.string(roomId)) throw new TypeError('`roomId` must have type of string');
|
|
52
52
|
var topic = getTopic(roomId);
|
|
53
53
|
if (!subscribedTopics[topic]) return;
|
|
54
54
|
mqttAdapter.unsubscribe(topic);
|
package/lib/lib/adapters/mqtt.js
CHANGED
|
@@ -44,9 +44,7 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
44
44
|
shouldConnect = _ref$shouldConnect === void 0 ? true : _ref$shouldConnect,
|
|
45
45
|
brokerLbUrl = _ref.brokerLbUrl,
|
|
46
46
|
enableLb = _ref.enableLb,
|
|
47
|
-
getClientId = _ref.getClientId
|
|
48
|
-
mqttUsername = _ref.mqttUsername,
|
|
49
|
-
mqttPassword = _ref.mqttPassword;
|
|
47
|
+
getClientId = _ref.getClientId;
|
|
50
48
|
(0, _classCallCheck2["default"])(this, MqttAdapter);
|
|
51
49
|
(0, _defineProperty2["default"])(this, "_getClientId", function () {
|
|
52
50
|
if (_this.getClientId == null) return "".concat(_this.core.AppId, "_").concat(_this.core.user_id, "_").concat(Date.now());
|
|
@@ -87,8 +85,6 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
87
85
|
// reconnectPeriod: 0,
|
|
88
86
|
// connectTimeout: 1 * 1000,
|
|
89
87
|
};
|
|
90
|
-
if (_this.mqttUsername != null) opts.username = _this.mqttUsername;
|
|
91
|
-
if (_this.mqttPassword != null) opts.password = _this.mqttPassword;
|
|
92
88
|
if (brokerUrl == null) brokerUrl = _this.cacheRealtimeURL;
|
|
93
89
|
if (_this.mqtt != null) {
|
|
94
90
|
var _topics = Object.keys(_this.mqtt._resubscribeTopics);
|
|
@@ -195,10 +191,7 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
195
191
|
}), (0, _match2.when)(), function (topic) {
|
|
196
192
|
return _this.logger('topic not handled', topic);
|
|
197
193
|
}));
|
|
198
|
-
this.mqttUsername = mqttUsername;
|
|
199
|
-
this.mqttPassword = mqttPassword;
|
|
200
194
|
var _mqtt = this.__mqtt_conneck(_url);
|
|
201
|
-
this.cacheRealtimeURL = _url;
|
|
202
195
|
this.mqtt = _mqtt;
|
|
203
196
|
|
|
204
197
|
// if appConfig set realtimeEnabled to false,
|
|
@@ -215,11 +208,6 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
215
208
|
// })
|
|
216
209
|
}
|
|
217
210
|
return (0, _createClass2["default"])(MqttAdapter, [{
|
|
218
|
-
key: "http",
|
|
219
|
-
get: function get() {
|
|
220
|
-
return this.core.HTTPAdapter;
|
|
221
|
-
}
|
|
222
|
-
}, {
|
|
223
211
|
key: "cacheRealtimeURL",
|
|
224
212
|
get: function get() {
|
|
225
213
|
return this.core.mqttURL;
|
|
@@ -243,16 +231,9 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
243
231
|
return _regenerator["default"].wrap(function (_context2) {
|
|
244
232
|
while (1) switch (_context2.prev = _context2.next) {
|
|
245
233
|
case 0:
|
|
246
|
-
if (!(this.mqtt != null)) {
|
|
247
|
-
_context2.next = 1;
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
_context2.next = 1;
|
|
251
|
-
return this.closeConnection();
|
|
252
|
-
case 1:
|
|
253
234
|
this.shouldConnect = true;
|
|
254
235
|
this.mqtt = this.__mqtt_conneck();
|
|
255
|
-
case
|
|
236
|
+
case 1:
|
|
256
237
|
case "end":
|
|
257
238
|
return _context2.stop();
|
|
258
239
|
}
|
|
@@ -276,20 +257,13 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
276
257
|
while (1) switch (_context3.prev = _context3.next) {
|
|
277
258
|
case 0:
|
|
278
259
|
this.shouldConnect = false;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
_this2.logger('error when close connection', err.message);
|
|
284
|
-
reject(err);
|
|
285
|
-
} else {
|
|
286
|
-
resolve();
|
|
287
|
-
}
|
|
288
|
-
});
|
|
260
|
+
this.mqtt.end(true, function (err) {
|
|
261
|
+
if (err) {
|
|
262
|
+
_this2.logger('error when close connection', err.message);
|
|
263
|
+
}
|
|
289
264
|
});
|
|
290
|
-
case 1:
|
|
291
265
|
this.mqtt = null;
|
|
292
|
-
case
|
|
266
|
+
case 1:
|
|
293
267
|
case "end":
|
|
294
268
|
return _context3.stop();
|
|
295
269
|
}
|
|
@@ -304,20 +278,17 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
304
278
|
key: "getMqttNode",
|
|
305
279
|
value: function () {
|
|
306
280
|
var _getMqttNode = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
307
|
-
var res,
|
|
281
|
+
var res, url, port;
|
|
308
282
|
return _regenerator["default"].wrap(function (_context4) {
|
|
309
283
|
while (1) switch (_context4.prev = _context4.next) {
|
|
310
284
|
case 0:
|
|
311
285
|
_context4.next = 1;
|
|
312
|
-
return
|
|
286
|
+
return _superagent["default"].get(this.brokerLbUrl);
|
|
313
287
|
case 1:
|
|
314
288
|
res = _context4.sent;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this.mqttUsername = mqttUsername;
|
|
319
|
-
this.mqttPassword = mqttPassword;
|
|
320
|
-
return _context4.abrupt("return", mqttURL);
|
|
289
|
+
url = res.body.data.url;
|
|
290
|
+
port = res.body.data.wss_port;
|
|
291
|
+
return _context4.abrupt("return", "wss://".concat(url, ":").concat(port, "/mqtt"));
|
|
321
292
|
case 2:
|
|
322
293
|
case "end":
|
|
323
294
|
return _context4.stop();
|
|
@@ -410,7 +381,7 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
|
|
|
410
381
|
}, {
|
|
411
382
|
key: "logger",
|
|
412
383
|
get: function get() {
|
|
413
|
-
if (!this.
|
|
384
|
+
if (!this.core.debugMQTTMode) return this.noop;
|
|
414
385
|
return console.log.bind(console, 'QRealtime ->');
|
|
415
386
|
}
|
|
416
387
|
|
package/lib/lib/is.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
// Minimal internal replacement for the `is_js` package.
|
|
8
|
+
//
|
|
9
|
+
// We only port the handful of type predicates the SDK actually uses, with the
|
|
10
|
+
// exact same semantics as `is_js@0.9.0`. The prototype-pollution surface of
|
|
11
|
+
// is_js (CVE-2020-26302) lives in unused helpers (`propertyDefined`,
|
|
12
|
+
// `propertyCount`, the regex-namespace plumbing), which are intentionally not
|
|
13
|
+
// reimplemented here.
|
|
14
|
+
|
|
15
|
+
var toString = Object.prototype.toString;
|
|
16
|
+
var is = {};
|
|
17
|
+
is.array = Array.isArray;
|
|
18
|
+
is.undefined = function (value) {
|
|
19
|
+
return value === undefined;
|
|
20
|
+
};
|
|
21
|
+
is.string = function (value) {
|
|
22
|
+
return toString.call(value) === '[object String]';
|
|
23
|
+
};
|
|
24
|
+
is.object = function (value) {
|
|
25
|
+
return Object(value) === value;
|
|
26
|
+
};
|
|
27
|
+
is['function'] = function (value) {
|
|
28
|
+
return toString.call(value) === '[object Function]' || typeof value === 'function';
|
|
29
|
+
};
|
|
30
|
+
is.json = function (value) {
|
|
31
|
+
return toString.call(value) === '[object Object]';
|
|
32
|
+
};
|
|
33
|
+
is.not = {
|
|
34
|
+
array: function array(value) {
|
|
35
|
+
return !is.array(value);
|
|
36
|
+
},
|
|
37
|
+
string: function string(value) {
|
|
38
|
+
return !is.string(value);
|
|
39
|
+
},
|
|
40
|
+
object: function object(value) {
|
|
41
|
+
return !is.object(value);
|
|
42
|
+
},
|
|
43
|
+
"function": function _function(value) {
|
|
44
|
+
return !is['function'](value);
|
|
45
|
+
},
|
|
46
|
+
json: function json(value) {
|
|
47
|
+
return !is.json(value);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var _default = exports["default"] = is;
|
|
51
|
+
module.exports = exports.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qiscus-sdk-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"description": "Qiscus Web SDK Core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"prepublishOnly": "npm-run-all clean build",
|
|
29
29
|
"serve": "http-server -p 1234 -c-1 dist",
|
|
30
30
|
"dev:serve": "run-p serve watch",
|
|
31
|
-
"release:patch": "np patch --any-branch --yolo"
|
|
32
|
-
"release:minor": "np minor --any-branch --yolo"
|
|
31
|
+
"release:patch": "np patch --any-branch --yolo"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@babel/cli": "^7.10.5",
|
|
@@ -66,7 +65,6 @@
|
|
|
66
65
|
"dependencies": {
|
|
67
66
|
"@babel/runtime": "^7.11.2",
|
|
68
67
|
"date-fns": "^1.30.1",
|
|
69
|
-
"is_js": "^0.9.0",
|
|
70
68
|
"lodash.debounce": "^4.0.8",
|
|
71
69
|
"lodash.throttle": "^4.1.1",
|
|
72
70
|
"mitt": "^1.2.0",
|
|
@@ -96,5 +94,5 @@
|
|
|
96
94
|
"engines": {
|
|
97
95
|
"node": "16.15.1"
|
|
98
96
|
},
|
|
99
|
-
"packageManager": "pnpm@
|
|
97
|
+
"packageManager": "pnpm@8.15.9"
|
|
100
98
|
}
|