qiscus-sdk-core 2.16.0 → 2.16.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.
@@ -1,26 +1,17 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var _dateFns = require("date-fns");
11
- var _utils = require("./utils.js");
12
- var Comment = /*#__PURE__*/function () {
13
- function Comment(comment) {
14
- (0, _classCallCheck2["default"])(this, Comment);
2
+ const dateFns = require("date-fns");
3
+ const utils = require("./utils.js");
4
+ class Comment {
5
+ constructor(comment) {
15
6
  this.id = comment.id;
16
7
  this.before_id = comment.comment_before_id;
17
- this.message = (0, _utils.escapeHTML)(comment.message);
8
+ this.message = utils.escapeHTML(comment.message);
18
9
  this.username_as = comment.username_as || comment.username;
19
10
  this.username_real = comment.username_real || comment.email;
20
11
  this.email = this.username_real;
21
12
  this.user_extras = comment.user_extras;
22
- this.date = (0, _dateFns.format)(comment.timestamp, 'YYYY-MM-DD');
23
- this.time = (0, _dateFns.format)(comment.timestamp, 'HH:mm');
13
+ this.date = dateFns.format(comment.timestamp, "YYYY-MM-DD");
14
+ this.time = dateFns.format(comment.timestamp, "HH:mm");
24
15
  this.timestamp = comment.timestamp;
25
16
  this.unique_id = comment.unique_temp_id || comment.unique_id;
26
17
  this.unique_temp_id = comment.unique_temp_id || comment.unique_id;
@@ -30,8 +21,6 @@ var Comment = /*#__PURE__*/function () {
30
21
  this.unix_timestamp = comment.unix_timestamp;
31
22
  this.unix_nano_timestamp = comment.unix_nano_timestamp;
32
23
  this.extras = comment.extras;
33
-
34
- /* comment status */
35
24
  this.is_deleted = comment.is_deleted;
36
25
  this.isPending = false;
37
26
  this.isFailed = false;
@@ -41,136 +30,94 @@ var Comment = /*#__PURE__*/function () {
41
30
  this.attachment = null;
42
31
  this.payload = comment.payload;
43
32
  this.status = comment.status;
44
-
45
- // manage comment type
46
- if (comment.type === 'reply') {
47
- comment.payload.replied_comment_message = (0, _utils.escapeHTML)(comment.payload.replied_comment_message);
48
- comment.payload.text = (0, _utils.escapeHTML)(comment.payload.text);
33
+ if (comment.type === "reply") {
34
+ comment.payload.replied_comment_message = utils.escapeHTML(
35
+ comment.payload.replied_comment_message
36
+ );
37
+ comment.payload.text = utils.escapeHTML(comment.payload.text);
49
38
  }
50
-
51
- // supported comment type text, account_linking, buttons
52
- // let supported_comment_type = [
53
- // 'text','account_linking','buttons','reply','system_event','card', 'custom', 'contact_person', 'location',
54
- // 'carousel'
55
- // ];
56
39
  this.type = comment.type;
57
- this.subtype = comment.type === 'custom' ? comment.payload.type : null;
58
- // comment status
59
- // comment status
60
- if (comment.status === 'sent') {
40
+ this.subtype = comment.type === "custom" ? comment.payload.type : null;
41
+ if (comment.status === "sent") {
61
42
  this.markAsSent();
62
- } else if (comment.status === 'delivered') {
43
+ } else if (comment.status === "delivered") {
63
44
  this.markAsDelivered();
64
- } else if (comment.status === 'read') {
45
+ } else if (comment.status === "read") {
65
46
  this.markAsRead();
66
47
  }
67
48
  }
68
- return (0, _createClass2["default"])(Comment, [{
69
- key: "isAttachment",
70
- value: function isAttachment(message) {
71
- return message.substring(0, '[file]'.length) === '[file]';
72
- }
73
- }, {
74
- key: "isImageAttachment",
75
- value: function isImageAttachment(message) {
76
- return this.isAttachment(message) && message.match(/\.(jpg|jpeg|gif|png)/i) != null;
77
- }
78
- }, {
79
- key: "attachUniqueId",
80
- value: function attachUniqueId(uniqueId) {
81
- this.unique_id = uniqueId;
82
- }
83
- }, {
84
- key: "getAttachmentURI",
85
- value: function getAttachmentURI(message) {
86
- if (!this.isAttachment(message)) return;
87
- var messageLength = message.length;
88
- var beginIndex = '[file]'.length;
89
- var endIndex = messageLength - '[/file]'.length;
90
- return message.substring(beginIndex, endIndex).trim();
91
- }
92
- }, {
93
- key: "setAttachment",
94
- value: function setAttachment(attachment) {
95
- this.attachment = attachment;
96
- }
97
- }, {
98
- key: "markAsPending",
99
- value: function markAsPending() {
100
- this.isPending = true;
101
- this.isDelivered = false;
102
- this.status = 'pending';
103
- }
104
- }, {
105
- key: "markAsSent",
106
- value: function markAsSent() {
107
- this.isSent = true;
108
- this.isPending = false;
109
- this.isFailed = false;
110
- this.status = 'sent';
111
- }
112
- }, {
113
- key: "markAsDelivered",
114
- value: function markAsDelivered() {
115
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
116
- actor = _ref.actor,
117
- activeActorId = _ref.activeActorId;
118
- if (actor === activeActorId) return;
119
- if (this.isRead || this.status === 'read') return;
120
- this.isSent = true;
121
- this.isRead = false;
122
- this.isDelivered = true;
123
- this.status = 'delivered';
124
- }
125
- }, {
126
- key: "markAsRead",
127
- value: function markAsRead() {
128
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
129
- actor = _ref2.actor,
130
- activeActorId = _ref2.activeActorId;
131
- if (actor === activeActorId) return;
132
- this.isPending = false;
133
- this.isSent = true;
134
- this.isDelivered = true;
135
- this.isRead = true;
136
- this.status = 'read';
137
- }
138
- }, {
139
- key: "markAsFailed",
140
- value: function markAsFailed() {
141
- this.isFailed = true;
142
- this.isPending = false;
143
- this.isStatus = 'failed';
49
+ isAttachment(message) {
50
+ return message.substring(0, "[file]".length) === "[file]";
51
+ }
52
+ isImageAttachment(message) {
53
+ return this.isAttachment(message) && message.match(/\.(jpg|jpeg|gif|png)/i) != null;
54
+ }
55
+ attachUniqueId(uniqueId) {
56
+ this.unique_id = uniqueId;
57
+ }
58
+ getAttachmentURI(message) {
59
+ if (!this.isAttachment(message)) return;
60
+ const messageLength = message.length;
61
+ const beginIndex = "[file]".length;
62
+ const endIndex = messageLength - "[/file]".length;
63
+ return message.substring(beginIndex, endIndex).trim();
64
+ }
65
+ setAttachment(attachment) {
66
+ this.attachment = attachment;
67
+ }
68
+ markAsPending() {
69
+ this.isPending = true;
70
+ this.isDelivered = false;
71
+ this.status = "pending";
72
+ }
73
+ markAsSent() {
74
+ this.isSent = true;
75
+ this.isPending = false;
76
+ this.isFailed = false;
77
+ this.status = "sent";
78
+ }
79
+ markAsDelivered({ actor, activeActorId } = {}) {
80
+ if (actor === activeActorId) return;
81
+ if (this.isRead || this.status === "read") return;
82
+ this.isSent = true;
83
+ this.isRead = false;
84
+ this.isDelivered = true;
85
+ this.status = "delivered";
86
+ }
87
+ markAsRead({ actor, activeActorId } = {}) {
88
+ if (actor === activeActorId) return;
89
+ this.isPending = false;
90
+ this.isSent = true;
91
+ this.isDelivered = true;
92
+ this.isRead = true;
93
+ this.status = "read";
94
+ }
95
+ markAsFailed() {
96
+ this.isFailed = true;
97
+ this.isPending = false;
98
+ this.isStatus = "failed";
99
+ }
100
+ // usually called when there's new comment with the same id
101
+ // we just need to update its content
102
+ update(data) {
103
+ this.id = data.id;
104
+ this.before_id = data.comment_before_id;
105
+ this.message = utils.escapeHTML(data.message);
106
+ if (data.payload) this.payload = data.payload;
107
+ if (data.status) this.status = data.status;
108
+ if (data.type === "reply") {
109
+ this.payload.replied_comment_message = utils.escapeHTML(
110
+ data.payload.replied_comment_message
111
+ );
112
+ this.payload.text = utils.escapeHTML(data.payload.text);
144
113
  }
145
- // usually called when there's new comment with the same id
146
- // we just need to update its content
147
- }, {
148
- key: "update",
149
- value: function update(data) {
150
- // update properties that usually change
151
- this.id = data.id;
152
- this.before_id = data.comment_before_id;
153
- this.message = (0, _utils.escapeHTML)(data.message);
154
- /* comment status */
155
- if (data.payload) this.payload = data.payload;
156
- if (data.status) this.status = data.status;
157
-
158
- // manage comment type
159
- if (data.type === 'reply') {
160
- this.payload.replied_comment_message = (0, _utils.escapeHTML)(data.payload.replied_comment_message);
161
- this.payload.text = (0, _utils.escapeHTML)(data.payload.text);
162
- }
163
-
164
- // comment status
165
- if (data.status === 'sent') {
166
- this.markAsSent();
167
- } else if (data.status === 'delivered') {
168
- this.markAsDelivered();
169
- } else if (data.status === 'read') {
170
- this.markAsRead();
171
- }
114
+ if (data.status === "sent") {
115
+ this.markAsSent();
116
+ } else if (data.status === "delivered") {
117
+ this.markAsDelivered();
118
+ } else if (data.status === "read") {
119
+ this.markAsRead();
172
120
  }
173
- }]);
174
- }();
175
- var _default = exports["default"] = Comment;
176
- module.exports = exports.default;
121
+ }
122
+ }
123
+ module.exports = Comment;
package/lib/lib/Room.js CHANGED
@@ -1,23 +1,6 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = exports.Room = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _Comment = _interopRequireDefault(require("./Comment"));
12
- /**
13
- * Holds chat rooms for qiscus chat sdk
14
- *
15
- * @example
16
- * let Room = new Room(roomData);
17
- * @export
18
- * @class Room
19
- */
20
- var Room = exports.Room = /*#__PURE__*/function () {
2
+ const Comment = require("./Comment.js");
3
+ class Room {
21
4
  /**
22
5
  * Creates an instance of Room.
23
6
  * @param {any} roomData
@@ -26,8 +9,7 @@ var Room = exports.Room = /*#__PURE__*/function () {
26
9
  * @param {string} last_comment_message
27
10
  * @memberof Room
28
11
  */
29
- function Room(roomData) {
30
- (0, _classCallCheck2["default"])(this, Room);
12
+ constructor(roomData) {
31
13
  this.id = roomData.id;
32
14
  this.last_comment_id = roomData.last_comment_id;
33
15
  this.last_comment_message = roomData.last_comment_message;
@@ -52,78 +34,54 @@ var Room = exports.Room = /*#__PURE__*/function () {
52
34
  this.participantNumber = roomData.room_total_participants;
53
35
  if (roomData.comments) this.receiveComments(roomData.comments);
54
36
  }
55
- return (0, _createClass2["default"])(Room, [{
56
- key: "isCurrentlySelected",
57
- value: function isCurrentlySelected(selected) {
58
- return this.id === selected.id;
59
- }
60
- }, {
61
- key: "getParticipantCount",
62
- value: function getParticipantCount() {
63
- if (this.participants == null) {
64
- return this.participantNumber;
65
- } else {
66
- return this.participants.length;
67
- }
68
- }
69
- }, {
70
- key: "setTitle",
71
- value: function setTitle(title) {
72
- this.custom_title = title;
73
- }
74
- }, {
75
- key: "setSubTitle",
76
- value: function setSubTitle(subtitle) {
77
- this.custom_subtitle = subtitle;
78
- }
79
-
80
- /**
81
- * Receive a single comment
82
- *
83
- * @param {Comment} comment
84
- * @memberof Room
85
- */
86
- }, {
87
- key: "receiveComment",
88
- value: function receiveComment(comment) {
89
- // Ignore if not from the same room
90
- if (comment.room_id !== this.id) return;
91
- // let's check first whether this room already has this specific comment
92
- var commentToFind = this.comments.find(function (cmt) {
93
- return cmt.unique_id === comment.unique_id;
94
- });
95
- if (commentToFind) {
96
- commentToFind.id = comment.id;
97
- commentToFind.message = comment.message;
98
- commentToFind.date = comment.date;
99
- commentToFind.time = comment.time;
100
- commentToFind.unix_timestamp = comment.unix_timestamp;
101
- } else {
102
- this.comments = [].concat((0, _toConsumableArray2["default"])(this.comments), [comment]);
103
- }
104
- }
105
- }, {
106
- key: "receiveComments",
107
- value: function receiveComments(comments) {
108
- var _this = this;
109
- comments.forEach(function (comment) {
110
- _this.receiveComment(new _Comment["default"](comment));
111
- });
112
- }
113
- }, {
114
- key: "getParticipant",
115
- value: function getParticipant(participantEmail) {
116
- return this.participants.find(function (p) {
117
- return p.email === participantEmail;
118
- }) || null;
37
+ isCurrentlySelected(selected) {
38
+ return this.id === selected.id;
39
+ }
40
+ getParticipantCount() {
41
+ if (this.participants == null) {
42
+ return this.participantNumber;
43
+ } else {
44
+ return this.participants.length;
119
45
  }
120
- }, {
121
- key: "addParticipant",
122
- value: function addParticipant(participant) {
123
- // get if there's existing participant, if any then push
124
- var participantToFind = this.getParticipant(participant.email);
125
- if (!participantToFind) this.participants.push(participant);
46
+ }
47
+ setTitle(title) {
48
+ this.custom_title = title;
49
+ }
50
+ setSubTitle(subtitle) {
51
+ this.custom_subtitle = subtitle;
52
+ }
53
+ /**
54
+ * Receive a single comment
55
+ *
56
+ * @param {Comment} comment
57
+ * @memberof Room
58
+ */
59
+ receiveComment(comment) {
60
+ if (comment.room_id !== this.id) return;
61
+ const commentToFind = this.comments.find(
62
+ (cmt) => cmt.unique_id === comment.unique_id
63
+ );
64
+ if (commentToFind) {
65
+ commentToFind.id = comment.id;
66
+ commentToFind.message = comment.message;
67
+ commentToFind.date = comment.date;
68
+ commentToFind.time = comment.time;
69
+ commentToFind.unix_timestamp = comment.unix_timestamp;
70
+ } else {
71
+ this.comments = [...this.comments, comment];
126
72
  }
127
- }]);
128
- }();
129
- var _default = exports["default"] = Room;
73
+ }
74
+ receiveComments(comments) {
75
+ comments.forEach((comment) => {
76
+ this.receiveComment(new Comment(comment));
77
+ });
78
+ }
79
+ getParticipant(participantEmail) {
80
+ return this.participants.find((p) => p.email === participantEmail) || null;
81
+ }
82
+ addParticipant(participant) {
83
+ let participantToFind = this.getParticipant(participant.email);
84
+ if (!participantToFind) this.participants.push(participant);
85
+ }
86
+ }
87
+ module.exports = Room;
@@ -1,81 +1,54 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var AuthAdapter = exports["default"] = /*#__PURE__*/function () {
2
+ class AuthAdapter {
11
3
  /**
12
4
  * Params used in this class
13
5
  * @method constructor
14
6
  * @param {Object} HTTPAdapter [Qiscus HTTP adapter]
15
7
  * @return {void} Returns nothing
16
8
  */
17
- function AuthAdapter(HTTPAdapter) {
18
- (0, _classCallCheck2["default"])(this, AuthAdapter);
9
+ constructor(HTTPAdapter) {
19
10
  this.HTTPAdapter = HTTPAdapter;
20
11
  this.refreshToken = null;
21
12
  this.userId = null;
22
13
  this.autoRefreshToken = false;
23
14
  }
24
- return (0, _createClass2["default"])(AuthAdapter, [{
25
- key: "getNonce",
26
- value: function getNonce() {
27
- return this.HTTPAdapter.post('api/v2/sdk/auth/nonce').then(function (res) {
28
- return res.body.results;
29
- });
30
- }
31
- }, {
32
- key: "loginOrRegister",
33
- value: function loginOrRegister(params) {
34
- var _this = this;
35
- return this.HTTPAdapter.post('api/v2/sdk/login_or_register', params).then(function (resp) {
36
- if (resp.body.status !== 200) return Promise.reject(resp);
37
- var result = resp.body.results;
38
- _this.userId = result.user.email;
39
- _this.refreshToken = result.user.refresh_token;
40
- return result;
41
- });
42
- }
43
- }, {
44
- key: "verifyIdentityToken",
45
- value: function verifyIdentityToken(token) {
46
- var _this2 = this;
47
- return this.HTTPAdapter.post('api/v2/sdk/auth/verify_identity_token', {
48
- identity_token: token
49
- }).then(function (resp) {
50
- var result = resp.body.results;
51
- _this2.userId = result.user.email;
52
- _this2.refreshToken = result.user.refresh_token;
53
- return result;
54
- });
55
- }
56
- }, {
57
- key: "refreshAuthToken",
58
- value: function refreshAuthToken() {
59
- var _this3 = this;
60
- return this.HTTPAdapter.post('api/v2/sdk/refresh_user_token', {
61
- user_id: this.userId,
62
- refresh_token: this.refreshToken
63
- }).then(function (r) {
64
- var res = r.body.results;
65
- _this3.refreshToken = res.refresh_token;
66
- _this3.HTTPAdapter.token = res.token;
67
- return res;
68
- });
69
- }
70
- }, {
71
- key: "expiredAuthToken",
72
- value: function expiredAuthToken() {
73
- return this.HTTPAdapter.post("api/v2/sdk/expire_user_token", {
74
- user_id: this.userId
75
- }).then(function (r) {
76
- return r.body.results;
77
- });
78
- }
79
- }]);
80
- }();
81
- module.exports = exports.default;
15
+ getNonce() {
16
+ return this.HTTPAdapter.post("api/v2/sdk/auth/nonce").then((res) => res.body.results);
17
+ }
18
+ loginOrRegister(params) {
19
+ return this.HTTPAdapter.post("api/v2/sdk/login_or_register", params).then((resp) => {
20
+ if (resp.body.status !== 200) return Promise.reject(resp);
21
+ let result = resp.body.results;
22
+ this.userId = result.user.email;
23
+ this.refreshToken = result.user.refresh_token;
24
+ return result;
25
+ });
26
+ }
27
+ verifyIdentityToken(token) {
28
+ return this.HTTPAdapter.post("api/v2/sdk/auth/verify_identity_token", {
29
+ identity_token: token
30
+ }).then((resp) => {
31
+ let result = resp.body.results;
32
+ this.userId = result.user.email;
33
+ this.refreshToken = result.user.refresh_token;
34
+ return result;
35
+ });
36
+ }
37
+ refreshAuthToken() {
38
+ return this.HTTPAdapter.post("api/v2/sdk/refresh_user_token", {
39
+ user_id: this.userId,
40
+ refresh_token: this.refreshToken
41
+ }).then((r) => {
42
+ let res = r.body.results;
43
+ this.refreshToken = res.refresh_token;
44
+ this.HTTPAdapter.token = res.token;
45
+ return res;
46
+ });
47
+ }
48
+ expiredAuthToken() {
49
+ return this.HTTPAdapter.post(`api/v2/sdk/expire_user_token`, {
50
+ user_id: this.userId
51
+ }).then((r) => r.body.results);
52
+ }
53
+ }
54
+ module.exports = AuthAdapter;
@@ -1,55 +1,46 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = CustomEventAdapter;
8
- var _is = _interopRequireDefault(require("../is"));
9
- var _mitt = _interopRequireDefault(require("mitt"));
2
+ const is = require("../is.js");
3
+ const mitt = require("mitt");
10
4
  function CustomEventAdapter(mqttAdapter, userId) {
11
- var events = (0, _mitt["default"])();
12
- var subscribedTopics = {};
13
- var reTopic = /^r\/[\w]+\/[\w]+\/e$/i;
14
- mqttAdapter.mqtt.on('message', function (topic, payload) {
5
+ const events = mitt();
6
+ const subscribedTopics = {};
7
+ const reTopic = /^r\/[\w]+\/[\w]+\/e$/i;
8
+ mqttAdapter.mqtt.on("message", (topic, payload) => {
15
9
  if (reTopic.test(topic)) events.emit(topic, payload);
16
10
  });
17
- var getTopic = function getTopic(roomId) {
18
- return "r/".concat(roomId, "/").concat(roomId, "/e");
19
- };
11
+ const getTopic = (roomId) => `r/${roomId}/${roomId}/e`;
20
12
  return {
21
- publishEvent: function publishEvent(roomId, payload) {
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
- var _payload = JSON.stringify({
13
+ publishEvent(roomId, payload) {
14
+ if (is.undefined(roomId)) throw new Error("`roomId` required");
15
+ if (is.not.string(roomId)) throw new TypeError("`roomId` must have type of string");
16
+ if (is.undefined(payload)) throw new Error("`payload` required");
17
+ if (is.not.object(payload)) throw new TypeError("`payload` must have type of object");
18
+ const _payload = JSON.stringify({
27
19
  sender: userId,
28
20
  // ?
29
21
  data: payload
30
22
  });
31
23
  mqttAdapter.publish(getTopic(roomId), _payload);
32
24
  },
33
- subscribeEvent: function subscribeEvent(roomId, callback) {
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
- var topic = getTopic(roomId);
39
- // Only allow 1 subcription for now
25
+ subscribeEvent(roomId, callback) {
26
+ if (is.undefined(roomId)) throw new Error("`roomId` required");
27
+ if (is.not.string(roomId)) throw new TypeError("`roomId` must have type of string");
28
+ if (is.undefined(callback)) throw new Error("`callback` required");
29
+ if (is.not.function(callback)) throw new TypeError("`callback` must have type of function");
30
+ const topic = getTopic(roomId);
40
31
  if (subscribedTopics[topic]) return;
41
32
  mqttAdapter.subscribe(topic);
42
- var cb = function cb(payload) {
43
- var parsedPayload = JSON.parse(payload);
33
+ const cb = (payload) => {
34
+ const parsedPayload = JSON.parse(payload);
44
35
  callback(parsedPayload);
45
36
  };
46
37
  events.on(topic, cb);
47
38
  subscribedTopics[topic] = cb;
48
39
  },
49
- unsubscribeEvent: function unsubscribeEvent(roomId) {
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
- var topic = getTopic(roomId);
40
+ unsubscribeEvent(roomId) {
41
+ if (is.undefined(roomId)) throw new Error("`roomId` required");
42
+ if (is.not.string(roomId)) throw new TypeError("`roomId` must have type of string");
43
+ const topic = getTopic(roomId);
53
44
  if (!subscribedTopics[topic]) return;
54
45
  mqttAdapter.unsubscribe(topic);
55
46
  events.off(topic, subscribedTopics[topic]);
@@ -58,4 +49,4 @@ function CustomEventAdapter(mqttAdapter, userId) {
58
49
  }
59
50
  };
60
51
  }
61
- module.exports = exports.default;
52
+ module.exports = CustomEventAdapter;