qiscus-sdk-core 2.12.6 → 2.13.1

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/lib/index.js CHANGED
@@ -371,6 +371,18 @@ var QiscusSDK = /*#__PURE__*/function () {
371
371
  _this2.options.messageUpdatedCallback(message);
372
372
  }
373
373
  });
374
+ this.realtimeAdapter.on('room-typing', function (data) {
375
+ _this2.events.emit('typing', {
376
+ message: data.text,
377
+ username: data.sender_name,
378
+ email: data.sender_id,
379
+ room_id: data.room_id
380
+ });
381
+ if (_this2.options.onRoomTypingCallback != null) {
382
+ _this2.events.emit('room-typing', data);
383
+ _this2.options.onRoomTypingCallback(data);
384
+ }
385
+ });
374
386
  this.syncAdapter = (0, _sync["default"])(function () {
375
387
  return _this2.HTTPAdapter;
376
388
  }, {
@@ -457,7 +469,7 @@ var QiscusSDK = /*#__PURE__*/function () {
457
469
  });
458
470
  this.customEventAdapter = (0, _customEvent["default"])(this.realtimeAdapter, this.user_id);
459
471
  this.setEventListeners();
460
- case 54:
472
+ case 55:
461
473
  case "end":
462
474
  return _context3.stop();
463
475
  }
@@ -18,6 +18,8 @@ var _connect = _interopRequireDefault(require("mqtt/lib/connect"));
18
18
  var _superagent = _interopRequireDefault(require("superagent"));
19
19
  var _lodash = _interopRequireDefault(require("lodash.debounce"));
20
20
  var _util = require("../util");
21
+ 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; }
22
+ 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; }
21
23
  var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
22
24
  /**
23
25
  * @typedef {Function} GetClientId
@@ -168,12 +170,14 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
168
170
  this.getClientId = getClientId;
169
171
  this.enableLb = enableLb;
170
172
  this.shouldConnect = shouldConnect;
171
- this.matcher = (0, _match2.match)((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, (0, _match2.when)(this.reNewMessage), function (topic) {
173
+ this.matcher = (0, _match2.match)((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, (0, _match2.when)(this.reNewMessage), function (topic) {
172
174
  return _this.newMessageHandler.bind(_this, topic);
173
175
  }), (0, _match2.when)(this.reNotification), function (topic) {
174
176
  return _this.notificationHandler.bind(_this, topic);
175
177
  }), (0, _match2.when)(this.reTyping), function (topic) {
176
178
  return _this.typingHandler.bind(_this, topic);
179
+ }), (0, _match2.when)(this.reRoomTyping), function (topic) {
180
+ return _this.roomTypingHandler.bind(_this, topic);
177
181
  }), (0, _match2.when)(this.reDelivery), function (topic) {
178
182
  return _this.deliveryReceiptHandler.bind(_this, topic);
179
183
  }), (0, _match2.when)(this.reRead), function (topic) {
@@ -392,6 +396,11 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
392
396
  get: function get() {
393
397
  return /^r\/([\d]+)\/([\d]+)\/(.+)\/t$/i;
394
398
  }
399
+ }, {
400
+ key: "reRoomTyping",
401
+ get: function get() {
402
+ return /^r\/(.+)\/typing$/i;
403
+ }
395
404
  }, {
396
405
  key: "reDelivery",
397
406
  get: function get() {
@@ -451,6 +460,43 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
451
460
  });
452
461
  }
453
462
  }
463
+
464
+ /**
465
+ * @param {string} t
466
+ * @param {string} message
467
+ */
468
+ }, {
469
+ key: "roomTypingHandler",
470
+ value: function roomTypingHandler(t, message) {
471
+ var _t$match;
472
+ this.logger('on:room-typing', t);
473
+ // topic: r/{roomId}/typing
474
+
475
+ var roomId = (_t$match = t.match(this.reRoomTyping)) === null || _t$match === void 0 ? void 0 : _t$match[1];
476
+
477
+ /**
478
+ * {
479
+ * "room_id": "12333",
480
+ * "status": "typing_on",// or "typing_off"
481
+ * "sender_id": "user-987",
482
+ * "sender_name": "Botku AI",
483
+ * "text": "Analyzing your request..." // optional, max 50 chars
484
+ * }
485
+ * @typedef {Object} RoomTypingPayload
486
+ * @property {number} room_id
487
+ * @property {('typing_on'|'typing_off')} status
488
+ * @property {string} sender_id
489
+ * @property {string} text
490
+ */
491
+
492
+ /**
493
+ * @type {RoomTypingPayload}
494
+ */
495
+ var parsedMessage = JSON.parse(message);
496
+ this.emit('room-typing', _objectSpread(_objectSpread({}, parsedMessage), {}, {
497
+ room_id: roomId
498
+ }));
499
+ }
454
500
  }, {
455
501
  key: "typingHandler",
456
502
  value: function typingHandler(t, message) {
@@ -549,6 +595,7 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
549
595
  value: function subscribeRoom(roomId) {
550
596
  if (this.core.selected == null) return;
551
597
  roomId = roomId || this.core.selected.id;
598
+ this.subscribe("r/".concat(roomId, "/typing"));
552
599
  this.subscribe("r/".concat(roomId, "/").concat(roomId, "/+/t"));
553
600
  this.subscribe("r/".concat(roomId, "/").concat(roomId, "/+/d"));
554
601
  this.subscribe("r/".concat(roomId, "/").concat(roomId, "/+/r"));
@@ -558,6 +605,7 @@ var MqttAdapter = exports["default"] = /*#__PURE__*/function () {
558
605
  value: function unsubscribeRoom(roomId) {
559
606
  if (this.core.selected == null) return;
560
607
  roomId = roomId || this.core.selected.id;
608
+ this.unsubscribe("r/".concat(roomId, "/typing"));
561
609
  this.unsubscribe("r/".concat(roomId, "/").concat(roomId, "/+/t"));
562
610
  this.unsubscribe("r/".concat(roomId, "/").concat(roomId, "/+/d"));
563
611
  this.unsubscribe("r/".concat(roomId, "/").concat(roomId, "/+/r"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qiscus-sdk-core",
3
- "version": "2.12.6",
3
+ "version": "2.13.1",
4
4
  "description": "Qiscus Web SDK Core",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -11,7 +11,7 @@
11
11
  "dist"
12
12
  ],
13
13
  "scripts": {
14
- "build": "npm-run-all --parallel build:node build:web",
14
+ "build": "npm-run-all --parallel build:node build:web build:web:dev",
15
15
  "build:dev": "npm-run-all --parallel build:node build:web:dev",
16
16
  "build:dev:watch": "npm-run-all --parallel build:web:watch serve",
17
17
  "build:node": "babel -d lib src",
@@ -69,7 +69,7 @@
69
69
  "lodash.debounce": "^4.0.8",
70
70
  "lodash.throttle": "^4.1.1",
71
71
  "mitt": "^1.2.0",
72
- "mqtt": "^4.2.6",
72
+ "mqtt": "~4.2.6",
73
73
  "superagent": "^3.8.3"
74
74
  },
75
75
  "babel": {