1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var protobufLight = _interopDefault(require('protobufjs/dist/protobuf-light'));
|
8 | var EventEmitter = _interopDefault(require('eventemitter3'));
|
9 | var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
|
10 | var _toConsumableArray = _interopDefault(require('@babel/runtime/helpers/toConsumableArray'));
|
11 | var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
|
12 | var _objectWithoutProperties = _interopDefault(require('@babel/runtime/helpers/objectWithoutProperties'));
|
13 | var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
|
14 | var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
|
15 | var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
|
16 | var d = _interopDefault(require('debug'));
|
17 | var shuffle = _interopDefault(require('lodash/shuffle'));
|
18 | var values = _interopDefault(require('lodash/values'));
|
19 | var _toArray = _interopDefault(require('@babel/runtime/helpers/toArray'));
|
20 | var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass'));
|
21 | var _applyDecoratedDescriptor = _interopDefault(require('@babel/runtime/helpers/applyDecoratedDescriptor'));
|
22 | var StateMachine = _interopDefault(require('javascript-state-machine'));
|
23 | var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof'));
|
24 | var isPlainObject = _interopDefault(require('lodash/isPlainObject'));
|
25 | var promiseTimeout = require('promise-timeout');
|
26 |
|
27 | var messageCompiled = protobufLight.newBuilder({})['import']({
|
28 | "package": 'push_server.messages2',
|
29 | syntax: 'proto2',
|
30 | options: {
|
31 | objc_class_prefix: 'AVIM'
|
32 | },
|
33 | messages: [{
|
34 | name: 'JsonObjectMessage',
|
35 | syntax: 'proto2',
|
36 | fields: [{
|
37 | rule: 'required',
|
38 | type: 'string',
|
39 | name: 'data',
|
40 | id: 1
|
41 | }]
|
42 | }, {
|
43 | name: 'UnreadTuple',
|
44 | syntax: 'proto2',
|
45 | fields: [{
|
46 | rule: 'required',
|
47 | type: 'string',
|
48 | name: 'cid',
|
49 | id: 1
|
50 | }, {
|
51 | rule: 'required',
|
52 | type: 'int32',
|
53 | name: 'unread',
|
54 | id: 2
|
55 | }, {
|
56 | rule: 'optional',
|
57 | type: 'string',
|
58 | name: 'mid',
|
59 | id: 3
|
60 | }, {
|
61 | rule: 'optional',
|
62 | type: 'int64',
|
63 | name: 'timestamp',
|
64 | id: 4
|
65 | }, {
|
66 | rule: 'optional',
|
67 | type: 'string',
|
68 | name: 'from',
|
69 | id: 5
|
70 | }, {
|
71 | rule: 'optional',
|
72 | type: 'string',
|
73 | name: 'data',
|
74 | id: 6
|
75 | }, {
|
76 | rule: 'optional',
|
77 | type: 'int64',
|
78 | name: 'patchTimestamp',
|
79 | id: 7
|
80 | }, {
|
81 | rule: 'optional',
|
82 | type: 'bool',
|
83 | name: 'mentioned',
|
84 | id: 8
|
85 | }, {
|
86 | rule: 'optional',
|
87 | type: 'bytes',
|
88 | name: 'binaryMsg',
|
89 | id: 9
|
90 | }, {
|
91 | rule: 'optional',
|
92 | type: 'int32',
|
93 | name: 'convType',
|
94 | id: 10
|
95 | }]
|
96 | }, {
|
97 | name: 'LogItem',
|
98 | syntax: 'proto2',
|
99 | fields: [{
|
100 | rule: 'optional',
|
101 | type: 'string',
|
102 | name: 'from',
|
103 | id: 1
|
104 | }, {
|
105 | rule: 'optional',
|
106 | type: 'string',
|
107 | name: 'data',
|
108 | id: 2
|
109 | }, {
|
110 | rule: 'optional',
|
111 | type: 'int64',
|
112 | name: 'timestamp',
|
113 | id: 3
|
114 | }, {
|
115 | rule: 'optional',
|
116 | type: 'string',
|
117 | name: 'msgId',
|
118 | id: 4
|
119 | }, {
|
120 | rule: 'optional',
|
121 | type: 'int64',
|
122 | name: 'ackAt',
|
123 | id: 5
|
124 | }, {
|
125 | rule: 'optional',
|
126 | type: 'int64',
|
127 | name: 'readAt',
|
128 | id: 6
|
129 | }, {
|
130 | rule: 'optional',
|
131 | type: 'int64',
|
132 | name: 'patchTimestamp',
|
133 | id: 7
|
134 | }, {
|
135 | rule: 'optional',
|
136 | type: 'bool',
|
137 | name: 'mentionAll',
|
138 | id: 8
|
139 | }, {
|
140 | rule: 'repeated',
|
141 | type: 'string',
|
142 | name: 'mentionPids',
|
143 | id: 9
|
144 | }, {
|
145 | rule: 'optional',
|
146 | type: 'bool',
|
147 | name: 'bin',
|
148 | id: 10
|
149 | }, {
|
150 | rule: 'optional',
|
151 | type: 'int32',
|
152 | name: 'convType',
|
153 | id: 11
|
154 | }]
|
155 | }, {
|
156 | name: 'ConvMemberInfo',
|
157 | syntax: 'proto2',
|
158 | fields: [{
|
159 | rule: 'optional',
|
160 | type: 'string',
|
161 | name: 'pid',
|
162 | id: 1
|
163 | }, {
|
164 | rule: 'optional',
|
165 | type: 'string',
|
166 | name: 'role',
|
167 | id: 2
|
168 | }, {
|
169 | rule: 'optional',
|
170 | type: 'string',
|
171 | name: 'infoId',
|
172 | id: 3
|
173 | }]
|
174 | }, {
|
175 | name: 'DataCommand',
|
176 | syntax: 'proto2',
|
177 | fields: [{
|
178 | rule: 'repeated',
|
179 | type: 'string',
|
180 | name: 'ids',
|
181 | id: 1
|
182 | }, {
|
183 | rule: 'repeated',
|
184 | type: 'JsonObjectMessage',
|
185 | name: 'msg',
|
186 | id: 2
|
187 | }, {
|
188 | rule: 'optional',
|
189 | type: 'bool',
|
190 | name: 'offline',
|
191 | id: 3
|
192 | }]
|
193 | }, {
|
194 | name: 'SessionCommand',
|
195 | syntax: 'proto2',
|
196 | fields: [{
|
197 | rule: 'optional',
|
198 | type: 'int64',
|
199 | name: 't',
|
200 | id: 1
|
201 | }, {
|
202 | rule: 'optional',
|
203 | type: 'string',
|
204 | name: 'n',
|
205 | id: 2
|
206 | }, {
|
207 | rule: 'optional',
|
208 | type: 'string',
|
209 | name: 's',
|
210 | id: 3
|
211 | }, {
|
212 | rule: 'optional',
|
213 | type: 'string',
|
214 | name: 'ua',
|
215 | id: 4
|
216 | }, {
|
217 | rule: 'optional',
|
218 | type: 'bool',
|
219 | name: 'r',
|
220 | id: 5
|
221 | }, {
|
222 | rule: 'optional',
|
223 | type: 'string',
|
224 | name: 'tag',
|
225 | id: 6
|
226 | }, {
|
227 | rule: 'optional',
|
228 | type: 'string',
|
229 | name: 'deviceId',
|
230 | id: 7
|
231 | }, {
|
232 | rule: 'repeated',
|
233 | type: 'string',
|
234 | name: 'sessionPeerIds',
|
235 | id: 8
|
236 | }, {
|
237 | rule: 'repeated',
|
238 | type: 'string',
|
239 | name: 'onlineSessionPeerIds',
|
240 | id: 9
|
241 | }, {
|
242 | rule: 'optional',
|
243 | type: 'string',
|
244 | name: 'st',
|
245 | id: 10
|
246 | }, {
|
247 | rule: 'optional',
|
248 | type: 'int32',
|
249 | name: 'stTtl',
|
250 | id: 11
|
251 | }, {
|
252 | rule: 'optional',
|
253 | type: 'int32',
|
254 | name: 'code',
|
255 | id: 12
|
256 | }, {
|
257 | rule: 'optional',
|
258 | type: 'string',
|
259 | name: 'reason',
|
260 | id: 13
|
261 | }, {
|
262 | rule: 'optional',
|
263 | type: 'string',
|
264 | name: 'deviceToken',
|
265 | id: 14
|
266 | }, {
|
267 | rule: 'optional',
|
268 | type: 'bool',
|
269 | name: 'sp',
|
270 | id: 15
|
271 | }, {
|
272 | rule: 'optional',
|
273 | type: 'string',
|
274 | name: 'detail',
|
275 | id: 16
|
276 | }, {
|
277 | rule: 'optional',
|
278 | type: 'int64',
|
279 | name: 'lastUnreadNotifTime',
|
280 | id: 17
|
281 | }, {
|
282 | rule: 'optional',
|
283 | type: 'int64',
|
284 | name: 'lastPatchTime',
|
285 | id: 18
|
286 | }, {
|
287 | rule: 'optional',
|
288 | type: 'int64',
|
289 | name: 'configBitmap',
|
290 | id: 19
|
291 | }]
|
292 | }, {
|
293 | name: 'ErrorCommand',
|
294 | syntax: 'proto2',
|
295 | fields: [{
|
296 | rule: 'required',
|
297 | type: 'int32',
|
298 | name: 'code',
|
299 | id: 1
|
300 | }, {
|
301 | rule: 'required',
|
302 | type: 'string',
|
303 | name: 'reason',
|
304 | id: 2
|
305 | }, {
|
306 | rule: 'optional',
|
307 | type: 'int32',
|
308 | name: 'appCode',
|
309 | id: 3
|
310 | }, {
|
311 | rule: 'optional',
|
312 | type: 'string',
|
313 | name: 'detail',
|
314 | id: 4
|
315 | }, {
|
316 | rule: 'repeated',
|
317 | type: 'string',
|
318 | name: 'pids',
|
319 | id: 5
|
320 | }, {
|
321 | rule: 'optional',
|
322 | type: 'string',
|
323 | name: 'appMsg',
|
324 | id: 6
|
325 | }]
|
326 | }, {
|
327 | name: 'DirectCommand',
|
328 | syntax: 'proto2',
|
329 | fields: [{
|
330 | rule: 'optional',
|
331 | type: 'string',
|
332 | name: 'msg',
|
333 | id: 1
|
334 | }, {
|
335 | rule: 'optional',
|
336 | type: 'string',
|
337 | name: 'uid',
|
338 | id: 2
|
339 | }, {
|
340 | rule: 'optional',
|
341 | type: 'string',
|
342 | name: 'fromPeerId',
|
343 | id: 3
|
344 | }, {
|
345 | rule: 'optional',
|
346 | type: 'int64',
|
347 | name: 'timestamp',
|
348 | id: 4
|
349 | }, {
|
350 | rule: 'optional',
|
351 | type: 'bool',
|
352 | name: 'offline',
|
353 | id: 5
|
354 | }, {
|
355 | rule: 'optional',
|
356 | type: 'bool',
|
357 | name: 'hasMore',
|
358 | id: 6
|
359 | }, {
|
360 | rule: 'repeated',
|
361 | type: 'string',
|
362 | name: 'toPeerIds',
|
363 | id: 7
|
364 | }, {
|
365 | rule: 'optional',
|
366 | type: 'bool',
|
367 | name: 'r',
|
368 | id: 10
|
369 | }, {
|
370 | rule: 'optional',
|
371 | type: 'string',
|
372 | name: 'cid',
|
373 | id: 11
|
374 | }, {
|
375 | rule: 'optional',
|
376 | type: 'string',
|
377 | name: 'id',
|
378 | id: 12
|
379 | }, {
|
380 | rule: 'optional',
|
381 | type: 'bool',
|
382 | name: 'transient',
|
383 | id: 13
|
384 | }, {
|
385 | rule: 'optional',
|
386 | type: 'string',
|
387 | name: 'dt',
|
388 | id: 14
|
389 | }, {
|
390 | rule: 'optional',
|
391 | type: 'string',
|
392 | name: 'roomId',
|
393 | id: 15
|
394 | }, {
|
395 | rule: 'optional',
|
396 | type: 'string',
|
397 | name: 'pushData',
|
398 | id: 16
|
399 | }, {
|
400 | rule: 'optional',
|
401 | type: 'bool',
|
402 | name: 'will',
|
403 | id: 17
|
404 | }, {
|
405 | rule: 'optional',
|
406 | type: 'int64',
|
407 | name: 'patchTimestamp',
|
408 | id: 18
|
409 | }, {
|
410 | rule: 'optional',
|
411 | type: 'bytes',
|
412 | name: 'binaryMsg',
|
413 | id: 19
|
414 | }, {
|
415 | rule: 'repeated',
|
416 | type: 'string',
|
417 | name: 'mentionPids',
|
418 | id: 20
|
419 | }, {
|
420 | rule: 'optional',
|
421 | type: 'bool',
|
422 | name: 'mentionAll',
|
423 | id: 21
|
424 | }, {
|
425 | rule: 'optional',
|
426 | type: 'int32',
|
427 | name: 'convType',
|
428 | id: 22
|
429 | }]
|
430 | }, {
|
431 | name: 'AckCommand',
|
432 | syntax: 'proto2',
|
433 | fields: [{
|
434 | rule: 'optional',
|
435 | type: 'int32',
|
436 | name: 'code',
|
437 | id: 1
|
438 | }, {
|
439 | rule: 'optional',
|
440 | type: 'string',
|
441 | name: 'reason',
|
442 | id: 2
|
443 | }, {
|
444 | rule: 'optional',
|
445 | type: 'string',
|
446 | name: 'mid',
|
447 | id: 3
|
448 | }, {
|
449 | rule: 'optional',
|
450 | type: 'string',
|
451 | name: 'cid',
|
452 | id: 4
|
453 | }, {
|
454 | rule: 'optional',
|
455 | type: 'int64',
|
456 | name: 't',
|
457 | id: 5
|
458 | }, {
|
459 | rule: 'optional',
|
460 | type: 'string',
|
461 | name: 'uid',
|
462 | id: 6
|
463 | }, {
|
464 | rule: 'optional',
|
465 | type: 'int64',
|
466 | name: 'fromts',
|
467 | id: 7
|
468 | }, {
|
469 | rule: 'optional',
|
470 | type: 'int64',
|
471 | name: 'tots',
|
472 | id: 8
|
473 | }, {
|
474 | rule: 'optional',
|
475 | type: 'string',
|
476 | name: 'type',
|
477 | id: 9
|
478 | }, {
|
479 | rule: 'repeated',
|
480 | type: 'string',
|
481 | name: 'ids',
|
482 | id: 10
|
483 | }, {
|
484 | rule: 'optional',
|
485 | type: 'int32',
|
486 | name: 'appCode',
|
487 | id: 11
|
488 | }, {
|
489 | rule: 'optional',
|
490 | type: 'string',
|
491 | name: 'appMsg',
|
492 | id: 12
|
493 | }]
|
494 | }, {
|
495 | name: 'UnreadCommand',
|
496 | syntax: 'proto2',
|
497 | fields: [{
|
498 | rule: 'repeated',
|
499 | type: 'UnreadTuple',
|
500 | name: 'convs',
|
501 | id: 1
|
502 | }, {
|
503 | rule: 'optional',
|
504 | type: 'int64',
|
505 | name: 'notifTime',
|
506 | id: 2
|
507 | }]
|
508 | }, {
|
509 | name: 'ConvCommand',
|
510 | syntax: 'proto2',
|
511 | fields: [{
|
512 | rule: 'repeated',
|
513 | type: 'string',
|
514 | name: 'm',
|
515 | id: 1
|
516 | }, {
|
517 | rule: 'optional',
|
518 | type: 'bool',
|
519 | name: 'transient',
|
520 | id: 2
|
521 | }, {
|
522 | rule: 'optional',
|
523 | type: 'bool',
|
524 | name: 'unique',
|
525 | id: 3
|
526 | }, {
|
527 | rule: 'optional',
|
528 | type: 'string',
|
529 | name: 'cid',
|
530 | id: 4
|
531 | }, {
|
532 | rule: 'optional',
|
533 | type: 'string',
|
534 | name: 'cdate',
|
535 | id: 5
|
536 | }, {
|
537 | rule: 'optional',
|
538 | type: 'string',
|
539 | name: 'initBy',
|
540 | id: 6
|
541 | }, {
|
542 | rule: 'optional',
|
543 | type: 'string',
|
544 | name: 'sort',
|
545 | id: 7
|
546 | }, {
|
547 | rule: 'optional',
|
548 | type: 'int32',
|
549 | name: 'limit',
|
550 | id: 8
|
551 | }, {
|
552 | rule: 'optional',
|
553 | type: 'int32',
|
554 | name: 'skip',
|
555 | id: 9
|
556 | }, {
|
557 | rule: 'optional',
|
558 | type: 'int32',
|
559 | name: 'flag',
|
560 | id: 10
|
561 | }, {
|
562 | rule: 'optional',
|
563 | type: 'int32',
|
564 | name: 'count',
|
565 | id: 11
|
566 | }, {
|
567 | rule: 'optional',
|
568 | type: 'string',
|
569 | name: 'udate',
|
570 | id: 12
|
571 | }, {
|
572 | rule: 'optional',
|
573 | type: 'int64',
|
574 | name: 't',
|
575 | id: 13
|
576 | }, {
|
577 | rule: 'optional',
|
578 | type: 'string',
|
579 | name: 'n',
|
580 | id: 14
|
581 | }, {
|
582 | rule: 'optional',
|
583 | type: 'string',
|
584 | name: 's',
|
585 | id: 15
|
586 | }, {
|
587 | rule: 'optional',
|
588 | type: 'bool',
|
589 | name: 'statusSub',
|
590 | id: 16
|
591 | }, {
|
592 | rule: 'optional',
|
593 | type: 'bool',
|
594 | name: 'statusPub',
|
595 | id: 17
|
596 | }, {
|
597 | rule: 'optional',
|
598 | type: 'int32',
|
599 | name: 'statusTTL',
|
600 | id: 18
|
601 | }, {
|
602 | rule: 'optional',
|
603 | type: 'string',
|
604 | name: 'uniqueId',
|
605 | id: 19
|
606 | }, {
|
607 | rule: 'optional',
|
608 | type: 'string',
|
609 | name: 'targetClientId',
|
610 | id: 20
|
611 | }, {
|
612 | rule: 'optional',
|
613 | type: 'int64',
|
614 | name: 'maxReadTimestamp',
|
615 | id: 21
|
616 | }, {
|
617 | rule: 'optional',
|
618 | type: 'int64',
|
619 | name: 'maxAckTimestamp',
|
620 | id: 22
|
621 | }, {
|
622 | rule: 'optional',
|
623 | type: 'bool',
|
624 | name: 'queryAllMembers',
|
625 | id: 23
|
626 | }, {
|
627 | rule: 'repeated',
|
628 | type: 'MaxReadTuple',
|
629 | name: 'maxReadTuples',
|
630 | id: 24
|
631 | }, {
|
632 | rule: 'repeated',
|
633 | type: 'string',
|
634 | name: 'cids',
|
635 | id: 25
|
636 | }, {
|
637 | rule: 'optional',
|
638 | type: 'ConvMemberInfo',
|
639 | name: 'info',
|
640 | id: 26
|
641 | }, {
|
642 | rule: 'optional',
|
643 | type: 'bool',
|
644 | name: 'tempConv',
|
645 | id: 27
|
646 | }, {
|
647 | rule: 'optional',
|
648 | type: 'int32',
|
649 | name: 'tempConvTTL',
|
650 | id: 28
|
651 | }, {
|
652 | rule: 'repeated',
|
653 | type: 'string',
|
654 | name: 'tempConvIds',
|
655 | id: 29
|
656 | }, {
|
657 | rule: 'repeated',
|
658 | type: 'string',
|
659 | name: 'allowedPids',
|
660 | id: 30
|
661 | }, {
|
662 | rule: 'repeated',
|
663 | type: 'ErrorCommand',
|
664 | name: 'failedPids',
|
665 | id: 31
|
666 | }, {
|
667 | rule: 'optional',
|
668 | type: 'string',
|
669 | name: 'next',
|
670 | id: 40
|
671 | }, {
|
672 | rule: 'optional',
|
673 | type: 'JsonObjectMessage',
|
674 | name: 'results',
|
675 | id: 100
|
676 | }, {
|
677 | rule: 'optional',
|
678 | type: 'JsonObjectMessage',
|
679 | name: 'where',
|
680 | id: 101
|
681 | }, {
|
682 | rule: 'optional',
|
683 | type: 'JsonObjectMessage',
|
684 | name: 'attr',
|
685 | id: 103
|
686 | }, {
|
687 | rule: 'optional',
|
688 | type: 'JsonObjectMessage',
|
689 | name: 'attrModified',
|
690 | id: 104
|
691 | }]
|
692 | }, {
|
693 | name: 'RoomCommand',
|
694 | syntax: 'proto2',
|
695 | fields: [{
|
696 | rule: 'optional',
|
697 | type: 'string',
|
698 | name: 'roomId',
|
699 | id: 1
|
700 | }, {
|
701 | rule: 'optional',
|
702 | type: 'string',
|
703 | name: 's',
|
704 | id: 2
|
705 | }, {
|
706 | rule: 'optional',
|
707 | type: 'int64',
|
708 | name: 't',
|
709 | id: 3
|
710 | }, {
|
711 | rule: 'optional',
|
712 | type: 'string',
|
713 | name: 'n',
|
714 | id: 4
|
715 | }, {
|
716 | rule: 'optional',
|
717 | type: 'bool',
|
718 | name: 'transient',
|
719 | id: 5
|
720 | }, {
|
721 | rule: 'repeated',
|
722 | type: 'string',
|
723 | name: 'roomPeerIds',
|
724 | id: 6
|
725 | }, {
|
726 | rule: 'optional',
|
727 | type: 'string',
|
728 | name: 'byPeerId',
|
729 | id: 7
|
730 | }]
|
731 | }, {
|
732 | name: 'LogsCommand',
|
733 | syntax: 'proto2',
|
734 | fields: [{
|
735 | rule: 'optional',
|
736 | type: 'string',
|
737 | name: 'cid',
|
738 | id: 1
|
739 | }, {
|
740 | rule: 'optional',
|
741 | type: 'int32',
|
742 | name: 'l',
|
743 | id: 2
|
744 | }, {
|
745 | rule: 'optional',
|
746 | type: 'int32',
|
747 | name: 'limit',
|
748 | id: 3
|
749 | }, {
|
750 | rule: 'optional',
|
751 | type: 'int64',
|
752 | name: 't',
|
753 | id: 4
|
754 | }, {
|
755 | rule: 'optional',
|
756 | type: 'int64',
|
757 | name: 'tt',
|
758 | id: 5
|
759 | }, {
|
760 | rule: 'optional',
|
761 | type: 'string',
|
762 | name: 'tmid',
|
763 | id: 6
|
764 | }, {
|
765 | rule: 'optional',
|
766 | type: 'string',
|
767 | name: 'mid',
|
768 | id: 7
|
769 | }, {
|
770 | rule: 'optional',
|
771 | type: 'string',
|
772 | name: 'checksum',
|
773 | id: 8
|
774 | }, {
|
775 | rule: 'optional',
|
776 | type: 'bool',
|
777 | name: 'stored',
|
778 | id: 9
|
779 | }, {
|
780 | rule: 'optional',
|
781 | type: 'QueryDirection',
|
782 | name: 'direction',
|
783 | id: 10,
|
784 | options: {
|
785 | "default": 'OLD'
|
786 | }
|
787 | }, {
|
788 | rule: 'optional',
|
789 | type: 'bool',
|
790 | name: 'tIncluded',
|
791 | id: 11
|
792 | }, {
|
793 | rule: 'optional',
|
794 | type: 'bool',
|
795 | name: 'ttIncluded',
|
796 | id: 12
|
797 | }, {
|
798 | rule: 'optional',
|
799 | type: 'int32',
|
800 | name: 'lctype',
|
801 | id: 13
|
802 | }, {
|
803 | rule: 'repeated',
|
804 | type: 'LogItem',
|
805 | name: 'logs',
|
806 | id: 105
|
807 | }],
|
808 | enums: [{
|
809 | name: 'QueryDirection',
|
810 | syntax: 'proto2',
|
811 | values: [{
|
812 | name: 'OLD',
|
813 | id: 1
|
814 | }, {
|
815 | name: 'NEW',
|
816 | id: 2
|
817 | }]
|
818 | }]
|
819 | }, {
|
820 | name: 'RcpCommand',
|
821 | syntax: 'proto2',
|
822 | fields: [{
|
823 | rule: 'optional',
|
824 | type: 'string',
|
825 | name: 'id',
|
826 | id: 1
|
827 | }, {
|
828 | rule: 'optional',
|
829 | type: 'string',
|
830 | name: 'cid',
|
831 | id: 2
|
832 | }, {
|
833 | rule: 'optional',
|
834 | type: 'int64',
|
835 | name: 't',
|
836 | id: 3
|
837 | }, {
|
838 | rule: 'optional',
|
839 | type: 'bool',
|
840 | name: 'read',
|
841 | id: 4
|
842 | }, {
|
843 | rule: 'optional',
|
844 | type: 'string',
|
845 | name: 'from',
|
846 | id: 5
|
847 | }]
|
848 | }, {
|
849 | name: 'ReadTuple',
|
850 | syntax: 'proto2',
|
851 | fields: [{
|
852 | rule: 'required',
|
853 | type: 'string',
|
854 | name: 'cid',
|
855 | id: 1
|
856 | }, {
|
857 | rule: 'optional',
|
858 | type: 'int64',
|
859 | name: 'timestamp',
|
860 | id: 2
|
861 | }, {
|
862 | rule: 'optional',
|
863 | type: 'string',
|
864 | name: 'mid',
|
865 | id: 3
|
866 | }]
|
867 | }, {
|
868 | name: 'MaxReadTuple',
|
869 | syntax: 'proto2',
|
870 | fields: [{
|
871 | rule: 'optional',
|
872 | type: 'string',
|
873 | name: 'pid',
|
874 | id: 1
|
875 | }, {
|
876 | rule: 'optional',
|
877 | type: 'int64',
|
878 | name: 'maxAckTimestamp',
|
879 | id: 2
|
880 | }, {
|
881 | rule: 'optional',
|
882 | type: 'int64',
|
883 | name: 'maxReadTimestamp',
|
884 | id: 3
|
885 | }]
|
886 | }, {
|
887 | name: 'ReadCommand',
|
888 | syntax: 'proto2',
|
889 | fields: [{
|
890 | rule: 'optional',
|
891 | type: 'string',
|
892 | name: 'cid',
|
893 | id: 1
|
894 | }, {
|
895 | rule: 'repeated',
|
896 | type: 'string',
|
897 | name: 'cids',
|
898 | id: 2
|
899 | }, {
|
900 | rule: 'repeated',
|
901 | type: 'ReadTuple',
|
902 | name: 'convs',
|
903 | id: 3
|
904 | }]
|
905 | }, {
|
906 | name: 'PresenceCommand',
|
907 | syntax: 'proto2',
|
908 | fields: [{
|
909 | rule: 'optional',
|
910 | type: 'StatusType',
|
911 | name: 'status',
|
912 | id: 1
|
913 | }, {
|
914 | rule: 'repeated',
|
915 | type: 'string',
|
916 | name: 'sessionPeerIds',
|
917 | id: 2
|
918 | }, {
|
919 | rule: 'optional',
|
920 | type: 'string',
|
921 | name: 'cid',
|
922 | id: 3
|
923 | }]
|
924 | }, {
|
925 | name: 'ReportCommand',
|
926 | syntax: 'proto2',
|
927 | fields: [{
|
928 | rule: 'optional',
|
929 | type: 'bool',
|
930 | name: 'initiative',
|
931 | id: 1
|
932 | }, {
|
933 | rule: 'optional',
|
934 | type: 'string',
|
935 | name: 'type',
|
936 | id: 2
|
937 | }, {
|
938 | rule: 'optional',
|
939 | type: 'string',
|
940 | name: 'data',
|
941 | id: 3
|
942 | }]
|
943 | }, {
|
944 | name: 'PatchItem',
|
945 | syntax: 'proto2',
|
946 | fields: [{
|
947 | rule: 'optional',
|
948 | type: 'string',
|
949 | name: 'cid',
|
950 | id: 1
|
951 | }, {
|
952 | rule: 'optional',
|
953 | type: 'string',
|
954 | name: 'mid',
|
955 | id: 2
|
956 | }, {
|
957 | rule: 'optional',
|
958 | type: 'int64',
|
959 | name: 'timestamp',
|
960 | id: 3
|
961 | }, {
|
962 | rule: 'optional',
|
963 | type: 'bool',
|
964 | name: 'recall',
|
965 | id: 4
|
966 | }, {
|
967 | rule: 'optional',
|
968 | type: 'string',
|
969 | name: 'data',
|
970 | id: 5
|
971 | }, {
|
972 | rule: 'optional',
|
973 | type: 'int64',
|
974 | name: 'patchTimestamp',
|
975 | id: 6
|
976 | }, {
|
977 | rule: 'optional',
|
978 | type: 'string',
|
979 | name: 'from',
|
980 | id: 7
|
981 | }, {
|
982 | rule: 'optional',
|
983 | type: 'bytes',
|
984 | name: 'binaryMsg',
|
985 | id: 8
|
986 | }, {
|
987 | rule: 'optional',
|
988 | type: 'bool',
|
989 | name: 'mentionAll',
|
990 | id: 9
|
991 | }, {
|
992 | rule: 'repeated',
|
993 | type: 'string',
|
994 | name: 'mentionPids',
|
995 | id: 10
|
996 | }, {
|
997 | rule: 'optional',
|
998 | type: 'int64',
|
999 | name: 'patchCode',
|
1000 | id: 11
|
1001 | }, {
|
1002 | rule: 'optional',
|
1003 | type: 'string',
|
1004 | name: 'patchReason',
|
1005 | id: 12
|
1006 | }]
|
1007 | }, {
|
1008 | name: 'PatchCommand',
|
1009 | syntax: 'proto2',
|
1010 | fields: [{
|
1011 | rule: 'repeated',
|
1012 | type: 'PatchItem',
|
1013 | name: 'patches',
|
1014 | id: 1
|
1015 | }, {
|
1016 | rule: 'optional',
|
1017 | type: 'int64',
|
1018 | name: 'lastPatchTime',
|
1019 | id: 2
|
1020 | }]
|
1021 | }, {
|
1022 | name: 'PubsubCommand',
|
1023 | syntax: 'proto2',
|
1024 | fields: [{
|
1025 | rule: 'optional',
|
1026 | type: 'string',
|
1027 | name: 'cid',
|
1028 | id: 1
|
1029 | }, {
|
1030 | rule: 'repeated',
|
1031 | type: 'string',
|
1032 | name: 'cids',
|
1033 | id: 2
|
1034 | }, {
|
1035 | rule: 'optional',
|
1036 | type: 'string',
|
1037 | name: 'topic',
|
1038 | id: 3
|
1039 | }, {
|
1040 | rule: 'optional',
|
1041 | type: 'string',
|
1042 | name: 'subtopic',
|
1043 | id: 4
|
1044 | }, {
|
1045 | rule: 'repeated',
|
1046 | type: 'string',
|
1047 | name: 'topics',
|
1048 | id: 5
|
1049 | }, {
|
1050 | rule: 'repeated',
|
1051 | type: 'string',
|
1052 | name: 'subtopics',
|
1053 | id: 6
|
1054 | }, {
|
1055 | rule: 'optional',
|
1056 | type: 'JsonObjectMessage',
|
1057 | name: 'results',
|
1058 | id: 7
|
1059 | }]
|
1060 | }, {
|
1061 | name: 'BlacklistCommand',
|
1062 | syntax: 'proto2',
|
1063 | fields: [{
|
1064 | rule: 'optional',
|
1065 | type: 'string',
|
1066 | name: 'srcCid',
|
1067 | id: 1
|
1068 | }, {
|
1069 | rule: 'repeated',
|
1070 | type: 'string',
|
1071 | name: 'toPids',
|
1072 | id: 2
|
1073 | }, {
|
1074 | rule: 'optional',
|
1075 | type: 'string',
|
1076 | name: 'srcPid',
|
1077 | id: 3
|
1078 | }, {
|
1079 | rule: 'repeated',
|
1080 | type: 'string',
|
1081 | name: 'toCids',
|
1082 | id: 4
|
1083 | }, {
|
1084 | rule: 'optional',
|
1085 | type: 'int32',
|
1086 | name: 'limit',
|
1087 | id: 5
|
1088 | }, {
|
1089 | rule: 'optional',
|
1090 | type: 'string',
|
1091 | name: 'next',
|
1092 | id: 6
|
1093 | }, {
|
1094 | rule: 'repeated',
|
1095 | type: 'string',
|
1096 | name: 'blockedPids',
|
1097 | id: 8
|
1098 | }, {
|
1099 | rule: 'repeated',
|
1100 | type: 'string',
|
1101 | name: 'blockedCids',
|
1102 | id: 9
|
1103 | }, {
|
1104 | rule: 'repeated',
|
1105 | type: 'string',
|
1106 | name: 'allowedPids',
|
1107 | id: 10
|
1108 | }, {
|
1109 | rule: 'repeated',
|
1110 | type: 'ErrorCommand',
|
1111 | name: 'failedPids',
|
1112 | id: 11
|
1113 | }, {
|
1114 | rule: 'optional',
|
1115 | type: 'int64',
|
1116 | name: 't',
|
1117 | id: 12
|
1118 | }, {
|
1119 | rule: 'optional',
|
1120 | type: 'string',
|
1121 | name: 'n',
|
1122 | id: 13
|
1123 | }, {
|
1124 | rule: 'optional',
|
1125 | type: 'string',
|
1126 | name: 's',
|
1127 | id: 14
|
1128 | }]
|
1129 | }, {
|
1130 | name: 'GenericCommand',
|
1131 | syntax: 'proto2',
|
1132 | fields: [{
|
1133 | rule: 'optional',
|
1134 | type: 'CommandType',
|
1135 | name: 'cmd',
|
1136 | id: 1
|
1137 | }, {
|
1138 | rule: 'optional',
|
1139 | type: 'OpType',
|
1140 | name: 'op',
|
1141 | id: 2
|
1142 | }, {
|
1143 | rule: 'optional',
|
1144 | type: 'string',
|
1145 | name: 'appId',
|
1146 | id: 3
|
1147 | }, {
|
1148 | rule: 'optional',
|
1149 | type: 'string',
|
1150 | name: 'peerId',
|
1151 | id: 4
|
1152 | }, {
|
1153 | rule: 'optional',
|
1154 | type: 'int32',
|
1155 | name: 'i',
|
1156 | id: 5
|
1157 | }, {
|
1158 | rule: 'optional',
|
1159 | type: 'string',
|
1160 | name: 'installationId',
|
1161 | id: 6
|
1162 | }, {
|
1163 | rule: 'optional',
|
1164 | type: 'int32',
|
1165 | name: 'priority',
|
1166 | id: 7
|
1167 | }, {
|
1168 | rule: 'optional',
|
1169 | type: 'int32',
|
1170 | name: 'service',
|
1171 | id: 8
|
1172 | }, {
|
1173 | rule: 'optional',
|
1174 | type: 'int64',
|
1175 | name: 'serverTs',
|
1176 | id: 9
|
1177 | }, {
|
1178 | rule: 'optional',
|
1179 | type: 'int64',
|
1180 | name: 'clientTs',
|
1181 | id: 10
|
1182 | }, {
|
1183 | rule: 'optional',
|
1184 | type: 'int32',
|
1185 | name: 'notificationType',
|
1186 | id: 11
|
1187 | }, {
|
1188 | rule: 'optional',
|
1189 | type: 'DataCommand',
|
1190 | name: 'dataMessage',
|
1191 | id: 101
|
1192 | }, {
|
1193 | rule: 'optional',
|
1194 | type: 'SessionCommand',
|
1195 | name: 'sessionMessage',
|
1196 | id: 102
|
1197 | }, {
|
1198 | rule: 'optional',
|
1199 | type: 'ErrorCommand',
|
1200 | name: 'errorMessage',
|
1201 | id: 103
|
1202 | }, {
|
1203 | rule: 'optional',
|
1204 | type: 'DirectCommand',
|
1205 | name: 'directMessage',
|
1206 | id: 104
|
1207 | }, {
|
1208 | rule: 'optional',
|
1209 | type: 'AckCommand',
|
1210 | name: 'ackMessage',
|
1211 | id: 105
|
1212 | }, {
|
1213 | rule: 'optional',
|
1214 | type: 'UnreadCommand',
|
1215 | name: 'unreadMessage',
|
1216 | id: 106
|
1217 | }, {
|
1218 | rule: 'optional',
|
1219 | type: 'ReadCommand',
|
1220 | name: 'readMessage',
|
1221 | id: 107
|
1222 | }, {
|
1223 | rule: 'optional',
|
1224 | type: 'RcpCommand',
|
1225 | name: 'rcpMessage',
|
1226 | id: 108
|
1227 | }, {
|
1228 | rule: 'optional',
|
1229 | type: 'LogsCommand',
|
1230 | name: 'logsMessage',
|
1231 | id: 109
|
1232 | }, {
|
1233 | rule: 'optional',
|
1234 | type: 'ConvCommand',
|
1235 | name: 'convMessage',
|
1236 | id: 110
|
1237 | }, {
|
1238 | rule: 'optional',
|
1239 | type: 'RoomCommand',
|
1240 | name: 'roomMessage',
|
1241 | id: 111
|
1242 | }, {
|
1243 | rule: 'optional',
|
1244 | type: 'PresenceCommand',
|
1245 | name: 'presenceMessage',
|
1246 | id: 112
|
1247 | }, {
|
1248 | rule: 'optional',
|
1249 | type: 'ReportCommand',
|
1250 | name: 'reportMessage',
|
1251 | id: 113
|
1252 | }, {
|
1253 | rule: 'optional',
|
1254 | type: 'PatchCommand',
|
1255 | name: 'patchMessage',
|
1256 | id: 114
|
1257 | }, {
|
1258 | rule: 'optional',
|
1259 | type: 'PubsubCommand',
|
1260 | name: 'pubsubMessage',
|
1261 | id: 115
|
1262 | }, {
|
1263 | rule: 'optional',
|
1264 | type: 'BlacklistCommand',
|
1265 | name: 'blacklistMessage',
|
1266 | id: 116
|
1267 | }]
|
1268 | }],
|
1269 | enums: [{
|
1270 | name: 'CommandType',
|
1271 | syntax: 'proto2',
|
1272 | values: [{
|
1273 | name: 'session',
|
1274 | id: 0
|
1275 | }, {
|
1276 | name: 'conv',
|
1277 | id: 1
|
1278 | }, {
|
1279 | name: 'direct',
|
1280 | id: 2
|
1281 | }, {
|
1282 | name: 'ack',
|
1283 | id: 3
|
1284 | }, {
|
1285 | name: 'rcp',
|
1286 | id: 4
|
1287 | }, {
|
1288 | name: 'unread',
|
1289 | id: 5
|
1290 | }, {
|
1291 | name: 'logs',
|
1292 | id: 6
|
1293 | }, {
|
1294 | name: 'error',
|
1295 | id: 7
|
1296 | }, {
|
1297 | name: 'login',
|
1298 | id: 8
|
1299 | }, {
|
1300 | name: 'data',
|
1301 | id: 9
|
1302 | }, {
|
1303 | name: 'room',
|
1304 | id: 10
|
1305 | }, {
|
1306 | name: 'read',
|
1307 | id: 11
|
1308 | }, {
|
1309 | name: 'presence',
|
1310 | id: 12
|
1311 | }, {
|
1312 | name: 'report',
|
1313 | id: 13
|
1314 | }, {
|
1315 | name: 'echo',
|
1316 | id: 14
|
1317 | }, {
|
1318 | name: 'loggedin',
|
1319 | id: 15
|
1320 | }, {
|
1321 | name: 'logout',
|
1322 | id: 16
|
1323 | }, {
|
1324 | name: 'loggedout',
|
1325 | id: 17
|
1326 | }, {
|
1327 | name: 'patch',
|
1328 | id: 18
|
1329 | }, {
|
1330 | name: 'pubsub',
|
1331 | id: 19
|
1332 | }, {
|
1333 | name: 'blacklist',
|
1334 | id: 20
|
1335 | }, {
|
1336 | name: 'goaway',
|
1337 | id: 21
|
1338 | }]
|
1339 | }, {
|
1340 | name: 'OpType',
|
1341 | syntax: 'proto2',
|
1342 | values: [{
|
1343 | name: 'open',
|
1344 | id: 1
|
1345 | }, {
|
1346 | name: 'add',
|
1347 | id: 2
|
1348 | }, {
|
1349 | name: 'remove',
|
1350 | id: 3
|
1351 | }, {
|
1352 | name: 'close',
|
1353 | id: 4
|
1354 | }, {
|
1355 | name: 'opened',
|
1356 | id: 5
|
1357 | }, {
|
1358 | name: 'closed',
|
1359 | id: 6
|
1360 | }, {
|
1361 | name: 'query',
|
1362 | id: 7
|
1363 | }, {
|
1364 | name: 'query_result',
|
1365 | id: 8
|
1366 | }, {
|
1367 | name: 'conflict',
|
1368 | id: 9
|
1369 | }, {
|
1370 | name: 'added',
|
1371 | id: 10
|
1372 | }, {
|
1373 | name: 'removed',
|
1374 | id: 11
|
1375 | }, {
|
1376 | name: 'refresh',
|
1377 | id: 12
|
1378 | }, {
|
1379 | name: 'refreshed',
|
1380 | id: 13
|
1381 | }, {
|
1382 | name: 'start',
|
1383 | id: 30
|
1384 | }, {
|
1385 | name: 'started',
|
1386 | id: 31
|
1387 | }, {
|
1388 | name: 'joined',
|
1389 | id: 32
|
1390 | }, {
|
1391 | name: 'members_joined',
|
1392 | id: 33
|
1393 | }, {
|
1394 | name: 'left',
|
1395 | id: 39
|
1396 | }, {
|
1397 | name: 'members_left',
|
1398 | id: 40
|
1399 | }, {
|
1400 | name: 'results',
|
1401 | id: 42
|
1402 | }, {
|
1403 | name: 'count',
|
1404 | id: 43
|
1405 | }, {
|
1406 | name: 'result',
|
1407 | id: 44
|
1408 | }, {
|
1409 | name: 'update',
|
1410 | id: 45
|
1411 | }, {
|
1412 | name: 'updated',
|
1413 | id: 46
|
1414 | }, {
|
1415 | name: 'mute',
|
1416 | id: 47
|
1417 | }, {
|
1418 | name: 'unmute',
|
1419 | id: 48
|
1420 | }, {
|
1421 | name: 'status',
|
1422 | id: 49
|
1423 | }, {
|
1424 | name: 'members',
|
1425 | id: 50
|
1426 | }, {
|
1427 | name: 'max_read',
|
1428 | id: 51
|
1429 | }, {
|
1430 | name: 'is_member',
|
1431 | id: 52
|
1432 | }, {
|
1433 | name: 'member_info_update',
|
1434 | id: 53
|
1435 | }, {
|
1436 | name: 'member_info_updated',
|
1437 | id: 54
|
1438 | }, {
|
1439 | name: 'member_info_changed',
|
1440 | id: 55
|
1441 | }, {
|
1442 | name: 'join',
|
1443 | id: 80
|
1444 | }, {
|
1445 | name: 'invite',
|
1446 | id: 81
|
1447 | }, {
|
1448 | name: 'leave',
|
1449 | id: 82
|
1450 | }, {
|
1451 | name: 'kick',
|
1452 | id: 83
|
1453 | }, {
|
1454 | name: 'reject',
|
1455 | id: 84
|
1456 | }, {
|
1457 | name: 'invited',
|
1458 | id: 85
|
1459 | }, {
|
1460 | name: 'kicked',
|
1461 | id: 86
|
1462 | }, {
|
1463 | name: 'upload',
|
1464 | id: 100
|
1465 | }, {
|
1466 | name: 'uploaded',
|
1467 | id: 101
|
1468 | }, {
|
1469 | name: 'subscribe',
|
1470 | id: 120
|
1471 | }, {
|
1472 | name: 'subscribed',
|
1473 | id: 121
|
1474 | }, {
|
1475 | name: 'unsubscribe',
|
1476 | id: 122
|
1477 | }, {
|
1478 | name: 'unsubscribed',
|
1479 | id: 123
|
1480 | }, {
|
1481 | name: 'is_subscribed',
|
1482 | id: 124
|
1483 | }, {
|
1484 | name: 'modify',
|
1485 | id: 150
|
1486 | }, {
|
1487 | name: 'modified',
|
1488 | id: 151
|
1489 | }, {
|
1490 | name: 'block',
|
1491 | id: 170
|
1492 | }, {
|
1493 | name: 'unblock',
|
1494 | id: 171
|
1495 | }, {
|
1496 | name: 'blocked',
|
1497 | id: 172
|
1498 | }, {
|
1499 | name: 'unblocked',
|
1500 | id: 173
|
1501 | }, {
|
1502 | name: 'members_blocked',
|
1503 | id: 174
|
1504 | }, {
|
1505 | name: 'members_unblocked',
|
1506 | id: 175
|
1507 | }, {
|
1508 | name: 'check_block',
|
1509 | id: 176
|
1510 | }, {
|
1511 | name: 'check_result',
|
1512 | id: 177
|
1513 | }, {
|
1514 | name: 'add_shutup',
|
1515 | id: 180
|
1516 | }, {
|
1517 | name: 'remove_shutup',
|
1518 | id: 181
|
1519 | }, {
|
1520 | name: 'query_shutup',
|
1521 | id: 182
|
1522 | }, {
|
1523 | name: 'shutup_added',
|
1524 | id: 183
|
1525 | }, {
|
1526 | name: 'shutup_removed',
|
1527 | id: 184
|
1528 | }, {
|
1529 | name: 'shutup_result',
|
1530 | id: 185
|
1531 | }, {
|
1532 | name: 'shutuped',
|
1533 | id: 186
|
1534 | }, {
|
1535 | name: 'unshutuped',
|
1536 | id: 187
|
1537 | }, {
|
1538 | name: 'members_shutuped',
|
1539 | id: 188
|
1540 | }, {
|
1541 | name: 'members_unshutuped',
|
1542 | id: 189
|
1543 | }, {
|
1544 | name: 'check_shutup',
|
1545 | id: 190
|
1546 | }]
|
1547 | }, {
|
1548 | name: 'StatusType',
|
1549 | syntax: 'proto2',
|
1550 | values: [{
|
1551 | name: 'on',
|
1552 | id: 1
|
1553 | }, {
|
1554 | name: 'off',
|
1555 | id: 2
|
1556 | }]
|
1557 | }],
|
1558 | isNamespace: true
|
1559 | }).build();
|
1560 |
|
1561 | var _messages$push_server = messageCompiled.push_server.messages2,
|
1562 | JsonObjectMessage = _messages$push_server.JsonObjectMessage,
|
1563 | UnreadTuple = _messages$push_server.UnreadTuple,
|
1564 | LogItem = _messages$push_server.LogItem,
|
1565 | DataCommand = _messages$push_server.DataCommand,
|
1566 | SessionCommand = _messages$push_server.SessionCommand,
|
1567 | ErrorCommand = _messages$push_server.ErrorCommand,
|
1568 | DirectCommand = _messages$push_server.DirectCommand,
|
1569 | AckCommand = _messages$push_server.AckCommand,
|
1570 | UnreadCommand = _messages$push_server.UnreadCommand,
|
1571 | ConvCommand = _messages$push_server.ConvCommand,
|
1572 | RoomCommand = _messages$push_server.RoomCommand,
|
1573 | LogsCommand = _messages$push_server.LogsCommand,
|
1574 | RcpCommand = _messages$push_server.RcpCommand,
|
1575 | ReadTuple = _messages$push_server.ReadTuple,
|
1576 | MaxReadTuple = _messages$push_server.MaxReadTuple,
|
1577 | ReadCommand = _messages$push_server.ReadCommand,
|
1578 | PresenceCommand = _messages$push_server.PresenceCommand,
|
1579 | ReportCommand = _messages$push_server.ReportCommand,
|
1580 | GenericCommand = _messages$push_server.GenericCommand,
|
1581 | BlacklistCommand = _messages$push_server.BlacklistCommand,
|
1582 | PatchCommand = _messages$push_server.PatchCommand,
|
1583 | PatchItem = _messages$push_server.PatchItem,
|
1584 | ConvMemberInfo = _messages$push_server.ConvMemberInfo,
|
1585 | CommandType = _messages$push_server.CommandType,
|
1586 | OpType = _messages$push_server.OpType,
|
1587 | StatusType = _messages$push_server.StatusType;
|
1588 |
|
1589 | var message = Object.freeze({
|
1590 | __proto__: null,
|
1591 | JsonObjectMessage: JsonObjectMessage,
|
1592 | UnreadTuple: UnreadTuple,
|
1593 | LogItem: LogItem,
|
1594 | DataCommand: DataCommand,
|
1595 | SessionCommand: SessionCommand,
|
1596 | ErrorCommand: ErrorCommand,
|
1597 | DirectCommand: DirectCommand,
|
1598 | AckCommand: AckCommand,
|
1599 | UnreadCommand: UnreadCommand,
|
1600 | ConvCommand: ConvCommand,
|
1601 | RoomCommand: RoomCommand,
|
1602 | LogsCommand: LogsCommand,
|
1603 | RcpCommand: RcpCommand,
|
1604 | ReadTuple: ReadTuple,
|
1605 | MaxReadTuple: MaxReadTuple,
|
1606 | ReadCommand: ReadCommand,
|
1607 | PresenceCommand: PresenceCommand,
|
1608 | ReportCommand: ReportCommand,
|
1609 | GenericCommand: GenericCommand,
|
1610 | BlacklistCommand: BlacklistCommand,
|
1611 | PatchCommand: PatchCommand,
|
1612 | PatchItem: PatchItem,
|
1613 | ConvMemberInfo: ConvMemberInfo,
|
1614 | CommandType: CommandType,
|
1615 | OpType: OpType,
|
1616 | StatusType: StatusType
|
1617 | });
|
1618 |
|
1619 | var adapters = {};
|
1620 | var getAdapter = function getAdapter(name) {
|
1621 | var adapter = adapters[name];
|
1622 | if (adapter === undefined) {
|
1623 | throw new Error("".concat(name, " adapter is not configured"));
|
1624 | }
|
1625 | return adapter;
|
1626 | };
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 | var setAdapters = function setAdapters(newAdapters) {
|
1635 | Object.assign(adapters, newAdapters);
|
1636 | };
|
1637 |
|
1638 |
|
1639 | var global$1 = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
|
1640 |
|
1641 | var EXPIRED = Symbol('expired');
|
1642 | var debug = d('LC:Expirable');
|
1643 | var Expirable = function () {
|
1644 | function Expirable(value, ttl) {
|
1645 | this.originalValue = value;
|
1646 | if (typeof ttl === 'number') {
|
1647 | this.expiredAt = Date.now() + ttl;
|
1648 | }
|
1649 | }
|
1650 | _createClass(Expirable, [{
|
1651 | key: "value",
|
1652 | get: function get() {
|
1653 | var expired = this.expiredAt && this.expiredAt <= Date.now();
|
1654 | if (expired) debug("expired: ".concat(this.originalValue));
|
1655 | return expired ? EXPIRED : this.originalValue;
|
1656 | }
|
1657 | }]);
|
1658 | return Expirable;
|
1659 | }();
|
1660 | Expirable.EXPIRED = EXPIRED;
|
1661 |
|
1662 | var debug$1 = d('LC:Cache');
|
1663 | var Cache = function () {
|
1664 | function Cache() {
|
1665 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'anonymous';
|
1666 | this.name = name;
|
1667 | this._map = {};
|
1668 | }
|
1669 | var _proto = Cache.prototype;
|
1670 | _proto.get = function get(key) {
|
1671 | var cache = this._map[key];
|
1672 | if (cache) {
|
1673 | var value = cache.value;
|
1674 | if (value !== Expirable.EXPIRED) {
|
1675 | debug$1('[%s] hit: %s', this.name, key);
|
1676 | return value;
|
1677 | }
|
1678 | delete this._map[key];
|
1679 | }
|
1680 | debug$1("[".concat(this.name, "] missed: ").concat(key));
|
1681 | return null;
|
1682 | };
|
1683 | _proto.set = function set(key, value, ttl) {
|
1684 | debug$1('[%s] set: %s %d', this.name, key, ttl);
|
1685 | this._map[key] = new Expirable(value, ttl);
|
1686 | };
|
1687 | return Cache;
|
1688 | }();
|
1689 |
|
1690 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
1691 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 | var debug$2 = {
|
1702 | enable: function enable() {
|
1703 | var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'LC*';
|
1704 | return d.enable(namespaces);
|
1705 | },
|
1706 | disable: d.disable
|
1707 | };
|
1708 | var tryAll = function tryAll(promiseConstructors) {
|
1709 | var promise = new Promise(promiseConstructors[0]);
|
1710 | if (promiseConstructors.length === 1) {
|
1711 | return promise;
|
1712 | }
|
1713 | return promise["catch"](function () {
|
1714 | return tryAll(promiseConstructors.slice(1));
|
1715 | });
|
1716 | };
|
1717 |
|
1718 |
|
1719 | var tap = function tap(interceptor) {
|
1720 | return function (value) {
|
1721 | return interceptor(value), value;
|
1722 | };
|
1723 | };
|
1724 | var isIE10 = global$1.navigator && global$1.navigator.userAgent && global$1.navigator.userAgent.indexOf('MSIE 10.') !== -1;
|
1725 | var map = new WeakMap();
|
1726 |
|
1727 |
|
1728 | var internal = function internal(object) {
|
1729 | if (!map.has(object)) {
|
1730 | map.set(object, {});
|
1731 | }
|
1732 | return map.get(object);
|
1733 | };
|
1734 | var compact = function compact(obj, filter) {
|
1735 | if (!isPlainObject(obj)) return obj;
|
1736 | var object = _objectSpread({}, obj);
|
1737 | Object.keys(object).forEach(function (prop) {
|
1738 | var value = object[prop];
|
1739 | if (value === filter) {
|
1740 | delete object[prop];
|
1741 | } else {
|
1742 | object[prop] = compact(value, filter);
|
1743 | }
|
1744 | });
|
1745 | return object;
|
1746 | };
|
1747 |
|
1748 |
|
1749 | var removeNull = function removeNull(obj) {
|
1750 | return compact(obj, null);
|
1751 | };
|
1752 | var trim = function trim(message) {
|
1753 | return removeNull(JSON.parse(JSON.stringify(message)));
|
1754 | };
|
1755 | var ensureArray = function ensureArray(target) {
|
1756 | if (Array.isArray(target)) {
|
1757 | return target;
|
1758 | }
|
1759 | if (target === undefined || target === null) {
|
1760 | return [];
|
1761 | }
|
1762 | return [target];
|
1763 | };
|
1764 | var isWeapp =
|
1765 |
|
1766 | (typeof wx === "undefined" ? "undefined" : _typeof(wx)) === 'object' && typeof wx.connectSocket === 'function';
|
1767 | var isCNApp = function isCNApp(appId) {
|
1768 | return appId.slice(-9) !== '-MdYXbMMI';
|
1769 | };
|
1770 | var equalBuffer = function equalBuffer(buffer1, buffer2) {
|
1771 | if (!buffer1 || !buffer2) return false;
|
1772 | if (buffer1.byteLength !== buffer2.byteLength) return false;
|
1773 | var a = new Uint8Array(buffer1);
|
1774 | var b = new Uint8Array(buffer2);
|
1775 | return !a.some(function (value, index) {
|
1776 | return value !== b[index];
|
1777 | });
|
1778 | };
|
1779 |
|
1780 | var _class;
|
1781 | function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
1782 | function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
1783 | var debug$3 = d('LC:WebSocketPlus');
|
1784 | var OPEN = 'open';
|
1785 | var DISCONNECT = 'disconnect';
|
1786 | var RECONNECT = 'reconnect';
|
1787 | var RETRY = 'retry';
|
1788 | var SCHEDULE = 'schedule';
|
1789 | var OFFLINE = 'offline';
|
1790 | var ONLINE = 'online';
|
1791 | var ERROR = 'error';
|
1792 | var MESSAGE = 'message';
|
1793 | var HEARTBEAT_TIME = 180000;
|
1794 | var TIMEOUT_TIME = 380000;
|
1795 | var DEFAULT_RETRY_STRATEGY = function DEFAULT_RETRY_STRATEGY(attempt) {
|
1796 | return Math.min(1000 * Math.pow(2, attempt), 300000);
|
1797 | };
|
1798 | var requireConnected = function requireConnected(target, name, descriptor) {
|
1799 | return _objectSpread$1(_objectSpread$1({}, descriptor), {}, {
|
1800 | value: function requireConnectedWrapper() {
|
1801 | var _descriptor$value;
|
1802 | this.checkConnectionAvailability(name);
|
1803 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
1804 | args[_key] = arguments[_key];
|
1805 | }
|
1806 | return (_descriptor$value = descriptor.value).call.apply(_descriptor$value, [this].concat(args));
|
1807 | }
|
1808 | });
|
1809 | };
|
1810 | var WebSocketPlus = (_class = function (_EventEmitter) {
|
1811 | _inheritsLoose(WebSocketPlus, _EventEmitter);
|
1812 | function WebSocketPlus(getUrls, protocol) {
|
1813 | var _this;
|
1814 | _this = _EventEmitter.call(this) || this;
|
1815 | _this.init();
|
1816 | _this._protocol = protocol;
|
1817 | Promise.resolve(typeof getUrls === 'function' ? getUrls() : getUrls).then(ensureArray).then(function (urls) {
|
1818 | _this._urls = urls;
|
1819 | return _this._open();
|
1820 | }).then(function () {
|
1821 | _this.__postponeTimeoutTimer = _this._postponeTimeoutTimer.bind(_assertThisInitialized(_this));
|
1822 | if (global$1.addEventListener) {
|
1823 | _this.__pause = function () {
|
1824 | if (_this.can('pause')) _this.pause();
|
1825 | };
|
1826 | _this.__resume = function () {
|
1827 | if (_this.can('resume')) _this.resume();
|
1828 | };
|
1829 | global$1.addEventListener('offline', _this.__pause);
|
1830 | global$1.addEventListener('online', _this.__resume);
|
1831 | }
|
1832 | _this.open();
|
1833 | })["catch"](_this["throw"].bind(_assertThisInitialized(_this)));
|
1834 | return _this;
|
1835 | }
|
1836 | var _proto = WebSocketPlus.prototype;
|
1837 | _proto._open = function _open() {
|
1838 | var _this2 = this;
|
1839 | return this._createWs(this._urls, this._protocol).then(function (ws) {
|
1840 | var _this2$_urls = _toArray(_this2._urls),
|
1841 | first = _this2$_urls[0],
|
1842 | reset = _this2$_urls.slice(1);
|
1843 | _this2._urls = [].concat(_toConsumableArray(reset), [first]);
|
1844 | return ws;
|
1845 | });
|
1846 | };
|
1847 | _proto._createWs = function _createWs(urls, protocol) {
|
1848 | var _this3 = this;
|
1849 | return tryAll(urls.map(function (url) {
|
1850 | return function (resolve, reject) {
|
1851 | debug$3("connect [".concat(url, "] ").concat(protocol));
|
1852 | var WebSocket = getAdapter('WebSocket');
|
1853 | var ws = protocol ? new WebSocket(url, protocol) : new WebSocket(url);
|
1854 | ws.binaryType = _this3.binaryType || 'arraybuffer';
|
1855 | ws.onopen = function () {
|
1856 | return resolve(ws);
|
1857 | };
|
1858 | ws.onclose = function (error) {
|
1859 | if (error instanceof Error) {
|
1860 | return reject(error);
|
1861 | }
|
1862 |
|
1863 | return reject(new Error("Failed to connect [".concat(url, "]")));
|
1864 | };
|
1865 | ws.onerror = ws.onclose;
|
1866 | };
|
1867 | })).then(function (ws) {
|
1868 | _this3._ws = ws;
|
1869 | _this3._ws.onclose = _this3._handleClose.bind(_this3);
|
1870 | _this3._ws.onmessage = _this3._handleMessage.bind(_this3);
|
1871 | return ws;
|
1872 | });
|
1873 | };
|
1874 | _proto._destroyWs = function _destroyWs() {
|
1875 | var ws = this._ws;
|
1876 | if (!ws) return;
|
1877 | ws.onopen = null;
|
1878 | ws.onclose = null;
|
1879 | ws.onerror = null;
|
1880 | ws.onmessage = null;
|
1881 | this._ws = null;
|
1882 | ws.close();
|
1883 | }
|
1884 |
|
1885 |
|
1886 | ;
|
1887 | _proto.onbeforeevent = function onbeforeevent(event, from, to) {
|
1888 | for (var _len2 = arguments.length, payload = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
1889 | payload[_key2 - 3] = arguments[_key2];
|
1890 | }
|
1891 | debug$3("".concat(event, ": ").concat(from, " -> ").concat(to, " %o"), payload);
|
1892 | };
|
1893 | _proto.onopen = function onopen() {
|
1894 | this.emit(OPEN);
|
1895 | };
|
1896 | _proto.onconnected = function onconnected() {
|
1897 | this._startConnectionKeeper();
|
1898 | };
|
1899 | _proto.onleaveconnected = function onleaveconnected(event, from, to) {
|
1900 | this._stopConnectionKeeper();
|
1901 | this._destroyWs();
|
1902 | if (to === 'offline' || to === 'disconnected') {
|
1903 | this.emit(DISCONNECT);
|
1904 | }
|
1905 | };
|
1906 | _proto.onpause = function onpause() {
|
1907 | this.emit(OFFLINE);
|
1908 | };
|
1909 | _proto.onbeforeresume = function onbeforeresume() {
|
1910 | this.emit(ONLINE);
|
1911 | };
|
1912 | _proto.onreconnect = function onreconnect() {
|
1913 | this.emit(RECONNECT);
|
1914 | };
|
1915 | _proto.ondisconnected = function ondisconnected(event, from, to) {
|
1916 | var _this4 = this;
|
1917 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
1918 | var delay = from === OFFLINE ? 0 : DEFAULT_RETRY_STRATEGY.call(null, attempt);
|
1919 | debug$3("schedule attempt=".concat(attempt, " delay=").concat(delay));
|
1920 | this.emit(SCHEDULE, attempt, delay);
|
1921 | if (this.__scheduledRetry) {
|
1922 | clearTimeout(this.__scheduledRetry);
|
1923 | }
|
1924 | this.__scheduledRetry = setTimeout(function () {
|
1925 | if (_this4.is('disconnected')) {
|
1926 | _this4.retry(attempt);
|
1927 | }
|
1928 | }, delay);
|
1929 | };
|
1930 | _proto.onretry = function onretry(event, from, to) {
|
1931 | var _this5 = this;
|
1932 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
1933 | this.emit(RETRY, attempt);
|
1934 | this._open().then(function () {
|
1935 | return _this5.can('reconnect') && _this5.reconnect();
|
1936 | }, function () {
|
1937 | return _this5.can('fail') && _this5.fail(attempt + 1);
|
1938 | });
|
1939 | };
|
1940 | _proto.onerror = function onerror(event, from, to, error) {
|
1941 | this.emit(ERROR, error);
|
1942 | };
|
1943 | _proto.onclose = function onclose() {
|
1944 | if (global$1.removeEventListener) {
|
1945 | if (this.__pause) global$1.removeEventListener('offline', this.__pause);
|
1946 | if (this.__resume) global$1.removeEventListener('online', this.__resume);
|
1947 | }
|
1948 | };
|
1949 | _proto.checkConnectionAvailability = function checkConnectionAvailability() {
|
1950 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'API';
|
1951 | if (!this.is('connected')) {
|
1952 | var currentState = this.current;
|
1953 | console.warn("".concat(name, " should not be called when the connection is ").concat(currentState));
|
1954 | if (this.is('disconnected') || this.is('reconnecting')) {
|
1955 | console.warn('disconnect and reconnect event should be handled to avoid such calls.');
|
1956 | }
|
1957 | throw new Error('Connection unavailable');
|
1958 | }
|
1959 | }
|
1960 |
|
1961 |
|
1962 | ;
|
1963 | _proto.
|
1964 |
|
1965 | _ping = function _ping() {
|
1966 | debug$3('ping');
|
1967 | try {
|
1968 | this.ping();
|
1969 | } catch (error) {
|
1970 | console.warn("websocket ping error: ".concat(error.message));
|
1971 | }
|
1972 | };
|
1973 | _proto.ping = function ping() {
|
1974 | if (this._ws.ping) {
|
1975 | this._ws.ping();
|
1976 | } else {
|
1977 | console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.");
|
1978 | }
|
1979 | };
|
1980 | _proto._postponeTimeoutTimer = function _postponeTimeoutTimer() {
|
1981 | var _this6 = this;
|
1982 | debug$3('_postponeTimeoutTimer');
|
1983 | this._clearTimeoutTimers();
|
1984 | this._timeoutTimer = setTimeout(function () {
|
1985 | debug$3('timeout');
|
1986 | _this6.disconnect();
|
1987 | }, TIMEOUT_TIME);
|
1988 | };
|
1989 | _proto._clearTimeoutTimers = function _clearTimeoutTimers() {
|
1990 | if (this._timeoutTimer) {
|
1991 | clearTimeout(this._timeoutTimer);
|
1992 | }
|
1993 | };
|
1994 | _proto._startConnectionKeeper = function _startConnectionKeeper() {
|
1995 | debug$3('start connection keeper');
|
1996 | this._heartbeatTimer = setInterval(this._ping.bind(this), HEARTBEAT_TIME);
|
1997 | var addListener = this._ws.addListener || this._ws.addEventListener;
|
1998 | if (!addListener) {
|
1999 | debug$3('connection keeper disabled due to the lack of #addEventListener.');
|
2000 | return;
|
2001 | }
|
2002 | addListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
2003 | addListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
2004 | this._postponeTimeoutTimer();
|
2005 | };
|
2006 | _proto._stopConnectionKeeper = function _stopConnectionKeeper() {
|
2007 | debug$3('stop connection keeper');
|
2008 |
|
2009 | var removeListener = this._ws.removeListener || this._ws.removeEventListener;
|
2010 | if (removeListener) {
|
2011 | removeListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
2012 | removeListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
2013 | this._clearTimeoutTimers();
|
2014 | }
|
2015 | if (this._heartbeatTimer) {
|
2016 | clearInterval(this._heartbeatTimer);
|
2017 | }
|
2018 | };
|
2019 | _proto._handleClose = function _handleClose(event) {
|
2020 | debug$3("ws closed [".concat(event.code, "] ").concat(event.reason));
|
2021 |
|
2022 | if (this.isFinished()) return;
|
2023 | this.handleClose(event);
|
2024 | };
|
2025 | _proto.handleClose = function handleClose() {
|
2026 |
|
2027 | this.disconnect();
|
2028 | }
|
2029 |
|
2030 |
|
2031 | ;
|
2032 | _proto.
|
2033 |
|
2034 | send = function send(data) {
|
2035 | debug$3('send', data);
|
2036 | this._ws.send(data);
|
2037 | };
|
2038 | _proto._handleMessage = function _handleMessage(event) {
|
2039 | debug$3('message', event.data);
|
2040 | this.handleMessage(event.data);
|
2041 | };
|
2042 | _proto.handleMessage = function handleMessage(message) {
|
2043 | this.emit(MESSAGE, message);
|
2044 | };
|
2045 | _createClass(WebSocketPlus, [{
|
2046 | key: "urls",
|
2047 | get: function get() {
|
2048 | return this._urls;
|
2049 | },
|
2050 | set: function set(urls) {
|
2051 | this._urls = ensureArray(urls);
|
2052 | }
|
2053 | }]);
|
2054 | return WebSocketPlus;
|
2055 | }(EventEmitter), (_applyDecoratedDescriptor(_class.prototype, "_ping", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "_ping"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "send", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "send"), _class.prototype)), _class);
|
2056 | StateMachine.create({
|
2057 | target: WebSocketPlus.prototype,
|
2058 | initial: {
|
2059 | state: 'initialized',
|
2060 | event: 'init',
|
2061 | defer: true
|
2062 | },
|
2063 | terminal: 'closed',
|
2064 | events: [{
|
2065 | name: 'open',
|
2066 | from: 'initialized',
|
2067 | to: 'connected'
|
2068 | }, {
|
2069 | name: 'disconnect',
|
2070 | from: 'connected',
|
2071 | to: 'disconnected'
|
2072 | }, {
|
2073 | name: 'retry',
|
2074 | from: 'disconnected',
|
2075 | to: 'reconnecting'
|
2076 | }, {
|
2077 | name: 'fail',
|
2078 | from: 'reconnecting',
|
2079 | to: 'disconnected'
|
2080 | }, {
|
2081 | name: 'reconnect',
|
2082 | from: 'reconnecting',
|
2083 | to: 'connected'
|
2084 | }, {
|
2085 | name: 'pause',
|
2086 | from: ['connected', 'disconnected', 'reconnecting'],
|
2087 | to: 'offline'
|
2088 | }, {}, {
|
2089 | name: 'resume',
|
2090 | from: 'offline',
|
2091 | to: 'disconnected'
|
2092 | }, {
|
2093 | name: 'close',
|
2094 | from: ['connected', 'disconnected', 'reconnecting', 'offline'],
|
2095 | to: 'closed'
|
2096 | }, {
|
2097 | name: 'throw',
|
2098 | from: '*',
|
2099 | to: 'error'
|
2100 | }]
|
2101 | });
|
2102 |
|
2103 | var error = Object.freeze({
|
2104 | 1000: {
|
2105 | name: 'CLOSE_NORMAL'
|
2106 | },
|
2107 | 1006: {
|
2108 | name: 'CLOSE_ABNORMAL'
|
2109 | },
|
2110 | 4100: {
|
2111 | name: 'APP_NOT_AVAILABLE',
|
2112 | message: 'App not exists or realtime message service is disabled.'
|
2113 | },
|
2114 | 4102: {
|
2115 | name: 'SIGNATURE_FAILED',
|
2116 | message: 'Login signature mismatch.'
|
2117 | },
|
2118 | 4103: {
|
2119 | name: 'INVALID_LOGIN',
|
2120 | message: 'Malformed clientId.'
|
2121 | },
|
2122 | 4105: {
|
2123 | name: 'SESSION_REQUIRED',
|
2124 | message: 'Message sent before session opened.'
|
2125 | },
|
2126 | 4107: {
|
2127 | name: 'READ_TIMEOUT'
|
2128 | },
|
2129 | 4108: {
|
2130 | name: 'LOGIN_TIMEOUT'
|
2131 | },
|
2132 | 4109: {
|
2133 | name: 'FRAME_TOO_LONG'
|
2134 | },
|
2135 | 4110: {
|
2136 | name: 'INVALID_ORIGIN',
|
2137 | message: 'Access denied by domain whitelist.'
|
2138 | },
|
2139 | 4111: {
|
2140 | name: 'SESSION_CONFLICT'
|
2141 | },
|
2142 | 4112: {
|
2143 | name: 'SESSION_TOKEN_EXPIRED'
|
2144 | },
|
2145 | 4113: {
|
2146 | name: 'APP_QUOTA_EXCEEDED',
|
2147 | message: 'The daily active users limit exceeded.'
|
2148 | },
|
2149 | 4116: {
|
2150 | name: 'MESSAGE_SENT_QUOTA_EXCEEDED',
|
2151 | message: 'Command sent too fast.'
|
2152 | },
|
2153 | 4200: {
|
2154 | name: 'INTERNAL_ERROR',
|
2155 | message: 'Internal error, please contact LeanCloud for support.'
|
2156 | },
|
2157 | 4301: {
|
2158 | name: 'CONVERSATION_API_FAILED',
|
2159 | message: 'Upstream Conversatoin API failed, see error.detail for details.'
|
2160 | },
|
2161 | 4302: {
|
2162 | name: 'CONVERSATION_SIGNATURE_FAILED',
|
2163 | message: 'Conversation action signature mismatch.'
|
2164 | },
|
2165 | 4303: {
|
2166 | name: 'CONVERSATION_NOT_FOUND'
|
2167 | },
|
2168 | 4304: {
|
2169 | name: 'CONVERSATION_FULL'
|
2170 | },
|
2171 | 4305: {
|
2172 | name: 'CONVERSATION_REJECTED_BY_APP',
|
2173 | message: 'Conversation action rejected by hook.'
|
2174 | },
|
2175 | 4306: {
|
2176 | name: 'CONVERSATION_UPDATE_FAILED'
|
2177 | },
|
2178 | 4307: {
|
2179 | name: 'CONVERSATION_READ_ONLY'
|
2180 | },
|
2181 | 4308: {
|
2182 | name: 'CONVERSATION_NOT_ALLOWED'
|
2183 | },
|
2184 | 4309: {
|
2185 | name: 'CONVERSATION_UPDATE_REJECTED',
|
2186 | message: 'Conversation update rejected because the client is not a member.'
|
2187 | },
|
2188 | 4310: {
|
2189 | name: 'CONVERSATION_QUERY_FAILED',
|
2190 | message: 'Conversation query failed because it is too expansive.'
|
2191 | },
|
2192 | 4311: {
|
2193 | name: 'CONVERSATION_LOG_FAILED'
|
2194 | },
|
2195 | 4312: {
|
2196 | name: 'CONVERSATION_LOG_REJECTED',
|
2197 | message: 'Message query rejected because the client is not a member of the conversation.'
|
2198 | },
|
2199 | 4313: {
|
2200 | name: 'SYSTEM_CONVERSATION_REQUIRED'
|
2201 | },
|
2202 | 4314: {
|
2203 | name: 'NORMAL_CONVERSATION_REQUIRED'
|
2204 | },
|
2205 | 4315: {
|
2206 | name: 'CONVERSATION_BLACKLISTED',
|
2207 | message: 'Blacklisted in the conversation.'
|
2208 | },
|
2209 | 4316: {
|
2210 | name: 'TRANSIENT_CONVERSATION_REQUIRED'
|
2211 | },
|
2212 | 4317: {
|
2213 | name: 'CONVERSATION_MEMBERSHIP_REQUIRED'
|
2214 | },
|
2215 | 4318: {
|
2216 | name: 'CONVERSATION_API_QUOTA_EXCEEDED',
|
2217 | message: 'LeanCloud API quota exceeded. You may upgrade your plan.'
|
2218 | },
|
2219 | 4323: {
|
2220 | name: 'TEMPORARY_CONVERSATION_EXPIRED',
|
2221 | message: 'Temporary conversation expired or does not exist.'
|
2222 | },
|
2223 | 4401: {
|
2224 | name: 'INVALID_MESSAGING_TARGET',
|
2225 | message: 'Conversation does not exist or client is not a member.'
|
2226 | },
|
2227 | 4402: {
|
2228 | name: 'MESSAGE_REJECTED_BY_APP',
|
2229 | message: 'Message rejected by hook.'
|
2230 | },
|
2231 | 4403: {
|
2232 | name: 'MESSAGE_OWNERSHIP_REQUIRED'
|
2233 | },
|
2234 | 4404: {
|
2235 | name: 'MESSAGE_NOT_FOUND'
|
2236 | },
|
2237 | 4405: {
|
2238 | name: 'MESSAGE_UPDATE_REJECTED_BY_APP',
|
2239 | message: 'Message update rejected by hook.'
|
2240 | },
|
2241 | 4406: {
|
2242 | name: 'MESSAGE_EDIT_DISABLED'
|
2243 | },
|
2244 | 4407: {
|
2245 | name: 'MESSAGE_RECALL_DISABLED'
|
2246 | },
|
2247 | 5130: {
|
2248 | name: 'OWNER_PROMOTION_NOT_ALLOWED',
|
2249 | message: "Updating a member's role to owner is not allowed."
|
2250 | }
|
2251 | });
|
2252 | var ErrorCode = Object.freeze(Object.keys(error).reduce(function (result, code) {
|
2253 | return Object.assign(result, _defineProperty({}, error[code].name, Number(code)));
|
2254 | }, {}));
|
2255 | var createError = function createError(_ref) {
|
2256 | var code = _ref.code,
|
2257 | reason = _ref.reason,
|
2258 | appCode = _ref.appCode,
|
2259 | detail = _ref.detail,
|
2260 | errorMessage = _ref.error;
|
2261 | var message = reason || detail || errorMessage;
|
2262 | var name = reason;
|
2263 | if (!message && error[code]) {
|
2264 | name = error[code].name;
|
2265 | message = error[code].message || name;
|
2266 | }
|
2267 | if (!message) {
|
2268 | message = "Unknow Error: ".concat(code);
|
2269 | }
|
2270 | var err = new Error(message);
|
2271 | return Object.assign(err, {
|
2272 | code: code,
|
2273 | appCode: appCode,
|
2274 | detail: detail,
|
2275 | name: name
|
2276 | });
|
2277 | };
|
2278 |
|
2279 | var debug$4 = d('LC:Connection');
|
2280 | var COMMAND_TIMEOUT = 20000;
|
2281 | var EXPIRE = Symbol('expire');
|
2282 | var isIdempotentCommand = function isIdempotentCommand(command) {
|
2283 | return !(command.cmd === CommandType.direct || command.cmd === CommandType.session && command.op === OpType.open || command.cmd === CommandType.conv && (command.op === OpType.start || command.op === OpType.update || command.op === OpType.members));
|
2284 | };
|
2285 | var Connection = function (_WebSocketPlus) {
|
2286 | _inheritsLoose(Connection, _WebSocketPlus);
|
2287 | function Connection(getUrl, _ref) {
|
2288 | var _this;
|
2289 | var format = _ref.format,
|
2290 | version = _ref.version;
|
2291 | debug$4('initializing Connection');
|
2292 | var protocolString = "lc.".concat(format, ".").concat(version);
|
2293 | _this = _WebSocketPlus.call(this, getUrl, protocolString) || this;
|
2294 | _this._protocolFormat = format;
|
2295 | _this._commands = {};
|
2296 | _this._serialId = 0;
|
2297 | return _this;
|
2298 | }
|
2299 | var _proto = Connection.prototype;
|
2300 | _proto.send = function () {
|
2301 | var _send = _asyncToGenerator( _regeneratorRuntime.mark(function _callee(command) {
|
2302 | var _this2 = this;
|
2303 | var waitingForRespond,
|
2304 | buffer,
|
2305 | serialId,
|
2306 | duplicatedCommand,
|
2307 | message,
|
2308 | promise,
|
2309 | _args = arguments;
|
2310 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
2311 | while (1) switch (_context.prev = _context.next) {
|
2312 | case 0:
|
2313 | waitingForRespond = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
|
2314 | if (!waitingForRespond) {
|
2315 | _context.next = 11;
|
2316 | break;
|
2317 | }
|
2318 | if (!isIdempotentCommand(command)) {
|
2319 | _context.next = 8;
|
2320 | break;
|
2321 | }
|
2322 | buffer = command.toArrayBuffer();
|
2323 | duplicatedCommand = values(this._commands).find(function (_ref2) {
|
2324 | var targetBuffer = _ref2.buffer,
|
2325 | targetCommand = _ref2.command;
|
2326 | return targetCommand.cmd === command.cmd && targetCommand.op === command.op && equalBuffer(targetBuffer, buffer);
|
2327 | });
|
2328 | if (!duplicatedCommand) {
|
2329 | _context.next = 8;
|
2330 | break;
|
2331 | }
|
2332 | console.warn("Duplicated command [cmd:".concat(command.cmd, " op:").concat(command.op, "] is throttled."));
|
2333 | return _context.abrupt("return", duplicatedCommand.promise);
|
2334 | case 8:
|
2335 | this._serialId += 1;
|
2336 | serialId = this._serialId;
|
2337 | command.i = serialId;
|
2338 | case 11:
|
2339 | if (debug$4.enabled) debug$4('↑ %O sent', trim(command));
|
2340 | if (this._protocolFormat === 'proto2base64') {
|
2341 | message = command.toBase64();
|
2342 | } else if (command.toArrayBuffer) {
|
2343 | message = command.toArrayBuffer();
|
2344 | }
|
2345 | if (message) {
|
2346 | _context.next = 15;
|
2347 | break;
|
2348 | }
|
2349 | throw new TypeError("".concat(command, " is not a GenericCommand"));
|
2350 | case 15:
|
2351 | _WebSocketPlus.prototype.send.call(this, message);
|
2352 | if (waitingForRespond) {
|
2353 | _context.next = 18;
|
2354 | break;
|
2355 | }
|
2356 | return _context.abrupt("return", undefined);
|
2357 | case 18:
|
2358 | promise = new Promise(function (resolve, reject) {
|
2359 | _this2._commands[serialId] = {
|
2360 | command: command,
|
2361 | buffer: buffer,
|
2362 | resolve: resolve,
|
2363 | reject: reject,
|
2364 | timeout: setTimeout(function () {
|
2365 | if (_this2._commands[serialId]) {
|
2366 | if (debug$4.enabled) debug$4('✗ %O timeout', trim(command));
|
2367 | reject(createError({
|
2368 | error: "Command Timeout [cmd:".concat(command.cmd, " op:").concat(command.op, "]"),
|
2369 | name: 'COMMAND_TIMEOUT'
|
2370 | }));
|
2371 | delete _this2._commands[serialId];
|
2372 | }
|
2373 | }, COMMAND_TIMEOUT)
|
2374 | };
|
2375 | });
|
2376 | this._commands[serialId].promise = promise;
|
2377 | return _context.abrupt("return", promise);
|
2378 | case 21:
|
2379 | case "end":
|
2380 | return _context.stop();
|
2381 | }
|
2382 | }, _callee, this);
|
2383 | }));
|
2384 | function send(_x) {
|
2385 | return _send.apply(this, arguments);
|
2386 | }
|
2387 | return send;
|
2388 | }();
|
2389 | _proto.handleMessage = function handleMessage(msg) {
|
2390 | var message;
|
2391 | try {
|
2392 | message = GenericCommand.decode(msg);
|
2393 | if (debug$4.enabled) debug$4('↓ %O received', trim(message));
|
2394 | } catch (e) {
|
2395 | console.warn('Decode message failed:', e.message, msg);
|
2396 | return;
|
2397 | }
|
2398 | var serialId = message.i;
|
2399 | if (serialId) {
|
2400 | if (this._commands[serialId]) {
|
2401 | clearTimeout(this._commands[serialId].timeout);
|
2402 | if (message.cmd === CommandType.error) {
|
2403 | this._commands[serialId].reject(createError(message.errorMessage));
|
2404 | } else {
|
2405 | this._commands[serialId].resolve(message);
|
2406 | }
|
2407 | delete this._commands[serialId];
|
2408 | } else {
|
2409 | console.warn("Unexpected command received with serialId [".concat(serialId, "],\n which have timed out or never been requested."));
|
2410 | }
|
2411 | } else {
|
2412 | switch (message.cmd) {
|
2413 | case CommandType.error:
|
2414 | {
|
2415 | this.emit(ERROR, createError(message.errorMessage));
|
2416 | return;
|
2417 | }
|
2418 | case CommandType.goaway:
|
2419 | {
|
2420 | this.emit(EXPIRE);
|
2421 | return;
|
2422 | }
|
2423 | default:
|
2424 | {
|
2425 | this.emit(MESSAGE, message);
|
2426 | }
|
2427 | }
|
2428 | }
|
2429 | };
|
2430 | _proto.ping = function ping() {
|
2431 | return this.send(new GenericCommand({
|
2432 | cmd: CommandType.echo
|
2433 | }))["catch"](function (error) {
|
2434 | return debug$4('ping failed:', error);
|
2435 | });
|
2436 | };
|
2437 | return Connection;
|
2438 | }(WebSocketPlus);
|
2439 |
|
2440 | var debug$5 = d('LC:request');
|
2441 | var request = (function (_ref) {
|
2442 | var _ref$method = _ref.method,
|
2443 | method = _ref$method === void 0 ? 'GET' : _ref$method,
|
2444 | _url = _ref.url,
|
2445 | query = _ref.query,
|
2446 | headers = _ref.headers,
|
2447 | data = _ref.data,
|
2448 | time = _ref.timeout;
|
2449 | var url = _url;
|
2450 | if (query) {
|
2451 | var queryString = Object.keys(query).map(function (key) {
|
2452 | var value = query[key];
|
2453 | if (value === undefined) return undefined;
|
2454 | var v = isPlainObject(value) ? JSON.stringify(value) : value;
|
2455 | return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(v));
|
2456 | }).filter(function (qs) {
|
2457 | return qs;
|
2458 | }).join('&');
|
2459 | url = "".concat(url, "?").concat(queryString);
|
2460 | }
|
2461 | debug$5('Req: %O %O %O', method, url, {
|
2462 | headers: headers,
|
2463 | data: data
|
2464 | });
|
2465 | var request = getAdapter('request');
|
2466 | var promise = request(url, {
|
2467 | method: method,
|
2468 | headers: headers,
|
2469 | data: data
|
2470 | }).then(function (response) {
|
2471 | if (response.ok === false) {
|
2472 | var error = createError(response.data);
|
2473 | error.response = response;
|
2474 | throw error;
|
2475 | }
|
2476 | debug$5('Res: %O %O %O', url, response.status, response.data);
|
2477 | return response.data;
|
2478 | })["catch"](function (error) {
|
2479 | if (error.response) {
|
2480 | debug$5('Error: %O %O %O', url, error.response.status, error.response.data);
|
2481 | }
|
2482 | throw error;
|
2483 | });
|
2484 | return time ? promiseTimeout.timeout(promise, time) : promise;
|
2485 | });
|
2486 |
|
2487 | var applyDecorators = function applyDecorators(decorators, target) {
|
2488 | if (decorators) {
|
2489 | decorators.forEach(function (decorator) {
|
2490 | try {
|
2491 | decorator(target);
|
2492 | } catch (error) {
|
2493 | if (decorator._pluginName) {
|
2494 | error.message += "[".concat(decorator._pluginName, "]");
|
2495 | }
|
2496 | throw error;
|
2497 | }
|
2498 | });
|
2499 | }
|
2500 | };
|
2501 | var applyDispatcher = function applyDispatcher(dispatchers, payload) {
|
2502 | return ensureArray(dispatchers).reduce(function (resultPromise, dispatcher) {
|
2503 | return resultPromise.then(function (shouldDispatch) {
|
2504 | return shouldDispatch === false ? false : dispatcher.apply(void 0, _toConsumableArray(payload));
|
2505 | })["catch"](function (error) {
|
2506 | if (dispatcher._pluginName) {
|
2507 |
|
2508 | error.message += "[".concat(dispatcher._pluginName, "]");
|
2509 | }
|
2510 | throw error;
|
2511 | });
|
2512 | }, Promise.resolve(true));
|
2513 | };
|
2514 |
|
2515 | var version = "5.0.0-rc.8";
|
2516 |
|
2517 | var _excluded = ["plugins"];
|
2518 | function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2519 | function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
2520 | var debug$6 = d('LC:Realtime');
|
2521 | var routerCache = new Cache('push-router');
|
2522 | var initializedApp = {};
|
2523 | var Realtime = function (_EventEmitter) {
|
2524 | _inheritsLoose(Realtime, _EventEmitter);
|
2525 | |
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 | function Realtime(_ref) {
|
2538 | var _this2;
|
2539 | var plugins = _ref.plugins,
|
2540 | options = _objectWithoutProperties(_ref, _excluded);
|
2541 | debug$6('initializing Realtime %s %O', version, options);
|
2542 | _this2 = _EventEmitter.call(this) || this;
|
2543 | var appId = options.appId;
|
2544 | if (typeof appId !== 'string') {
|
2545 | throw new TypeError("appId [".concat(appId, "] is not a string"));
|
2546 | }
|
2547 | if (initializedApp[appId]) {
|
2548 | throw new Error("App [".concat(appId, "] is already initialized."));
|
2549 | }
|
2550 | initializedApp[appId] = true;
|
2551 | if (typeof options.appKey !== 'string') {
|
2552 | throw new TypeError("appKey [".concat(options.appKey, "] is not a string"));
|
2553 | }
|
2554 | if (isCNApp(appId)) {
|
2555 | if (!options.server) {
|
2556 | throw new TypeError("server option is required for apps from CN region");
|
2557 | }
|
2558 | }
|
2559 | _this2._options = _objectSpread$2({
|
2560 | appId: undefined,
|
2561 | appKey: undefined,
|
2562 | noBinary: false,
|
2563 | ssl: true,
|
2564 | RTMServerName: typeof process !== 'undefined' ? process.env.RTM_SERVER_NAME : undefined
|
2565 | }, options);
|
2566 | _this2._cache = new Cache('endpoints');
|
2567 | var _this = internal(_assertThisInitialized(_this2));
|
2568 | _this.clients = new Set();
|
2569 | _this.pendingClients = new Set();
|
2570 | var mergedPlugins = [].concat(_toConsumableArray(ensureArray(Realtime.__preRegisteredPlugins)), _toConsumableArray(ensureArray(plugins)));
|
2571 | debug$6('Using plugins %o', mergedPlugins.map(function (plugin) {
|
2572 | return plugin.name;
|
2573 | }));
|
2574 | _this2._plugins = mergedPlugins.reduce(function (result, plugin) {
|
2575 | Object.keys(plugin).forEach(function (hook) {
|
2576 | if ({}.hasOwnProperty.call(plugin, hook) && hook !== 'name') {
|
2577 | if (plugin.name) {
|
2578 | ensureArray(plugin[hook]).forEach(function (value) {
|
2579 |
|
2580 | value._pluginName = plugin.name;
|
2581 | });
|
2582 | }
|
2583 |
|
2584 | result[hook] = ensureArray(result[hook]).concat(plugin[hook]);
|
2585 | }
|
2586 | });
|
2587 | return result;
|
2588 | }, {});
|
2589 |
|
2590 | applyDecorators(_this2._plugins.onRealtimeCreate, _assertThisInitialized(_this2));
|
2591 | return _this2;
|
2592 | }
|
2593 | var _proto = Realtime.prototype;
|
2594 | _proto._request = function () {
|
2595 | var _request2 = _asyncToGenerator( _regeneratorRuntime.mark(function _callee(_ref2) {
|
2596 | var method, _url, _ref2$version, version, path, query, headers, data, url, _this$_options, appId, server, _yield$this$construct, api;
|
2597 | return _regeneratorRuntime.wrap(function _callee$(_context) {
|
2598 | while (1) switch (_context.prev = _context.next) {
|
2599 | case 0:
|
2600 | method = _ref2.method, _url = _ref2.url, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1.1' : _ref2$version, path = _ref2.path, query = _ref2.query, headers = _ref2.headers, data = _ref2.data;
|
2601 | url = _url;
|
2602 | if (url) {
|
2603 | _context.next = 9;
|
2604 | break;
|
2605 | }
|
2606 | _this$_options = this._options, appId = _this$_options.appId, server = _this$_options.server;
|
2607 | _context.next = 6;
|
2608 | return this.constructor._getServerUrls({
|
2609 | appId: appId,
|
2610 | server: server
|
2611 | });
|
2612 | case 6:
|
2613 | _yield$this$construct = _context.sent;
|
2614 | api = _yield$this$construct.api;
|
2615 | url = "".concat(api, "/").concat(version).concat(path);
|
2616 | case 9:
|
2617 | return _context.abrupt("return", request({
|
2618 | url: url,
|
2619 | method: method,
|
2620 | query: query,
|
2621 | headers: _objectSpread$2({
|
2622 | 'X-LC-Id': this._options.appId,
|
2623 | 'X-LC-Key': this._options.appKey
|
2624 | }, headers),
|
2625 | data: data
|
2626 | }));
|
2627 | case 10:
|
2628 | case "end":
|
2629 | return _context.stop();
|
2630 | }
|
2631 | }, _callee, this);
|
2632 | }));
|
2633 | function _request(_x) {
|
2634 | return _request2.apply(this, arguments);
|
2635 | }
|
2636 | return _request;
|
2637 | }();
|
2638 | _proto._open = function _open() {
|
2639 | var _this3 = this;
|
2640 | if (this._openPromise) return this._openPromise;
|
2641 | var format = 'protobuf2';
|
2642 | if (this._options.noBinary) {
|
2643 |
|
2644 | format = 'proto2base64';
|
2645 | }
|
2646 | var version = 3;
|
2647 | var protocol = {
|
2648 | format: format,
|
2649 | version: version
|
2650 | };
|
2651 | this._openPromise = new Promise(function (resolve, reject) {
|
2652 | debug$6('No connection established, create a new one.');
|
2653 | var connection = new Connection(function () {
|
2654 | return _this3._getRTMServers(_this3._options);
|
2655 | }, protocol);
|
2656 | connection.on(OPEN, function () {
|
2657 | return resolve(connection);
|
2658 | }).on(ERROR, function (error) {
|
2659 | delete _this3._openPromise;
|
2660 | reject(error);
|
2661 | }).on(EXPIRE, _asyncToGenerator( _regeneratorRuntime.mark(function _callee2() {
|
2662 | return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
2663 | while (1) switch (_context2.prev = _context2.next) {
|
2664 | case 0:
|
2665 | debug$6('Connection expired. Refresh endpoints.');
|
2666 | _this3._cache.set('endpoints', null, 0);
|
2667 | _context2.next = 4;
|
2668 | return _this3._getRTMServers(_this3._options);
|
2669 | case 4:
|
2670 | connection.urls = _context2.sent;
|
2671 | connection.disconnect();
|
2672 | case 6:
|
2673 | case "end":
|
2674 | return _context2.stop();
|
2675 | }
|
2676 | }, _callee2);
|
2677 | }))).on(MESSAGE, _this3._dispatchCommand.bind(_this3));
|
2678 | |
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 | |
2685 |
|
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 | |
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 | |
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 | |
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 | |
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 | |
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 | |
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 | |
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 | |
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 | |
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 | [DISCONNECT, RECONNECT, RETRY, SCHEDULE, OFFLINE, ONLINE].forEach(function (event) {
|
2748 | return connection.on(event, function () {
|
2749 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
2750 | payload[_key] = arguments[_key];
|
2751 | }
|
2752 | debug$6("".concat(event, " event emitted. %o"), payload);
|
2753 | _this3.emit.apply(_this3, [event].concat(payload));
|
2754 | if (event !== RECONNECT) {
|
2755 | internal(_this3).clients.forEach(function (client) {
|
2756 | client.emit.apply(client, [event].concat(payload));
|
2757 | });
|
2758 | }
|
2759 | });
|
2760 | });
|
2761 |
|
2762 | connection.handleClose = function handleClose(event) {
|
2763 | var isFatal = [ErrorCode.APP_NOT_AVAILABLE, ErrorCode.INVALID_LOGIN, ErrorCode.INVALID_ORIGIN].some(function (errorCode) {
|
2764 | return errorCode === event.code;
|
2765 | });
|
2766 | if (isFatal) {
|
2767 |
|
2768 | this["throw"](createError(event));
|
2769 | } else {
|
2770 |
|
2771 | this.disconnect();
|
2772 | }
|
2773 | };
|
2774 | internal(_this3).connection = connection;
|
2775 | });
|
2776 | return this._openPromise;
|
2777 | };
|
2778 | _proto._getRTMServers = function () {
|
2779 | var _getRTMServers2 = _asyncToGenerator( _regeneratorRuntime.mark(function _callee3(options) {
|
2780 | var info, cachedEndPoints, _info, server, secondary, ttl;
|
2781 | return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
2782 | while (1) switch (_context3.prev = _context3.next) {
|
2783 | case 0:
|
2784 | if (!options.RTMServers) {
|
2785 | _context3.next = 2;
|
2786 | break;
|
2787 | }
|
2788 | return _context3.abrupt("return", shuffle(ensureArray(options.RTMServers)));
|
2789 | case 2:
|
2790 | cachedEndPoints = this._cache.get('endpoints');
|
2791 | if (!cachedEndPoints) {
|
2792 | _context3.next = 7;
|
2793 | break;
|
2794 | }
|
2795 | info = cachedEndPoints;
|
2796 | _context3.next = 14;
|
2797 | break;
|
2798 | case 7:
|
2799 | _context3.next = 9;
|
2800 | return this.constructor._fetchRTMServers(options);
|
2801 | case 9:
|
2802 | info = _context3.sent;
|
2803 | _info = info, server = _info.server, secondary = _info.secondary, ttl = _info.ttl;
|
2804 | if (!(typeof server !== 'string' && typeof secondary !== 'string' && typeof ttl !== 'number')) {
|
2805 | _context3.next = 13;
|
2806 | break;
|
2807 | }
|
2808 | throw new Error("malformed RTM route response: ".concat(JSON.stringify(info)));
|
2809 | case 13:
|
2810 | this._cache.set('endpoints', info, info.ttl * 1000);
|
2811 | case 14:
|
2812 | debug$6('endpoint info: %O', info);
|
2813 | return _context3.abrupt("return", [info.server, info.secondary]);
|
2814 | case 16:
|
2815 | case "end":
|
2816 | return _context3.stop();
|
2817 | }
|
2818 | }, _callee3, this);
|
2819 | }));
|
2820 | function _getRTMServers(_x2) {
|
2821 | return _getRTMServers2.apply(this, arguments);
|
2822 | }
|
2823 | return _getRTMServers;
|
2824 | }();
|
2825 | Realtime._getServerUrls = function () {
|
2826 | var _getServerUrls2 = _asyncToGenerator( _regeneratorRuntime.mark(function _callee4(_ref4) {
|
2827 | var appId, server, cachedRouter, defaultProtocol;
|
2828 | return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
2829 | while (1) switch (_context4.prev = _context4.next) {
|
2830 | case 0:
|
2831 | appId = _ref4.appId, server = _ref4.server;
|
2832 | debug$6('fetch server urls');
|
2833 | if (!server) {
|
2834 | _context4.next = 6;
|
2835 | break;
|
2836 | }
|
2837 | if (!(typeof server !== 'string')) {
|
2838 | _context4.next = 5;
|
2839 | break;
|
2840 | }
|
2841 | return _context4.abrupt("return", server);
|
2842 | case 5:
|
2843 | return _context4.abrupt("return", {
|
2844 | RTMRouter: server,
|
2845 | api: server
|
2846 | });
|
2847 | case 6:
|
2848 | cachedRouter = routerCache.get(appId);
|
2849 | if (!cachedRouter) {
|
2850 | _context4.next = 9;
|
2851 | break;
|
2852 | }
|
2853 | return _context4.abrupt("return", cachedRouter);
|
2854 | case 9:
|
2855 | defaultProtocol = 'https://';
|
2856 | return _context4.abrupt("return", request({
|
2857 | url: 'https://app-router.com/2/route',
|
2858 | query: {
|
2859 | appId: appId
|
2860 | },
|
2861 | timeout: 20000
|
2862 | }).then(tap(debug$6)).then(function (_ref5) {
|
2863 | var RTMRouterServer = _ref5.rtm_router_server,
|
2864 | APIServer = _ref5.api_server,
|
2865 | _ref5$ttl = _ref5.ttl,
|
2866 | ttl = _ref5$ttl === void 0 ? 3600 : _ref5$ttl;
|
2867 | if (!RTMRouterServer) {
|
2868 | throw new Error('rtm router not exists');
|
2869 | }
|
2870 | var serverUrls = {
|
2871 | RTMRouter: "".concat(defaultProtocol).concat(RTMRouterServer),
|
2872 | api: "".concat(defaultProtocol).concat(APIServer)
|
2873 | };
|
2874 | routerCache.set(appId, serverUrls, ttl * 1000);
|
2875 | return serverUrls;
|
2876 | })["catch"](function () {
|
2877 | var id = appId.slice(0, 8).toLowerCase();
|
2878 | var domain = 'lncldglobal.com';
|
2879 | return {
|
2880 | RTMRouter: "".concat(defaultProtocol).concat(id, ".rtm.").concat(domain),
|
2881 | api: "".concat(defaultProtocol).concat(id, ".api.").concat(domain)
|
2882 | };
|
2883 | }));
|
2884 | case 11:
|
2885 | case "end":
|
2886 | return _context4.stop();
|
2887 | }
|
2888 | }, _callee4);
|
2889 | }));
|
2890 | function _getServerUrls(_x3) {
|
2891 | return _getServerUrls2.apply(this, arguments);
|
2892 | }
|
2893 | return _getServerUrls;
|
2894 | }();
|
2895 | Realtime._fetchRTMServers = function _fetchRTMServers(_ref6) {
|
2896 | var appId = _ref6.appId,
|
2897 | ssl = _ref6.ssl,
|
2898 | server = _ref6.server,
|
2899 | RTMServerName = _ref6.RTMServerName;
|
2900 | debug$6('fetch endpoint info');
|
2901 | return this._getServerUrls({
|
2902 | appId: appId,
|
2903 | server: server
|
2904 | }).then(tap(debug$6)).then(function (_ref7) {
|
2905 | var RTMRouter = _ref7.RTMRouter;
|
2906 | return request({
|
2907 | url: "".concat(RTMRouter, "/v1/route"),
|
2908 | query: {
|
2909 | appId: appId,
|
2910 | secure: ssl,
|
2911 | features: isWeapp ? 'wechat' : undefined,
|
2912 | server: RTMServerName,
|
2913 | _t: Date.now()
|
2914 | },
|
2915 | timeout: 20000
|
2916 | }).then(tap(debug$6));
|
2917 | });
|
2918 | };
|
2919 | _proto._close = function _close() {
|
2920 | if (this._openPromise) {
|
2921 | this._openPromise.then(function (connection) {
|
2922 | return connection.close();
|
2923 | });
|
2924 | }
|
2925 | delete this._openPromise;
|
2926 | }
|
2927 |
|
2928 | |
2929 |
|
2930 |
|
2931 |
|
2932 | ;
|
2933 | _proto.retry = function retry() {
|
2934 | var _internal = internal(this),
|
2935 | connection = _internal.connection;
|
2936 | if (!connection) {
|
2937 | throw new Error('no connection established');
|
2938 | }
|
2939 | if (connection.cannot('retry')) {
|
2940 | throw new Error("retrying not allowed when not disconnected. the connection is now ".concat(connection.current));
|
2941 | }
|
2942 | return connection.retry();
|
2943 | }
|
2944 |
|
2945 | |
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 | ;
|
2953 | _proto.pause = function pause() {
|
2954 |
|
2955 |
|
2956 | var _internal2 = internal(this),
|
2957 | connection = _internal2.connection;
|
2958 | if (!connection) return;
|
2959 | if (connection.can('pause')) connection.pause();
|
2960 | }
|
2961 |
|
2962 | |
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 | ;
|
2969 | _proto.resume = function resume() {
|
2970 |
|
2971 | var _internal3 = internal(this),
|
2972 | connection = _internal3.connection;
|
2973 | if (!connection) return;
|
2974 | if (connection.can('resume')) connection.resume();
|
2975 | };
|
2976 | _proto._registerPending = function _registerPending(value) {
|
2977 | internal(this).pendingClients.add(value);
|
2978 | };
|
2979 | _proto._deregisterPending = function _deregisterPending(client) {
|
2980 | internal(this).pendingClients["delete"](client);
|
2981 | };
|
2982 | _proto._register = function _register(client) {
|
2983 | internal(this).clients.add(client);
|
2984 | };
|
2985 | _proto._deregister = function _deregister(client) {
|
2986 | var _this = internal(this);
|
2987 | _this.clients["delete"](client);
|
2988 | if (_this.clients.size + _this.pendingClients.size === 0) {
|
2989 | this._close();
|
2990 | }
|
2991 | };
|
2992 | _proto._dispatchCommand = function _dispatchCommand(command) {
|
2993 | return applyDispatcher(this._plugins.beforeCommandDispatch, [command, this]).then(function (shouldDispatch) {
|
2994 |
|
2995 | if (shouldDispatch) return debug$6('[WARN] Unexpected message received: %O', trim(command));
|
2996 | return false;
|
2997 | });
|
2998 | };
|
2999 | return Realtime;
|
3000 | }(EventEmitter);
|
3001 |
|
3002 | var polyfilledPromise = Promise;
|
3003 |
|
3004 | exports.EventEmitter = EventEmitter;
|
3005 | exports.Promise = polyfilledPromise;
|
3006 | exports.Protocals = message;
|
3007 | exports.Protocols = message;
|
3008 | exports.Realtime = Realtime;
|
3009 | exports.debug = debug$2;
|
3010 | exports.getAdapter = getAdapter;
|
3011 | exports.setAdapters = setAdapters;
|
3012 |
|