ncloudchat 0.0.19-beta

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.
Files changed (104) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +69 -0
  3. package/esm/CloudChat.d.ts +38 -0
  4. package/esm/CloudChat.js +592 -0
  5. package/esm/CloudChat.js.map +1 -0
  6. package/esm/CoreManager.d.ts +5 -0
  7. package/esm/CoreManager.js +27 -0
  8. package/esm/CoreManager.js.map +1 -0
  9. package/esm/Dispatcher.d.ts +21 -0
  10. package/esm/Dispatcher.js +78 -0
  11. package/esm/Dispatcher.js.map +1 -0
  12. package/esm/Type.d.ts +35 -0
  13. package/esm/Type.js +12 -0
  14. package/esm/Type.js.map +1 -0
  15. package/esm/index.d.ts +2 -0
  16. package/esm/index.js +3 -0
  17. package/esm/index.js.map +1 -0
  18. package/esm/logger.d.ts +4 -0
  19. package/esm/logger.js +11 -0
  20. package/esm/logger.js.map +1 -0
  21. package/esm/mutations/channel.d.ts +4 -0
  22. package/esm/mutations/channel.js +162 -0
  23. package/esm/mutations/channel.js.map +1 -0
  24. package/esm/mutations/friend.d.ts +5 -0
  25. package/esm/mutations/friend.js +146 -0
  26. package/esm/mutations/friend.js.map +1 -0
  27. package/esm/mutations/index.d.ts +14 -0
  28. package/esm/mutations/index.js +15 -0
  29. package/esm/mutations/index.js.map +1 -0
  30. package/esm/mutations/invite.d.ts +1 -0
  31. package/esm/mutations/invite.js +71 -0
  32. package/esm/mutations/invite.js.map +1 -0
  33. package/esm/mutations/memberinvitation.d.ts +2 -0
  34. package/esm/mutations/memberinvitation.js +103 -0
  35. package/esm/mutations/memberinvitation.js.map +1 -0
  36. package/esm/mutations/memberreport.d.ts +10 -0
  37. package/esm/mutations/memberreport.js +110 -0
  38. package/esm/mutations/memberreport.js.map +1 -0
  39. package/esm/mutations/message.d.ts +2 -0
  40. package/esm/mutations/message.js +97 -0
  41. package/esm/mutations/message.js.map +1 -0
  42. package/esm/mutations/messageread.d.ts +1 -0
  43. package/esm/mutations/messageread.js +69 -0
  44. package/esm/mutations/messageread.js.map +1 -0
  45. package/esm/mutations/subscription.d.ts +4 -0
  46. package/esm/mutations/subscription.js +139 -0
  47. package/esm/mutations/subscription.js.map +1 -0
  48. package/esm/mutations/user.d.ts +1 -0
  49. package/esm/mutations/user.js +74 -0
  50. package/esm/mutations/user.js.map +1 -0
  51. package/esm/queries/channel.d.ts +2 -0
  52. package/esm/queries/channel.js +119 -0
  53. package/esm/queries/channel.js.map +1 -0
  54. package/esm/queries/friend.d.ts +1 -0
  55. package/esm/queries/friend.js +80 -0
  56. package/esm/queries/friend.js.map +1 -0
  57. package/esm/queries/index.d.ts +7 -0
  58. package/esm/queries/index.js +8 -0
  59. package/esm/queries/index.js.map +1 -0
  60. package/esm/queries/memberinvitation.d.ts +2 -0
  61. package/esm/queries/memberinvitation.js +110 -0
  62. package/esm/queries/memberinvitation.js.map +1 -0
  63. package/esm/queries/message.d.ts +2 -0
  64. package/esm/queries/message.js +117 -0
  65. package/esm/queries/message.js.map +1 -0
  66. package/esm/queries/messageread.d.ts +1 -0
  67. package/esm/queries/messageread.js +74 -0
  68. package/esm/queries/messageread.js.map +1 -0
  69. package/esm/queries/project.d.ts +1 -0
  70. package/esm/queries/project.js +74 -0
  71. package/esm/queries/project.js.map +1 -0
  72. package/esm/queries/subscription.d.ts +2 -0
  73. package/esm/queries/subscription.js +112 -0
  74. package/esm/queries/subscription.js.map +1 -0
  75. package/lib/CloudChat.js +1032 -0
  76. package/lib/CoreManager.js +35 -0
  77. package/lib/Dispatcher.js +109 -0
  78. package/lib/Type.js +25 -0
  79. package/lib/index.js +18 -0
  80. package/lib/logger.js +27 -0
  81. package/lib/mutations/channel.js +324 -0
  82. package/lib/mutations/friend.js +319 -0
  83. package/lib/mutations/index.js +128 -0
  84. package/lib/mutations/invite.js +208 -0
  85. package/lib/mutations/memberinvitation.js +271 -0
  86. package/lib/mutations/memberreport.js +272 -0
  87. package/lib/mutations/message.js +246 -0
  88. package/lib/mutations/messageread.js +215 -0
  89. package/lib/mutations/subscription.js +299 -0
  90. package/lib/mutations/user.js +207 -0
  91. package/lib/queries/channel.js +274 -0
  92. package/lib/queries/friend.js +220 -0
  93. package/lib/queries/index.js +102 -0
  94. package/lib/queries/memberinvitation.js +273 -0
  95. package/lib/queries/message.js +267 -0
  96. package/lib/queries/messageread.js +219 -0
  97. package/lib/queries/project.js +217 -0
  98. package/lib/queries/subscription.js +264 -0
  99. package/ncloudchat_javascript.md +290 -0
  100. package/package copy.json +74 -0
  101. package/package.json +76 -0
  102. package/tsconfig.json +31 -0
  103. package/types/exif.d.ts +10 -0
  104. package/types/window.d.ts +5 -0
@@ -0,0 +1,1032 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
+
5
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ exports["default"] = void 0;
12
+
13
+ require("core-js/modules/es6.array.map");
14
+
15
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
16
+
17
+ require("core-js/modules/es6.regexp.split");
18
+
19
+ require("core-js/modules/es6.function.bind");
20
+
21
+ require("core-js/modules/es6.function.name");
22
+
23
+ var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));
24
+
25
+ var _symbol = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol"));
26
+
27
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
28
+
29
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
30
+
31
+ var _socket = require("socket.io-client");
32
+
33
+ var _CoreManager = _interopRequireDefault(require("./CoreManager"));
34
+
35
+ var _Dispatcher = _interopRequireDefault(require("./Dispatcher"));
36
+
37
+ var _logger = require("./logger");
38
+
39
+ var _queries = require("./queries");
40
+
41
+ var _mutations = require("./mutations");
42
+
43
+ var __assign = void 0 && (void 0).__assign || function () {
44
+ __assign = _assign["default"] || function (t) {
45
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
46
+ s = arguments[i];
47
+
48
+ for (var p in s) {
49
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
50
+ }
51
+ }
52
+
53
+ return t;
54
+ };
55
+
56
+ return __assign.apply(this, arguments);
57
+ };
58
+
59
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
60
+ function adopt(value) {
61
+ return value instanceof P ? value : new P(function (resolve) {
62
+ resolve(value);
63
+ });
64
+ }
65
+
66
+ return new (P || (P = _promise["default"]))(function (resolve, reject) {
67
+ function fulfilled(value) {
68
+ try {
69
+ step(generator.next(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ }
74
+
75
+ function rejected(value) {
76
+ try {
77
+ step(generator["throw"](value));
78
+ } catch (e) {
79
+ reject(e);
80
+ }
81
+ }
82
+
83
+ function step(result) {
84
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
85
+ }
86
+
87
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
88
+ });
89
+ };
90
+
91
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
92
+ var _ = {
93
+ label: 0,
94
+ sent: function sent() {
95
+ if (t[0] & 1) throw t[1];
96
+ return t[1];
97
+ },
98
+ trys: [],
99
+ ops: []
100
+ },
101
+ f,
102
+ y,
103
+ t,
104
+ g;
105
+ return g = {
106
+ next: verb(0),
107
+ "throw": verb(1),
108
+ "return": verb(2)
109
+ }, typeof _symbol["default"] === "function" && (g[_iterator["default"]] = function () {
110
+ return this;
111
+ }), g;
112
+
113
+ function verb(n) {
114
+ return function (v) {
115
+ return step([n, v]);
116
+ };
117
+ }
118
+
119
+ function step(op) {
120
+ if (f) throw new TypeError("Generator is already executing.");
121
+
122
+ while (_) {
123
+ try {
124
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
125
+ if (y = 0, t) op = [op[0] & 2, t.value];
126
+
127
+ switch (op[0]) {
128
+ case 0:
129
+ case 1:
130
+ t = op;
131
+ break;
132
+
133
+ case 4:
134
+ _.label++;
135
+ return {
136
+ value: op[1],
137
+ done: false
138
+ };
139
+
140
+ case 5:
141
+ _.label++;
142
+ y = op[1];
143
+ op = [0];
144
+ continue;
145
+
146
+ case 7:
147
+ op = _.ops.pop();
148
+
149
+ _.trys.pop();
150
+
151
+ continue;
152
+
153
+ default:
154
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
155
+ _ = 0;
156
+ continue;
157
+ }
158
+
159
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
160
+ _.label = op[1];
161
+ break;
162
+ }
163
+
164
+ if (op[0] === 6 && _.label < t[1]) {
165
+ _.label = t[1];
166
+ t = op;
167
+ break;
168
+ }
169
+
170
+ if (t && _.label < t[2]) {
171
+ _.label = t[2];
172
+
173
+ _.ops.push(op);
174
+
175
+ break;
176
+ }
177
+
178
+ if (t[2]) _.ops.pop();
179
+
180
+ _.trys.pop();
181
+
182
+ continue;
183
+ }
184
+
185
+ op = body.call(thisArg, _);
186
+ } catch (e) {
187
+ op = [6, e];
188
+ y = 0;
189
+ } finally {
190
+ f = t = 0;
191
+ }
192
+ }
193
+
194
+ if (op[0] & 5) throw op[1];
195
+ return {
196
+ value: op[0] ? op[1] : void 0,
197
+ done: true
198
+ };
199
+ }
200
+ };
201
+
202
+ var NCloudChat =
203
+ /** @class */
204
+ function () {
205
+ function NCloudChat() {
206
+ this.socket = null;
207
+ this.connected = false;
208
+ this.connectedCount = 0;
209
+ this.dp = new _Dispatcher["default"]();
210
+ }
211
+
212
+ NCloudChat.prototype.clear = function () {};
213
+
214
+ NCloudChat.prototype.initialize = function (projectId) {
215
+ _CoreManager["default"].set("PROJECT_ID", projectId);
216
+
217
+ _CoreManager["default"].set("USER", {
218
+ id: "",
219
+ name: "",
220
+ image: ""
221
+ });
222
+ };
223
+
224
+ NCloudChat.prototype.getLang = function () {
225
+ return navigator.language;
226
+ };
227
+
228
+ NCloudChat.prototype.getUser = function () {
229
+ return _CoreManager["default"].get("USER");
230
+ };
231
+
232
+ NCloudChat.prototype.setServerUrl = function (url) {
233
+ if (!/^[hHtTpP]{4}(s)?(:\/\/)[a-zA-Z0-9\.\/-:]+/.test(url)) {
234
+ throw Error("invalied url : (ex)http://domain.com, https://domain.com");
235
+ return;
236
+ }
237
+
238
+ if (url.length > 1 && url.substring(url.length - 1) === '/') {
239
+ url = url.substring(0, url.length - 1);
240
+ }
241
+
242
+ return _CoreManager["default"].set("SERVER_URL", url);
243
+ };
244
+
245
+ NCloudChat.prototype.setSocketUrl = function (url) {
246
+ _CoreManager["default"].set("SOCKET_URL", url);
247
+ };
248
+
249
+ NCloudChat.prototype.setProjectId = function (projectId) {
250
+ return _CoreManager["default"].set("PROJECT_ID", projectId);
251
+ };
252
+
253
+ NCloudChat.prototype.setUser = function (user) {
254
+ _CoreManager["default"].set("USER", user);
255
+ };
256
+
257
+ NCloudChat.prototype.connect = function (user_id, callback) {
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ var url, project_id, user, image, name, lang, token, e_1, options;
260
+
261
+ var _this = this;
262
+
263
+ return __generator(this, function (_a) {
264
+ switch (_a.label) {
265
+ case 0:
266
+ if (!this.isConnected()) return [3
267
+ /*break*/
268
+ , 2];
269
+ return [4
270
+ /*yield*/
271
+ , this.disconnect()];
272
+
273
+ case 1:
274
+ _a.sent();
275
+
276
+ _a.label = 2;
277
+
278
+ case 2:
279
+ url = _CoreManager["default"].get("SOCKET_URL") + '/cloudchat';
280
+ project_id = _CoreManager["default"].get("PROJECT_ID");
281
+
282
+ if (!project_id) {
283
+ throw Error("Project ID not found");
284
+ }
285
+
286
+ user = _CoreManager["default"].get("USER");
287
+ if (!user_id && user.id) user_id = user.id;
288
+
289
+ if (!user_id) {
290
+ throw Error("UserID not found");
291
+ }
292
+
293
+ image = user.image;
294
+ name = user.name;
295
+ lang = this.getLang();
296
+ token = null;
297
+ _a.label = 3;
298
+
299
+ case 3:
300
+ _a.trys.push([3, 5,, 6]);
301
+
302
+ return [4
303
+ /*yield*/
304
+ , (0, _mutations.login)(user_id)];
305
+
306
+ case 4:
307
+ token = _a.sent();
308
+ return [3
309
+ /*break*/
310
+ , 6];
311
+
312
+ case 5:
313
+ e_1 = _a.sent();
314
+ throw e_1;
315
+
316
+ case 6:
317
+ if (token == false) {
318
+ throw Error("token is not found");
319
+ }
320
+
321
+ _CoreManager["default"].set("TOKEN", token);
322
+
323
+ options = {
324
+ transports: ["websocket"],
325
+ reconnection: true,
326
+ reconnectionAttempts: 10,
327
+ reconnectionDelay: 2000,
328
+ reconnectionDelayMax: 2000 * 100,
329
+ randomizationFactor: 0.5,
330
+ query: {
331
+ project_id: project_id,
332
+ token: token,
333
+ lang: lang,
334
+ image: image,
335
+ name: name
336
+ }
337
+ };
338
+ this.socket = (0, _socket.io)(url, options);
339
+ this.socket.on("connect", function (data) {
340
+ _this.connectedCount++;
341
+ _this.connected = true;
342
+ (0, _logger.info)("Connected to " + url + " with id: " + _this.socket.id + ", ConnectCount:" + _this.connectedCount);
343
+
344
+ _this.dp.dispatch("onConnected", data);
345
+ });
346
+ this.socket.on("unauthorized", function (data) {});
347
+ this.socket.on("disconnect", function (reason) {
348
+ _this.connected = false;
349
+ (0, _logger.info)("Disconnected to " + url + " with id: " + _this.socket.id);
350
+
351
+ _this.dp.dispatch("onDisconnected", reason);
352
+ });
353
+ this.socket.on("message", function (payload) {
354
+ var message = JSON.parse(payload);
355
+
356
+ _this.dp.dispatch("onMessageReceived", message.channel_id, message);
357
+ });
358
+ this.socket.on("event", function (payload) {
359
+ var message = JSON.parse(payload);
360
+
361
+ _this.dp.dispatch("onEventReceived", message.channel_id, message);
362
+ });
363
+ this.socket.on("result", function (payload) {
364
+ var message = JSON.parse(payload);
365
+
366
+ _this.dp.dispatch("onResult", message);
367
+ });
368
+ this.socket.on("error", function (payload) {
369
+ var message = JSON.parse(payload);
370
+
371
+ _this.dp.dispatch("onErrorReceived", message);
372
+ });
373
+ return [2
374
+ /*return*/
375
+ , user];
376
+ }
377
+ });
378
+ });
379
+ };
380
+
381
+ NCloudChat.prototype.subscribe = function (channel, language) {
382
+ if (language === void 0) {
383
+ language = 'en';
384
+ }
385
+
386
+ return __awaiter(this, void 0, void 0, function () {
387
+ var subscription, e_2;
388
+ return __generator(this, function (_a) {
389
+ switch (_a.label) {
390
+ case 0:
391
+ if (!this.isConnected()) {
392
+ throw Error("You are not connected.");
393
+ }
394
+
395
+ _a.label = 1;
396
+
397
+ case 1:
398
+ _a.trys.push([1, 3,, 4]);
399
+
400
+ return [4
401
+ /*yield*/
402
+ , (0, _mutations.createSubscription)(channel, language)];
403
+
404
+ case 2:
405
+ subscription = _a.sent();
406
+ return [2
407
+ /*return*/
408
+ , subscription];
409
+
410
+ case 3:
411
+ e_2 = _a.sent();
412
+ throw e_2;
413
+
414
+ case 4:
415
+ return [2
416
+ /*return*/
417
+ , null];
418
+ }
419
+ });
420
+ });
421
+ };
422
+
423
+ NCloudChat.prototype.unsubscribe = function (channel) {
424
+ return __awaiter(this, void 0, void 0, function () {
425
+ var user, subscription, e_3;
426
+ return __generator(this, function (_a) {
427
+ switch (_a.label) {
428
+ case 0:
429
+ if (!this.isConnected()) {
430
+ throw Error("You are not connected.");
431
+ }
432
+
433
+ _a.label = 1;
434
+
435
+ case 1:
436
+ _a.trys.push([1, 3,, 4]);
437
+
438
+ user = _CoreManager["default"].get("USER");
439
+ if (!user.id) throw Error("unauthorized");
440
+ return [4
441
+ /*yield*/
442
+ , (0, _mutations.deleteSubscription)(channel)];
443
+
444
+ case 2:
445
+ subscription = _a.sent();
446
+ return [2
447
+ /*return*/
448
+ , subscription];
449
+
450
+ case 3:
451
+ e_3 = _a.sent();
452
+ throw e_3;
453
+
454
+ case 4:
455
+ return [2
456
+ /*return*/
457
+ , null];
458
+ }
459
+ });
460
+ });
461
+ };
462
+
463
+ NCloudChat.prototype.translateMessage = function (source, target, message) {
464
+ return __awaiter(this, void 0, void 0, function () {
465
+ var user, result, e_4;
466
+ return __generator(this, function (_a) {
467
+ switch (_a.label) {
468
+ case 0:
469
+ if (!this.isConnected()) {
470
+ throw Error("You are not connected.");
471
+ }
472
+
473
+ _a.label = 1;
474
+
475
+ case 1:
476
+ _a.trys.push([1, 3,, 4]);
477
+
478
+ user = _CoreManager["default"].get("USER");
479
+ return [4
480
+ /*yield*/
481
+ , (0, _mutations.translate)(source, target, message)];
482
+
483
+ case 2:
484
+ result = _a.sent();
485
+ return [2
486
+ /*return*/
487
+ , result];
488
+
489
+ case 3:
490
+ e_4 = _a.sent();
491
+ throw e_4;
492
+
493
+ case 4:
494
+ return [2
495
+ /*return*/
496
+ , null];
497
+ }
498
+ });
499
+ });
500
+ };
501
+
502
+ NCloudChat.prototype.sendMessage = function (channel, opt) {
503
+ return __awaiter(this, void 0, void 0, function () {
504
+ var user, data;
505
+ return __generator(this, function (_a) {
506
+ if (!this.isConnected()) {
507
+ throw Error("You are not connected.");
508
+ } // 채널 아이디가 존재하지 않을 경우 오류
509
+
510
+
511
+ if (!channel) {
512
+ throw Error("Channel ID is not found");
513
+ }
514
+
515
+ if (!opt.type) opt.type = "text";
516
+
517
+ if (!opt.message) {
518
+ throw Error("Message is NULL");
519
+ }
520
+
521
+ user = _CoreManager["default"].get("USER");
522
+
523
+ try {
524
+ data = __assign({
525
+ channelId: channel,
526
+ user: user
527
+ }, opt);
528
+ this.socket.emit("message", data);
529
+ return [2
530
+ /*return*/
531
+ , data];
532
+ } catch (e) {
533
+ return [2
534
+ /*return*/
535
+ , false];
536
+ }
537
+
538
+ return [2
539
+ /*return*/
540
+ ];
541
+ });
542
+ });
543
+ };
544
+
545
+ NCloudChat.prototype.sendImage = function (channel, file) {
546
+ return __awaiter(this, void 0, void 0, function () {
547
+ var user, result;
548
+ return __generator(this, function (_a) {
549
+ switch (_a.label) {
550
+ case 0:
551
+ if (!this.isConnected()) {
552
+ throw Error("You are not connected.");
553
+ }
554
+
555
+ user = _CoreManager["default"].get("USER");
556
+ return [4
557
+ /*yield*/
558
+ , (0, _mutations.upload)(channel, file)];
559
+
560
+ case 1:
561
+ result = _a.sent();
562
+ if (!result.status) throw Error(result.message);
563
+ return [4
564
+ /*yield*/
565
+ , this.sendMessage(channel, {
566
+ type: "file",
567
+ message: result.url,
568
+ file: result
569
+ })];
570
+
571
+ case 2:
572
+ _a.sent();
573
+
574
+ return [2
575
+ /*return*/
576
+ ];
577
+ }
578
+ });
579
+ });
580
+ };
581
+
582
+ NCloudChat.prototype.updateMessage = function (channel, message_id, message) {
583
+ return __awaiter(this, void 0, void 0, function () {
584
+ return __generator(this, function (_a) {
585
+ return [2
586
+ /*return*/
587
+ ];
588
+ });
589
+ });
590
+ };
591
+
592
+ NCloudChat.prototype.deleteMessage = function (channel, message_id) {
593
+ return __awaiter(this, void 0, void 0, function () {
594
+ return __generator(this, function (_a) {
595
+ return [2
596
+ /*return*/
597
+ ];
598
+ });
599
+ });
600
+ };
601
+
602
+ NCloudChat.prototype.disconnect = function () {
603
+ return __awaiter(this, void 0, void 0, function () {
604
+ return __generator(this, function (_a) {
605
+ if (!this.isConnected()) return [2
606
+ /*return*/
607
+ ];
608
+ this.socket.disconnect();
609
+ return [2
610
+ /*return*/
611
+ ];
612
+ });
613
+ });
614
+ };
615
+
616
+ NCloudChat.prototype.isConnected = function () {
617
+ return this.connected ? true : false;
618
+ };
619
+
620
+ NCloudChat.prototype.bind = function (id, fn) {
621
+ return __awaiter(this, void 0, void 0, function () {
622
+ return __generator(this, function (_a) {
623
+ this.dp.on(id, fn);
624
+ return [2
625
+ /*return*/
626
+ ];
627
+ });
628
+ });
629
+ };
630
+
631
+ NCloudChat.prototype.unbind = function (id, fn) {
632
+ return __awaiter(this, void 0, void 0, function () {
633
+ return __generator(this, function (_a) {
634
+ this.dp.off(id, fn);
635
+ return [2
636
+ /*return*/
637
+ ];
638
+ });
639
+ });
640
+ };
641
+
642
+ NCloudChat.prototype.unbindall = function (id) {
643
+ return __awaiter(this, void 0, void 0, function () {
644
+ return __generator(this, function (_a) {
645
+ this.dp.offall(id);
646
+ return [2
647
+ /*return*/
648
+ ];
649
+ });
650
+ });
651
+ };
652
+
653
+ NCloudChat.prototype.ObjectId = function (id) {
654
+ if (!id) return "";
655
+ return atob(id).split(":")[1];
656
+ };
657
+
658
+ NCloudChat.prototype.getChannels = function (filter, sort, option) {
659
+ if (sort === void 0) {
660
+ sort = {};
661
+ }
662
+
663
+ if (option === void 0) {
664
+ option = {};
665
+ }
666
+
667
+ return __awaiter(this, void 0, void 0, function () {
668
+ var entries, channels, e_5;
669
+
670
+ var _this = this;
671
+
672
+ return __generator(this, function (_a) {
673
+ switch (_a.label) {
674
+ case 0:
675
+ if (!this.isConnected()) {
676
+ throw Error("You are not connected.");
677
+ }
678
+
679
+ _a.label = 1;
680
+
681
+ case 1:
682
+ _a.trys.push([1, 3,, 4]);
683
+
684
+ return [4
685
+ /*yield*/
686
+ , (0, _queries.getChannels)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
687
+
688
+ case 2:
689
+ entries = _a.sent();
690
+
691
+ if (entries) {
692
+ channels = entries.map(function (item) {
693
+ return __assign(__assign({}, item.node), {
694
+ id: _this.ObjectId(item.node.id)
695
+ });
696
+ });
697
+ return [2
698
+ /*return*/
699
+ , channels];
700
+ }
701
+
702
+ return [2
703
+ /*return*/
704
+ , entries];
705
+
706
+ case 3:
707
+ e_5 = _a.sent();
708
+ throw e_5;
709
+
710
+ case 4:
711
+ return [2
712
+ /*return*/
713
+ ];
714
+ }
715
+ });
716
+ });
717
+ };
718
+
719
+ NCloudChat.prototype.getChannel = function (channelId) {
720
+ return __awaiter(this, void 0, void 0, function () {
721
+ var entry, e_6;
722
+ return __generator(this, function (_a) {
723
+ switch (_a.label) {
724
+ case 0:
725
+ if (!this.isConnected()) {
726
+ throw Error("You are not connected.");
727
+ }
728
+
729
+ _a.label = 1;
730
+
731
+ case 1:
732
+ _a.trys.push([1, 3,, 4]);
733
+
734
+ return [4
735
+ /*yield*/
736
+ , (0, _queries.getChannel)(channelId)];
737
+
738
+ case 2:
739
+ entry = _a.sent();
740
+
741
+ if (entry) {
742
+ entry.id = this.ObjectId(entry.id);
743
+ return [2
744
+ /*return*/
745
+ , entry];
746
+ }
747
+
748
+ return [2
749
+ /*return*/
750
+ , null];
751
+
752
+ case 3:
753
+ e_6 = _a.sent();
754
+ throw e_6;
755
+
756
+ case 4:
757
+ return [2
758
+ /*return*/
759
+ ];
760
+ }
761
+ });
762
+ });
763
+ };
764
+
765
+ NCloudChat.prototype.getMessage = function (channelId, messageId) {
766
+ return __awaiter(this, void 0, void 0, function () {
767
+ var entry, e_7;
768
+ return __generator(this, function (_a) {
769
+ switch (_a.label) {
770
+ case 0:
771
+ if (!this.isConnected()) {
772
+ throw Error("You are not connected.");
773
+ }
774
+
775
+ _a.label = 1;
776
+
777
+ case 1:
778
+ _a.trys.push([1, 3,, 4]);
779
+
780
+ return [4
781
+ /*yield*/
782
+ , (0, _queries.getMessage)(channelId, messageId)];
783
+
784
+ case 2:
785
+ entry = _a.sent();
786
+
787
+ if (entry) {
788
+ entry.id = this.ObjectId(entry.id);
789
+ return [2
790
+ /*return*/
791
+ , entry];
792
+ }
793
+
794
+ return [2
795
+ /*return*/
796
+ , null];
797
+
798
+ case 3:
799
+ e_7 = _a.sent();
800
+ throw e_7;
801
+
802
+ case 4:
803
+ return [2
804
+ /*return*/
805
+ ];
806
+ }
807
+ });
808
+ });
809
+ };
810
+
811
+ NCloudChat.prototype.getMessages = function (filter, sort, option) {
812
+ return __awaiter(this, void 0, void 0, function () {
813
+ var entries, messages, e_8;
814
+
815
+ var _this = this;
816
+
817
+ return __generator(this, function (_a) {
818
+ switch (_a.label) {
819
+ case 0:
820
+ if (!this.isConnected()) {
821
+ throw Error("You are not connected.");
822
+ }
823
+
824
+ _a.label = 1;
825
+
826
+ case 1:
827
+ _a.trys.push([1, 3,, 4]);
828
+
829
+ return [4
830
+ /*yield*/
831
+ , (0, _queries.getMessages)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
832
+
833
+ case 2:
834
+ entries = _a.sent();
835
+
836
+ if (entries) {
837
+ messages = entries.map(function (item) {
838
+ return __assign(__assign({}, item.node), {
839
+ id: _this.ObjectId(item.node.id)
840
+ });
841
+ });
842
+ return [2
843
+ /*return*/
844
+ , messages];
845
+ }
846
+
847
+ return [2
848
+ /*return*/
849
+ , entries];
850
+
851
+ case 3:
852
+ e_8 = _a.sent();
853
+ throw e_8;
854
+
855
+ case 4:
856
+ return [2
857
+ /*return*/
858
+ ];
859
+ }
860
+ });
861
+ });
862
+ };
863
+
864
+ NCloudChat.prototype.getSubscriptions = function (filter, sort, option) {
865
+ return __awaiter(this, void 0, void 0, function () {
866
+ var entries, subscribes, e_9;
867
+
868
+ var _this = this;
869
+
870
+ return __generator(this, function (_a) {
871
+ switch (_a.label) {
872
+ case 0:
873
+ if (!this.isConnected()) {
874
+ throw Error("You are not connected.");
875
+ }
876
+
877
+ _a.label = 1;
878
+
879
+ case 1:
880
+ _a.trys.push([1, 3,, 4]);
881
+
882
+ return [4
883
+ /*yield*/
884
+ , (0, _queries.getSubscriptions)((0, _stringify["default"])(filter), (0, _stringify["default"])(sort), (0, _stringify["default"])(option))];
885
+
886
+ case 2:
887
+ entries = _a.sent();
888
+
889
+ if (entries) {
890
+ subscribes = entries.map(function (item) {
891
+ return __assign(__assign({}, item.node), {
892
+ id: _this.ObjectId(item.node.id)
893
+ });
894
+ });
895
+ return [2
896
+ /*return*/
897
+ , subscribes];
898
+ }
899
+
900
+ return [2
901
+ /*return*/
902
+ , entries];
903
+
904
+ case 3:
905
+ e_9 = _a.sent();
906
+ throw e_9;
907
+
908
+ case 4:
909
+ return [2
910
+ /*return*/
911
+ ];
912
+ }
913
+ });
914
+ });
915
+ };
916
+
917
+ NCloudChat.prototype.createChannel = function (channel) {
918
+ return __awaiter(this, void 0, void 0, function () {
919
+ var e_10;
920
+ return __generator(this, function (_a) {
921
+ switch (_a.label) {
922
+ case 0:
923
+ if (!this.isConnected()) {
924
+ throw Error("You are not connected.");
925
+ }
926
+
927
+ _a.label = 1;
928
+
929
+ case 1:
930
+ _a.trys.push([1, 3,, 4]);
931
+
932
+ return [4
933
+ /*yield*/
934
+ , (0, _mutations.createChannel)(channel)];
935
+
936
+ case 2:
937
+ return [2
938
+ /*return*/
939
+ , _a.sent()];
940
+
941
+ case 3:
942
+ e_10 = _a.sent();
943
+ throw e_10;
944
+
945
+ case 4:
946
+ return [2
947
+ /*return*/
948
+ ];
949
+ }
950
+ });
951
+ });
952
+ };
953
+
954
+ NCloudChat.prototype.deleteChannel = function (channelId) {
955
+ return __awaiter(this, void 0, void 0, function () {
956
+ var e_11;
957
+ return __generator(this, function (_a) {
958
+ switch (_a.label) {
959
+ case 0:
960
+ if (!this.isConnected()) {
961
+ throw Error("You are not connected.");
962
+ }
963
+
964
+ _a.label = 1;
965
+
966
+ case 1:
967
+ _a.trys.push([1, 3,, 4]);
968
+
969
+ return [4
970
+ /*yield*/
971
+ , (0, _mutations.deleteChannel)(channelId)];
972
+
973
+ case 2:
974
+ return [2
975
+ /*return*/
976
+ , _a.sent()];
977
+
978
+ case 3:
979
+ e_11 = _a.sent();
980
+ throw e_11;
981
+
982
+ case 4:
983
+ return [2
984
+ /*return*/
985
+ ];
986
+ }
987
+ });
988
+ });
989
+ };
990
+
991
+ NCloudChat.prototype.markRead = function (channelId, mark) {
992
+ return __awaiter(this, void 0, void 0, function () {
993
+ var e_12;
994
+ return __generator(this, function (_a) {
995
+ switch (_a.label) {
996
+ case 0:
997
+ if (!this.isConnected()) {
998
+ throw Error("You are not connected.");
999
+ }
1000
+
1001
+ _a.label = 1;
1002
+
1003
+ case 1:
1004
+ _a.trys.push([1, 3,, 4]);
1005
+
1006
+ return [4
1007
+ /*yield*/
1008
+ , (0, _mutations.updateSubscription)(channelId, mark)];
1009
+
1010
+ case 2:
1011
+ return [2
1012
+ /*return*/
1013
+ , _a.sent()];
1014
+
1015
+ case 3:
1016
+ e_12 = _a.sent();
1017
+ throw e_12;
1018
+
1019
+ case 4:
1020
+ return [2
1021
+ /*return*/
1022
+ ];
1023
+ }
1024
+ });
1025
+ });
1026
+ };
1027
+
1028
+ return NCloudChat;
1029
+ }();
1030
+
1031
+ var _default = NCloudChat;
1032
+ exports["default"] = _default;