1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define('leancloud-realtime', ['exports'], factory) :
|
4 | (global = global || self, factory(global.AV = global.AV || {}));
|
5 | }(this, function (exports) { 'use strict';
|
6 |
|
7 | var define = undefined;
|
8 | var require = require || function(id) {throw new Error('Unexpected required ' + id)};
|
9 |
|
10 |
|
11 |
|
12 | var process = (typeof window !== 'undefined' && window.process) || {};
|
13 | process.env = process.env || {};
|
14 |
|
15 | var XMLHttpRequest;
|
16 |
|
17 | function _typeof(obj) {
|
18 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
19 | _typeof = function (obj) {
|
20 | return typeof obj;
|
21 | };
|
22 | } else {
|
23 | _typeof = function (obj) {
|
24 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
25 | };
|
26 | }
|
27 |
|
28 | return _typeof(obj);
|
29 | }
|
30 |
|
31 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
32 | try {
|
33 | var info = gen[key](arg);
|
34 | var value = info.value;
|
35 | } catch (error) {
|
36 | reject(error);
|
37 | return;
|
38 | }
|
39 |
|
40 | if (info.done) {
|
41 | resolve(value);
|
42 | } else {
|
43 | Promise.resolve(value).then(_next, _throw);
|
44 | }
|
45 | }
|
46 |
|
47 | function _asyncToGenerator(fn) {
|
48 | return function () {
|
49 | var self = this,
|
50 | args = arguments;
|
51 | return new Promise(function (resolve, reject) {
|
52 | var gen = fn.apply(self, args);
|
53 |
|
54 | function _next(value) {
|
55 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
56 | }
|
57 |
|
58 | function _throw(err) {
|
59 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
60 | }
|
61 |
|
62 | _next(undefined);
|
63 | });
|
64 | };
|
65 | }
|
66 |
|
67 | function _defineProperties(target, props) {
|
68 | for (var i = 0; i < props.length; i++) {
|
69 | var descriptor = props[i];
|
70 | descriptor.enumerable = descriptor.enumerable || false;
|
71 | descriptor.configurable = true;
|
72 | if ("value" in descriptor) descriptor.writable = true;
|
73 | Object.defineProperty(target, descriptor.key, descriptor);
|
74 | }
|
75 | }
|
76 |
|
77 | function _createClass(Constructor, protoProps, staticProps) {
|
78 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
79 | if (staticProps) _defineProperties(Constructor, staticProps);
|
80 | return Constructor;
|
81 | }
|
82 |
|
83 | function _defineProperty(obj, key, value) {
|
84 | if (key in obj) {
|
85 | Object.defineProperty(obj, key, {
|
86 | value: value,
|
87 | enumerable: true,
|
88 | configurable: true,
|
89 | writable: true
|
90 | });
|
91 | } else {
|
92 | obj[key] = value;
|
93 | }
|
94 |
|
95 | return obj;
|
96 | }
|
97 |
|
98 | function _objectSpread(target) {
|
99 | for (var i = 1; i < arguments.length; i++) {
|
100 | var source = arguments[i] != null ? arguments[i] : {};
|
101 | var ownKeys = Object.keys(source);
|
102 |
|
103 | if (typeof Object.getOwnPropertySymbols === 'function') {
|
104 | ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
105 | return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
106 | }));
|
107 | }
|
108 |
|
109 | ownKeys.forEach(function (key) {
|
110 | _defineProperty(target, key, source[key]);
|
111 | });
|
112 | }
|
113 |
|
114 | return target;
|
115 | }
|
116 |
|
117 | function _inheritsLoose(subClass, superClass) {
|
118 | subClass.prototype = Object.create(superClass.prototype);
|
119 | subClass.prototype.constructor = subClass;
|
120 | subClass.__proto__ = superClass;
|
121 | }
|
122 |
|
123 | function _objectWithoutPropertiesLoose(source, excluded) {
|
124 | if (source == null) return {};
|
125 | var target = {};
|
126 | var sourceKeys = Object.keys(source);
|
127 | var key, i;
|
128 |
|
129 | for (i = 0; i < sourceKeys.length; i++) {
|
130 | key = sourceKeys[i];
|
131 | if (excluded.indexOf(key) >= 0) continue;
|
132 | target[key] = source[key];
|
133 | }
|
134 |
|
135 | return target;
|
136 | }
|
137 |
|
138 | function _objectWithoutProperties(source, excluded) {
|
139 | if (source == null) return {};
|
140 |
|
141 | var target = _objectWithoutPropertiesLoose(source, excluded);
|
142 |
|
143 | var key, i;
|
144 |
|
145 | if (Object.getOwnPropertySymbols) {
|
146 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
147 |
|
148 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
149 | key = sourceSymbolKeys[i];
|
150 | if (excluded.indexOf(key) >= 0) continue;
|
151 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
152 | target[key] = source[key];
|
153 | }
|
154 | }
|
155 |
|
156 | return target;
|
157 | }
|
158 |
|
159 | function _assertThisInitialized(self) {
|
160 | if (self === void 0) {
|
161 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
162 | }
|
163 |
|
164 | return self;
|
165 | }
|
166 |
|
167 | function _slicedToArray(arr, i) {
|
168 | return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
|
169 | }
|
170 |
|
171 | function _toArray(arr) {
|
172 | return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
|
173 | }
|
174 |
|
175 | function _toConsumableArray(arr) {
|
176 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
177 | }
|
178 |
|
179 | function _arrayWithoutHoles(arr) {
|
180 | if (Array.isArray(arr)) {
|
181 | for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
182 |
|
183 | return arr2;
|
184 | }
|
185 | }
|
186 |
|
187 | function _arrayWithHoles(arr) {
|
188 | if (Array.isArray(arr)) return arr;
|
189 | }
|
190 |
|
191 | function _iterableToArray(iter) {
|
192 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
193 | }
|
194 |
|
195 | function _iterableToArrayLimit(arr, i) {
|
196 | var _arr = [];
|
197 | var _n = true;
|
198 | var _d = false;
|
199 | var _e = undefined;
|
200 |
|
201 | try {
|
202 | for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
203 | _arr.push(_s.value);
|
204 |
|
205 | if (i && _arr.length === i) break;
|
206 | }
|
207 | } catch (err) {
|
208 | _d = true;
|
209 | _e = err;
|
210 | } finally {
|
211 | try {
|
212 | if (!_n && _i["return"] != null) _i["return"]();
|
213 | } finally {
|
214 | if (_d) throw _e;
|
215 | }
|
216 | }
|
217 |
|
218 | return _arr;
|
219 | }
|
220 |
|
221 | function _nonIterableSpread() {
|
222 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
223 | }
|
224 |
|
225 | function _nonIterableRest() {
|
226 | throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
227 | }
|
228 |
|
229 | function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
230 | var desc = {};
|
231 | Object['ke' + 'ys'](descriptor).forEach(function (key) {
|
232 | desc[key] = descriptor[key];
|
233 | });
|
234 | desc.enumerable = !!desc.enumerable;
|
235 | desc.configurable = !!desc.configurable;
|
236 |
|
237 | if ('value' in desc || desc.initializer) {
|
238 | desc.writable = true;
|
239 | }
|
240 |
|
241 | desc = decorators.slice().reverse().reduce(function (desc, decorator) {
|
242 | return decorator(target, property, desc) || desc;
|
243 | }, desc);
|
244 |
|
245 | if (context && desc.initializer !== void 0) {
|
246 | desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
247 | desc.initializer = undefined;
|
248 | }
|
249 |
|
250 | if (desc.initializer === void 0) {
|
251 | Object['define' + 'Property'](target, property, desc);
|
252 | desc = null;
|
253 | }
|
254 |
|
255 | return desc;
|
256 | }
|
257 |
|
258 | var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
259 |
|
260 | function commonjsRequire () {
|
261 | throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
|
262 | }
|
263 |
|
264 | function createCommonjsModule(fn, module) {
|
265 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
266 | }
|
267 |
|
268 | function getCjsExportFromNamespace (n) {
|
269 | return n && n.default || n;
|
270 | }
|
271 |
|
272 | var Storage =
|
273 |
|
274 | function () {
|
275 | function Storage() {}
|
276 |
|
277 | var _proto = Storage.prototype;
|
278 |
|
279 | _proto.getItem = function getItem(key) {
|
280 | return wx.getStorageSync(key);
|
281 | };
|
282 |
|
283 | _proto.setItem = function setItem(key, value) {
|
284 | return wx.setStorageSync(key, value);
|
285 | };
|
286 |
|
287 | _proto.removeItem = function removeItem(key) {
|
288 | return this.setItem(key, '');
|
289 | };
|
290 |
|
291 | _proto.clear = function clear() {
|
292 | return wx.clearStorageSync();
|
293 | };
|
294 |
|
295 | return Storage;
|
296 | }();
|
297 |
|
298 | var localstorage = new Storage();
|
299 |
|
300 | |
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
307 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
308 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
309 |
|
310 | function toObject(val) {
|
311 | if (val === null || val === undefined) {
|
312 | throw new TypeError('Object.assign cannot be called with null or undefined');
|
313 | }
|
314 |
|
315 | return Object(val);
|
316 | }
|
317 |
|
318 | function shouldUseNative() {
|
319 | try {
|
320 | if (!Object.assign) {
|
321 | return false;
|
322 | }
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | var test1 = new String('abc');
|
328 | test1[5] = 'de';
|
329 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
330 | return false;
|
331 | }
|
332 |
|
333 |
|
334 | var test2 = {};
|
335 | for (var i = 0; i < 10; i++) {
|
336 | test2['_' + String.fromCharCode(i)] = i;
|
337 | }
|
338 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
339 | return test2[n];
|
340 | });
|
341 | if (order2.join('') !== '0123456789') {
|
342 | return false;
|
343 | }
|
344 |
|
345 |
|
346 | var test3 = {};
|
347 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
348 | test3[letter] = letter;
|
349 | });
|
350 | if (Object.keys(Object.assign({}, test3)).join('') !==
|
351 | 'abcdefghijklmnopqrst') {
|
352 | return false;
|
353 | }
|
354 |
|
355 | return true;
|
356 | } catch (err) {
|
357 |
|
358 | return false;
|
359 | }
|
360 | }
|
361 |
|
362 | var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
363 | var from;
|
364 | var to = toObject(target);
|
365 | var symbols;
|
366 |
|
367 | for (var s = 1; s < arguments.length; s++) {
|
368 | from = Object(arguments[s]);
|
369 |
|
370 | for (var key in from) {
|
371 | if (hasOwnProperty.call(from, key)) {
|
372 | to[key] = from[key];
|
373 | }
|
374 | }
|
375 |
|
376 | if (getOwnPropertySymbols) {
|
377 | symbols = getOwnPropertySymbols(from);
|
378 | for (var i = 0; i < symbols.length; i++) {
|
379 | if (propIsEnumerable.call(from, symbols[i])) {
|
380 | to[symbols[i]] = from[symbols[i]];
|
381 | }
|
382 | }
|
383 | }
|
384 | }
|
385 |
|
386 | return to;
|
387 | };
|
388 |
|
389 | var commons = createCommonjsModule(function (module, exports) {
|
390 |
|
391 | |
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | var createUniqueKey = exports.createUniqueKey = (typeof Symbol !== "undefined" ?
|
399 | Symbol :
|
400 | function createUniqueKey(name) {
|
401 | return "[[" + name + "_" + Math.random().toFixed(8).slice(2) + "]]";
|
402 | });
|
403 |
|
404 | |
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 | exports.LISTENERS = createUniqueKey("listeners");
|
411 |
|
412 | |
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | exports.CAPTURE = 1;
|
419 |
|
420 | |
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 | exports.BUBBLE = 2;
|
427 |
|
428 | |
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 | exports.ATTRIBUTE = 3;
|
435 |
|
436 | |
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | |
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 | exports.newNode = function newNode(listener, kind) {
|
452 | return {listener: listener, kind: kind, next: null};
|
453 | };
|
454 | });
|
455 | var commons_1 = commons.createUniqueKey;
|
456 | var commons_2 = commons.LISTENERS;
|
457 | var commons_3 = commons.CAPTURE;
|
458 | var commons_4 = commons.BUBBLE;
|
459 | var commons_5 = commons.ATTRIBUTE;
|
460 | var commons_6 = commons.newNode;
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 | var LISTENERS = commons.LISTENERS;
|
468 | var ATTRIBUTE = commons.ATTRIBUTE;
|
469 | var newNode = commons.newNode;
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 | |
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | function getAttributeListener(eventTarget, type) {
|
483 | var node = eventTarget[LISTENERS][type];
|
484 | while (node != null) {
|
485 | if (node.kind === ATTRIBUTE) {
|
486 | return node.listener;
|
487 | }
|
488 | node = node.next;
|
489 | }
|
490 | return null;
|
491 | }
|
492 |
|
493 | |
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 | function setAttributeListener(eventTarget, type, listener) {
|
502 | if (typeof listener !== "function" && typeof listener !== "object") {
|
503 | listener = null;
|
504 | }
|
505 |
|
506 | var prev = null;
|
507 | var node = eventTarget[LISTENERS][type];
|
508 | while (node != null) {
|
509 | if (node.kind === ATTRIBUTE) {
|
510 |
|
511 | if (prev == null) {
|
512 | eventTarget[LISTENERS][type] = node.next;
|
513 | }
|
514 | else {
|
515 | prev.next = node.next;
|
516 | }
|
517 | }
|
518 | else {
|
519 | prev = node;
|
520 | }
|
521 |
|
522 | node = node.next;
|
523 | }
|
524 |
|
525 |
|
526 | if (listener != null) {
|
527 | if (prev == null) {
|
528 | eventTarget[LISTENERS][type] = newNode(listener, ATTRIBUTE);
|
529 | }
|
530 | else {
|
531 | prev.next = newNode(listener, ATTRIBUTE);
|
532 | }
|
533 | }
|
534 | }
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 | |
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 | var defineCustomEventTarget = function(EventTargetBase, types) {
|
548 | function EventTarget() {
|
549 | EventTargetBase.call(this);
|
550 | }
|
551 |
|
552 | var descripter = {
|
553 | constructor: {
|
554 | value: EventTarget,
|
555 | configurable: true,
|
556 | writable: true
|
557 | }
|
558 | };
|
559 |
|
560 | types.forEach(function(type) {
|
561 | descripter["on" + type] = {
|
562 | get: function() { return getAttributeListener(this, type); },
|
563 | set: function(listener) { setAttributeListener(this, type, listener); },
|
564 | configurable: true,
|
565 | enumerable: true
|
566 | };
|
567 | });
|
568 |
|
569 | EventTarget.prototype = Object.create(EventTargetBase.prototype, descripter);
|
570 |
|
571 | return EventTarget;
|
572 | };
|
573 |
|
574 | var customEventTarget = {
|
575 | defineCustomEventTarget: defineCustomEventTarget
|
576 | };
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | var createUniqueKey = commons.createUniqueKey;
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 | |
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 | var STOP_IMMEDIATE_PROPAGATION_FLAG =
|
595 | createUniqueKey("stop_immediate_propagation_flag");
|
596 |
|
597 | |
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 | var CANCELED_FLAG = createUniqueKey("canceled_flag");
|
604 |
|
605 | |
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 | var ORIGINAL_EVENT = createUniqueKey("original_event");
|
612 |
|
613 | |
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 | var wrapperPrototypeDefinition = Object.freeze({
|
620 | stopPropagation: Object.freeze({
|
621 | value: function stopPropagation() {
|
622 | var e = this[ORIGINAL_EVENT];
|
623 | if (typeof e.stopPropagation === "function") {
|
624 | e.stopPropagation();
|
625 | }
|
626 | },
|
627 | writable: true,
|
628 | configurable: true
|
629 | }),
|
630 |
|
631 | stopImmediatePropagation: Object.freeze({
|
632 | value: function stopImmediatePropagation() {
|
633 | this[STOP_IMMEDIATE_PROPAGATION_FLAG] = true;
|
634 |
|
635 | var e = this[ORIGINAL_EVENT];
|
636 | if (typeof e.stopImmediatePropagation === "function") {
|
637 | e.stopImmediatePropagation();
|
638 | }
|
639 | },
|
640 | writable: true,
|
641 | configurable: true
|
642 | }),
|
643 |
|
644 | preventDefault: Object.freeze({
|
645 | value: function preventDefault() {
|
646 | if (this.cancelable === true) {
|
647 | this[CANCELED_FLAG] = true;
|
648 | }
|
649 |
|
650 | var e = this[ORIGINAL_EVENT];
|
651 | if (typeof e.preventDefault === "function") {
|
652 | e.preventDefault();
|
653 | }
|
654 | },
|
655 | writable: true,
|
656 | configurable: true
|
657 | }),
|
658 |
|
659 | defaultPrevented: Object.freeze({
|
660 | get: function defaultPrevented() { return this[CANCELED_FLAG]; },
|
661 | enumerable: true,
|
662 | configurable: true
|
663 | })
|
664 | });
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 | var STOP_IMMEDIATE_PROPAGATION_FLAG_1 = STOP_IMMEDIATE_PROPAGATION_FLAG;
|
671 |
|
672 | |
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 | var createEventWrapper = function createEventWrapper(event, eventTarget) {
|
684 | var timeStamp = (
|
685 | typeof event.timeStamp === "number" ? event.timeStamp : Date.now()
|
686 | );
|
687 | var propertyDefinition = {
|
688 | type: {value: event.type, enumerable: true},
|
689 | target: {value: eventTarget, enumerable: true},
|
690 | currentTarget: {value: eventTarget, enumerable: true},
|
691 | eventPhase: {value: 2, enumerable: true},
|
692 | bubbles: {value: Boolean(event.bubbles), enumerable: true},
|
693 | cancelable: {value: Boolean(event.cancelable), enumerable: true},
|
694 | timeStamp: {value: timeStamp, enumerable: true},
|
695 | isTrusted: {value: false, enumerable: true}
|
696 | };
|
697 | propertyDefinition[STOP_IMMEDIATE_PROPAGATION_FLAG] = {value: false, writable: true};
|
698 | propertyDefinition[CANCELED_FLAG] = {value: false, writable: true};
|
699 | propertyDefinition[ORIGINAL_EVENT] = {value: event};
|
700 |
|
701 |
|
702 | if (typeof event.detail !== "undefined") {
|
703 | propertyDefinition.detail = {value: event.detail, enumerable: true};
|
704 | }
|
705 |
|
706 | return Object.create(
|
707 | Object.create(event, wrapperPrototypeDefinition),
|
708 | propertyDefinition
|
709 | );
|
710 | };
|
711 |
|
712 | var eventWrapper = {
|
713 | STOP_IMMEDIATE_PROPAGATION_FLAG: STOP_IMMEDIATE_PROPAGATION_FLAG_1,
|
714 | createEventWrapper: createEventWrapper
|
715 | };
|
716 |
|
717 | var eventTarget = createCommonjsModule(function (module) {
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 | var LISTENERS = commons.LISTENERS;
|
727 | var CAPTURE = commons.CAPTURE;
|
728 | var BUBBLE = commons.BUBBLE;
|
729 | var ATTRIBUTE = commons.ATTRIBUTE;
|
730 | var newNode = commons.newNode;
|
731 | var defineCustomEventTarget = customEventTarget.defineCustomEventTarget;
|
732 | var createEventWrapper = eventWrapper.createEventWrapper;
|
733 | var STOP_IMMEDIATE_PROPAGATION_FLAG =
|
734 | eventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | |
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 | var HAS_EVENTTARGET_INTERFACE = (
|
747 | typeof window !== "undefined" &&
|
748 | typeof window.EventTarget !== "undefined"
|
749 | );
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 | |
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 | var EventTarget = module.exports = function EventTarget() {
|
762 | if (this instanceof EventTarget) {
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 | Object.defineProperty(this, LISTENERS, {value: Object.create(null)});
|
773 | }
|
774 | else if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
775 | return defineCustomEventTarget(EventTarget, arguments[0]);
|
776 | }
|
777 | else if (arguments.length > 0) {
|
778 | var types = Array(arguments.length);
|
779 | for (var i = 0; i < arguments.length; ++i) {
|
780 | types[i] = arguments[i];
|
781 | }
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 | return defineCustomEventTarget(EventTarget, types);
|
789 | }
|
790 | else {
|
791 | throw new TypeError("Cannot call a class as a function");
|
792 | }
|
793 | };
|
794 |
|
795 | EventTarget.prototype = Object.create(
|
796 | (HAS_EVENTTARGET_INTERFACE ? window.EventTarget : Object).prototype,
|
797 | {
|
798 | constructor: {
|
799 | value: EventTarget,
|
800 | writable: true,
|
801 | configurable: true
|
802 | },
|
803 |
|
804 | addEventListener: {
|
805 | value: function addEventListener(type, listener, capture) {
|
806 | if (listener == null) {
|
807 | return false;
|
808 | }
|
809 | if (typeof listener !== "function" && typeof listener !== "object") {
|
810 | throw new TypeError("\"listener\" is not an object.");
|
811 | }
|
812 |
|
813 | var kind = (capture ? CAPTURE : BUBBLE);
|
814 | var node = this[LISTENERS][type];
|
815 | if (node == null) {
|
816 | this[LISTENERS][type] = newNode(listener, kind);
|
817 | return true;
|
818 | }
|
819 |
|
820 | var prev = null;
|
821 | while (node != null) {
|
822 | if (node.listener === listener && node.kind === kind) {
|
823 |
|
824 | return false;
|
825 | }
|
826 | prev = node;
|
827 | node = node.next;
|
828 | }
|
829 |
|
830 | prev.next = newNode(listener, kind);
|
831 | return true;
|
832 | },
|
833 | configurable: true,
|
834 | writable: true
|
835 | },
|
836 |
|
837 | removeEventListener: {
|
838 | value: function removeEventListener(type, listener, capture) {
|
839 | if (listener == null) {
|
840 | return false;
|
841 | }
|
842 |
|
843 | var kind = (capture ? CAPTURE : BUBBLE);
|
844 | var prev = null;
|
845 | var node = this[LISTENERS][type];
|
846 | while (node != null) {
|
847 | if (node.listener === listener && node.kind === kind) {
|
848 | if (prev == null) {
|
849 | this[LISTENERS][type] = node.next;
|
850 | }
|
851 | else {
|
852 | prev.next = node.next;
|
853 | }
|
854 | return true;
|
855 | }
|
856 |
|
857 | prev = node;
|
858 | node = node.next;
|
859 | }
|
860 |
|
861 | return false;
|
862 | },
|
863 | configurable: true,
|
864 | writable: true
|
865 | },
|
866 |
|
867 | dispatchEvent: {
|
868 | value: function dispatchEvent(event) {
|
869 |
|
870 | var node = this[LISTENERS][event.type];
|
871 | if (node == null) {
|
872 | return true;
|
873 | }
|
874 |
|
875 |
|
876 | var wrapped = createEventWrapper(event, this);
|
877 |
|
878 |
|
879 |
|
880 | while (node != null) {
|
881 | if (typeof node.listener === "function") {
|
882 | node.listener.call(this, wrapped);
|
883 | }
|
884 | else if (node.kind !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
|
885 | node.listener.handleEvent(wrapped);
|
886 | }
|
887 |
|
888 | if (wrapped[STOP_IMMEDIATE_PROPAGATION_FLAG]) {
|
889 | break;
|
890 | }
|
891 | node = node.next;
|
892 | }
|
893 |
|
894 | return !wrapped.defaultPrevented;
|
895 | },
|
896 | configurable: true,
|
897 | writable: true
|
898 | }
|
899 | }
|
900 | );
|
901 | });
|
902 |
|
903 | var FormData$1 =
|
904 |
|
905 | function () {
|
906 | function FormData() {
|
907 | this._entries = [];
|
908 | }
|
909 |
|
910 | var _proto = FormData.prototype;
|
911 |
|
912 | _proto.append = function append(name, value) {
|
913 | if (typeof name !== 'string') {
|
914 | throw new TypeError('FormData name must be a string');
|
915 | }
|
916 |
|
917 | if (typeof value !== 'string') {
|
918 | if (_typeof(value) !== 'object' || typeof value.uri !== 'string') {
|
919 | throw new TypeError('FormData value must be a string or { uri: tempFilePath }');
|
920 | }
|
921 | }
|
922 |
|
923 | this._entries.push([name, value]);
|
924 | };
|
925 |
|
926 | _proto.set = function set(name, value) {
|
927 | var entry = this.get(name);
|
928 |
|
929 | if (entry) {
|
930 | entry[1] = value;
|
931 | } else {
|
932 | this.append(name, value);
|
933 | }
|
934 | };
|
935 |
|
936 | _proto.delete = function _delete(name) {
|
937 | this._entries = this._entries.filter(function (entry) {
|
938 | return entry[0] !== name;
|
939 | });
|
940 | };
|
941 |
|
942 | _proto.entries = function entries() {
|
943 | return this._entries;
|
944 | };
|
945 |
|
946 | _proto.get = function get(name) {
|
947 | return this._entries.find(function (entry) {
|
948 | return entry[0] === name;
|
949 | });
|
950 | };
|
951 |
|
952 | _proto.getAll = function getAll(name) {
|
953 | return this._entries.filter(function (entry) {
|
954 | return entry[0] === name;
|
955 | });
|
956 | };
|
957 |
|
958 | _proto.has = function has(name) {
|
959 | return this._entries.some(function (entry) {
|
960 | return entry[0] === name;
|
961 | });
|
962 | };
|
963 |
|
964 | _proto.keys = function keys() {
|
965 | return this._entries.map(function (entry) {
|
966 | return entry[0];
|
967 | });
|
968 | };
|
969 |
|
970 | _proto.values = function values() {
|
971 | return this._entries.map(function (entry) {
|
972 | return entry[1];
|
973 | });
|
974 | };
|
975 |
|
976 | return FormData;
|
977 | }();
|
978 |
|
979 | var formdata = FormData$1;
|
980 |
|
981 | var UNSENT = 0;
|
982 | var OPENED = 1;
|
983 | var HEADERS_RECEIVED = 2;
|
984 | var LOADING = 3;
|
985 | var DONE = 4;
|
986 | var REQUEST_EVENTS = ['abort', 'error', 'load', 'loadstart', 'progress', 'timeout', 'loadend', 'readystatechange'];
|
987 | var REQUEST_UPLOAD_EVENTS = ['abort', 'error', 'load', 'loadstart', 'progress', 'timeout', 'loadend'];
|
988 |
|
989 | function successCallback(response) {
|
990 | this.status = response.statusCode;
|
991 | this.statusText = response.statusCode;
|
992 |
|
993 | if (response.header) {
|
994 | this._responseHeaders = Object.keys(response.header).reduce(function (headers, key) {
|
995 | headers[key.toLowerCase()] = response.header[key];
|
996 | return headers;
|
997 | }, {});
|
998 | }
|
999 |
|
1000 | var text = response.data;
|
1001 |
|
1002 | if (typeof text !== 'string') {
|
1003 | text = JSON.stringify(text);
|
1004 | }
|
1005 |
|
1006 | this.responseText = this.response = text;
|
1007 | this.readyState = DONE;
|
1008 | this.dispatchEvent({
|
1009 | type: 'readystatechange'
|
1010 | });
|
1011 | }
|
1012 |
|
1013 | var XMLHttpRequestUpload =
|
1014 |
|
1015 | function (_EventTarget) {
|
1016 | _inheritsLoose(XMLHttpRequestUpload, _EventTarget);
|
1017 |
|
1018 | function XMLHttpRequestUpload() {
|
1019 | return _EventTarget.apply(this, arguments) || this;
|
1020 | }
|
1021 |
|
1022 | return XMLHttpRequestUpload;
|
1023 | }(eventTarget(REQUEST_UPLOAD_EVENTS));
|
1024 |
|
1025 | var XMLHttpRequest$1 =
|
1026 |
|
1027 | function (_EventTarget2) {
|
1028 | _inheritsLoose(XMLHttpRequest, _EventTarget2);
|
1029 |
|
1030 | function XMLHttpRequest() {
|
1031 | var _this;
|
1032 |
|
1033 | _this = _EventTarget2.call(this) || this;
|
1034 | _this.readyState = UNSENT;
|
1035 | _this._headers = {};
|
1036 | _this.upload = new XMLHttpRequestUpload();
|
1037 | return _this;
|
1038 | }
|
1039 |
|
1040 | var _proto = XMLHttpRequest.prototype;
|
1041 |
|
1042 | _proto.abort = function abort() {
|
1043 |
|
1044 | if (!this._request || this._request.abort) {
|
1045 | this.status = 0;
|
1046 | this.readyState = DONE;
|
1047 | return this._request.abort();
|
1048 | }
|
1049 |
|
1050 | throw new Error('该版本基础库不支持 abort request');
|
1051 | };
|
1052 |
|
1053 | _proto.getAllResponseHeaders = function getAllResponseHeaders() {
|
1054 | var _this2 = this;
|
1055 |
|
1056 | return this._responseHeaders ? Object.keys(this._responseHeaders).map(function (key) {
|
1057 | return "".concat(key, ": ").concat(_this2._responseHeaders[key]);
|
1058 | }).join('\r\n') : '';
|
1059 | };
|
1060 |
|
1061 | _proto.getResponseHeader = function getResponseHeader(key) {
|
1062 | var lowserCasedKey = key.toLowerCase();
|
1063 |
|
1064 | if (this._responseHeaders && this._responseHeaders[lowserCasedKey]) {
|
1065 | return this._responseHeaders[lowserCasedKey];
|
1066 | }
|
1067 |
|
1068 | return null;
|
1069 | };
|
1070 |
|
1071 | _proto.overrideMimeType = function overrideMimeType() {
|
1072 | throw new Error('not supported in weapp');
|
1073 | };
|
1074 |
|
1075 | _proto.open = function open(method, url) {
|
1076 | var async = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
1077 |
|
1078 | if (this.readyState !== UNSENT) {
|
1079 | throw new Error('request is already opened');
|
1080 | }
|
1081 |
|
1082 | if (!async) {
|
1083 | throw new Error('sync request is not supported');
|
1084 | }
|
1085 |
|
1086 | this._method = method;
|
1087 | this._url = url;
|
1088 | this.readyState = OPENED;
|
1089 | this.dispatchEvent({
|
1090 | type: 'readystatechange'
|
1091 | });
|
1092 | };
|
1093 |
|
1094 | _proto.setRequestHeader = function setRequestHeader(header, value) {
|
1095 | if (this.readyState !== OPENED) {
|
1096 | throw new Error('request is not opened');
|
1097 | }
|
1098 |
|
1099 | this._headers[header.toLowerCase()] = value;
|
1100 | };
|
1101 |
|
1102 | _proto.send = function send(data) {
|
1103 | var _this3 = this;
|
1104 |
|
1105 | if (this.readyState !== OPENED) {
|
1106 | throw new Error('request is not opened');
|
1107 | }
|
1108 |
|
1109 | if (data instanceof formdata) {
|
1110 | var entries = data.entries();
|
1111 | var blobs = entries.filter(function (entry) {
|
1112 | return typeof entry[1] !== 'string';
|
1113 | });
|
1114 |
|
1115 | if (blobs.length === 0) {
|
1116 | throw new Error('Must specify a Blob field in FormData');
|
1117 | }
|
1118 |
|
1119 | if (blobs.length > 1) {
|
1120 | console.warn('Only the first Blob will be send in Weapp');
|
1121 | }
|
1122 |
|
1123 | var restData = entries.filter(function (entry) {
|
1124 | return typeof entry[1] === 'string';
|
1125 | }).reduce(function (result, entry) {
|
1126 | return objectAssign(result, _defineProperty({}, entry[0], entry[1]));
|
1127 | }, {});
|
1128 | this._request = wx.uploadFile({
|
1129 | url: this._url,
|
1130 | name: blobs[0][0],
|
1131 | filePath: blobs[0][1].uri,
|
1132 | formData: restData,
|
1133 | header: this._headers,
|
1134 | success: successCallback.bind(this),
|
1135 | fail: function fail(error) {
|
1136 | _this3.status = 0;
|
1137 | _this3.readyState = DONE;
|
1138 |
|
1139 | _this3.dispatchEvent({
|
1140 | type: 'readystatechange'
|
1141 | });
|
1142 |
|
1143 | _this3.dispatchEvent({
|
1144 | type: 'error'
|
1145 | });
|
1146 | }
|
1147 | });
|
1148 |
|
1149 | if (this._request && this._request.onProgressUpdate) {
|
1150 | this._request.onProgressUpdate(function (_ref) {
|
1151 | var totalBytesSent = _ref.totalBytesSent,
|
1152 | totalBytesExpectedToSend = _ref.totalBytesExpectedToSend;
|
1153 |
|
1154 | _this3.upload.dispatchEvent({
|
1155 | type: 'progress',
|
1156 | loaded: totalBytesSent,
|
1157 | total: totalBytesExpectedToSend
|
1158 | });
|
1159 | });
|
1160 | }
|
1161 | } else {
|
1162 | this._request = wx.request({
|
1163 | url: this._url,
|
1164 | data: data || '',
|
1165 |
|
1166 | method: this._method.toUpperCase(),
|
1167 | header: this._headers,
|
1168 | success: successCallback.bind(this),
|
1169 | fail: function fail(error) {
|
1170 | _this3.status = 0;
|
1171 | _this3.readyState = DONE;
|
1172 |
|
1173 | _this3.dispatchEvent({
|
1174 | type: 'readystatechange'
|
1175 | });
|
1176 |
|
1177 | _this3.dispatchEvent({
|
1178 | type: 'error'
|
1179 | });
|
1180 | }
|
1181 | });
|
1182 | }
|
1183 | };
|
1184 |
|
1185 | return XMLHttpRequest;
|
1186 | }(eventTarget(REQUEST_EVENTS));
|
1187 |
|
1188 | objectAssign(XMLHttpRequest$1, {
|
1189 | UNSENT: UNSENT,
|
1190 | OPENED: OPENED,
|
1191 | HEADERS_RECEIVED: HEADERS_RECEIVED,
|
1192 | LOADING: LOADING,
|
1193 | DONE: DONE
|
1194 | });
|
1195 | var xmlhttprequest = XMLHttpRequest$1;
|
1196 |
|
1197 | var CONNECTING = 0;
|
1198 | var OPEN = 1;
|
1199 | var CLOSING = 2;
|
1200 | var CLOSED = 3;
|
1201 | var EVENTS = ['open', 'error', 'message', 'close'];
|
1202 |
|
1203 | var WebSocket$1 =
|
1204 |
|
1205 | function (_EventTarget) {
|
1206 | _inheritsLoose(WebSocket, _EventTarget);
|
1207 |
|
1208 | function WebSocket(url, protocal) {
|
1209 | var _this;
|
1210 |
|
1211 | if (!url) {
|
1212 | throw new TypeError('Failed to construct \'WebSocket\': url required');
|
1213 | }
|
1214 |
|
1215 | if (protocal && !(wx.canIUse && wx.canIUse('connectSocket.object.protocols'))) {
|
1216 | throw new Error('subprotocal not supported in weapp');
|
1217 | }
|
1218 |
|
1219 | _this = _EventTarget.call(this) || this;
|
1220 | _this._url = url;
|
1221 | _this._protocal = protocal || '';
|
1222 |
|
1223 | _this._readyState = CONNECTING;
|
1224 |
|
1225 | var errorHandler = function errorHandler(event) {
|
1226 | _this._readyState = CLOSED;
|
1227 |
|
1228 | _this.dispatchEvent({
|
1229 | type: 'error',
|
1230 | message: event.errMsg
|
1231 | });
|
1232 | };
|
1233 |
|
1234 | var socketTask = wx.connectSocket({
|
1235 | url: url,
|
1236 | protocals: _this._protocal,
|
1237 | fail: function fail(error) {
|
1238 | return setTimeout(function () {
|
1239 | return errorHandler(error);
|
1240 | }, 0);
|
1241 | }
|
1242 | });
|
1243 | _this._socketTask = socketTask;
|
1244 | socketTask.onOpen(function (event) {
|
1245 | _this._readyState = OPEN;
|
1246 |
|
1247 | _this.dispatchEvent({
|
1248 | type: 'open'
|
1249 | });
|
1250 | });
|
1251 | socketTask.onError(errorHandler);
|
1252 | socketTask.onMessage(function (event) {
|
1253 | var data = event.data,
|
1254 | origin = event.origin,
|
1255 | ports = event.ports,
|
1256 | source = event.source;
|
1257 |
|
1258 | _this.dispatchEvent({
|
1259 | data: data,
|
1260 | origin: origin,
|
1261 | ports: ports,
|
1262 | source: source,
|
1263 | type: 'message'
|
1264 | });
|
1265 | });
|
1266 | socketTask.onClose(function (event) {
|
1267 | _this._readyState = CLOSED;
|
1268 | var code = event.code,
|
1269 | reason = event.reason,
|
1270 | wasClean = event.wasClean;
|
1271 |
|
1272 | _this.dispatchEvent({
|
1273 | code: code,
|
1274 | reason: reason,
|
1275 | wasClean: wasClean,
|
1276 | type: 'close'
|
1277 | });
|
1278 | });
|
1279 | return _this;
|
1280 | }
|
1281 |
|
1282 | var _proto = WebSocket.prototype;
|
1283 |
|
1284 | _proto.close = function close() {
|
1285 | if (this.readyState === CLOSED) return;
|
1286 |
|
1287 | if (this.readyState === CONNECTING) {
|
1288 | console.warn('close WebSocket which is connecting might not work');
|
1289 | }
|
1290 |
|
1291 | this._socketTask.close();
|
1292 | };
|
1293 |
|
1294 | _proto.send = function send(data) {
|
1295 | if (this.readyState !== OPEN) {
|
1296 | throw new Error('INVALID_STATE_ERR');
|
1297 | }
|
1298 |
|
1299 | if (!(typeof data === 'string' || data instanceof ArrayBuffer)) {
|
1300 | throw new TypeError('only String/ArrayBuffer supported');
|
1301 | }
|
1302 |
|
1303 | this._socketTask.send({
|
1304 | data: data
|
1305 | });
|
1306 | };
|
1307 |
|
1308 | _createClass(WebSocket, [{
|
1309 | key: "url",
|
1310 | get: function get() {
|
1311 | return this._url;
|
1312 | }
|
1313 | }, {
|
1314 | key: "protocal",
|
1315 | get: function get() {
|
1316 | return this._protocal;
|
1317 | }
|
1318 | }, {
|
1319 | key: "readyState",
|
1320 | get: function get() {
|
1321 | return this._readyState;
|
1322 | }
|
1323 | }]);
|
1324 |
|
1325 | return WebSocket;
|
1326 | }(eventTarget(EVENTS));
|
1327 |
|
1328 | objectAssign(WebSocket$1, {
|
1329 | CONNECTING: CONNECTING,
|
1330 | OPEN: OPEN,
|
1331 | CLOSING: CLOSING,
|
1332 | CLOSED: CLOSED
|
1333 | });
|
1334 | var websocket = WebSocket$1;
|
1335 |
|
1336 | var polyfill = function polyfill(target) {
|
1337 | if (!wx.onNetworkStatusChange) return;
|
1338 | if (target.__onlineOfflinePolyfilled) return;
|
1339 | target.__onlineOfflinePolyfilled = true;
|
1340 | var internalEventTarget = new eventTarget();
|
1341 |
|
1342 | if (!target.dispatchEvent) {
|
1343 | target.addEventListener = internalEventTarget.addEventListener.bind(internalEventTarget);
|
1344 | target.removeEventListener = internalEventTarget.removeEventListener.bind(internalEventTarget);
|
1345 | target.dispatchEvent = internalEventTarget.dispatchEvent.bind(internalEventTarget);
|
1346 |
|
1347 |
|
1348 | if (typeof postMessage == 'function' && !target.importScripts) {
|
1349 | target.importScripts = function () {
|
1350 | throw new Error('mocked');
|
1351 | };
|
1352 | }
|
1353 | }
|
1354 |
|
1355 | wx.getNetworkType({
|
1356 | success: function success(_ref) {
|
1357 | var networkType = _ref.networkType;
|
1358 | target.onLine = networkType !== 'none';
|
1359 | wx.onNetworkStatusChange(function (_ref2) {
|
1360 | var isConnected = _ref2.isConnected;
|
1361 | if (target.onLine === isConnected) return;
|
1362 | target.onLine = isConnected;
|
1363 | target.dispatchEvent({
|
1364 | type: isConnected ? 'online' : 'offline'
|
1365 | });
|
1366 | });
|
1367 | }
|
1368 | });
|
1369 | };
|
1370 |
|
1371 | var onlineOfflineEvents = {
|
1372 | polyfill: polyfill
|
1373 | };
|
1374 |
|
1375 | var navigator$1 = {};
|
1376 |
|
1377 | var weappPolyfill = {
|
1378 | polyfill: function polyfill() {
|
1379 | var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : commonjsGlobal || window;
|
1380 |
|
1381 | if (_typeof(target) !== 'object') {
|
1382 | throw new Error('polyfill target is not an Object');
|
1383 | }
|
1384 |
|
1385 | var polyfills = {
|
1386 | localStorage: localstorage,
|
1387 | XMLHttpRequest: xmlhttprequest,
|
1388 | FormData: formdata,
|
1389 | WebSocket: websocket,
|
1390 | Object: Object,
|
1391 | navigator: navigator$1
|
1392 | };
|
1393 |
|
1394 | for (var k in polyfills) {
|
1395 | if (!target[k]) target[k] = polyfills[k];
|
1396 | }
|
1397 |
|
1398 | onlineOfflineEvents.polyfill(target);
|
1399 |
|
1400 | target.navigator.product = 'ReactNative';
|
1401 | },
|
1402 | localStorage: localstorage,
|
1403 | XMLHttpRequest: xmlhttprequest,
|
1404 | FormData: formdata,
|
1405 | WebSocket: websocket
|
1406 | };
|
1407 |
|
1408 | var polyfill$1 = weappPolyfill.polyfill;
|
1409 |
|
1410 | try {
|
1411 | polyfill$1();
|
1412 | } catch (e) {}
|
1413 |
|
1414 | try {
|
1415 | polyfill$1(GameGlobal);
|
1416 | } catch (e) {}
|
1417 |
|
1418 | try {
|
1419 | window = window || {};
|
1420 | polyfill$1(window);
|
1421 | } catch (e) {}
|
1422 |
|
1423 | try {
|
1424 | localStorage = localStorage || localstorage;
|
1425 | } catch (e) {}
|
1426 |
|
1427 | try {
|
1428 | XMLHttpRequest = XMLHttpRequest || xmlhttprequest;
|
1429 | } catch (e) {}
|
1430 |
|
1431 | try {
|
1432 | FormData = FormData || formdata;
|
1433 | } catch (e) {}
|
1434 |
|
1435 | try {
|
1436 | WebSocket = WebSocket || websocket;
|
1437 | } catch (e) {}
|
1438 |
|
1439 | try {
|
1440 | navigator = navigator || navigator$1;
|
1441 | } catch (e) {}
|
1442 |
|
1443 |
|
1444 |
|
1445 | var long_1 = createCommonjsModule(function (module) {
|
1446 | |
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 | |
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 | (function(global, factory) {
|
1469 |
|
1470 | if (typeof commonjsRequire === 'function' && 'object' === "object" && module && module["exports"])
|
1471 | module["exports"] = factory();
|
1472 | else
|
1473 | (global["dcodeIO"] = global["dcodeIO"] || {})["Long"] = factory();
|
1474 |
|
1475 | })(commonjsGlobal, function() {
|
1476 |
|
1477 | |
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 | function Long(low, high, unsigned) {
|
1488 |
|
1489 | |
1490 |
|
1491 |
|
1492 |
|
1493 | this.low = low | 0;
|
1494 |
|
1495 | |
1496 |
|
1497 |
|
1498 |
|
1499 | this.high = high | 0;
|
1500 |
|
1501 | |
1502 |
|
1503 |
|
1504 |
|
1505 | this.unsigned = !!unsigned;
|
1506 | }
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 | |
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 | Long.prototype.__isLong__;
|
1532 |
|
1533 | Object.defineProperty(Long.prototype, "__isLong__", {
|
1534 | value: true,
|
1535 | enumerable: false,
|
1536 | configurable: false
|
1537 | });
|
1538 |
|
1539 | |
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 | function isLong(obj) {
|
1546 | return (obj && obj["__isLong__"]) === true;
|
1547 | }
|
1548 |
|
1549 | |
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 | Long.isLong = isLong;
|
1556 |
|
1557 | |
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 | var INT_CACHE = {};
|
1563 |
|
1564 | |
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 | var UINT_CACHE = {};
|
1570 |
|
1571 | |
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 | function fromInt(value, unsigned) {
|
1578 | var obj, cachedObj, cache;
|
1579 | if (unsigned) {
|
1580 | value >>>= 0;
|
1581 | if (cache = (0 <= value && value < 256)) {
|
1582 | cachedObj = UINT_CACHE[value];
|
1583 | if (cachedObj)
|
1584 | return cachedObj;
|
1585 | }
|
1586 | obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
|
1587 | if (cache)
|
1588 | UINT_CACHE[value] = obj;
|
1589 | return obj;
|
1590 | } else {
|
1591 | value |= 0;
|
1592 | if (cache = (-128 <= value && value < 128)) {
|
1593 | cachedObj = INT_CACHE[value];
|
1594 | if (cachedObj)
|
1595 | return cachedObj;
|
1596 | }
|
1597 | obj = fromBits(value, value < 0 ? -1 : 0, false);
|
1598 | if (cache)
|
1599 | INT_CACHE[value] = obj;
|
1600 | return obj;
|
1601 | }
|
1602 | }
|
1603 |
|
1604 | |
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 | Long.fromInt = fromInt;
|
1612 |
|
1613 | |
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 | function fromNumber(value, unsigned) {
|
1620 | if (isNaN(value) || !isFinite(value))
|
1621 | return unsigned ? UZERO : ZERO;
|
1622 | if (unsigned) {
|
1623 | if (value < 0)
|
1624 | return UZERO;
|
1625 | if (value >= TWO_PWR_64_DBL)
|
1626 | return MAX_UNSIGNED_VALUE;
|
1627 | } else {
|
1628 | if (value <= -TWO_PWR_63_DBL)
|
1629 | return MIN_VALUE;
|
1630 | if (value + 1 >= TWO_PWR_63_DBL)
|
1631 | return MAX_VALUE;
|
1632 | }
|
1633 | if (value < 0)
|
1634 | return fromNumber(-value, unsigned).neg();
|
1635 | return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
1636 | }
|
1637 |
|
1638 | |
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 | Long.fromNumber = fromNumber;
|
1646 |
|
1647 | |
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 | function fromBits(lowBits, highBits, unsigned) {
|
1655 | return new Long(lowBits, highBits, unsigned);
|
1656 | }
|
1657 |
|
1658 | |
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 | Long.fromBits = fromBits;
|
1668 |
|
1669 | |
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 | var pow_dbl = Math.pow;
|
1677 |
|
1678 | |
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 |
|
1685 | function fromString(str, unsigned, radix) {
|
1686 | if (str.length === 0)
|
1687 | throw Error('empty string');
|
1688 | if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
|
1689 | return ZERO;
|
1690 | if (typeof unsigned === 'number') {
|
1691 |
|
1692 | radix = unsigned,
|
1693 | unsigned = false;
|
1694 | } else {
|
1695 | unsigned = !! unsigned;
|
1696 | }
|
1697 | radix = radix || 10;
|
1698 | if (radix < 2 || 36 < radix)
|
1699 | throw RangeError('radix');
|
1700 |
|
1701 | var p;
|
1702 | if ((p = str.indexOf('-')) > 0)
|
1703 | throw Error('interior hyphen');
|
1704 | else if (p === 0) {
|
1705 | return fromString(str.substring(1), unsigned, radix).neg();
|
1706 | }
|
1707 |
|
1708 |
|
1709 |
|
1710 | var radixToPower = fromNumber(pow_dbl(radix, 8));
|
1711 |
|
1712 | var result = ZERO;
|
1713 | for (var i = 0; i < str.length; i += 8) {
|
1714 | var size = Math.min(8, str.length - i),
|
1715 | value = parseInt(str.substring(i, i + size), radix);
|
1716 | if (size < 8) {
|
1717 | var power = fromNumber(pow_dbl(radix, size));
|
1718 | result = result.mul(power).add(fromNumber(value));
|
1719 | } else {
|
1720 | result = result.mul(radixToPower);
|
1721 | result = result.add(fromNumber(value));
|
1722 | }
|
1723 | }
|
1724 | result.unsigned = unsigned;
|
1725 | return result;
|
1726 | }
|
1727 |
|
1728 | |
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 |
|
1736 | Long.fromString = fromString;
|
1737 |
|
1738 | |
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 | function fromValue(val) {
|
1745 | if (val instanceof Long)
|
1746 | return val;
|
1747 | if (typeof val === 'number')
|
1748 | return fromNumber(val);
|
1749 | if (typeof val === 'string')
|
1750 | return fromString(val);
|
1751 |
|
1752 | return fromBits(val.low, val.high, val.unsigned);
|
1753 | }
|
1754 |
|
1755 | |
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 | Long.fromValue = fromValue;
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 | |
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 | var TWO_PWR_16_DBL = 1 << 16;
|
1772 |
|
1773 | |
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 | var TWO_PWR_24_DBL = 1 << 24;
|
1779 |
|
1780 | |
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 | var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
|
1786 |
|
1787 | |
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 | var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
|
1793 |
|
1794 | |
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 | var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
|
1800 |
|
1801 | |
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 | var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
|
1807 |
|
1808 | |
1809 |
|
1810 |
|
1811 |
|
1812 | var ZERO = fromInt(0);
|
1813 |
|
1814 | |
1815 |
|
1816 |
|
1817 |
|
1818 | Long.ZERO = ZERO;
|
1819 |
|
1820 | |
1821 |
|
1822 |
|
1823 |
|
1824 | var UZERO = fromInt(0, true);
|
1825 |
|
1826 | |
1827 |
|
1828 |
|
1829 |
|
1830 | Long.UZERO = UZERO;
|
1831 |
|
1832 | |
1833 |
|
1834 |
|
1835 |
|
1836 | var ONE = fromInt(1);
|
1837 |
|
1838 | |
1839 |
|
1840 |
|
1841 |
|
1842 | Long.ONE = ONE;
|
1843 |
|
1844 | |
1845 |
|
1846 |
|
1847 |
|
1848 | var UONE = fromInt(1, true);
|
1849 |
|
1850 | |
1851 |
|
1852 |
|
1853 |
|
1854 | Long.UONE = UONE;
|
1855 |
|
1856 | |
1857 |
|
1858 |
|
1859 |
|
1860 | var NEG_ONE = fromInt(-1);
|
1861 |
|
1862 | |
1863 |
|
1864 |
|
1865 |
|
1866 | Long.NEG_ONE = NEG_ONE;
|
1867 |
|
1868 | |
1869 |
|
1870 |
|
1871 |
|
1872 | var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false);
|
1873 |
|
1874 | |
1875 |
|
1876 |
|
1877 |
|
1878 | Long.MAX_VALUE = MAX_VALUE;
|
1879 |
|
1880 | |
1881 |
|
1882 |
|
1883 |
|
1884 | var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true);
|
1885 |
|
1886 | |
1887 |
|
1888 |
|
1889 |
|
1890 | Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
|
1891 |
|
1892 | |
1893 |
|
1894 |
|
1895 |
|
1896 | var MIN_VALUE = fromBits(0, 0x80000000|0, false);
|
1897 |
|
1898 | |
1899 |
|
1900 |
|
1901 |
|
1902 | Long.MIN_VALUE = MIN_VALUE;
|
1903 |
|
1904 | |
1905 |
|
1906 |
|
1907 |
|
1908 | var LongPrototype = Long.prototype;
|
1909 |
|
1910 | |
1911 |
|
1912 |
|
1913 |
|
1914 | LongPrototype.toInt = function toInt() {
|
1915 | return this.unsigned ? this.low >>> 0 : this.low;
|
1916 | };
|
1917 |
|
1918 | |
1919 |
|
1920 |
|
1921 |
|
1922 | LongPrototype.toNumber = function toNumber() {
|
1923 | if (this.unsigned)
|
1924 | return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
|
1925 | return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
1926 | };
|
1927 |
|
1928 | |
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 | LongPrototype.toString = function toString(radix) {
|
1936 | radix = radix || 10;
|
1937 | if (radix < 2 || 36 < radix)
|
1938 | throw RangeError('radix');
|
1939 | if (this.isZero())
|
1940 | return '0';
|
1941 | if (this.isNegative()) {
|
1942 | if (this.eq(MIN_VALUE)) {
|
1943 |
|
1944 |
|
1945 | var radixLong = fromNumber(radix),
|
1946 | div = this.div(radixLong),
|
1947 | rem1 = div.mul(radixLong).sub(this);
|
1948 | return div.toString(radix) + rem1.toInt().toString(radix);
|
1949 | } else
|
1950 | return '-' + this.neg().toString(radix);
|
1951 | }
|
1952 |
|
1953 |
|
1954 |
|
1955 | var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
|
1956 | rem = this;
|
1957 | var result = '';
|
1958 | while (true) {
|
1959 | var remDiv = rem.div(radixToPower),
|
1960 | intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
|
1961 | digits = intval.toString(radix);
|
1962 | rem = remDiv;
|
1963 | if (rem.isZero())
|
1964 | return digits + result;
|
1965 | else {
|
1966 | while (digits.length < 6)
|
1967 | digits = '0' + digits;
|
1968 | result = '' + digits + result;
|
1969 | }
|
1970 | }
|
1971 | };
|
1972 |
|
1973 | |
1974 |
|
1975 |
|
1976 |
|
1977 | LongPrototype.getHighBits = function getHighBits() {
|
1978 | return this.high;
|
1979 | };
|
1980 |
|
1981 | |
1982 |
|
1983 |
|
1984 |
|
1985 | LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
|
1986 | return this.high >>> 0;
|
1987 | };
|
1988 |
|
1989 | |
1990 |
|
1991 |
|
1992 |
|
1993 | LongPrototype.getLowBits = function getLowBits() {
|
1994 | return this.low;
|
1995 | };
|
1996 |
|
1997 | |
1998 |
|
1999 |
|
2000 |
|
2001 | LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
2002 | return this.low >>> 0;
|
2003 | };
|
2004 |
|
2005 | |
2006 |
|
2007 |
|
2008 |
|
2009 | LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
2010 | if (this.isNegative())
|
2011 | return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
2012 | var val = this.high != 0 ? this.high : this.low;
|
2013 | for (var bit = 31; bit > 0; bit--)
|
2014 | if ((val & (1 << bit)) != 0)
|
2015 | break;
|
2016 | return this.high != 0 ? bit + 33 : bit + 1;
|
2017 | };
|
2018 |
|
2019 | |
2020 |
|
2021 |
|
2022 |
|
2023 | LongPrototype.isZero = function isZero() {
|
2024 | return this.high === 0 && this.low === 0;
|
2025 | };
|
2026 |
|
2027 | |
2028 |
|
2029 |
|
2030 |
|
2031 | LongPrototype.isNegative = function isNegative() {
|
2032 | return !this.unsigned && this.high < 0;
|
2033 | };
|
2034 |
|
2035 | |
2036 |
|
2037 |
|
2038 |
|
2039 | LongPrototype.isPositive = function isPositive() {
|
2040 | return this.unsigned || this.high >= 0;
|
2041 | };
|
2042 |
|
2043 | |
2044 |
|
2045 |
|
2046 |
|
2047 | LongPrototype.isOdd = function isOdd() {
|
2048 | return (this.low & 1) === 1;
|
2049 | };
|
2050 |
|
2051 | |
2052 |
|
2053 |
|
2054 |
|
2055 | LongPrototype.isEven = function isEven() {
|
2056 | return (this.low & 1) === 0;
|
2057 | };
|
2058 |
|
2059 | |
2060 |
|
2061 |
|
2062 |
|
2063 |
|
2064 | LongPrototype.equals = function equals(other) {
|
2065 | if (!isLong(other))
|
2066 | other = fromValue(other);
|
2067 | if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
|
2068 | return false;
|
2069 | return this.high === other.high && this.low === other.low;
|
2070 | };
|
2071 |
|
2072 | |
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 | LongPrototype.eq = LongPrototype.equals;
|
2079 |
|
2080 | |
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 | LongPrototype.notEquals = function notEquals(other) {
|
2086 | return !this.eq( other);
|
2087 | };
|
2088 |
|
2089 | |
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 | LongPrototype.neq = LongPrototype.notEquals;
|
2096 |
|
2097 | |
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 | LongPrototype.lessThan = function lessThan(other) {
|
2103 | return this.comp( other) < 0;
|
2104 | };
|
2105 |
|
2106 | |
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 | LongPrototype.lt = LongPrototype.lessThan;
|
2113 |
|
2114 | |
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 | LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
2120 | return this.comp( other) <= 0;
|
2121 | };
|
2122 |
|
2123 | |
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 | LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
2130 |
|
2131 | |
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 | LongPrototype.greaterThan = function greaterThan(other) {
|
2137 | return this.comp( other) > 0;
|
2138 | };
|
2139 |
|
2140 | |
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 | LongPrototype.gt = LongPrototype.greaterThan;
|
2147 |
|
2148 | |
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 | LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
2154 | return this.comp( other) >= 0;
|
2155 | };
|
2156 |
|
2157 | |
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 | LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
2164 |
|
2165 | |
2166 |
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 | LongPrototype.compare = function compare(other) {
|
2172 | if (!isLong(other))
|
2173 | other = fromValue(other);
|
2174 | if (this.eq(other))
|
2175 | return 0;
|
2176 | var thisNeg = this.isNegative(),
|
2177 | otherNeg = other.isNegative();
|
2178 | if (thisNeg && !otherNeg)
|
2179 | return -1;
|
2180 | if (!thisNeg && otherNeg)
|
2181 | return 1;
|
2182 |
|
2183 | if (!this.unsigned)
|
2184 | return this.sub(other).isNegative() ? -1 : 1;
|
2185 |
|
2186 | return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
|
2187 | };
|
2188 |
|
2189 | |
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 | LongPrototype.comp = LongPrototype.compare;
|
2197 |
|
2198 | |
2199 |
|
2200 |
|
2201 |
|
2202 | LongPrototype.negate = function negate() {
|
2203 | if (!this.unsigned && this.eq(MIN_VALUE))
|
2204 | return MIN_VALUE;
|
2205 | return this.not().add(ONE);
|
2206 | };
|
2207 |
|
2208 | |
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 | LongPrototype.neg = LongPrototype.negate;
|
2214 |
|
2215 | |
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 | LongPrototype.add = function add(addend) {
|
2221 | if (!isLong(addend))
|
2222 | addend = fromValue(addend);
|
2223 |
|
2224 |
|
2225 |
|
2226 | var a48 = this.high >>> 16;
|
2227 | var a32 = this.high & 0xFFFF;
|
2228 | var a16 = this.low >>> 16;
|
2229 | var a00 = this.low & 0xFFFF;
|
2230 |
|
2231 | var b48 = addend.high >>> 16;
|
2232 | var b32 = addend.high & 0xFFFF;
|
2233 | var b16 = addend.low >>> 16;
|
2234 | var b00 = addend.low & 0xFFFF;
|
2235 |
|
2236 | var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
2237 | c00 += a00 + b00;
|
2238 | c16 += c00 >>> 16;
|
2239 | c00 &= 0xFFFF;
|
2240 | c16 += a16 + b16;
|
2241 | c32 += c16 >>> 16;
|
2242 | c16 &= 0xFFFF;
|
2243 | c32 += a32 + b32;
|
2244 | c48 += c32 >>> 16;
|
2245 | c32 &= 0xFFFF;
|
2246 | c48 += a48 + b48;
|
2247 | c48 &= 0xFFFF;
|
2248 | return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
2249 | };
|
2250 |
|
2251 | |
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 | LongPrototype.subtract = function subtract(subtrahend) {
|
2257 | if (!isLong(subtrahend))
|
2258 | subtrahend = fromValue(subtrahend);
|
2259 | return this.add(subtrahend.neg());
|
2260 | };
|
2261 |
|
2262 | |
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 | LongPrototype.sub = LongPrototype.subtract;
|
2269 |
|
2270 | |
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 | LongPrototype.multiply = function multiply(multiplier) {
|
2276 | if (this.isZero())
|
2277 | return ZERO;
|
2278 | if (!isLong(multiplier))
|
2279 | multiplier = fromValue(multiplier);
|
2280 | if (multiplier.isZero())
|
2281 | return ZERO;
|
2282 | if (this.eq(MIN_VALUE))
|
2283 | return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
2284 | if (multiplier.eq(MIN_VALUE))
|
2285 | return this.isOdd() ? MIN_VALUE : ZERO;
|
2286 |
|
2287 | if (this.isNegative()) {
|
2288 | if (multiplier.isNegative())
|
2289 | return this.neg().mul(multiplier.neg());
|
2290 | else
|
2291 | return this.neg().mul(multiplier).neg();
|
2292 | } else if (multiplier.isNegative())
|
2293 | return this.mul(multiplier.neg()).neg();
|
2294 |
|
2295 |
|
2296 | if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
|
2297 | return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 | var a48 = this.high >>> 16;
|
2303 | var a32 = this.high & 0xFFFF;
|
2304 | var a16 = this.low >>> 16;
|
2305 | var a00 = this.low & 0xFFFF;
|
2306 |
|
2307 | var b48 = multiplier.high >>> 16;
|
2308 | var b32 = multiplier.high & 0xFFFF;
|
2309 | var b16 = multiplier.low >>> 16;
|
2310 | var b00 = multiplier.low & 0xFFFF;
|
2311 |
|
2312 | var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
2313 | c00 += a00 * b00;
|
2314 | c16 += c00 >>> 16;
|
2315 | c00 &= 0xFFFF;
|
2316 | c16 += a16 * b00;
|
2317 | c32 += c16 >>> 16;
|
2318 | c16 &= 0xFFFF;
|
2319 | c16 += a00 * b16;
|
2320 | c32 += c16 >>> 16;
|
2321 | c16 &= 0xFFFF;
|
2322 | c32 += a32 * b00;
|
2323 | c48 += c32 >>> 16;
|
2324 | c32 &= 0xFFFF;
|
2325 | c32 += a16 * b16;
|
2326 | c48 += c32 >>> 16;
|
2327 | c32 &= 0xFFFF;
|
2328 | c32 += a00 * b32;
|
2329 | c48 += c32 >>> 16;
|
2330 | c32 &= 0xFFFF;
|
2331 | c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
2332 | c48 &= 0xFFFF;
|
2333 | return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
2334 | };
|
2335 |
|
2336 | |
2337 |
|
2338 |
|
2339 |
|
2340 |
|
2341 |
|
2342 | LongPrototype.mul = LongPrototype.multiply;
|
2343 |
|
2344 | |
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 | LongPrototype.divide = function divide(divisor) {
|
2351 | if (!isLong(divisor))
|
2352 | divisor = fromValue(divisor);
|
2353 | if (divisor.isZero())
|
2354 | throw Error('division by zero');
|
2355 | if (this.isZero())
|
2356 | return this.unsigned ? UZERO : ZERO;
|
2357 | var approx, rem, res;
|
2358 | if (!this.unsigned) {
|
2359 |
|
2360 |
|
2361 | if (this.eq(MIN_VALUE)) {
|
2362 | if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
2363 | return MIN_VALUE;
|
2364 | else if (divisor.eq(MIN_VALUE))
|
2365 | return ONE;
|
2366 | else {
|
2367 |
|
2368 | var halfThis = this.shr(1);
|
2369 | approx = halfThis.div(divisor).shl(1);
|
2370 | if (approx.eq(ZERO)) {
|
2371 | return divisor.isNegative() ? ONE : NEG_ONE;
|
2372 | } else {
|
2373 | rem = this.sub(divisor.mul(approx));
|
2374 | res = approx.add(rem.div(divisor));
|
2375 | return res;
|
2376 | }
|
2377 | }
|
2378 | } else if (divisor.eq(MIN_VALUE))
|
2379 | return this.unsigned ? UZERO : ZERO;
|
2380 | if (this.isNegative()) {
|
2381 | if (divisor.isNegative())
|
2382 | return this.neg().div(divisor.neg());
|
2383 | return this.neg().div(divisor).neg();
|
2384 | } else if (divisor.isNegative())
|
2385 | return this.div(divisor.neg()).neg();
|
2386 | res = ZERO;
|
2387 | } else {
|
2388 |
|
2389 |
|
2390 | if (!divisor.unsigned)
|
2391 | divisor = divisor.toUnsigned();
|
2392 | if (divisor.gt(this))
|
2393 | return UZERO;
|
2394 | if (divisor.gt(this.shru(1)))
|
2395 | return UONE;
|
2396 | res = UZERO;
|
2397 | }
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 | rem = this;
|
2405 | while (rem.gte(divisor)) {
|
2406 |
|
2407 |
|
2408 | approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
|
2409 |
|
2410 |
|
2411 |
|
2412 | var log2 = Math.ceil(Math.log(approx) / Math.LN2),
|
2413 | delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
|
2414 |
|
2415 |
|
2416 |
|
2417 | approxRes = fromNumber(approx),
|
2418 | approxRem = approxRes.mul(divisor);
|
2419 | while (approxRem.isNegative() || approxRem.gt(rem)) {
|
2420 | approx -= delta;
|
2421 | approxRes = fromNumber(approx, this.unsigned);
|
2422 | approxRem = approxRes.mul(divisor);
|
2423 | }
|
2424 |
|
2425 |
|
2426 |
|
2427 | if (approxRes.isZero())
|
2428 | approxRes = ONE;
|
2429 |
|
2430 | res = res.add(approxRes);
|
2431 | rem = rem.sub(approxRem);
|
2432 | }
|
2433 | return res;
|
2434 | };
|
2435 |
|
2436 | |
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 | LongPrototype.div = LongPrototype.divide;
|
2443 |
|
2444 | |
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 | LongPrototype.modulo = function modulo(divisor) {
|
2450 | if (!isLong(divisor))
|
2451 | divisor = fromValue(divisor);
|
2452 | return this.sub(this.div(divisor).mul(divisor));
|
2453 | };
|
2454 |
|
2455 | |
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 | LongPrototype.mod = LongPrototype.modulo;
|
2462 |
|
2463 | |
2464 |
|
2465 |
|
2466 |
|
2467 | LongPrototype.not = function not() {
|
2468 | return fromBits(~this.low, ~this.high, this.unsigned);
|
2469 | };
|
2470 |
|
2471 | |
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 | LongPrototype.and = function and(other) {
|
2477 | if (!isLong(other))
|
2478 | other = fromValue(other);
|
2479 | return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
2480 | };
|
2481 |
|
2482 | |
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 | LongPrototype.or = function or(other) {
|
2488 | if (!isLong(other))
|
2489 | other = fromValue(other);
|
2490 | return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
2491 | };
|
2492 |
|
2493 | |
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 | LongPrototype.xor = function xor(other) {
|
2499 | if (!isLong(other))
|
2500 | other = fromValue(other);
|
2501 | return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
2502 | };
|
2503 |
|
2504 | |
2505 |
|
2506 |
|
2507 |
|
2508 |
|
2509 | LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
2510 | if (isLong(numBits))
|
2511 | numBits = numBits.toInt();
|
2512 | if ((numBits &= 63) === 0)
|
2513 | return this;
|
2514 | else if (numBits < 32)
|
2515 | return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
|
2516 | else
|
2517 | return fromBits(0, this.low << (numBits - 32), this.unsigned);
|
2518 | };
|
2519 |
|
2520 | |
2521 |
|
2522 |
|
2523 |
|
2524 |
|
2525 |
|
2526 | LongPrototype.shl = LongPrototype.shiftLeft;
|
2527 |
|
2528 | |
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 | LongPrototype.shiftRight = function shiftRight(numBits) {
|
2534 | if (isLong(numBits))
|
2535 | numBits = numBits.toInt();
|
2536 | if ((numBits &= 63) === 0)
|
2537 | return this;
|
2538 | else if (numBits < 32)
|
2539 | return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
|
2540 | else
|
2541 | return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
|
2542 | };
|
2543 |
|
2544 | |
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 | LongPrototype.shr = LongPrototype.shiftRight;
|
2551 |
|
2552 | |
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 | LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
2558 | if (isLong(numBits))
|
2559 | numBits = numBits.toInt();
|
2560 | numBits &= 63;
|
2561 | if (numBits === 0)
|
2562 | return this;
|
2563 | else {
|
2564 | var high = this.high;
|
2565 | if (numBits < 32) {
|
2566 | var low = this.low;
|
2567 | return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
|
2568 | } else if (numBits === 32)
|
2569 | return fromBits(high, 0, this.unsigned);
|
2570 | else
|
2571 | return fromBits(high >>> (numBits - 32), 0, this.unsigned);
|
2572 | }
|
2573 | };
|
2574 |
|
2575 | |
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 |
|
2581 | LongPrototype.shru = LongPrototype.shiftRightUnsigned;
|
2582 |
|
2583 | |
2584 |
|
2585 |
|
2586 |
|
2587 | LongPrototype.toSigned = function toSigned() {
|
2588 | if (!this.unsigned)
|
2589 | return this;
|
2590 | return fromBits(this.low, this.high, false);
|
2591 | };
|
2592 |
|
2593 | |
2594 |
|
2595 |
|
2596 |
|
2597 | LongPrototype.toUnsigned = function toUnsigned() {
|
2598 | if (this.unsigned)
|
2599 | return this;
|
2600 | return fromBits(this.low, this.high, true);
|
2601 | };
|
2602 |
|
2603 | |
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 | LongPrototype.toBytes = function(le) {
|
2609 | return le ? this.toBytesLE() : this.toBytesBE();
|
2610 | };
|
2611 |
|
2612 | |
2613 |
|
2614 |
|
2615 |
|
2616 | LongPrototype.toBytesLE = function() {
|
2617 | var hi = this.high,
|
2618 | lo = this.low;
|
2619 | return [
|
2620 | lo & 0xff,
|
2621 | (lo >>> 8) & 0xff,
|
2622 | (lo >>> 16) & 0xff,
|
2623 | (lo >>> 24) & 0xff,
|
2624 | hi & 0xff,
|
2625 | (hi >>> 8) & 0xff,
|
2626 | (hi >>> 16) & 0xff,
|
2627 | (hi >>> 24) & 0xff
|
2628 | ];
|
2629 | };
|
2630 |
|
2631 | |
2632 |
|
2633 |
|
2634 |
|
2635 | LongPrototype.toBytesBE = function() {
|
2636 | var hi = this.high,
|
2637 | lo = this.low;
|
2638 | return [
|
2639 | (hi >>> 24) & 0xff,
|
2640 | (hi >>> 16) & 0xff,
|
2641 | (hi >>> 8) & 0xff,
|
2642 | hi & 0xff,
|
2643 | (lo >>> 24) & 0xff,
|
2644 | (lo >>> 16) & 0xff,
|
2645 | (lo >>> 8) & 0xff,
|
2646 | lo & 0xff
|
2647 | ];
|
2648 | };
|
2649 |
|
2650 | return Long;
|
2651 | });
|
2652 | });
|
2653 |
|
2654 | var bytebuffer = createCommonjsModule(function (module) {
|
2655 | |
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 | |
2672 |
|
2673 |
|
2674 |
|
2675 |
|
2676 |
|
2677 | (function(global, factory) {
|
2678 |
|
2679 | if (typeof commonjsRequire === 'function' && 'object' === "object" && module && module["exports"])
|
2680 | module['exports'] = (function() {
|
2681 | var Long; try { Long = long_1; } catch (e) {}
|
2682 | return factory(Long);
|
2683 | })();
|
2684 | else
|
2685 | (global["dcodeIO"] = global["dcodeIO"] || {})["ByteBuffer"] = factory(global["dcodeIO"]["Long"]);
|
2686 |
|
2687 | })(commonjsGlobal, function(Long) {
|
2688 |
|
2689 | |
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 | var ByteBuffer = function(capacity, littleEndian, noAssert) {
|
2702 | if (typeof capacity === 'undefined')
|
2703 | capacity = ByteBuffer.DEFAULT_CAPACITY;
|
2704 | if (typeof littleEndian === 'undefined')
|
2705 | littleEndian = ByteBuffer.DEFAULT_ENDIAN;
|
2706 | if (typeof noAssert === 'undefined')
|
2707 | noAssert = ByteBuffer.DEFAULT_NOASSERT;
|
2708 | if (!noAssert) {
|
2709 | capacity = capacity | 0;
|
2710 | if (capacity < 0)
|
2711 | throw RangeError("Illegal capacity");
|
2712 | littleEndian = !!littleEndian;
|
2713 | noAssert = !!noAssert;
|
2714 | }
|
2715 |
|
2716 | |
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 | this.buffer = capacity === 0 ? EMPTY_BUFFER : new ArrayBuffer(capacity);
|
2722 |
|
2723 | |
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 | this.view = capacity === 0 ? null : new Uint8Array(this.buffer);
|
2729 |
|
2730 | |
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 | this.offset = 0;
|
2738 |
|
2739 | |
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 | this.markedOffset = -1;
|
2747 |
|
2748 | |
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 | this.limit = capacity;
|
2756 |
|
2757 | |
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 | this.littleEndian = littleEndian;
|
2763 |
|
2764 | |
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 | this.noAssert = noAssert;
|
2770 | };
|
2771 |
|
2772 | |
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 |
|
2778 | ByteBuffer.VERSION = "5.0.1";
|
2779 |
|
2780 | |
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 | ByteBuffer.LITTLE_ENDIAN = true;
|
2787 |
|
2788 | |
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 | ByteBuffer.BIG_ENDIAN = false;
|
2795 |
|
2796 | |
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 | ByteBuffer.DEFAULT_CAPACITY = 16;
|
2802 |
|
2803 | |
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 | ByteBuffer.DEFAULT_ENDIAN = ByteBuffer.BIG_ENDIAN;
|
2809 |
|
2810 | |
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 | ByteBuffer.DEFAULT_NOASSERT = false;
|
2816 |
|
2817 | |
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 |
|
2825 | ByteBuffer.Long = Long || null;
|
2826 |
|
2827 | |
2828 |
|
2829 |
|
2830 |
|
2831 | var ByteBufferPrototype = ByteBuffer.prototype;
|
2832 |
|
2833 | |
2834 |
|
2835 |
|
2836 |
|
2837 |
|
2838 |
|
2839 |
|
2840 | ByteBufferPrototype.__isByteBuffer__;
|
2841 |
|
2842 | Object.defineProperty(ByteBufferPrototype, "__isByteBuffer__", {
|
2843 | value: true,
|
2844 | enumerable: false,
|
2845 | configurable: false
|
2846 | });
|
2847 |
|
2848 |
|
2849 |
|
2850 | |
2851 |
|
2852 |
|
2853 |
|
2854 | var EMPTY_BUFFER = new ArrayBuffer(0);
|
2855 |
|
2856 | |
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 | var stringFromCharCode = String.fromCharCode;
|
2862 |
|
2863 | |
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 | function stringSource(s) {
|
2872 | var i=0; return function() {
|
2873 | return i < s.length ? s.charCodeAt(i++) : null;
|
2874 | };
|
2875 | }
|
2876 |
|
2877 | |
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 | function stringDestination() {
|
2884 | var cs = [], ps = []; return function() {
|
2885 | if (arguments.length === 0)
|
2886 | return ps.join('')+stringFromCharCode.apply(String, cs);
|
2887 | if (cs.length + arguments.length > 1024)
|
2888 | ps.push(stringFromCharCode.apply(String, cs)),
|
2889 | cs.length = 0;
|
2890 | Array.prototype.push.apply(cs, arguments);
|
2891 | };
|
2892 | }
|
2893 |
|
2894 | |
2895 |
|
2896 |
|
2897 |
|
2898 |
|
2899 | ByteBuffer.accessor = function() {
|
2900 | return Uint8Array;
|
2901 | };
|
2902 | |
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 | ByteBuffer.allocate = function(capacity, littleEndian, noAssert) {
|
2913 | return new ByteBuffer(capacity, littleEndian, noAssert);
|
2914 | };
|
2915 |
|
2916 | |
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 | ByteBuffer.concat = function(buffers, encoding, littleEndian, noAssert) {
|
2929 | if (typeof encoding === 'boolean' || typeof encoding !== 'string') {
|
2930 | noAssert = littleEndian;
|
2931 | littleEndian = encoding;
|
2932 | encoding = undefined;
|
2933 | }
|
2934 | var capacity = 0;
|
2935 | for (var i=0, k=buffers.length, length; i<k; ++i) {
|
2936 | if (!ByteBuffer.isByteBuffer(buffers[i]))
|
2937 | buffers[i] = ByteBuffer.wrap(buffers[i], encoding);
|
2938 | length = buffers[i].limit - buffers[i].offset;
|
2939 | if (length > 0) capacity += length;
|
2940 | }
|
2941 | if (capacity === 0)
|
2942 | return new ByteBuffer(0, littleEndian, noAssert);
|
2943 | var bb = new ByteBuffer(capacity, littleEndian, noAssert),
|
2944 | bi;
|
2945 | i=0; while (i<k) {
|
2946 | bi = buffers[i++];
|
2947 | length = bi.limit - bi.offset;
|
2948 | if (length <= 0) continue;
|
2949 | bb.view.set(bi.view.subarray(bi.offset, bi.limit), bb.offset);
|
2950 | bb.offset += length;
|
2951 | }
|
2952 | bb.limit = bb.offset;
|
2953 | bb.offset = 0;
|
2954 | return bb;
|
2955 | };
|
2956 |
|
2957 | |
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 | ByteBuffer.isByteBuffer = function(bb) {
|
2964 | return (bb && bb["__isByteBuffer__"]) === true;
|
2965 | };
|
2966 | |
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 | ByteBuffer.type = function() {
|
2972 | return ArrayBuffer;
|
2973 | };
|
2974 | |
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 |
|
2984 |
|
2985 |
|
2986 |
|
2987 | ByteBuffer.wrap = function(buffer, encoding, littleEndian, noAssert) {
|
2988 | if (typeof encoding !== 'string') {
|
2989 | noAssert = littleEndian;
|
2990 | littleEndian = encoding;
|
2991 | encoding = undefined;
|
2992 | }
|
2993 | if (typeof buffer === 'string') {
|
2994 | if (typeof encoding === 'undefined')
|
2995 | encoding = "utf8";
|
2996 | switch (encoding) {
|
2997 | case "base64":
|
2998 | return ByteBuffer.fromBase64(buffer, littleEndian);
|
2999 | case "hex":
|
3000 | return ByteBuffer.fromHex(buffer, littleEndian);
|
3001 | case "binary":
|
3002 | return ByteBuffer.fromBinary(buffer, littleEndian);
|
3003 | case "utf8":
|
3004 | return ByteBuffer.fromUTF8(buffer, littleEndian);
|
3005 | case "debug":
|
3006 | return ByteBuffer.fromDebug(buffer, littleEndian);
|
3007 | default:
|
3008 | throw Error("Unsupported encoding: "+encoding);
|
3009 | }
|
3010 | }
|
3011 | if (buffer === null || typeof buffer !== 'object')
|
3012 | throw TypeError("Illegal buffer");
|
3013 | var bb;
|
3014 | if (ByteBuffer.isByteBuffer(buffer)) {
|
3015 | bb = ByteBufferPrototype.clone.call(buffer);
|
3016 | bb.markedOffset = -1;
|
3017 | return bb;
|
3018 | }
|
3019 | if (buffer instanceof Uint8Array) {
|
3020 | bb = new ByteBuffer(0, littleEndian, noAssert);
|
3021 | if (buffer.length > 0) {
|
3022 | bb.buffer = buffer.buffer;
|
3023 | bb.offset = buffer.byteOffset;
|
3024 | bb.limit = buffer.byteOffset + buffer.byteLength;
|
3025 | bb.view = new Uint8Array(buffer.buffer);
|
3026 | }
|
3027 | } else if (buffer instanceof ArrayBuffer) {
|
3028 | bb = new ByteBuffer(0, littleEndian, noAssert);
|
3029 | if (buffer.byteLength > 0) {
|
3030 | bb.buffer = buffer;
|
3031 | bb.offset = 0;
|
3032 | bb.limit = buffer.byteLength;
|
3033 | bb.view = buffer.byteLength > 0 ? new Uint8Array(buffer) : null;
|
3034 | }
|
3035 | } else if (Object.prototype.toString.call(buffer) === "[object Array]") {
|
3036 | bb = new ByteBuffer(buffer.length, littleEndian, noAssert);
|
3037 | bb.limit = buffer.length;
|
3038 | for (var i=0; i<buffer.length; ++i)
|
3039 | bb.view[i] = buffer[i];
|
3040 | } else
|
3041 | throw TypeError("Illegal buffer");
|
3042 | return bb;
|
3043 | };
|
3044 |
|
3045 | |
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 | ByteBufferPrototype.writeBitSet = function(value, offset) {
|
3053 | var relative = typeof offset === 'undefined';
|
3054 | if (relative) offset = this.offset;
|
3055 | if (!this.noAssert) {
|
3056 | if (!(value instanceof Array))
|
3057 | throw TypeError("Illegal BitSet: Not an array");
|
3058 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3059 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3060 | offset >>>= 0;
|
3061 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3062 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3063 | }
|
3064 |
|
3065 | var start = offset,
|
3066 | bits = value.length,
|
3067 | bytes = (bits >> 3),
|
3068 | bit = 0,
|
3069 | k;
|
3070 |
|
3071 | offset += this.writeVarint32(bits,offset);
|
3072 |
|
3073 | while(bytes--) {
|
3074 | k = (!!value[bit++] & 1) |
|
3075 | ((!!value[bit++] & 1) << 1) |
|
3076 | ((!!value[bit++] & 1) << 2) |
|
3077 | ((!!value[bit++] & 1) << 3) |
|
3078 | ((!!value[bit++] & 1) << 4) |
|
3079 | ((!!value[bit++] & 1) << 5) |
|
3080 | ((!!value[bit++] & 1) << 6) |
|
3081 | ((!!value[bit++] & 1) << 7);
|
3082 | this.writeByte(k,offset++);
|
3083 | }
|
3084 |
|
3085 | if(bit < bits) {
|
3086 | var m = 0; k = 0;
|
3087 | while(bit < bits) k = k | ((!!value[bit++] & 1) << (m++));
|
3088 | this.writeByte(k,offset++);
|
3089 | }
|
3090 |
|
3091 | if (relative) {
|
3092 | this.offset = offset;
|
3093 | return this;
|
3094 | }
|
3095 | return offset - start;
|
3096 | };
|
3097 |
|
3098 | |
3099 |
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 | ByteBufferPrototype.readBitSet = function(offset) {
|
3105 | var relative = typeof offset === 'undefined';
|
3106 | if (relative) offset = this.offset;
|
3107 |
|
3108 | var ret = this.readVarint32(offset),
|
3109 | bits = ret.value,
|
3110 | bytes = (bits >> 3),
|
3111 | bit = 0,
|
3112 | value = [],
|
3113 | k;
|
3114 |
|
3115 | offset += ret.length;
|
3116 |
|
3117 | while(bytes--) {
|
3118 | k = this.readByte(offset++);
|
3119 | value[bit++] = !!(k & 0x01);
|
3120 | value[bit++] = !!(k & 0x02);
|
3121 | value[bit++] = !!(k & 0x04);
|
3122 | value[bit++] = !!(k & 0x08);
|
3123 | value[bit++] = !!(k & 0x10);
|
3124 | value[bit++] = !!(k & 0x20);
|
3125 | value[bit++] = !!(k & 0x40);
|
3126 | value[bit++] = !!(k & 0x80);
|
3127 | }
|
3128 |
|
3129 | if(bit < bits) {
|
3130 | var m = 0;
|
3131 | k = this.readByte(offset++);
|
3132 | while(bit < bits) value[bit++] = !!((k >> (m++)) & 1);
|
3133 | }
|
3134 |
|
3135 | if (relative) {
|
3136 | this.offset = offset;
|
3137 | }
|
3138 | return value;
|
3139 | };
|
3140 | |
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 | ByteBufferPrototype.readBytes = function(length, offset) {
|
3148 | var relative = typeof offset === 'undefined';
|
3149 | if (relative) offset = this.offset;
|
3150 | if (!this.noAssert) {
|
3151 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3152 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3153 | offset >>>= 0;
|
3154 | if (offset < 0 || offset + length > this.buffer.byteLength)
|
3155 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength);
|
3156 | }
|
3157 | var slice = this.slice(offset, offset + length);
|
3158 | if (relative) this.offset += length;
|
3159 | return slice;
|
3160 | };
|
3161 |
|
3162 | |
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 | ByteBufferPrototype.writeBytes = ByteBufferPrototype.append;
|
3174 |
|
3175 |
|
3176 |
|
3177 | |
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 | ByteBufferPrototype.writeInt8 = function(value, offset) {
|
3185 | var relative = typeof offset === 'undefined';
|
3186 | if (relative) offset = this.offset;
|
3187 | if (!this.noAssert) {
|
3188 | if (typeof value !== 'number' || value % 1 !== 0)
|
3189 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3190 | value |= 0;
|
3191 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3192 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3193 | offset >>>= 0;
|
3194 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3195 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3196 | }
|
3197 | offset += 1;
|
3198 | var capacity0 = this.buffer.byteLength;
|
3199 | if (offset > capacity0)
|
3200 | this.resize((capacity0 *= 2) > offset ? capacity0 : offset);
|
3201 | offset -= 1;
|
3202 | this.view[offset] = value;
|
3203 | if (relative) this.offset += 1;
|
3204 | return this;
|
3205 | };
|
3206 |
|
3207 | |
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 | ByteBufferPrototype.writeByte = ByteBufferPrototype.writeInt8;
|
3216 |
|
3217 | |
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 | ByteBufferPrototype.readInt8 = function(offset) {
|
3224 | var relative = typeof offset === 'undefined';
|
3225 | if (relative) offset = this.offset;
|
3226 | if (!this.noAssert) {
|
3227 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3228 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3229 | offset >>>= 0;
|
3230 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
3231 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
3232 | }
|
3233 | var value = this.view[offset];
|
3234 | if ((value & 0x80) === 0x80) value = -(0xFF - value + 1);
|
3235 | if (relative) this.offset += 1;
|
3236 | return value;
|
3237 | };
|
3238 |
|
3239 | |
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 | ByteBufferPrototype.readByte = ByteBufferPrototype.readInt8;
|
3247 |
|
3248 | |
3249 |
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 | ByteBufferPrototype.writeUint8 = function(value, offset) {
|
3256 | var relative = typeof offset === 'undefined';
|
3257 | if (relative) offset = this.offset;
|
3258 | if (!this.noAssert) {
|
3259 | if (typeof value !== 'number' || value % 1 !== 0)
|
3260 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3261 | value >>>= 0;
|
3262 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3263 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3264 | offset >>>= 0;
|
3265 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3266 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3267 | }
|
3268 | offset += 1;
|
3269 | var capacity1 = this.buffer.byteLength;
|
3270 | if (offset > capacity1)
|
3271 | this.resize((capacity1 *= 2) > offset ? capacity1 : offset);
|
3272 | offset -= 1;
|
3273 | this.view[offset] = value;
|
3274 | if (relative) this.offset += 1;
|
3275 | return this;
|
3276 | };
|
3277 |
|
3278 | |
3279 |
|
3280 |
|
3281 |
|
3282 |
|
3283 |
|
3284 |
|
3285 |
|
3286 | ByteBufferPrototype.writeUInt8 = ByteBufferPrototype.writeUint8;
|
3287 |
|
3288 | |
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 | ByteBufferPrototype.readUint8 = function(offset) {
|
3295 | var relative = typeof offset === 'undefined';
|
3296 | if (relative) offset = this.offset;
|
3297 | if (!this.noAssert) {
|
3298 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3299 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3300 | offset >>>= 0;
|
3301 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
3302 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
3303 | }
|
3304 | var value = this.view[offset];
|
3305 | if (relative) this.offset += 1;
|
3306 | return value;
|
3307 | };
|
3308 |
|
3309 | |
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 | ByteBufferPrototype.readUInt8 = ByteBufferPrototype.readUint8;
|
3317 |
|
3318 |
|
3319 |
|
3320 | |
3321 |
|
3322 |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 | ByteBufferPrototype.writeInt16 = function(value, offset) {
|
3329 | var relative = typeof offset === 'undefined';
|
3330 | if (relative) offset = this.offset;
|
3331 | if (!this.noAssert) {
|
3332 | if (typeof value !== 'number' || value % 1 !== 0)
|
3333 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3334 | value |= 0;
|
3335 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3336 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3337 | offset >>>= 0;
|
3338 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3339 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3340 | }
|
3341 | offset += 2;
|
3342 | var capacity2 = this.buffer.byteLength;
|
3343 | if (offset > capacity2)
|
3344 | this.resize((capacity2 *= 2) > offset ? capacity2 : offset);
|
3345 | offset -= 2;
|
3346 | if (this.littleEndian) {
|
3347 | this.view[offset+1] = (value & 0xFF00) >>> 8;
|
3348 | this.view[offset ] = value & 0x00FF;
|
3349 | } else {
|
3350 | this.view[offset] = (value & 0xFF00) >>> 8;
|
3351 | this.view[offset+1] = value & 0x00FF;
|
3352 | }
|
3353 | if (relative) this.offset += 2;
|
3354 | return this;
|
3355 | };
|
3356 |
|
3357 | |
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 | ByteBufferPrototype.writeShort = ByteBufferPrototype.writeInt16;
|
3367 |
|
3368 | |
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 | ByteBufferPrototype.readInt16 = function(offset) {
|
3377 | var relative = typeof offset === 'undefined';
|
3378 | if (relative) offset = this.offset;
|
3379 | if (!this.noAssert) {
|
3380 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3381 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3382 | offset >>>= 0;
|
3383 | if (offset < 0 || offset + 2 > this.buffer.byteLength)
|
3384 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.byteLength);
|
3385 | }
|
3386 | var value = 0;
|
3387 | if (this.littleEndian) {
|
3388 | value = this.view[offset ];
|
3389 | value |= this.view[offset+1] << 8;
|
3390 | } else {
|
3391 | value = this.view[offset ] << 8;
|
3392 | value |= this.view[offset+1];
|
3393 | }
|
3394 | if ((value & 0x8000) === 0x8000) value = -(0xFFFF - value + 1);
|
3395 | if (relative) this.offset += 2;
|
3396 | return value;
|
3397 | };
|
3398 |
|
3399 | |
3400 |
|
3401 |
|
3402 |
|
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 | ByteBufferPrototype.readShort = ByteBufferPrototype.readInt16;
|
3409 |
|
3410 | |
3411 |
|
3412 |
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 | ByteBufferPrototype.writeUint16 = function(value, offset) {
|
3419 | var relative = typeof offset === 'undefined';
|
3420 | if (relative) offset = this.offset;
|
3421 | if (!this.noAssert) {
|
3422 | if (typeof value !== 'number' || value % 1 !== 0)
|
3423 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3424 | value >>>= 0;
|
3425 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3426 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3427 | offset >>>= 0;
|
3428 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3429 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3430 | }
|
3431 | offset += 2;
|
3432 | var capacity3 = this.buffer.byteLength;
|
3433 | if (offset > capacity3)
|
3434 | this.resize((capacity3 *= 2) > offset ? capacity3 : offset);
|
3435 | offset -= 2;
|
3436 | if (this.littleEndian) {
|
3437 | this.view[offset+1] = (value & 0xFF00) >>> 8;
|
3438 | this.view[offset ] = value & 0x00FF;
|
3439 | } else {
|
3440 | this.view[offset] = (value & 0xFF00) >>> 8;
|
3441 | this.view[offset+1] = value & 0x00FF;
|
3442 | }
|
3443 | if (relative) this.offset += 2;
|
3444 | return this;
|
3445 | };
|
3446 |
|
3447 | |
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 |
|
3456 | ByteBufferPrototype.writeUInt16 = ByteBufferPrototype.writeUint16;
|
3457 |
|
3458 | |
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 | ByteBufferPrototype.readUint16 = function(offset) {
|
3467 | var relative = typeof offset === 'undefined';
|
3468 | if (relative) offset = this.offset;
|
3469 | if (!this.noAssert) {
|
3470 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3471 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3472 | offset >>>= 0;
|
3473 | if (offset < 0 || offset + 2 > this.buffer.byteLength)
|
3474 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.byteLength);
|
3475 | }
|
3476 | var value = 0;
|
3477 | if (this.littleEndian) {
|
3478 | value = this.view[offset ];
|
3479 | value |= this.view[offset+1] << 8;
|
3480 | } else {
|
3481 | value = this.view[offset ] << 8;
|
3482 | value |= this.view[offset+1];
|
3483 | }
|
3484 | if (relative) this.offset += 2;
|
3485 | return value;
|
3486 | };
|
3487 |
|
3488 | |
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 | ByteBufferPrototype.readUInt16 = ByteBufferPrototype.readUint16;
|
3498 |
|
3499 |
|
3500 |
|
3501 | |
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 | ByteBufferPrototype.writeInt32 = function(value, offset) {
|
3508 | var relative = typeof offset === 'undefined';
|
3509 | if (relative) offset = this.offset;
|
3510 | if (!this.noAssert) {
|
3511 | if (typeof value !== 'number' || value % 1 !== 0)
|
3512 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3513 | value |= 0;
|
3514 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3515 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3516 | offset >>>= 0;
|
3517 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3518 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3519 | }
|
3520 | offset += 4;
|
3521 | var capacity4 = this.buffer.byteLength;
|
3522 | if (offset > capacity4)
|
3523 | this.resize((capacity4 *= 2) > offset ? capacity4 : offset);
|
3524 | offset -= 4;
|
3525 | if (this.littleEndian) {
|
3526 | this.view[offset+3] = (value >>> 24) & 0xFF;
|
3527 | this.view[offset+2] = (value >>> 16) & 0xFF;
|
3528 | this.view[offset+1] = (value >>> 8) & 0xFF;
|
3529 | this.view[offset ] = value & 0xFF;
|
3530 | } else {
|
3531 | this.view[offset ] = (value >>> 24) & 0xFF;
|
3532 | this.view[offset+1] = (value >>> 16) & 0xFF;
|
3533 | this.view[offset+2] = (value >>> 8) & 0xFF;
|
3534 | this.view[offset+3] = value & 0xFF;
|
3535 | }
|
3536 | if (relative) this.offset += 4;
|
3537 | return this;
|
3538 | };
|
3539 |
|
3540 | |
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 | ByteBufferPrototype.writeInt = ByteBufferPrototype.writeInt32;
|
3547 |
|
3548 | |
3549 |
|
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 | ByteBufferPrototype.readInt32 = function(offset) {
|
3555 | var relative = typeof offset === 'undefined';
|
3556 | if (relative) offset = this.offset;
|
3557 | if (!this.noAssert) {
|
3558 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3559 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3560 | offset >>>= 0;
|
3561 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
3562 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
3563 | }
|
3564 | var value = 0;
|
3565 | if (this.littleEndian) {
|
3566 | value = this.view[offset+2] << 16;
|
3567 | value |= this.view[offset+1] << 8;
|
3568 | value |= this.view[offset ];
|
3569 | value += this.view[offset+3] << 24 >>> 0;
|
3570 | } else {
|
3571 | value = this.view[offset+1] << 16;
|
3572 | value |= this.view[offset+2] << 8;
|
3573 | value |= this.view[offset+3];
|
3574 | value += this.view[offset ] << 24 >>> 0;
|
3575 | }
|
3576 | value |= 0;
|
3577 | if (relative) this.offset += 4;
|
3578 | return value;
|
3579 | };
|
3580 |
|
3581 | |
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 | ByteBufferPrototype.readInt = ByteBufferPrototype.readInt32;
|
3588 |
|
3589 | |
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 | ByteBufferPrototype.writeUint32 = function(value, offset) {
|
3596 | var relative = typeof offset === 'undefined';
|
3597 | if (relative) offset = this.offset;
|
3598 | if (!this.noAssert) {
|
3599 | if (typeof value !== 'number' || value % 1 !== 0)
|
3600 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3601 | value >>>= 0;
|
3602 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3603 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3604 | offset >>>= 0;
|
3605 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3606 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3607 | }
|
3608 | offset += 4;
|
3609 | var capacity5 = this.buffer.byteLength;
|
3610 | if (offset > capacity5)
|
3611 | this.resize((capacity5 *= 2) > offset ? capacity5 : offset);
|
3612 | offset -= 4;
|
3613 | if (this.littleEndian) {
|
3614 | this.view[offset+3] = (value >>> 24) & 0xFF;
|
3615 | this.view[offset+2] = (value >>> 16) & 0xFF;
|
3616 | this.view[offset+1] = (value >>> 8) & 0xFF;
|
3617 | this.view[offset ] = value & 0xFF;
|
3618 | } else {
|
3619 | this.view[offset ] = (value >>> 24) & 0xFF;
|
3620 | this.view[offset+1] = (value >>> 16) & 0xFF;
|
3621 | this.view[offset+2] = (value >>> 8) & 0xFF;
|
3622 | this.view[offset+3] = value & 0xFF;
|
3623 | }
|
3624 | if (relative) this.offset += 4;
|
3625 | return this;
|
3626 | };
|
3627 |
|
3628 | |
3629 |
|
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 | ByteBufferPrototype.writeUInt32 = ByteBufferPrototype.writeUint32;
|
3636 |
|
3637 | |
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 |
|
3643 | ByteBufferPrototype.readUint32 = function(offset) {
|
3644 | var relative = typeof offset === 'undefined';
|
3645 | if (relative) offset = this.offset;
|
3646 | if (!this.noAssert) {
|
3647 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3648 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3649 | offset >>>= 0;
|
3650 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
3651 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
3652 | }
|
3653 | var value = 0;
|
3654 | if (this.littleEndian) {
|
3655 | value = this.view[offset+2] << 16;
|
3656 | value |= this.view[offset+1] << 8;
|
3657 | value |= this.view[offset ];
|
3658 | value += this.view[offset+3] << 24 >>> 0;
|
3659 | } else {
|
3660 | value = this.view[offset+1] << 16;
|
3661 | value |= this.view[offset+2] << 8;
|
3662 | value |= this.view[offset+3];
|
3663 | value += this.view[offset ] << 24 >>> 0;
|
3664 | }
|
3665 | if (relative) this.offset += 4;
|
3666 | return value;
|
3667 | };
|
3668 |
|
3669 | |
3670 |
|
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 | ByteBufferPrototype.readUInt32 = ByteBufferPrototype.readUint32;
|
3677 |
|
3678 |
|
3679 |
|
3680 | if (Long) {
|
3681 |
|
3682 | |
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 |
|
3688 |
|
3689 | ByteBufferPrototype.writeInt64 = function(value, offset) {
|
3690 | var relative = typeof offset === 'undefined';
|
3691 | if (relative) offset = this.offset;
|
3692 | if (!this.noAssert) {
|
3693 | if (typeof value === 'number')
|
3694 | value = Long.fromNumber(value);
|
3695 | else if (typeof value === 'string')
|
3696 | value = Long.fromString(value);
|
3697 | else if (!(value && value instanceof Long))
|
3698 | throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
3699 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3700 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3701 | offset >>>= 0;
|
3702 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3703 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3704 | }
|
3705 | if (typeof value === 'number')
|
3706 | value = Long.fromNumber(value);
|
3707 | else if (typeof value === 'string')
|
3708 | value = Long.fromString(value);
|
3709 | offset += 8;
|
3710 | var capacity6 = this.buffer.byteLength;
|
3711 | if (offset > capacity6)
|
3712 | this.resize((capacity6 *= 2) > offset ? capacity6 : offset);
|
3713 | offset -= 8;
|
3714 | var lo = value.low,
|
3715 | hi = value.high;
|
3716 | if (this.littleEndian) {
|
3717 | this.view[offset+3] = (lo >>> 24) & 0xFF;
|
3718 | this.view[offset+2] = (lo >>> 16) & 0xFF;
|
3719 | this.view[offset+1] = (lo >>> 8) & 0xFF;
|
3720 | this.view[offset ] = lo & 0xFF;
|
3721 | offset += 4;
|
3722 | this.view[offset+3] = (hi >>> 24) & 0xFF;
|
3723 | this.view[offset+2] = (hi >>> 16) & 0xFF;
|
3724 | this.view[offset+1] = (hi >>> 8) & 0xFF;
|
3725 | this.view[offset ] = hi & 0xFF;
|
3726 | } else {
|
3727 | this.view[offset ] = (hi >>> 24) & 0xFF;
|
3728 | this.view[offset+1] = (hi >>> 16) & 0xFF;
|
3729 | this.view[offset+2] = (hi >>> 8) & 0xFF;
|
3730 | this.view[offset+3] = hi & 0xFF;
|
3731 | offset += 4;
|
3732 | this.view[offset ] = (lo >>> 24) & 0xFF;
|
3733 | this.view[offset+1] = (lo >>> 16) & 0xFF;
|
3734 | this.view[offset+2] = (lo >>> 8) & 0xFF;
|
3735 | this.view[offset+3] = lo & 0xFF;
|
3736 | }
|
3737 | if (relative) this.offset += 8;
|
3738 | return this;
|
3739 | };
|
3740 |
|
3741 | |
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 | ByteBufferPrototype.writeLong = ByteBufferPrototype.writeInt64;
|
3749 |
|
3750 | |
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 | ByteBufferPrototype.readInt64 = function(offset) {
|
3757 | var relative = typeof offset === 'undefined';
|
3758 | if (relative) offset = this.offset;
|
3759 | if (!this.noAssert) {
|
3760 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3761 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3762 | offset >>>= 0;
|
3763 | if (offset < 0 || offset + 8 > this.buffer.byteLength)
|
3764 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength);
|
3765 | }
|
3766 | var lo = 0,
|
3767 | hi = 0;
|
3768 | if (this.littleEndian) {
|
3769 | lo = this.view[offset+2] << 16;
|
3770 | lo |= this.view[offset+1] << 8;
|
3771 | lo |= this.view[offset ];
|
3772 | lo += this.view[offset+3] << 24 >>> 0;
|
3773 | offset += 4;
|
3774 | hi = this.view[offset+2] << 16;
|
3775 | hi |= this.view[offset+1] << 8;
|
3776 | hi |= this.view[offset ];
|
3777 | hi += this.view[offset+3] << 24 >>> 0;
|
3778 | } else {
|
3779 | hi = this.view[offset+1] << 16;
|
3780 | hi |= this.view[offset+2] << 8;
|
3781 | hi |= this.view[offset+3];
|
3782 | hi += this.view[offset ] << 24 >>> 0;
|
3783 | offset += 4;
|
3784 | lo = this.view[offset+1] << 16;
|
3785 | lo |= this.view[offset+2] << 8;
|
3786 | lo |= this.view[offset+3];
|
3787 | lo += this.view[offset ] << 24 >>> 0;
|
3788 | }
|
3789 | var value = new Long(lo, hi, false);
|
3790 | if (relative) this.offset += 8;
|
3791 | return value;
|
3792 | };
|
3793 |
|
3794 | |
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 | ByteBufferPrototype.readLong = ByteBufferPrototype.readInt64;
|
3801 |
|
3802 | |
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 | ByteBufferPrototype.writeUint64 = function(value, offset) {
|
3810 | var relative = typeof offset === 'undefined';
|
3811 | if (relative) offset = this.offset;
|
3812 | if (!this.noAssert) {
|
3813 | if (typeof value === 'number')
|
3814 | value = Long.fromNumber(value);
|
3815 | else if (typeof value === 'string')
|
3816 | value = Long.fromString(value);
|
3817 | else if (!(value && value instanceof Long))
|
3818 | throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
3819 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3820 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3821 | offset >>>= 0;
|
3822 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3823 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3824 | }
|
3825 | if (typeof value === 'number')
|
3826 | value = Long.fromNumber(value);
|
3827 | else if (typeof value === 'string')
|
3828 | value = Long.fromString(value);
|
3829 | offset += 8;
|
3830 | var capacity7 = this.buffer.byteLength;
|
3831 | if (offset > capacity7)
|
3832 | this.resize((capacity7 *= 2) > offset ? capacity7 : offset);
|
3833 | offset -= 8;
|
3834 | var lo = value.low,
|
3835 | hi = value.high;
|
3836 | if (this.littleEndian) {
|
3837 | this.view[offset+3] = (lo >>> 24) & 0xFF;
|
3838 | this.view[offset+2] = (lo >>> 16) & 0xFF;
|
3839 | this.view[offset+1] = (lo >>> 8) & 0xFF;
|
3840 | this.view[offset ] = lo & 0xFF;
|
3841 | offset += 4;
|
3842 | this.view[offset+3] = (hi >>> 24) & 0xFF;
|
3843 | this.view[offset+2] = (hi >>> 16) & 0xFF;
|
3844 | this.view[offset+1] = (hi >>> 8) & 0xFF;
|
3845 | this.view[offset ] = hi & 0xFF;
|
3846 | } else {
|
3847 | this.view[offset ] = (hi >>> 24) & 0xFF;
|
3848 | this.view[offset+1] = (hi >>> 16) & 0xFF;
|
3849 | this.view[offset+2] = (hi >>> 8) & 0xFF;
|
3850 | this.view[offset+3] = hi & 0xFF;
|
3851 | offset += 4;
|
3852 | this.view[offset ] = (lo >>> 24) & 0xFF;
|
3853 | this.view[offset+1] = (lo >>> 16) & 0xFF;
|
3854 | this.view[offset+2] = (lo >>> 8) & 0xFF;
|
3855 | this.view[offset+3] = lo & 0xFF;
|
3856 | }
|
3857 | if (relative) this.offset += 8;
|
3858 | return this;
|
3859 | };
|
3860 |
|
3861 | |
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 | ByteBufferPrototype.writeUInt64 = ByteBufferPrototype.writeUint64;
|
3870 |
|
3871 | |
3872 |
|
3873 |
|
3874 |
|
3875 |
|
3876 |
|
3877 | ByteBufferPrototype.readUint64 = function(offset) {
|
3878 | var relative = typeof offset === 'undefined';
|
3879 | if (relative) offset = this.offset;
|
3880 | if (!this.noAssert) {
|
3881 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3882 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3883 | offset >>>= 0;
|
3884 | if (offset < 0 || offset + 8 > this.buffer.byteLength)
|
3885 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength);
|
3886 | }
|
3887 | var lo = 0,
|
3888 | hi = 0;
|
3889 | if (this.littleEndian) {
|
3890 | lo = this.view[offset+2] << 16;
|
3891 | lo |= this.view[offset+1] << 8;
|
3892 | lo |= this.view[offset ];
|
3893 | lo += this.view[offset+3] << 24 >>> 0;
|
3894 | offset += 4;
|
3895 | hi = this.view[offset+2] << 16;
|
3896 | hi |= this.view[offset+1] << 8;
|
3897 | hi |= this.view[offset ];
|
3898 | hi += this.view[offset+3] << 24 >>> 0;
|
3899 | } else {
|
3900 | hi = this.view[offset+1] << 16;
|
3901 | hi |= this.view[offset+2] << 8;
|
3902 | hi |= this.view[offset+3];
|
3903 | hi += this.view[offset ] << 24 >>> 0;
|
3904 | offset += 4;
|
3905 | lo = this.view[offset+1] << 16;
|
3906 | lo |= this.view[offset+2] << 8;
|
3907 | lo |= this.view[offset+3];
|
3908 | lo += this.view[offset ] << 24 >>> 0;
|
3909 | }
|
3910 | var value = new Long(lo, hi, true);
|
3911 | if (relative) this.offset += 8;
|
3912 | return value;
|
3913 | };
|
3914 |
|
3915 | |
3916 |
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 | ByteBufferPrototype.readUInt64 = ByteBufferPrototype.readUint64;
|
3923 |
|
3924 | }
|
3925 |
|
3926 |
|
3927 |
|
3928 |
|
3929 | |
3930 |
|
3931 |
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 |
|
3951 |
|
3952 |
|
3953 |
|
3954 |
|
3955 | |
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 | function ieee754_read(buffer, offset, isLE, mLen, nBytes) {
|
3966 | var e, m,
|
3967 | eLen = nBytes * 8 - mLen - 1,
|
3968 | eMax = (1 << eLen) - 1,
|
3969 | eBias = eMax >> 1,
|
3970 | nBits = -7,
|
3971 | i = isLE ? (nBytes - 1) : 0,
|
3972 | d = isLE ? -1 : 1,
|
3973 | s = buffer[offset + i];
|
3974 |
|
3975 | i += d;
|
3976 |
|
3977 | e = s & ((1 << (-nBits)) - 1);
|
3978 | s >>= (-nBits);
|
3979 | nBits += eLen;
|
3980 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
3981 |
|
3982 | m = e & ((1 << (-nBits)) - 1);
|
3983 | e >>= (-nBits);
|
3984 | nBits += mLen;
|
3985 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
3986 |
|
3987 | if (e === 0) {
|
3988 | e = 1 - eBias;
|
3989 | } else if (e === eMax) {
|
3990 | return m ? NaN : ((s ? -1 : 1) * Infinity);
|
3991 | } else {
|
3992 | m = m + Math.pow(2, mLen);
|
3993 | e = e - eBias;
|
3994 | }
|
3995 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
3996 | }
|
3997 |
|
3998 | |
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 |
|
4004 |
|
4005 |
|
4006 |
|
4007 |
|
4008 | function ieee754_write(buffer, value, offset, isLE, mLen, nBytes) {
|
4009 | var e, m, c,
|
4010 | eLen = nBytes * 8 - mLen - 1,
|
4011 | eMax = (1 << eLen) - 1,
|
4012 | eBias = eMax >> 1,
|
4013 | rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
|
4014 | i = isLE ? 0 : (nBytes - 1),
|
4015 | d = isLE ? 1 : -1,
|
4016 | s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
4017 |
|
4018 | value = Math.abs(value);
|
4019 |
|
4020 | if (isNaN(value) || value === Infinity) {
|
4021 | m = isNaN(value) ? 1 : 0;
|
4022 | e = eMax;
|
4023 | } else {
|
4024 | e = Math.floor(Math.log(value) / Math.LN2);
|
4025 | if (value * (c = Math.pow(2, -e)) < 1) {
|
4026 | e--;
|
4027 | c *= 2;
|
4028 | }
|
4029 | if (e + eBias >= 1) {
|
4030 | value += rt / c;
|
4031 | } else {
|
4032 | value += rt * Math.pow(2, 1 - eBias);
|
4033 | }
|
4034 | if (value * c >= 2) {
|
4035 | e++;
|
4036 | c /= 2;
|
4037 | }
|
4038 |
|
4039 | if (e + eBias >= eMax) {
|
4040 | m = 0;
|
4041 | e = eMax;
|
4042 | } else if (e + eBias >= 1) {
|
4043 | m = (value * c - 1) * Math.pow(2, mLen);
|
4044 | e = e + eBias;
|
4045 | } else {
|
4046 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
4047 | e = 0;
|
4048 | }
|
4049 | }
|
4050 |
|
4051 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
4052 |
|
4053 | e = (e << mLen) | m;
|
4054 | eLen += mLen;
|
4055 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
4056 |
|
4057 | buffer[offset + i - d] |= s * 128;
|
4058 | }
|
4059 |
|
4060 | |
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 | ByteBufferPrototype.writeFloat32 = function(value, offset) {
|
4068 | var relative = typeof offset === 'undefined';
|
4069 | if (relative) offset = this.offset;
|
4070 | if (!this.noAssert) {
|
4071 | if (typeof value !== 'number')
|
4072 | throw TypeError("Illegal value: "+value+" (not a number)");
|
4073 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4074 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4075 | offset >>>= 0;
|
4076 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4077 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4078 | }
|
4079 | offset += 4;
|
4080 | var capacity8 = this.buffer.byteLength;
|
4081 | if (offset > capacity8)
|
4082 | this.resize((capacity8 *= 2) > offset ? capacity8 : offset);
|
4083 | offset -= 4;
|
4084 | ieee754_write(this.view, value, offset, this.littleEndian, 23, 4);
|
4085 | if (relative) this.offset += 4;
|
4086 | return this;
|
4087 | };
|
4088 |
|
4089 | |
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 | ByteBufferPrototype.writeFloat = ByteBufferPrototype.writeFloat32;
|
4098 |
|
4099 | |
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 | ByteBufferPrototype.readFloat32 = function(offset) {
|
4106 | var relative = typeof offset === 'undefined';
|
4107 | if (relative) offset = this.offset;
|
4108 | if (!this.noAssert) {
|
4109 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4110 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4111 | offset >>>= 0;
|
4112 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
4113 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
4114 | }
|
4115 | var value = ieee754_read(this.view, offset, this.littleEndian, 23, 4);
|
4116 | if (relative) this.offset += 4;
|
4117 | return value;
|
4118 | };
|
4119 |
|
4120 | |
4121 |
|
4122 |
|
4123 |
|
4124 |
|
4125 |
|
4126 |
|
4127 | ByteBufferPrototype.readFloat = ByteBufferPrototype.readFloat32;
|
4128 |
|
4129 |
|
4130 |
|
4131 | |
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 |
|
4138 | ByteBufferPrototype.writeFloat64 = function(value, offset) {
|
4139 | var relative = typeof offset === 'undefined';
|
4140 | if (relative) offset = this.offset;
|
4141 | if (!this.noAssert) {
|
4142 | if (typeof value !== 'number')
|
4143 | throw TypeError("Illegal value: "+value+" (not a number)");
|
4144 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4145 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4146 | offset >>>= 0;
|
4147 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4148 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4149 | }
|
4150 | offset += 8;
|
4151 | var capacity9 = this.buffer.byteLength;
|
4152 | if (offset > capacity9)
|
4153 | this.resize((capacity9 *= 2) > offset ? capacity9 : offset);
|
4154 | offset -= 8;
|
4155 | ieee754_write(this.view, value, offset, this.littleEndian, 52, 8);
|
4156 | if (relative) this.offset += 8;
|
4157 | return this;
|
4158 | };
|
4159 |
|
4160 | |
4161 |
|
4162 |
|
4163 |
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 | ByteBufferPrototype.writeDouble = ByteBufferPrototype.writeFloat64;
|
4169 |
|
4170 | |
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 | ByteBufferPrototype.readFloat64 = function(offset) {
|
4177 | var relative = typeof offset === 'undefined';
|
4178 | if (relative) offset = this.offset;
|
4179 | if (!this.noAssert) {
|
4180 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4181 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4182 | offset >>>= 0;
|
4183 | if (offset < 0 || offset + 8 > this.buffer.byteLength)
|
4184 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength);
|
4185 | }
|
4186 | var value = ieee754_read(this.view, offset, this.littleEndian, 52, 8);
|
4187 | if (relative) this.offset += 8;
|
4188 | return value;
|
4189 | };
|
4190 |
|
4191 | |
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 | ByteBufferPrototype.readDouble = ByteBufferPrototype.readFloat64;
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 | |
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 | ByteBuffer.MAX_VARINT32_BYTES = 5;
|
4210 |
|
4211 | |
4212 |
|
4213 |
|
4214 |
|
4215 |
|
4216 |
|
4217 | ByteBuffer.calculateVarint32 = function(value) {
|
4218 |
|
4219 | value = value >>> 0;
|
4220 | if (value < 1 << 7 ) return 1;
|
4221 | else if (value < 1 << 14) return 2;
|
4222 | else if (value < 1 << 21) return 3;
|
4223 | else if (value < 1 << 28) return 4;
|
4224 | else return 5;
|
4225 | };
|
4226 |
|
4227 | |
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 | ByteBuffer.zigZagEncode32 = function(n) {
|
4234 | return (((n |= 0) << 1) ^ (n >> 31)) >>> 0;
|
4235 | };
|
4236 |
|
4237 | |
4238 |
|
4239 |
|
4240 |
|
4241 |
|
4242 |
|
4243 | ByteBuffer.zigZagDecode32 = function(n) {
|
4244 | return ((n >>> 1) ^ -(n & 1)) | 0;
|
4245 | };
|
4246 |
|
4247 | |
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 | ByteBufferPrototype.writeVarint32 = function(value, offset) {
|
4256 | var relative = typeof offset === 'undefined';
|
4257 | if (relative) offset = this.offset;
|
4258 | if (!this.noAssert) {
|
4259 | if (typeof value !== 'number' || value % 1 !== 0)
|
4260 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
4261 | value |= 0;
|
4262 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4263 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4264 | offset >>>= 0;
|
4265 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4266 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4267 | }
|
4268 | var size = ByteBuffer.calculateVarint32(value),
|
4269 | b;
|
4270 | offset += size;
|
4271 | var capacity10 = this.buffer.byteLength;
|
4272 | if (offset > capacity10)
|
4273 | this.resize((capacity10 *= 2) > offset ? capacity10 : offset);
|
4274 | offset -= size;
|
4275 | value >>>= 0;
|
4276 | while (value >= 0x80) {
|
4277 | b = (value & 0x7f) | 0x80;
|
4278 | this.view[offset++] = b;
|
4279 | value >>>= 7;
|
4280 | }
|
4281 | this.view[offset++] = value;
|
4282 | if (relative) {
|
4283 | this.offset = offset;
|
4284 | return this;
|
4285 | }
|
4286 | return size;
|
4287 | };
|
4288 |
|
4289 | |
4290 |
|
4291 |
|
4292 |
|
4293 |
|
4294 |
|
4295 |
|
4296 |
|
4297 | ByteBufferPrototype.writeVarint32ZigZag = function(value, offset) {
|
4298 | return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset);
|
4299 | };
|
4300 |
|
4301 | |
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 |
|
4311 | ByteBufferPrototype.readVarint32 = function(offset) {
|
4312 | var relative = typeof offset === 'undefined';
|
4313 | if (relative) offset = this.offset;
|
4314 | if (!this.noAssert) {
|
4315 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4316 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4317 | offset >>>= 0;
|
4318 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4319 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4320 | }
|
4321 | var c = 0,
|
4322 | value = 0 >>> 0,
|
4323 | b;
|
4324 | do {
|
4325 | if (!this.noAssert && offset > this.limit) {
|
4326 | var err = Error("Truncated");
|
4327 | err['truncated'] = true;
|
4328 | throw err;
|
4329 | }
|
4330 | b = this.view[offset++];
|
4331 | if (c < 5)
|
4332 | value |= (b & 0x7f) << (7*c);
|
4333 | ++c;
|
4334 | } while ((b & 0x80) !== 0);
|
4335 | value |= 0;
|
4336 | if (relative) {
|
4337 | this.offset = offset;
|
4338 | return value;
|
4339 | }
|
4340 | return {
|
4341 | "value": value,
|
4342 | "length": c
|
4343 | };
|
4344 | };
|
4345 |
|
4346 | |
4347 |
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 | ByteBufferPrototype.readVarint32ZigZag = function(offset) {
|
4356 | var val = this.readVarint32(offset);
|
4357 | if (typeof val === 'object')
|
4358 | val["value"] = ByteBuffer.zigZagDecode32(val["value"]);
|
4359 | else
|
4360 | val = ByteBuffer.zigZagDecode32(val);
|
4361 | return val;
|
4362 | };
|
4363 |
|
4364 |
|
4365 |
|
4366 | if (Long) {
|
4367 |
|
4368 | |
4369 |
|
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 | ByteBuffer.MAX_VARINT64_BYTES = 10;
|
4375 |
|
4376 | |
4377 |
|
4378 |
|
4379 |
|
4380 |
|
4381 |
|
4382 | ByteBuffer.calculateVarint64 = function(value) {
|
4383 | if (typeof value === 'number')
|
4384 | value = Long.fromNumber(value);
|
4385 | else if (typeof value === 'string')
|
4386 | value = Long.fromString(value);
|
4387 |
|
4388 | var part0 = value.toInt() >>> 0,
|
4389 | part1 = value.shiftRightUnsigned(28).toInt() >>> 0,
|
4390 | part2 = value.shiftRightUnsigned(56).toInt() >>> 0;
|
4391 | if (part2 == 0) {
|
4392 | if (part1 == 0) {
|
4393 | if (part0 < 1 << 14)
|
4394 | return part0 < 1 << 7 ? 1 : 2;
|
4395 | else
|
4396 | return part0 < 1 << 21 ? 3 : 4;
|
4397 | } else {
|
4398 | if (part1 < 1 << 14)
|
4399 | return part1 < 1 << 7 ? 5 : 6;
|
4400 | else
|
4401 | return part1 < 1 << 21 ? 7 : 8;
|
4402 | }
|
4403 | } else
|
4404 | return part2 < 1 << 7 ? 9 : 10;
|
4405 | };
|
4406 |
|
4407 | |
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 | ByteBuffer.zigZagEncode64 = function(value) {
|
4414 | if (typeof value === 'number')
|
4415 | value = Long.fromNumber(value, false);
|
4416 | else if (typeof value === 'string')
|
4417 | value = Long.fromString(value, false);
|
4418 | else if (value.unsigned !== false) value = value.toSigned();
|
4419 |
|
4420 | return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned();
|
4421 | };
|
4422 |
|
4423 | |
4424 |
|
4425 |
|
4426 |
|
4427 |
|
4428 |
|
4429 | ByteBuffer.zigZagDecode64 = function(value) {
|
4430 | if (typeof value === 'number')
|
4431 | value = Long.fromNumber(value, false);
|
4432 | else if (typeof value === 'string')
|
4433 | value = Long.fromString(value, false);
|
4434 | else if (value.unsigned !== false) value = value.toSigned();
|
4435 |
|
4436 | return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned();
|
4437 | };
|
4438 |
|
4439 | |
4440 |
|
4441 |
|
4442 |
|
4443 |
|
4444 |
|
4445 |
|
4446 |
|
4447 | ByteBufferPrototype.writeVarint64 = function(value, offset) {
|
4448 | var relative = typeof offset === 'undefined';
|
4449 | if (relative) offset = this.offset;
|
4450 | if (!this.noAssert) {
|
4451 | if (typeof value === 'number')
|
4452 | value = Long.fromNumber(value);
|
4453 | else if (typeof value === 'string')
|
4454 | value = Long.fromString(value);
|
4455 | else if (!(value && value instanceof Long))
|
4456 | throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
4457 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4458 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4459 | offset >>>= 0;
|
4460 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4461 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4462 | }
|
4463 | if (typeof value === 'number')
|
4464 | value = Long.fromNumber(value, false);
|
4465 | else if (typeof value === 'string')
|
4466 | value = Long.fromString(value, false);
|
4467 | else if (value.unsigned !== false) value = value.toSigned();
|
4468 | var size = ByteBuffer.calculateVarint64(value),
|
4469 | part0 = value.toInt() >>> 0,
|
4470 | part1 = value.shiftRightUnsigned(28).toInt() >>> 0,
|
4471 | part2 = value.shiftRightUnsigned(56).toInt() >>> 0;
|
4472 | offset += size;
|
4473 | var capacity11 = this.buffer.byteLength;
|
4474 | if (offset > capacity11)
|
4475 | this.resize((capacity11 *= 2) > offset ? capacity11 : offset);
|
4476 | offset -= size;
|
4477 | switch (size) {
|
4478 | case 10: this.view[offset+9] = (part2 >>> 7) & 0x01;
|
4479 | case 9 : this.view[offset+8] = size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F;
|
4480 | case 8 : this.view[offset+7] = size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F;
|
4481 | case 7 : this.view[offset+6] = size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F;
|
4482 | case 6 : this.view[offset+5] = size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F;
|
4483 | case 5 : this.view[offset+4] = size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F;
|
4484 | case 4 : this.view[offset+3] = size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F;
|
4485 | case 3 : this.view[offset+2] = size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F;
|
4486 | case 2 : this.view[offset+1] = size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F;
|
4487 | case 1 : this.view[offset ] = size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F;
|
4488 | }
|
4489 | if (relative) {
|
4490 | this.offset += size;
|
4491 | return this;
|
4492 | } else {
|
4493 | return size;
|
4494 | }
|
4495 | };
|
4496 |
|
4497 | |
4498 |
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 |
|
4505 | ByteBufferPrototype.writeVarint64ZigZag = function(value, offset) {
|
4506 | return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset);
|
4507 | };
|
4508 |
|
4509 | |
4510 |
|
4511 |
|
4512 |
|
4513 |
|
4514 |
|
4515 |
|
4516 |
|
4517 |
|
4518 | ByteBufferPrototype.readVarint64 = function(offset) {
|
4519 | var relative = typeof offset === 'undefined';
|
4520 | if (relative) offset = this.offset;
|
4521 | if (!this.noAssert) {
|
4522 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4523 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4524 | offset >>>= 0;
|
4525 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4526 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4527 | }
|
4528 |
|
4529 | var start = offset,
|
4530 | part0 = 0,
|
4531 | part1 = 0,
|
4532 | part2 = 0,
|
4533 | b = 0;
|
4534 | b = this.view[offset++]; part0 = (b & 0x7F) ; if ( b & 0x80 ) {
|
4535 | b = this.view[offset++]; part0 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4536 | b = this.view[offset++]; part0 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4537 | b = this.view[offset++]; part0 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4538 | b = this.view[offset++]; part1 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4539 | b = this.view[offset++]; part1 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4540 | b = this.view[offset++]; part1 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4541 | b = this.view[offset++]; part1 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4542 | b = this.view[offset++]; part2 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4543 | b = this.view[offset++]; part2 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4544 | throw Error("Buffer overrun"); }}}}}}}}}}
|
4545 | var value = Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, false);
|
4546 | if (relative) {
|
4547 | this.offset = offset;
|
4548 | return value;
|
4549 | } else {
|
4550 | return {
|
4551 | 'value': value,
|
4552 | 'length': offset-start
|
4553 | };
|
4554 | }
|
4555 | };
|
4556 |
|
4557 | |
4558 |
|
4559 |
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 |
|
4566 | ByteBufferPrototype.readVarint64ZigZag = function(offset) {
|
4567 | var val = this.readVarint64(offset);
|
4568 | if (val && val['value'] instanceof Long)
|
4569 | val["value"] = ByteBuffer.zigZagDecode64(val["value"]);
|
4570 | else
|
4571 | val = ByteBuffer.zigZagDecode64(val);
|
4572 | return val;
|
4573 | };
|
4574 |
|
4575 | }
|
4576 |
|
4577 |
|
4578 |
|
4579 |
|
4580 | |
4581 |
|
4582 |
|
4583 |
|
4584 |
|
4585 |
|
4586 |
|
4587 |
|
4588 |
|
4589 | ByteBufferPrototype.writeCString = function(str, offset) {
|
4590 | var relative = typeof offset === 'undefined';
|
4591 | if (relative) offset = this.offset;
|
4592 | var i,
|
4593 | k = str.length;
|
4594 | if (!this.noAssert) {
|
4595 | if (typeof str !== 'string')
|
4596 | throw TypeError("Illegal str: Not a string");
|
4597 | for (i=0; i<k; ++i) {
|
4598 | if (str.charCodeAt(i) === 0)
|
4599 | throw RangeError("Illegal str: Contains NULL-characters");
|
4600 | }
|
4601 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4602 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4603 | offset >>>= 0;
|
4604 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4605 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4606 | }
|
4607 |
|
4608 | k = utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
4609 | offset += k+1;
|
4610 | var capacity12 = this.buffer.byteLength;
|
4611 | if (offset > capacity12)
|
4612 | this.resize((capacity12 *= 2) > offset ? capacity12 : offset);
|
4613 | offset -= k+1;
|
4614 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4615 | this.view[offset++] = b;
|
4616 | }.bind(this));
|
4617 | this.view[offset++] = 0;
|
4618 | if (relative) {
|
4619 | this.offset = offset;
|
4620 | return this;
|
4621 | }
|
4622 | return k;
|
4623 | };
|
4624 |
|
4625 | |
4626 |
|
4627 |
|
4628 |
|
4629 |
|
4630 |
|
4631 |
|
4632 |
|
4633 |
|
4634 | ByteBufferPrototype.readCString = function(offset) {
|
4635 | var relative = typeof offset === 'undefined';
|
4636 | if (relative) offset = this.offset;
|
4637 | if (!this.noAssert) {
|
4638 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4639 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4640 | offset >>>= 0;
|
4641 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4642 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4643 | }
|
4644 | var start = offset;
|
4645 |
|
4646 | var sd, b = -1;
|
4647 | utfx.decodeUTF8toUTF16(function() {
|
4648 | if (b === 0) return null;
|
4649 | if (offset >= this.limit)
|
4650 | throw RangeError("Illegal range: Truncated data, "+offset+" < "+this.limit);
|
4651 | b = this.view[offset++];
|
4652 | return b === 0 ? null : b;
|
4653 | }.bind(this), sd = stringDestination(), true);
|
4654 | if (relative) {
|
4655 | this.offset = offset;
|
4656 | return sd();
|
4657 | } else {
|
4658 | return {
|
4659 | "string": sd(),
|
4660 | "length": offset - start
|
4661 | };
|
4662 | }
|
4663 | };
|
4664 |
|
4665 |
|
4666 |
|
4667 | |
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 | ByteBufferPrototype.writeIString = function(str, offset) {
|
4677 | var relative = typeof offset === 'undefined';
|
4678 | if (relative) offset = this.offset;
|
4679 | if (!this.noAssert) {
|
4680 | if (typeof str !== 'string')
|
4681 | throw TypeError("Illegal str: Not a string");
|
4682 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4683 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4684 | offset >>>= 0;
|
4685 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4686 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4687 | }
|
4688 | var start = offset,
|
4689 | k;
|
4690 | k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];
|
4691 | offset += 4+k;
|
4692 | var capacity13 = this.buffer.byteLength;
|
4693 | if (offset > capacity13)
|
4694 | this.resize((capacity13 *= 2) > offset ? capacity13 : offset);
|
4695 | offset -= 4+k;
|
4696 | if (this.littleEndian) {
|
4697 | this.view[offset+3] = (k >>> 24) & 0xFF;
|
4698 | this.view[offset+2] = (k >>> 16) & 0xFF;
|
4699 | this.view[offset+1] = (k >>> 8) & 0xFF;
|
4700 | this.view[offset ] = k & 0xFF;
|
4701 | } else {
|
4702 | this.view[offset ] = (k >>> 24) & 0xFF;
|
4703 | this.view[offset+1] = (k >>> 16) & 0xFF;
|
4704 | this.view[offset+2] = (k >>> 8) & 0xFF;
|
4705 | this.view[offset+3] = k & 0xFF;
|
4706 | }
|
4707 | offset += 4;
|
4708 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4709 | this.view[offset++] = b;
|
4710 | }.bind(this));
|
4711 | if (offset !== start + 4 + k)
|
4712 | throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+4+k));
|
4713 | if (relative) {
|
4714 | this.offset = offset;
|
4715 | return this;
|
4716 | }
|
4717 | return offset - start;
|
4718 | };
|
4719 |
|
4720 | |
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 | ByteBufferPrototype.readIString = function(offset) {
|
4730 | var relative = typeof offset === 'undefined';
|
4731 | if (relative) offset = this.offset;
|
4732 | if (!this.noAssert) {
|
4733 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4734 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4735 | offset >>>= 0;
|
4736 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
4737 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
4738 | }
|
4739 | var start = offset;
|
4740 | var len = this.readUint32(offset);
|
4741 | var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4);
|
4742 | offset += str['length'];
|
4743 | if (relative) {
|
4744 | this.offset = offset;
|
4745 | return str['string'];
|
4746 | } else {
|
4747 | return {
|
4748 | 'string': str['string'],
|
4749 | 'length': offset - start
|
4750 | };
|
4751 | }
|
4752 | };
|
4753 |
|
4754 |
|
4755 |
|
4756 | |
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 | ByteBuffer.METRICS_CHARS = 'c';
|
4763 |
|
4764 | |
4765 |
|
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 | ByteBuffer.METRICS_BYTES = 'b';
|
4771 |
|
4772 | |
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 | ByteBufferPrototype.writeUTF8String = function(str, offset) {
|
4780 | var relative = typeof offset === 'undefined';
|
4781 | if (relative) offset = this.offset;
|
4782 | if (!this.noAssert) {
|
4783 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4784 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4785 | offset >>>= 0;
|
4786 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4787 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4788 | }
|
4789 | var k;
|
4790 | var start = offset;
|
4791 | k = utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
4792 | offset += k;
|
4793 | var capacity14 = this.buffer.byteLength;
|
4794 | if (offset > capacity14)
|
4795 | this.resize((capacity14 *= 2) > offset ? capacity14 : offset);
|
4796 | offset -= k;
|
4797 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4798 | this.view[offset++] = b;
|
4799 | }.bind(this));
|
4800 | if (relative) {
|
4801 | this.offset = offset;
|
4802 | return this;
|
4803 | }
|
4804 | return offset - start;
|
4805 | };
|
4806 |
|
4807 | |
4808 |
|
4809 |
|
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 | ByteBufferPrototype.writeString = ByteBufferPrototype.writeUTF8String;
|
4816 |
|
4817 | |
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 | ByteBuffer.calculateUTF8Chars = function(str) {
|
4825 | return utfx.calculateUTF16asUTF8(stringSource(str))[0];
|
4826 | };
|
4827 |
|
4828 | |
4829 |
|
4830 |
|
4831 |
|
4832 |
|
4833 |
|
4834 | ByteBuffer.calculateUTF8Bytes = function(str) {
|
4835 | return utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
4836 | };
|
4837 |
|
4838 | |
4839 |
|
4840 |
|
4841 |
|
4842 |
|
4843 |
|
4844 |
|
4845 | ByteBuffer.calculateString = ByteBuffer.calculateUTF8Bytes;
|
4846 |
|
4847 | |
4848 |
|
4849 |
|
4850 |
|
4851 |
|
4852 |
|
4853 |
|
4854 |
|
4855 |
|
4856 |
|
4857 |
|
4858 | ByteBufferPrototype.readUTF8String = function(length, metrics, offset) {
|
4859 | if (typeof metrics === 'number') {
|
4860 | offset = metrics;
|
4861 | metrics = undefined;
|
4862 | }
|
4863 | var relative = typeof offset === 'undefined';
|
4864 | if (relative) offset = this.offset;
|
4865 | if (typeof metrics === 'undefined') metrics = ByteBuffer.METRICS_CHARS;
|
4866 | if (!this.noAssert) {
|
4867 | if (typeof length !== 'number' || length % 1 !== 0)
|
4868 | throw TypeError("Illegal length: "+length+" (not an integer)");
|
4869 | length |= 0;
|
4870 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4871 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4872 | offset >>>= 0;
|
4873 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4874 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4875 | }
|
4876 | var i = 0,
|
4877 | start = offset,
|
4878 | sd;
|
4879 | if (metrics === ByteBuffer.METRICS_CHARS) {
|
4880 | sd = stringDestination();
|
4881 | utfx.decodeUTF8(function() {
|
4882 | return i < length && offset < this.limit ? this.view[offset++] : null;
|
4883 | }.bind(this), function(cp) {
|
4884 | ++i; utfx.UTF8toUTF16(cp, sd);
|
4885 | });
|
4886 | if (i !== length)
|
4887 | throw RangeError("Illegal range: Truncated data, "+i+" == "+length);
|
4888 | if (relative) {
|
4889 | this.offset = offset;
|
4890 | return sd();
|
4891 | } else {
|
4892 | return {
|
4893 | "string": sd(),
|
4894 | "length": offset - start
|
4895 | };
|
4896 | }
|
4897 | } else if (metrics === ByteBuffer.METRICS_BYTES) {
|
4898 | if (!this.noAssert) {
|
4899 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4900 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4901 | offset >>>= 0;
|
4902 | if (offset < 0 || offset + length > this.buffer.byteLength)
|
4903 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength);
|
4904 | }
|
4905 | var k = offset + length;
|
4906 | utfx.decodeUTF8toUTF16(function() {
|
4907 | return offset < k ? this.view[offset++] : null;
|
4908 | }.bind(this), sd = stringDestination(), this.noAssert);
|
4909 | if (offset !== k)
|
4910 | throw RangeError("Illegal range: Truncated data, "+offset+" == "+k);
|
4911 | if (relative) {
|
4912 | this.offset = offset;
|
4913 | return sd();
|
4914 | } else {
|
4915 | return {
|
4916 | 'string': sd(),
|
4917 | 'length': offset - start
|
4918 | };
|
4919 | }
|
4920 | } else
|
4921 | throw TypeError("Unsupported metrics: "+metrics);
|
4922 | };
|
4923 |
|
4924 | |
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 | ByteBufferPrototype.readString = ByteBufferPrototype.readUTF8String;
|
4937 |
|
4938 |
|
4939 |
|
4940 | |
4941 |
|
4942 |
|
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 | ByteBufferPrototype.writeVString = function(str, offset) {
|
4950 | var relative = typeof offset === 'undefined';
|
4951 | if (relative) offset = this.offset;
|
4952 | if (!this.noAssert) {
|
4953 | if (typeof str !== 'string')
|
4954 | throw TypeError("Illegal str: Not a string");
|
4955 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4956 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4957 | offset >>>= 0;
|
4958 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4959 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4960 | }
|
4961 | var start = offset,
|
4962 | k, l;
|
4963 | k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];
|
4964 | l = ByteBuffer.calculateVarint32(k);
|
4965 | offset += l+k;
|
4966 | var capacity15 = this.buffer.byteLength;
|
4967 | if (offset > capacity15)
|
4968 | this.resize((capacity15 *= 2) > offset ? capacity15 : offset);
|
4969 | offset -= l+k;
|
4970 | offset += this.writeVarint32(k, offset);
|
4971 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4972 | this.view[offset++] = b;
|
4973 | }.bind(this));
|
4974 | if (offset !== start+k+l)
|
4975 | throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+k+l));
|
4976 | if (relative) {
|
4977 | this.offset = offset;
|
4978 | return this;
|
4979 | }
|
4980 | return offset - start;
|
4981 | };
|
4982 |
|
4983 | |
4984 |
|
4985 |
|
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 | ByteBufferPrototype.readVString = function(offset) {
|
4993 | var relative = typeof offset === 'undefined';
|
4994 | if (relative) offset = this.offset;
|
4995 | if (!this.noAssert) {
|
4996 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4997 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4998 | offset >>>= 0;
|
4999 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
5000 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
5001 | }
|
5002 | var start = offset;
|
5003 | var len = this.readVarint32(offset);
|
5004 | var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']);
|
5005 | offset += str['length'];
|
5006 | if (relative) {
|
5007 | this.offset = offset;
|
5008 | return str['string'];
|
5009 | } else {
|
5010 | return {
|
5011 | 'string': str['string'],
|
5012 | 'length': offset - start
|
5013 | };
|
5014 | }
|
5015 | };
|
5016 |
|
5017 |
|
5018 | |
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 |
|
5029 |
|
5030 |
|
5031 | ByteBufferPrototype.append = function(source, encoding, offset) {
|
5032 | if (typeof encoding === 'number' || typeof encoding !== 'string') {
|
5033 | offset = encoding;
|
5034 | encoding = undefined;
|
5035 | }
|
5036 | var relative = typeof offset === 'undefined';
|
5037 | if (relative) offset = this.offset;
|
5038 | if (!this.noAssert) {
|
5039 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5040 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
5041 | offset >>>= 0;
|
5042 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
5043 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
5044 | }
|
5045 | if (!(source instanceof ByteBuffer))
|
5046 | source = ByteBuffer.wrap(source, encoding);
|
5047 | var length = source.limit - source.offset;
|
5048 | if (length <= 0) return this;
|
5049 | offset += length;
|
5050 | var capacity16 = this.buffer.byteLength;
|
5051 | if (offset > capacity16)
|
5052 | this.resize((capacity16 *= 2) > offset ? capacity16 : offset);
|
5053 | offset -= length;
|
5054 | this.view.set(source.view.subarray(source.offset, source.limit), offset);
|
5055 | source.offset += length;
|
5056 | if (relative) this.offset += length;
|
5057 | return this;
|
5058 | };
|
5059 |
|
5060 | |
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 | ByteBufferPrototype.appendTo = function(target, offset) {
|
5071 | target.append(this, offset);
|
5072 | return this;
|
5073 | };
|
5074 |
|
5075 | |
5076 |
|
5077 |
|
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 | ByteBufferPrototype.assert = function(assert) {
|
5083 | this.noAssert = !assert;
|
5084 | return this;
|
5085 | };
|
5086 |
|
5087 | |
5088 |
|
5089 |
|
5090 |
|
5091 |
|
5092 | ByteBufferPrototype.capacity = function() {
|
5093 | return this.buffer.byteLength;
|
5094 | };
|
5095 | |
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 | ByteBufferPrototype.clear = function() {
|
5102 | this.offset = 0;
|
5103 | this.limit = this.buffer.byteLength;
|
5104 | this.markedOffset = -1;
|
5105 | return this;
|
5106 | };
|
5107 |
|
5108 | |
5109 |
|
5110 |
|
5111 |
|
5112 |
|
5113 |
|
5114 |
|
5115 | ByteBufferPrototype.clone = function(copy) {
|
5116 | var bb = new ByteBuffer(0, this.littleEndian, this.noAssert);
|
5117 | if (copy) {
|
5118 | bb.buffer = new ArrayBuffer(this.buffer.byteLength);
|
5119 | bb.view = new Uint8Array(bb.buffer);
|
5120 | } else {
|
5121 | bb.buffer = this.buffer;
|
5122 | bb.view = this.view;
|
5123 | }
|
5124 | bb.offset = this.offset;
|
5125 | bb.markedOffset = this.markedOffset;
|
5126 | bb.limit = this.limit;
|
5127 | return bb;
|
5128 | };
|
5129 |
|
5130 | |
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 | ByteBufferPrototype.compact = function(begin, end) {
|
5140 | if (typeof begin === 'undefined') begin = this.offset;
|
5141 | if (typeof end === 'undefined') end = this.limit;
|
5142 | if (!this.noAssert) {
|
5143 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5144 | throw TypeError("Illegal begin: Not an integer");
|
5145 | begin >>>= 0;
|
5146 | if (typeof end !== 'number' || end % 1 !== 0)
|
5147 | throw TypeError("Illegal end: Not an integer");
|
5148 | end >>>= 0;
|
5149 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5150 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5151 | }
|
5152 | if (begin === 0 && end === this.buffer.byteLength)
|
5153 | return this;
|
5154 | var len = end - begin;
|
5155 | if (len === 0) {
|
5156 | this.buffer = EMPTY_BUFFER;
|
5157 | this.view = null;
|
5158 | if (this.markedOffset >= 0) this.markedOffset -= begin;
|
5159 | this.offset = 0;
|
5160 | this.limit = 0;
|
5161 | return this;
|
5162 | }
|
5163 | var buffer = new ArrayBuffer(len);
|
5164 | var view = new Uint8Array(buffer);
|
5165 | view.set(this.view.subarray(begin, end));
|
5166 | this.buffer = buffer;
|
5167 | this.view = view;
|
5168 | if (this.markedOffset >= 0) this.markedOffset -= begin;
|
5169 | this.offset = 0;
|
5170 | this.limit = len;
|
5171 | return this;
|
5172 | };
|
5173 |
|
5174 | |
5175 |
|
5176 |
|
5177 |
|
5178 |
|
5179 |
|
5180 |
|
5181 |
|
5182 | ByteBufferPrototype.copy = function(begin, end) {
|
5183 | if (typeof begin === 'undefined') begin = this.offset;
|
5184 | if (typeof end === 'undefined') end = this.limit;
|
5185 | if (!this.noAssert) {
|
5186 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5187 | throw TypeError("Illegal begin: Not an integer");
|
5188 | begin >>>= 0;
|
5189 | if (typeof end !== 'number' || end % 1 !== 0)
|
5190 | throw TypeError("Illegal end: Not an integer");
|
5191 | end >>>= 0;
|
5192 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5193 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5194 | }
|
5195 | if (begin === end)
|
5196 | return new ByteBuffer(0, this.littleEndian, this.noAssert);
|
5197 | var capacity = end - begin,
|
5198 | bb = new ByteBuffer(capacity, this.littleEndian, this.noAssert);
|
5199 | bb.offset = 0;
|
5200 | bb.limit = capacity;
|
5201 | if (bb.markedOffset >= 0) bb.markedOffset -= begin;
|
5202 | this.copyTo(bb, 0, begin, end);
|
5203 | return bb;
|
5204 | };
|
5205 |
|
5206 | |
5207 |
|
5208 |
|
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 |
|
5214 |
|
5215 |
|
5216 |
|
5217 |
|
5218 | ByteBufferPrototype.copyTo = function(target, targetOffset, sourceOffset, sourceLimit) {
|
5219 | var relative,
|
5220 | targetRelative;
|
5221 | if (!this.noAssert) {
|
5222 | if (!ByteBuffer.isByteBuffer(target))
|
5223 | throw TypeError("Illegal target: Not a ByteBuffer");
|
5224 | }
|
5225 | targetOffset = (targetRelative = typeof targetOffset === 'undefined') ? target.offset : targetOffset | 0;
|
5226 | sourceOffset = (relative = typeof sourceOffset === 'undefined') ? this.offset : sourceOffset | 0;
|
5227 | sourceLimit = typeof sourceLimit === 'undefined' ? this.limit : sourceLimit | 0;
|
5228 |
|
5229 | if (targetOffset < 0 || targetOffset > target.buffer.byteLength)
|
5230 | throw RangeError("Illegal target range: 0 <= "+targetOffset+" <= "+target.buffer.byteLength);
|
5231 | if (sourceOffset < 0 || sourceLimit > this.buffer.byteLength)
|
5232 | throw RangeError("Illegal source range: 0 <= "+sourceOffset+" <= "+this.buffer.byteLength);
|
5233 |
|
5234 | var len = sourceLimit - sourceOffset;
|
5235 | if (len === 0)
|
5236 | return target;
|
5237 |
|
5238 | target.ensureCapacity(targetOffset + len);
|
5239 |
|
5240 | target.view.set(this.view.subarray(sourceOffset, sourceLimit), targetOffset);
|
5241 |
|
5242 | if (relative) this.offset += len;
|
5243 | if (targetRelative) target.offset += len;
|
5244 |
|
5245 | return this;
|
5246 | };
|
5247 |
|
5248 | |
5249 |
|
5250 |
|
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 | ByteBufferPrototype.ensureCapacity = function(capacity) {
|
5257 | var current = this.buffer.byteLength;
|
5258 | if (current < capacity)
|
5259 | return this.resize((current *= 2) > capacity ? current : capacity);
|
5260 | return this;
|
5261 | };
|
5262 |
|
5263 | |
5264 |
|
5265 |
|
5266 |
|
5267 |
|
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 | ByteBufferPrototype.fill = function(value, begin, end) {
|
5275 | var relative = typeof begin === 'undefined';
|
5276 | if (relative) begin = this.offset;
|
5277 | if (typeof value === 'string' && value.length > 0)
|
5278 | value = value.charCodeAt(0);
|
5279 | if (typeof begin === 'undefined') begin = this.offset;
|
5280 | if (typeof end === 'undefined') end = this.limit;
|
5281 | if (!this.noAssert) {
|
5282 | if (typeof value !== 'number' || value % 1 !== 0)
|
5283 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
5284 | value |= 0;
|
5285 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5286 | throw TypeError("Illegal begin: Not an integer");
|
5287 | begin >>>= 0;
|
5288 | if (typeof end !== 'number' || end % 1 !== 0)
|
5289 | throw TypeError("Illegal end: Not an integer");
|
5290 | end >>>= 0;
|
5291 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5292 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5293 | }
|
5294 | if (begin >= end)
|
5295 | return this;
|
5296 | while (begin < end) this.view[begin++] = value;
|
5297 | if (relative) this.offset = begin;
|
5298 | return this;
|
5299 | };
|
5300 |
|
5301 | |
5302 |
|
5303 |
|
5304 |
|
5305 |
|
5306 |
|
5307 | ByteBufferPrototype.flip = function() {
|
5308 | this.limit = this.offset;
|
5309 | this.offset = 0;
|
5310 | return this;
|
5311 | };
|
5312 | |
5313 |
|
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
|
5321 | ByteBufferPrototype.mark = function(offset) {
|
5322 | offset = typeof offset === 'undefined' ? this.offset : offset;
|
5323 | if (!this.noAssert) {
|
5324 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5325 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
5326 | offset >>>= 0;
|
5327 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
5328 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
5329 | }
|
5330 | this.markedOffset = offset;
|
5331 | return this;
|
5332 | };
|
5333 | |
5334 |
|
5335 |
|
5336 |
|
5337 |
|
5338 |
|
5339 | ByteBufferPrototype.order = function(littleEndian) {
|
5340 | if (!this.noAssert) {
|
5341 | if (typeof littleEndian !== 'boolean')
|
5342 | throw TypeError("Illegal littleEndian: Not a boolean");
|
5343 | }
|
5344 | this.littleEndian = !!littleEndian;
|
5345 | return this;
|
5346 | };
|
5347 |
|
5348 | |
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 | ByteBufferPrototype.LE = function(littleEndian) {
|
5355 | this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true;
|
5356 | return this;
|
5357 | };
|
5358 |
|
5359 | |
5360 |
|
5361 |
|
5362 |
|
5363 |
|
5364 |
|
5365 | ByteBufferPrototype.BE = function(bigEndian) {
|
5366 | this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false;
|
5367 | return this;
|
5368 | };
|
5369 | |
5370 |
|
5371 |
|
5372 |
|
5373 |
|
5374 |
|
5375 |
|
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 |
|
5382 |
|
5383 | ByteBufferPrototype.prepend = function(source, encoding, offset) {
|
5384 | if (typeof encoding === 'number' || typeof encoding !== 'string') {
|
5385 | offset = encoding;
|
5386 | encoding = undefined;
|
5387 | }
|
5388 | var relative = typeof offset === 'undefined';
|
5389 | if (relative) offset = this.offset;
|
5390 | if (!this.noAssert) {
|
5391 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5392 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
5393 | offset >>>= 0;
|
5394 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
5395 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
5396 | }
|
5397 | if (!(source instanceof ByteBuffer))
|
5398 | source = ByteBuffer.wrap(source, encoding);
|
5399 | var len = source.limit - source.offset;
|
5400 | if (len <= 0) return this;
|
5401 | var diff = len - offset;
|
5402 | if (diff > 0) {
|
5403 | var buffer = new ArrayBuffer(this.buffer.byteLength + diff);
|
5404 | var view = new Uint8Array(buffer);
|
5405 | view.set(this.view.subarray(offset, this.buffer.byteLength), len);
|
5406 | this.buffer = buffer;
|
5407 | this.view = view;
|
5408 | this.offset += diff;
|
5409 | if (this.markedOffset >= 0) this.markedOffset += diff;
|
5410 | this.limit += diff;
|
5411 | offset += diff;
|
5412 | } else {
|
5413 | var arrayView = new Uint8Array(this.buffer);
|
5414 | }
|
5415 | this.view.set(source.view.subarray(source.offset, source.limit), offset - len);
|
5416 |
|
5417 | source.offset = source.limit;
|
5418 | if (relative)
|
5419 | this.offset -= len;
|
5420 | return this;
|
5421 | };
|
5422 |
|
5423 | |
5424 |
|
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 | ByteBufferPrototype.prependTo = function(target, offset) {
|
5435 | target.prepend(this, offset);
|
5436 | return this;
|
5437 | };
|
5438 | |
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 | ByteBufferPrototype.printDebug = function(out) {
|
5444 | if (typeof out !== 'function') out = console.log.bind(console);
|
5445 | out(
|
5446 | this.toString()+"\n"+
|
5447 | "-------------------------------------------------------------------\n"+
|
5448 | this.toDebug( true)
|
5449 | );
|
5450 | };
|
5451 |
|
5452 | |
5453 |
|
5454 |
|
5455 |
|
5456 |
|
5457 |
|
5458 | ByteBufferPrototype.remaining = function() {
|
5459 | return this.limit - this.offset;
|
5460 | };
|
5461 | |
5462 |
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 | ByteBufferPrototype.reset = function() {
|
5470 | if (this.markedOffset >= 0) {
|
5471 | this.offset = this.markedOffset;
|
5472 | this.markedOffset = -1;
|
5473 | } else {
|
5474 | this.offset = 0;
|
5475 | }
|
5476 | return this;
|
5477 | };
|
5478 | |
5479 |
|
5480 |
|
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 | ByteBufferPrototype.resize = function(capacity) {
|
5488 | if (!this.noAssert) {
|
5489 | if (typeof capacity !== 'number' || capacity % 1 !== 0)
|
5490 | throw TypeError("Illegal capacity: "+capacity+" (not an integer)");
|
5491 | capacity |= 0;
|
5492 | if (capacity < 0)
|
5493 | throw RangeError("Illegal capacity: 0 <= "+capacity);
|
5494 | }
|
5495 | if (this.buffer.byteLength < capacity) {
|
5496 | var buffer = new ArrayBuffer(capacity);
|
5497 | var view = new Uint8Array(buffer);
|
5498 | view.set(this.view);
|
5499 | this.buffer = buffer;
|
5500 | this.view = view;
|
5501 | }
|
5502 | return this;
|
5503 | };
|
5504 | |
5505 |
|
5506 |
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 | ByteBufferPrototype.reverse = function(begin, end) {
|
5512 | if (typeof begin === 'undefined') begin = this.offset;
|
5513 | if (typeof end === 'undefined') end = this.limit;
|
5514 | if (!this.noAssert) {
|
5515 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5516 | throw TypeError("Illegal begin: Not an integer");
|
5517 | begin >>>= 0;
|
5518 | if (typeof end !== 'number' || end % 1 !== 0)
|
5519 | throw TypeError("Illegal end: Not an integer");
|
5520 | end >>>= 0;
|
5521 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5522 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5523 | }
|
5524 | if (begin === end)
|
5525 | return this;
|
5526 | Array.prototype.reverse.call(this.view.subarray(begin, end));
|
5527 | return this;
|
5528 | };
|
5529 | |
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 | ByteBufferPrototype.skip = function(length) {
|
5536 | if (!this.noAssert) {
|
5537 | if (typeof length !== 'number' || length % 1 !== 0)
|
5538 | throw TypeError("Illegal length: "+length+" (not an integer)");
|
5539 | length |= 0;
|
5540 | }
|
5541 | var offset = this.offset + length;
|
5542 | if (!this.noAssert) {
|
5543 | if (offset < 0 || offset > this.buffer.byteLength)
|
5544 | throw RangeError("Illegal length: 0 <= "+this.offset+" + "+length+" <= "+this.buffer.byteLength);
|
5545 | }
|
5546 | this.offset = offset;
|
5547 | return this;
|
5548 | };
|
5549 |
|
5550 | |
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 | ByteBufferPrototype.slice = function(begin, end) {
|
5558 | if (typeof begin === 'undefined') begin = this.offset;
|
5559 | if (typeof end === 'undefined') end = this.limit;
|
5560 | if (!this.noAssert) {
|
5561 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5562 | throw TypeError("Illegal begin: Not an integer");
|
5563 | begin >>>= 0;
|
5564 | if (typeof end !== 'number' || end % 1 !== 0)
|
5565 | throw TypeError("Illegal end: Not an integer");
|
5566 | end >>>= 0;
|
5567 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5568 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5569 | }
|
5570 | var bb = this.clone();
|
5571 | bb.offset = begin;
|
5572 | bb.limit = end;
|
5573 | return bb;
|
5574 | };
|
5575 | |
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 | ByteBufferPrototype.toBuffer = function(forceCopy) {
|
5584 | var offset = this.offset,
|
5585 | limit = this.limit;
|
5586 | if (!this.noAssert) {
|
5587 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5588 | throw TypeError("Illegal offset: Not an integer");
|
5589 | offset >>>= 0;
|
5590 | if (typeof limit !== 'number' || limit % 1 !== 0)
|
5591 | throw TypeError("Illegal limit: Not an integer");
|
5592 | limit >>>= 0;
|
5593 | if (offset < 0 || offset > limit || limit > this.buffer.byteLength)
|
5594 | throw RangeError("Illegal range: 0 <= "+offset+" <= "+limit+" <= "+this.buffer.byteLength);
|
5595 | }
|
5596 |
|
5597 |
|
5598 | if (!forceCopy && offset === 0 && limit === this.buffer.byteLength)
|
5599 | return this.buffer;
|
5600 | if (offset === limit)
|
5601 | return EMPTY_BUFFER;
|
5602 | var buffer = new ArrayBuffer(limit - offset);
|
5603 | new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(offset, limit), 0);
|
5604 | return buffer;
|
5605 | };
|
5606 |
|
5607 | |
5608 |
|
5609 |
|
5610 |
|
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 | ByteBufferPrototype.toArrayBuffer = ByteBufferPrototype.toBuffer;
|
5617 |
|
5618 | |
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 |
|
5629 | ByteBufferPrototype.toString = function(encoding, begin, end) {
|
5630 | if (typeof encoding === 'undefined')
|
5631 | return "ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";
|
5632 | if (typeof encoding === 'number')
|
5633 | encoding = "utf8",
|
5634 | begin = encoding,
|
5635 | end = begin;
|
5636 | switch (encoding) {
|
5637 | case "utf8":
|
5638 | return this.toUTF8(begin, end);
|
5639 | case "base64":
|
5640 | return this.toBase64(begin, end);
|
5641 | case "hex":
|
5642 | return this.toHex(begin, end);
|
5643 | case "binary":
|
5644 | return this.toBinary(begin, end);
|
5645 | case "debug":
|
5646 | return this.toDebug();
|
5647 | case "columns":
|
5648 | return this.toColumns();
|
5649 | default:
|
5650 | throw Error("Unsupported encoding: "+encoding);
|
5651 | }
|
5652 | };
|
5653 |
|
5654 |
|
5655 |
|
5656 | |
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 | var lxiv = function() {
|
5662 |
|
5663 | |
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 | var lxiv = {};
|
5669 |
|
5670 | |
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 | var aout = [
|
5676 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
|
5677 | 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,
|
5678 | 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
|
5679 | 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47
|
5680 | ];
|
5681 |
|
5682 | |
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 | var ain = [];
|
5688 | for (var i=0, k=aout.length; i<k; ++i)
|
5689 | ain[aout[i]] = i;
|
5690 |
|
5691 | |
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 | lxiv.encode = function(src, dst) {
|
5699 | var b, t;
|
5700 | while ((b = src()) !== null) {
|
5701 | dst(aout[(b>>2)&0x3f]);
|
5702 | t = (b&0x3)<<4;
|
5703 | if ((b = src()) !== null) {
|
5704 | t |= (b>>4)&0xf;
|
5705 | dst(aout[(t|((b>>4)&0xf))&0x3f]);
|
5706 | t = (b&0xf)<<2;
|
5707 | if ((b = src()) !== null)
|
5708 | dst(aout[(t|((b>>6)&0x3))&0x3f]),
|
5709 | dst(aout[b&0x3f]);
|
5710 | else
|
5711 | dst(aout[t&0x3f]),
|
5712 | dst(61);
|
5713 | } else
|
5714 | dst(aout[t&0x3f]),
|
5715 | dst(61),
|
5716 | dst(61);
|
5717 | }
|
5718 | };
|
5719 |
|
5720 | |
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 | lxiv.decode = function(src, dst) {
|
5728 | var c, t1, t2;
|
5729 | function fail(c) {
|
5730 | throw Error("Illegal character code: "+c);
|
5731 | }
|
5732 | while ((c = src()) !== null) {
|
5733 | t1 = ain[c];
|
5734 | if (typeof t1 === 'undefined') fail(c);
|
5735 | if ((c = src()) !== null) {
|
5736 | t2 = ain[c];
|
5737 | if (typeof t2 === 'undefined') fail(c);
|
5738 | dst((t1<<2)>>>0|(t2&0x30)>>4);
|
5739 | if ((c = src()) !== null) {
|
5740 | t1 = ain[c];
|
5741 | if (typeof t1 === 'undefined')
|
5742 | if (c === 61) break; else fail(c);
|
5743 | dst(((t2&0xf)<<4)>>>0|(t1&0x3c)>>2);
|
5744 | if ((c = src()) !== null) {
|
5745 | t2 = ain[c];
|
5746 | if (typeof t2 === 'undefined')
|
5747 | if (c === 61) break; else fail(c);
|
5748 | dst(((t1&0x3)<<6)>>>0|t2);
|
5749 | }
|
5750 | }
|
5751 | }
|
5752 | }
|
5753 | };
|
5754 |
|
5755 | |
5756 |
|
5757 |
|
5758 |
|
5759 |
|
5760 | lxiv.test = function(str) {
|
5761 | return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
|
5762 | };
|
5763 |
|
5764 | return lxiv;
|
5765 | }();
|
5766 |
|
5767 |
|
5768 |
|
5769 | |
5770 |
|
5771 |
|
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 |
|
5777 | ByteBufferPrototype.toBase64 = function(begin, end) {
|
5778 | if (typeof begin === 'undefined')
|
5779 | begin = this.offset;
|
5780 | if (typeof end === 'undefined')
|
5781 | end = this.limit;
|
5782 | begin = begin | 0; end = end | 0;
|
5783 | if (begin < 0 || end > this.capacity || begin > end)
|
5784 | throw RangeError("begin, end");
|
5785 | var sd; lxiv.encode(function() {
|
5786 | return begin < end ? this.view[begin++] : null;
|
5787 | }.bind(this), sd = stringDestination());
|
5788 | return sd();
|
5789 | };
|
5790 |
|
5791 | |
5792 |
|
5793 |
|
5794 |
|
5795 |
|
5796 |
|
5797 |
|
5798 |
|
5799 | ByteBuffer.fromBase64 = function(str, littleEndian) {
|
5800 | if (typeof str !== 'string')
|
5801 | throw TypeError("str");
|
5802 | var bb = new ByteBuffer(str.length/4*3, littleEndian),
|
5803 | i = 0;
|
5804 | lxiv.decode(stringSource(str), function(b) {
|
5805 | bb.view[i++] = b;
|
5806 | });
|
5807 | bb.limit = i;
|
5808 | return bb;
|
5809 | };
|
5810 |
|
5811 | |
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 | ByteBuffer.btoa = function(str) {
|
5819 | return ByteBuffer.fromBinary(str).toBase64();
|
5820 | };
|
5821 |
|
5822 | |
5823 |
|
5824 |
|
5825 |
|
5826 |
|
5827 |
|
5828 |
|
5829 | ByteBuffer.atob = function(b64) {
|
5830 | return ByteBuffer.fromBase64(b64).toBinary();
|
5831 | };
|
5832 |
|
5833 |
|
5834 |
|
5835 | |
5836 |
|
5837 |
|
5838 |
|
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 | ByteBufferPrototype.toBinary = function(begin, end) {
|
5844 | if (typeof begin === 'undefined')
|
5845 | begin = this.offset;
|
5846 | if (typeof end === 'undefined')
|
5847 | end = this.limit;
|
5848 | begin |= 0; end |= 0;
|
5849 | if (begin < 0 || end > this.capacity() || begin > end)
|
5850 | throw RangeError("begin, end");
|
5851 | if (begin === end)
|
5852 | return "";
|
5853 | var chars = [],
|
5854 | parts = [];
|
5855 | while (begin < end) {
|
5856 | chars.push(this.view[begin++]);
|
5857 | if (chars.length >= 1024)
|
5858 | parts.push(String.fromCharCode.apply(String, chars)),
|
5859 | chars = [];
|
5860 | }
|
5861 | return parts.join('') + String.fromCharCode.apply(String, chars);
|
5862 | };
|
5863 |
|
5864 | |
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 | ByteBuffer.fromBinary = function(str, littleEndian) {
|
5873 | if (typeof str !== 'string')
|
5874 | throw TypeError("str");
|
5875 | var i = 0,
|
5876 | k = str.length,
|
5877 | charCode,
|
5878 | bb = new ByteBuffer(k, littleEndian);
|
5879 | while (i<k) {
|
5880 | charCode = str.charCodeAt(i);
|
5881 | if (charCode > 0xff)
|
5882 | throw RangeError("illegal char code: "+charCode);
|
5883 | bb.view[i++] = charCode;
|
5884 | }
|
5885 | bb.limit = k;
|
5886 | return bb;
|
5887 | };
|
5888 |
|
5889 |
|
5890 |
|
5891 | |
5892 |
|
5893 |
|
5894 |
|
5895 |
|
5896 |
|
5897 |
|
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 |
|
5908 | ByteBufferPrototype.toDebug = function(columns) {
|
5909 | var i = -1,
|
5910 | k = this.buffer.byteLength,
|
5911 | b,
|
5912 | hex = "",
|
5913 | asc = "",
|
5914 | out = "";
|
5915 | while (i<k) {
|
5916 | if (i !== -1) {
|
5917 | b = this.view[i];
|
5918 | if (b < 0x10) hex += "0"+b.toString(16).toUpperCase();
|
5919 | else hex += b.toString(16).toUpperCase();
|
5920 | if (columns)
|
5921 | asc += b > 32 && b < 127 ? String.fromCharCode(b) : '.';
|
5922 | }
|
5923 | ++i;
|
5924 | if (columns) {
|
5925 | if (i > 0 && i % 16 === 0 && i !== k) {
|
5926 | while (hex.length < 3*16+3) hex += " ";
|
5927 | out += hex+asc+"\n";
|
5928 | hex = asc = "";
|
5929 | }
|
5930 | }
|
5931 | if (i === this.offset && i === this.limit)
|
5932 | hex += i === this.markedOffset ? "!" : "|";
|
5933 | else if (i === this.offset)
|
5934 | hex += i === this.markedOffset ? "[" : "<";
|
5935 | else if (i === this.limit)
|
5936 | hex += i === this.markedOffset ? "]" : ">";
|
5937 | else
|
5938 | hex += i === this.markedOffset ? "'" : (columns || (i !== 0 && i !== k) ? " " : "");
|
5939 | }
|
5940 | if (columns && hex !== " ") {
|
5941 | while (hex.length < 3*16+3)
|
5942 | hex += " ";
|
5943 | out += hex + asc + "\n";
|
5944 | }
|
5945 | return columns ? out : hex;
|
5946 | };
|
5947 |
|
5948 | |
5949 |
|
5950 |
|
5951 |
|
5952 |
|
5953 |
|
5954 |
|
5955 |
|
5956 |
|
5957 |
|
5958 |
|
5959 | ByteBuffer.fromDebug = function(str, littleEndian, noAssert) {
|
5960 | var k = str.length,
|
5961 | bb = new ByteBuffer(((k+1)/3)|0, littleEndian, noAssert);
|
5962 | var i = 0, j = 0, ch, b,
|
5963 | rs = false,
|
5964 | ho = false, hm = false, hl = false,
|
5965 | fail = false;
|
5966 | while (i<k) {
|
5967 | switch (ch = str.charAt(i++)) {
|
5968 | case '!':
|
5969 | if (!noAssert) {
|
5970 | if (ho || hm || hl) {
|
5971 | fail = true;
|
5972 | break;
|
5973 | }
|
5974 | ho = hm = hl = true;
|
5975 | }
|
5976 | bb.offset = bb.markedOffset = bb.limit = j;
|
5977 | rs = false;
|
5978 | break;
|
5979 | case '|':
|
5980 | if (!noAssert) {
|
5981 | if (ho || hl) {
|
5982 | fail = true;
|
5983 | break;
|
5984 | }
|
5985 | ho = hl = true;
|
5986 | }
|
5987 | bb.offset = bb.limit = j;
|
5988 | rs = false;
|
5989 | break;
|
5990 | case '[':
|
5991 | if (!noAssert) {
|
5992 | if (ho || hm) {
|
5993 | fail = true;
|
5994 | break;
|
5995 | }
|
5996 | ho = hm = true;
|
5997 | }
|
5998 | bb.offset = bb.markedOffset = j;
|
5999 | rs = false;
|
6000 | break;
|
6001 | case '<':
|
6002 | if (!noAssert) {
|
6003 | if (ho) {
|
6004 | fail = true;
|
6005 | break;
|
6006 | }
|
6007 | ho = true;
|
6008 | }
|
6009 | bb.offset = j;
|
6010 | rs = false;
|
6011 | break;
|
6012 | case ']':
|
6013 | if (!noAssert) {
|
6014 | if (hl || hm) {
|
6015 | fail = true;
|
6016 | break;
|
6017 | }
|
6018 | hl = hm = true;
|
6019 | }
|
6020 | bb.limit = bb.markedOffset = j;
|
6021 | rs = false;
|
6022 | break;
|
6023 | case '>':
|
6024 | if (!noAssert) {
|
6025 | if (hl) {
|
6026 | fail = true;
|
6027 | break;
|
6028 | }
|
6029 | hl = true;
|
6030 | }
|
6031 | bb.limit = j;
|
6032 | rs = false;
|
6033 | break;
|
6034 | case "'":
|
6035 | if (!noAssert) {
|
6036 | if (hm) {
|
6037 | fail = true;
|
6038 | break;
|
6039 | }
|
6040 | hm = true;
|
6041 | }
|
6042 | bb.markedOffset = j;
|
6043 | rs = false;
|
6044 | break;
|
6045 | case ' ':
|
6046 | rs = false;
|
6047 | break;
|
6048 | default:
|
6049 | if (!noAssert) {
|
6050 | if (rs) {
|
6051 | fail = true;
|
6052 | break;
|
6053 | }
|
6054 | }
|
6055 | b = parseInt(ch+str.charAt(i++), 16);
|
6056 | if (!noAssert) {
|
6057 | if (isNaN(b) || b < 0 || b > 255)
|
6058 | throw TypeError("Illegal str: Not a debug encoded string");
|
6059 | }
|
6060 | bb.view[j++] = b;
|
6061 | rs = true;
|
6062 | }
|
6063 | if (fail)
|
6064 | throw TypeError("Illegal str: Invalid symbol at "+i);
|
6065 | }
|
6066 | if (!noAssert) {
|
6067 | if (!ho || !hl)
|
6068 | throw TypeError("Illegal str: Missing offset or limit");
|
6069 | if (j<bb.buffer.byteLength)
|
6070 | throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+j+" < "+k);
|
6071 | }
|
6072 | return bb;
|
6073 | };
|
6074 |
|
6075 |
|
6076 |
|
6077 | |
6078 |
|
6079 |
|
6080 |
|
6081 |
|
6082 |
|
6083 |
|
6084 | ByteBufferPrototype.toHex = function(begin, end) {
|
6085 | begin = typeof begin === 'undefined' ? this.offset : begin;
|
6086 | end = typeof end === 'undefined' ? this.limit : end;
|
6087 | if (!this.noAssert) {
|
6088 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
6089 | throw TypeError("Illegal begin: Not an integer");
|
6090 | begin >>>= 0;
|
6091 | if (typeof end !== 'number' || end % 1 !== 0)
|
6092 | throw TypeError("Illegal end: Not an integer");
|
6093 | end >>>= 0;
|
6094 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
6095 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
6096 | }
|
6097 | var out = new Array(end - begin),
|
6098 | b;
|
6099 | while (begin < end) {
|
6100 | b = this.view[begin++];
|
6101 | if (b < 0x10)
|
6102 | out.push("0", b.toString(16));
|
6103 | else out.push(b.toString(16));
|
6104 | }
|
6105 | return out.join('');
|
6106 | };
|
6107 |
|
6108 | |
6109 |
|
6110 |
|
6111 |
|
6112 |
|
6113 |
|
6114 |
|
6115 |
|
6116 |
|
6117 |
|
6118 | ByteBuffer.fromHex = function(str, littleEndian, noAssert) {
|
6119 | if (!noAssert) {
|
6120 | if (typeof str !== 'string')
|
6121 | throw TypeError("Illegal str: Not a string");
|
6122 | if (str.length % 2 !== 0)
|
6123 | throw TypeError("Illegal str: Length not a multiple of 2");
|
6124 | }
|
6125 | var k = str.length,
|
6126 | bb = new ByteBuffer((k / 2) | 0, littleEndian),
|
6127 | b;
|
6128 | for (var i=0, j=0; i<k; i+=2) {
|
6129 | b = parseInt(str.substring(i, i+2), 16);
|
6130 | if (!noAssert)
|
6131 | if (!isFinite(b) || b < 0 || b > 255)
|
6132 | throw TypeError("Illegal str: Contains non-hex characters");
|
6133 | bb.view[j++] = b;
|
6134 | }
|
6135 | bb.limit = j;
|
6136 | return bb;
|
6137 | };
|
6138 |
|
6139 |
|
6140 |
|
6141 | |
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 | var utfx = function() {
|
6147 |
|
6148 | |
6149 |
|
6150 |
|
6151 |
|
6152 |
|
6153 | var utfx = {};
|
6154 |
|
6155 | |
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 | utfx.MAX_CODEPOINT = 0x10FFFF;
|
6161 |
|
6162 | |
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 | utfx.encodeUTF8 = function(src, dst) {
|
6169 | var cp = null;
|
6170 | if (typeof src === 'number')
|
6171 | cp = src,
|
6172 | src = function() { return null; };
|
6173 | while (cp !== null || (cp = src()) !== null) {
|
6174 | if (cp < 0x80)
|
6175 | dst(cp&0x7F);
|
6176 | else if (cp < 0x800)
|
6177 | dst(((cp>>6)&0x1F)|0xC0),
|
6178 | dst((cp&0x3F)|0x80);
|
6179 | else if (cp < 0x10000)
|
6180 | dst(((cp>>12)&0x0F)|0xE0),
|
6181 | dst(((cp>>6)&0x3F)|0x80),
|
6182 | dst((cp&0x3F)|0x80);
|
6183 | else
|
6184 | dst(((cp>>18)&0x07)|0xF0),
|
6185 | dst(((cp>>12)&0x3F)|0x80),
|
6186 | dst(((cp>>6)&0x3F)|0x80),
|
6187 | dst((cp&0x3F)|0x80);
|
6188 | cp = null;
|
6189 | }
|
6190 | };
|
6191 |
|
6192 | |
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 |
|
6198 |
|
6199 |
|
6200 |
|
6201 | utfx.decodeUTF8 = function(src, dst) {
|
6202 | var a, b, c, d, fail = function(b) {
|
6203 | b = b.slice(0, b.indexOf(null));
|
6204 | var err = Error(b.toString());
|
6205 | err.name = "TruncatedError";
|
6206 | err['bytes'] = b;
|
6207 | throw err;
|
6208 | };
|
6209 | while ((a = src()) !== null) {
|
6210 | if ((a&0x80) === 0)
|
6211 | dst(a);
|
6212 | else if ((a&0xE0) === 0xC0)
|
6213 | ((b = src()) === null) && fail([a, b]),
|
6214 | dst(((a&0x1F)<<6) | (b&0x3F));
|
6215 | else if ((a&0xF0) === 0xE0)
|
6216 | ((b=src()) === null || (c=src()) === null) && fail([a, b, c]),
|
6217 | dst(((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F));
|
6218 | else if ((a&0xF8) === 0xF0)
|
6219 | ((b=src()) === null || (c=src()) === null || (d=src()) === null) && fail([a, b, c ,d]),
|
6220 | dst(((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F));
|
6221 | else throw RangeError("Illegal starting byte: "+a);
|
6222 | }
|
6223 | };
|
6224 |
|
6225 | |
6226 |
|
6227 |
|
6228 |
|
6229 |
|
6230 |
|
6231 |
|
6232 | utfx.UTF16toUTF8 = function(src, dst) {
|
6233 | var c1, c2 = null;
|
6234 | while (true) {
|
6235 | if ((c1 = c2 !== null ? c2 : src()) === null)
|
6236 | break;
|
6237 | if (c1 >= 0xD800 && c1 <= 0xDFFF) {
|
6238 | if ((c2 = src()) !== null) {
|
6239 | if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
|
6240 | dst((c1-0xD800)*0x400+c2-0xDC00+0x10000);
|
6241 | c2 = null; continue;
|
6242 | }
|
6243 | }
|
6244 | }
|
6245 | dst(c1);
|
6246 | }
|
6247 | if (c2 !== null) dst(c2);
|
6248 | };
|
6249 |
|
6250 | |
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 | utfx.UTF8toUTF16 = function(src, dst) {
|
6258 | var cp = null;
|
6259 | if (typeof src === 'number')
|
6260 | cp = src, src = function() { return null; };
|
6261 | while (cp !== null || (cp = src()) !== null) {
|
6262 | if (cp <= 0xFFFF)
|
6263 | dst(cp);
|
6264 | else
|
6265 | cp -= 0x10000,
|
6266 | dst((cp>>10)+0xD800),
|
6267 | dst((cp%0x400)+0xDC00);
|
6268 | cp = null;
|
6269 | }
|
6270 | };
|
6271 |
|
6272 | |
6273 |
|
6274 |
|
6275 |
|
6276 |
|
6277 |
|
6278 | utfx.encodeUTF16toUTF8 = function(src, dst) {
|
6279 | utfx.UTF16toUTF8(src, function(cp) {
|
6280 | utfx.encodeUTF8(cp, dst);
|
6281 | });
|
6282 | };
|
6283 |
|
6284 | |
6285 |
|
6286 |
|
6287 |
|
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 | utfx.decodeUTF8toUTF16 = function(src, dst) {
|
6293 | utfx.decodeUTF8(src, function(cp) {
|
6294 | utfx.UTF8toUTF16(cp, dst);
|
6295 | });
|
6296 | };
|
6297 |
|
6298 | |
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 | utfx.calculateCodePoint = function(cp) {
|
6304 | return (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;
|
6305 | };
|
6306 |
|
6307 | |
6308 |
|
6309 |
|
6310 |
|
6311 |
|
6312 |
|
6313 | utfx.calculateUTF8 = function(src) {
|
6314 | var cp, l=0;
|
6315 | while ((cp = src()) !== null)
|
6316 | l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;
|
6317 | return l;
|
6318 | };
|
6319 |
|
6320 | |
6321 |
|
6322 |
|
6323 |
|
6324 |
|
6325 |
|
6326 | utfx.calculateUTF16asUTF8 = function(src) {
|
6327 | var n=0, l=0;
|
6328 | utfx.UTF16toUTF8(src, function(cp) {
|
6329 | ++n; l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;
|
6330 | });
|
6331 | return [n,l];
|
6332 | };
|
6333 |
|
6334 | return utfx;
|
6335 | }();
|
6336 |
|
6337 |
|
6338 |
|
6339 | |
6340 |
|
6341 |
|
6342 |
|
6343 |
|
6344 |
|
6345 |
|
6346 | ByteBufferPrototype.toUTF8 = function(begin, end) {
|
6347 | if (typeof begin === 'undefined') begin = this.offset;
|
6348 | if (typeof end === 'undefined') end = this.limit;
|
6349 | if (!this.noAssert) {
|
6350 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
6351 | throw TypeError("Illegal begin: Not an integer");
|
6352 | begin >>>= 0;
|
6353 | if (typeof end !== 'number' || end % 1 !== 0)
|
6354 | throw TypeError("Illegal end: Not an integer");
|
6355 | end >>>= 0;
|
6356 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
6357 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
6358 | }
|
6359 | var sd; try {
|
6360 | utfx.decodeUTF8toUTF16(function() {
|
6361 | return begin < end ? this.view[begin++] : null;
|
6362 | }.bind(this), sd = stringDestination());
|
6363 | } catch (e) {
|
6364 | if (begin !== end)
|
6365 | throw RangeError("Illegal range: Truncated data, "+begin+" != "+end);
|
6366 | }
|
6367 | return sd();
|
6368 | };
|
6369 |
|
6370 | |
6371 |
|
6372 |
|
6373 |
|
6374 |
|
6375 |
|
6376 |
|
6377 |
|
6378 |
|
6379 |
|
6380 | ByteBuffer.fromUTF8 = function(str, littleEndian, noAssert) {
|
6381 | if (!noAssert)
|
6382 | if (typeof str !== 'string')
|
6383 | throw TypeError("Illegal str: Not a string");
|
6384 | var bb = new ByteBuffer(utfx.calculateUTF16asUTF8(stringSource(str), true)[1], littleEndian, noAssert),
|
6385 | i = 0;
|
6386 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
6387 | bb.view[i++] = b;
|
6388 | });
|
6389 | bb.limit = i;
|
6390 | return bb;
|
6391 | };
|
6392 |
|
6393 | return ByteBuffer;
|
6394 | });
|
6395 | });
|
6396 |
|
6397 | var empty = {};
|
6398 |
|
6399 | var empty$1 = Object.freeze({
|
6400 | default: empty
|
6401 | });
|
6402 |
|
6403 | var require$$2 = getCjsExportFromNamespace(empty$1);
|
6404 |
|
6405 | var protobufLight = createCommonjsModule(function (module) {
|
6406 | |
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 |
|
6420 |
|
6421 |
|
6422 | |
6423 |
|
6424 |
|
6425 |
|
6426 |
|
6427 | (function(global, factory) {
|
6428 |
|
6429 | if (typeof commonjsRequire === "function" && 'object' === "object" && module && module["exports"])
|
6430 | module["exports"] = factory(bytebuffer, true);
|
6431 | else
|
6432 | (global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
|
6433 |
|
6434 | })(commonjsGlobal, function(ByteBuffer, isCommonJS) {
|
6435 |
|
6436 | |
6437 |
|
6438 |
|
6439 |
|
6440 |
|
6441 |
|
6442 | var ProtoBuf = {};
|
6443 |
|
6444 | |
6445 |
|
6446 |
|
6447 |
|
6448 | ProtoBuf.ByteBuffer = ByteBuffer;
|
6449 |
|
6450 | |
6451 |
|
6452 |
|
6453 |
|
6454 | ProtoBuf.Long = ByteBuffer.Long || null;
|
6455 |
|
6456 | |
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 | ProtoBuf.VERSION = "5.0.3";
|
6463 |
|
6464 | |
6465 |
|
6466 |
|
6467 |
|
6468 |
|
6469 |
|
6470 | ProtoBuf.WIRE_TYPES = {};
|
6471 |
|
6472 | |
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 | ProtoBuf.WIRE_TYPES.VARINT = 0;
|
6478 |
|
6479 | |
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 | ProtoBuf.WIRE_TYPES.BITS64 = 1;
|
6486 |
|
6487 | |
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 | ProtoBuf.WIRE_TYPES.LDELIM = 2;
|
6494 |
|
6495 | |
6496 |
|
6497 |
|
6498 |
|
6499 |
|
6500 |
|
6501 | ProtoBuf.WIRE_TYPES.STARTGROUP = 3;
|
6502 |
|
6503 | |
6504 |
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 | ProtoBuf.WIRE_TYPES.ENDGROUP = 4;
|
6510 |
|
6511 | |
6512 |
|
6513 |
|
6514 |
|
6515 |
|
6516 |
|
6517 | ProtoBuf.WIRE_TYPES.BITS32 = 5;
|
6518 |
|
6519 | |
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 | ProtoBuf.PACKABLE_WIRE_TYPES = [
|
6526 | ProtoBuf.WIRE_TYPES.VARINT,
|
6527 | ProtoBuf.WIRE_TYPES.BITS64,
|
6528 | ProtoBuf.WIRE_TYPES.BITS32
|
6529 | ];
|
6530 |
|
6531 | |
6532 |
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 |
|
6538 | ProtoBuf.TYPES = {
|
6539 |
|
6540 | "int32": {
|
6541 | name: "int32",
|
6542 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6543 | defaultValue: 0
|
6544 | },
|
6545 | "uint32": {
|
6546 | name: "uint32",
|
6547 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6548 | defaultValue: 0
|
6549 | },
|
6550 | "sint32": {
|
6551 | name: "sint32",
|
6552 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6553 | defaultValue: 0
|
6554 | },
|
6555 | "int64": {
|
6556 | name: "int64",
|
6557 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6558 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined
|
6559 | },
|
6560 | "uint64": {
|
6561 | name: "uint64",
|
6562 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6563 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined
|
6564 | },
|
6565 | "sint64": {
|
6566 | name: "sint64",
|
6567 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6568 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined
|
6569 | },
|
6570 | "bool": {
|
6571 | name: "bool",
|
6572 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6573 | defaultValue: false
|
6574 | },
|
6575 | "double": {
|
6576 | name: "double",
|
6577 | wireType: ProtoBuf.WIRE_TYPES.BITS64,
|
6578 | defaultValue: 0
|
6579 | },
|
6580 | "string": {
|
6581 | name: "string",
|
6582 | wireType: ProtoBuf.WIRE_TYPES.LDELIM,
|
6583 | defaultValue: ""
|
6584 | },
|
6585 | "bytes": {
|
6586 | name: "bytes",
|
6587 | wireType: ProtoBuf.WIRE_TYPES.LDELIM,
|
6588 | defaultValue: null
|
6589 | },
|
6590 | "fixed32": {
|
6591 | name: "fixed32",
|
6592 | wireType: ProtoBuf.WIRE_TYPES.BITS32,
|
6593 | defaultValue: 0
|
6594 | },
|
6595 | "sfixed32": {
|
6596 | name: "sfixed32",
|
6597 | wireType: ProtoBuf.WIRE_TYPES.BITS32,
|
6598 | defaultValue: 0
|
6599 | },
|
6600 | "fixed64": {
|
6601 | name: "fixed64",
|
6602 | wireType: ProtoBuf.WIRE_TYPES.BITS64,
|
6603 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined
|
6604 | },
|
6605 | "sfixed64": {
|
6606 | name: "sfixed64",
|
6607 | wireType: ProtoBuf.WIRE_TYPES.BITS64,
|
6608 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined
|
6609 | },
|
6610 | "float": {
|
6611 | name: "float",
|
6612 | wireType: ProtoBuf.WIRE_TYPES.BITS32,
|
6613 | defaultValue: 0
|
6614 | },
|
6615 | "enum": {
|
6616 | name: "enum",
|
6617 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6618 | defaultValue: 0
|
6619 | },
|
6620 | "message": {
|
6621 | name: "message",
|
6622 | wireType: ProtoBuf.WIRE_TYPES.LDELIM,
|
6623 | defaultValue: null
|
6624 | },
|
6625 | "group": {
|
6626 | name: "group",
|
6627 | wireType: ProtoBuf.WIRE_TYPES.STARTGROUP,
|
6628 | defaultValue: null
|
6629 | }
|
6630 | };
|
6631 |
|
6632 | |
6633 |
|
6634 |
|
6635 |
|
6636 |
|
6637 |
|
6638 | ProtoBuf.MAP_KEY_TYPES = [
|
6639 | ProtoBuf.TYPES["int32"],
|
6640 | ProtoBuf.TYPES["sint32"],
|
6641 | ProtoBuf.TYPES["sfixed32"],
|
6642 | ProtoBuf.TYPES["uint32"],
|
6643 | ProtoBuf.TYPES["fixed32"],
|
6644 | ProtoBuf.TYPES["int64"],
|
6645 | ProtoBuf.TYPES["sint64"],
|
6646 | ProtoBuf.TYPES["sfixed64"],
|
6647 | ProtoBuf.TYPES["uint64"],
|
6648 | ProtoBuf.TYPES["fixed64"],
|
6649 | ProtoBuf.TYPES["bool"],
|
6650 | ProtoBuf.TYPES["string"],
|
6651 | ProtoBuf.TYPES["bytes"]
|
6652 | ];
|
6653 |
|
6654 | |
6655 |
|
6656 |
|
6657 |
|
6658 |
|
6659 |
|
6660 | ProtoBuf.ID_MIN = 1;
|
6661 |
|
6662 | |
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 | ProtoBuf.ID_MAX = 0x1FFFFFFF;
|
6669 |
|
6670 | |
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 | ProtoBuf.convertFieldsToCamelCase = false;
|
6677 |
|
6678 | |
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 | ProtoBuf.populateAccessors = true;
|
6685 |
|
6686 | |
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 | ProtoBuf.populateDefaults = true;
|
6693 |
|
6694 | |
6695 |
|
6696 |
|
6697 |
|
6698 | ProtoBuf.Util = (function() {
|
6699 |
|
6700 | |
6701 |
|
6702 |
|
6703 |
|
6704 |
|
6705 | var Util = {};
|
6706 |
|
6707 | |
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 | Util.IS_NODE = !!(
|
6714 | typeof process === 'object' && process+'' === '[object process]' && !process['browser']
|
6715 | );
|
6716 |
|
6717 | |
6718 |
|
6719 |
|
6720 |
|
6721 |
|
6722 |
|
6723 | Util.XHR = function() {
|
6724 |
|
6725 | var XMLHttpFactories = [
|
6726 | function () {return new XMLHttpRequest()},
|
6727 | function () {return new ActiveXObject("Msxml2.XMLHTTP")},
|
6728 | function () {return new ActiveXObject("Msxml3.XMLHTTP")},
|
6729 | function () {return new ActiveXObject("Microsoft.XMLHTTP")}
|
6730 | ];
|
6731 |
|
6732 | var xhr = null;
|
6733 | for (var i=0;i<XMLHttpFactories.length;i++) {
|
6734 | try { xhr = XMLHttpFactories[i](); }
|
6735 | catch (e) { continue; }
|
6736 | break;
|
6737 | }
|
6738 | if (!xhr)
|
6739 | throw Error("XMLHttpRequest is not supported");
|
6740 | return xhr;
|
6741 | };
|
6742 |
|
6743 | |
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 |
|
6751 | Util.fetch = function(path, callback) {
|
6752 | if (callback && typeof callback != 'function')
|
6753 | callback = null;
|
6754 | if (Util.IS_NODE) {
|
6755 | var fs = require$$2;
|
6756 | if (callback) {
|
6757 | fs.readFile(path, function(err, data) {
|
6758 | if (err)
|
6759 | callback(null);
|
6760 | else
|
6761 | callback(""+data);
|
6762 | });
|
6763 | } else
|
6764 | try {
|
6765 | return fs.readFileSync(path);
|
6766 | } catch (e) {
|
6767 | return null;
|
6768 | }
|
6769 | } else {
|
6770 | var xhr = Util.XHR();
|
6771 | xhr.open('GET', path, callback ? true : false);
|
6772 |
|
6773 | xhr.setRequestHeader('Accept', 'text/plain');
|
6774 | if (typeof xhr.overrideMimeType === 'function') xhr.overrideMimeType('text/plain');
|
6775 | if (callback) {
|
6776 | xhr.onreadystatechange = function() {
|
6777 | if (xhr.readyState != 4) return;
|
6778 | if ( xhr.status == 200 || (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
6779 | callback(xhr.responseText);
|
6780 | else
|
6781 | callback(null);
|
6782 | };
|
6783 | if (xhr.readyState == 4)
|
6784 | return;
|
6785 | xhr.send(null);
|
6786 | } else {
|
6787 | xhr.send(null);
|
6788 | if ( xhr.status == 200 || (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
6789 | return xhr.responseText;
|
6790 | return null;
|
6791 | }
|
6792 | }
|
6793 | };
|
6794 |
|
6795 | |
6796 |
|
6797 |
|
6798 |
|
6799 |
|
6800 |
|
6801 | Util.toCamelCase = function(str) {
|
6802 | return str.replace(/_([a-zA-Z])/g, function ($0, $1) {
|
6803 | return $1.toUpperCase();
|
6804 | });
|
6805 | };
|
6806 |
|
6807 | return Util;
|
6808 | })();
|
6809 |
|
6810 | |
6811 |
|
6812 |
|
6813 |
|
6814 |
|
6815 | ProtoBuf.Lang = {
|
6816 |
|
6817 |
|
6818 | DELIM: /[\s\{\}=;:\[\],'"\(\)<>]/g,
|
6819 |
|
6820 |
|
6821 | RULE: /^(?:required|optional|repeated|map)$/,
|
6822 |
|
6823 |
|
6824 | TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,
|
6825 |
|
6826 |
|
6827 | NAME: /^[a-zA-Z_][a-zA-Z_0-9]*$/,
|
6828 |
|
6829 |
|
6830 | TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/,
|
6831 |
|
6832 |
|
6833 | TYPEREF: /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
|
6834 |
|
6835 |
|
6836 | FQTYPEREF: /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,
|
6837 |
|
6838 |
|
6839 | NUMBER: /^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,
|
6840 |
|
6841 |
|
6842 | NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/,
|
6843 |
|
6844 |
|
6845 | NUMBER_HEX: /^0[xX][0-9a-fA-F]+$/,
|
6846 |
|
6847 |
|
6848 | NUMBER_OCT: /^0[0-7]+$/,
|
6849 |
|
6850 |
|
6851 | NUMBER_FLT: /^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,
|
6852 |
|
6853 |
|
6854 | BOOL: /^(?:true|false)$/i,
|
6855 |
|
6856 |
|
6857 | ID: /^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,
|
6858 |
|
6859 |
|
6860 | NEGID: /^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,
|
6861 |
|
6862 |
|
6863 | WHITESPACE: /\s/,
|
6864 |
|
6865 |
|
6866 | STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,
|
6867 |
|
6868 |
|
6869 | STRING_DQ: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,
|
6870 |
|
6871 |
|
6872 | STRING_SQ: /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g
|
6873 | };
|
6874 |
|
6875 |
|
6876 | |
6877 |
|
6878 |
|
6879 |
|
6880 | ProtoBuf.Reflect = (function(ProtoBuf) {
|
6881 |
|
6882 | |
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 | var Reflect = {};
|
6888 |
|
6889 | |
6890 |
|
6891 |
|
6892 |
|
6893 |
|
6894 |
|
6895 |
|
6896 |
|
6897 |
|
6898 | var T = function(builder, parent, name) {
|
6899 |
|
6900 | |
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 | this.builder = builder;
|
6906 |
|
6907 | |
6908 |
|
6909 |
|
6910 |
|
6911 |
|
6912 | this.parent = parent;
|
6913 |
|
6914 | |
6915 |
|
6916 |
|
6917 |
|
6918 |
|
6919 | this.name = name;
|
6920 |
|
6921 | |
6922 |
|
6923 |
|
6924 |
|
6925 |
|
6926 | this.className;
|
6927 | };
|
6928 |
|
6929 | |
6930 |
|
6931 |
|
6932 |
|
6933 | var TPrototype = T.prototype;
|
6934 |
|
6935 | |
6936 |
|
6937 |
|
6938 |
|
6939 |
|
6940 | TPrototype.fqn = function() {
|
6941 | var name = this.name,
|
6942 | ptr = this;
|
6943 | do {
|
6944 | ptr = ptr.parent;
|
6945 | if (ptr == null)
|
6946 | break;
|
6947 | name = ptr.name+"."+name;
|
6948 | } while (true);
|
6949 | return name;
|
6950 | };
|
6951 |
|
6952 | |
6953 |
|
6954 |
|
6955 |
|
6956 |
|
6957 |
|
6958 | TPrototype.toString = function(includeClass) {
|
6959 | return (includeClass ? this.className + " " : "") + this.fqn();
|
6960 | };
|
6961 |
|
6962 | |
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 | TPrototype.build = function() {
|
6968 | throw Error(this.toString(true)+" cannot be built directly");
|
6969 | };
|
6970 |
|
6971 | |
6972 |
|
6973 |
|
6974 |
|
6975 | Reflect.T = T;
|
6976 |
|
6977 | |
6978 |
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 | var Namespace = function(builder, parent, name, options, syntax) {
|
6989 | T.call(this, builder, parent, name);
|
6990 |
|
6991 | |
6992 |
|
6993 |
|
6994 | this.className = "Namespace";
|
6995 |
|
6996 | |
6997 |
|
6998 |
|
6999 |
|
7000 | this.children = [];
|
7001 |
|
7002 | |
7003 |
|
7004 |
|
7005 |
|
7006 | this.options = options || {};
|
7007 |
|
7008 | |
7009 |
|
7010 |
|
7011 |
|
7012 | this.syntax = syntax || "proto2";
|
7013 | };
|
7014 |
|
7015 | |
7016 |
|
7017 |
|
7018 |
|
7019 | var NamespacePrototype = Namespace.prototype = Object.create(T.prototype);
|
7020 |
|
7021 | |
7022 |
|
7023 |
|
7024 |
|
7025 |
|
7026 |
|
7027 | NamespacePrototype.getChildren = function(type) {
|
7028 | type = type || null;
|
7029 | if (type == null)
|
7030 | return this.children.slice();
|
7031 | var children = [];
|
7032 | for (var i=0, k=this.children.length; i<k; ++i)
|
7033 | if (this.children[i] instanceof type)
|
7034 | children.push(this.children[i]);
|
7035 | return children;
|
7036 | };
|
7037 |
|
7038 | |
7039 |
|
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 | NamespacePrototype.addChild = function(child) {
|
7045 | var other;
|
7046 | if (other = this.getChild(child.name)) {
|
7047 |
|
7048 | if (other instanceof Message.Field && other.name !== other.originalName && this.getChild(other.originalName) === null)
|
7049 | other.name = other.originalName;
|
7050 | else if (child instanceof Message.Field && child.name !== child.originalName && this.getChild(child.originalName) === null)
|
7051 | child.name = child.originalName;
|
7052 | else
|
7053 | throw Error("Duplicate name in namespace "+this.toString(true)+": "+child.name);
|
7054 | }
|
7055 | this.children.push(child);
|
7056 | };
|
7057 |
|
7058 | |
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 |
|
7064 | NamespacePrototype.getChild = function(nameOrId) {
|
7065 | var key = typeof nameOrId === 'number' ? 'id' : 'name';
|
7066 | for (var i=0, k=this.children.length; i<k; ++i)
|
7067 | if (this.children[i][key] === nameOrId)
|
7068 | return this.children[i];
|
7069 | return null;
|
7070 | };
|
7071 |
|
7072 | |
7073 |
|
7074 |
|
7075 |
|
7076 |
|
7077 |
|
7078 |
|
7079 | NamespacePrototype.resolve = function(qn, excludeNonNamespace) {
|
7080 | var part = typeof qn === 'string' ? qn.split(".") : qn,
|
7081 | ptr = this,
|
7082 | i = 0;
|
7083 | if (part[i] === "") {
|
7084 | while (ptr.parent !== null)
|
7085 | ptr = ptr.parent;
|
7086 | i++;
|
7087 | }
|
7088 | var child;
|
7089 | do {
|
7090 | do {
|
7091 | if (!(ptr instanceof Reflect.Namespace)) {
|
7092 | ptr = null;
|
7093 | break;
|
7094 | }
|
7095 | child = ptr.getChild(part[i]);
|
7096 | if (!child || !(child instanceof Reflect.T) || (excludeNonNamespace && !(child instanceof Reflect.Namespace))) {
|
7097 | ptr = null;
|
7098 | break;
|
7099 | }
|
7100 | ptr = child; i++;
|
7101 | } while (i < part.length);
|
7102 | if (ptr != null)
|
7103 | break;
|
7104 |
|
7105 | if (this.parent !== null)
|
7106 | return this.parent.resolve(qn, excludeNonNamespace);
|
7107 | } while (ptr != null);
|
7108 | return ptr;
|
7109 | };
|
7110 |
|
7111 | |
7112 |
|
7113 |
|
7114 |
|
7115 |
|
7116 |
|
7117 | NamespacePrototype.qn = function(t) {
|
7118 | var part = [], ptr = t;
|
7119 | do {
|
7120 | part.unshift(ptr.name);
|
7121 | ptr = ptr.parent;
|
7122 | } while (ptr !== null);
|
7123 | for (var len=1; len <= part.length; len++) {
|
7124 | var qn = part.slice(part.length-len);
|
7125 | if (t === this.resolve(qn, t instanceof Reflect.Namespace))
|
7126 | return qn.join(".");
|
7127 | }
|
7128 | return t.fqn();
|
7129 | };
|
7130 |
|
7131 | |
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 | NamespacePrototype.build = function() {
|
7137 |
|
7138 | var ns = {};
|
7139 | var children = this.children;
|
7140 | for (var i=0, k=children.length, child; i<k; ++i) {
|
7141 | child = children[i];
|
7142 | if (child instanceof Namespace)
|
7143 | ns[child.name] = child.build();
|
7144 | }
|
7145 | if (Object.defineProperty)
|
7146 | Object.defineProperty(ns, "$options", { "value": this.buildOpt() });
|
7147 | return ns;
|
7148 | };
|
7149 |
|
7150 | |
7151 |
|
7152 |
|
7153 |
|
7154 | NamespacePrototype.buildOpt = function() {
|
7155 | var opt = {},
|
7156 | keys = Object.keys(this.options);
|
7157 | for (var i=0, k=keys.length; i<k; ++i) {
|
7158 | var key = keys[i],
|
7159 | val = this.options[keys[i]];
|
7160 |
|
7161 |
|
7162 |
|
7163 |
|
7164 | opt[key] = val;
|
7165 |
|
7166 | }
|
7167 | return opt;
|
7168 | };
|
7169 |
|
7170 | |
7171 |
|
7172 |
|
7173 |
|
7174 |
|
7175 | NamespacePrototype.getOption = function(name) {
|
7176 | if (typeof name === 'undefined')
|
7177 | return this.options;
|
7178 | return typeof this.options[name] !== 'undefined' ? this.options[name] : null;
|
7179 | };
|
7180 |
|
7181 | |
7182 |
|
7183 |
|
7184 |
|
7185 | Reflect.Namespace = Namespace;
|
7186 |
|
7187 | |
7188 |
|
7189 |
|
7190 |
|
7191 |
|
7192 |
|
7193 |
|
7194 |
|
7195 |
|
7196 |
|
7197 |
|
7198 |
|
7199 |
|
7200 |
|
7201 |
|
7202 |
|
7203 |
|
7204 |
|
7205 |
|
7206 |
|
7207 |
|
7208 | var Element = function(type, resolvedType, isMapKey, syntax, name) {
|
7209 |
|
7210 | |
7211 |
|
7212 |
|
7213 |
|
7214 | this.type = type;
|
7215 |
|
7216 | |
7217 |
|
7218 |
|
7219 |
|
7220 | this.resolvedType = resolvedType;
|
7221 |
|
7222 | |
7223 |
|
7224 |
|
7225 |
|
7226 | this.isMapKey = isMapKey;
|
7227 |
|
7228 | |
7229 |
|
7230 |
|
7231 |
|
7232 | this.syntax = syntax;
|
7233 |
|
7234 | |
7235 |
|
7236 |
|
7237 |
|
7238 | this.name = name;
|
7239 |
|
7240 | if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0)
|
7241 | throw Error("Invalid map key type: " + type.name);
|
7242 | };
|
7243 |
|
7244 | var ElementPrototype = Element.prototype;
|
7245 |
|
7246 | |
7247 |
|
7248 |
|
7249 |
|
7250 |
|
7251 |
|
7252 | function mkDefault(type) {
|
7253 | if (typeof type === 'string')
|
7254 | type = ProtoBuf.TYPES[type];
|
7255 | if (typeof type.defaultValue === 'undefined')
|
7256 | throw Error("default value for type "+type.name+" is not supported");
|
7257 | if (type == ProtoBuf.TYPES["bytes"])
|
7258 | return new ByteBuffer(0);
|
7259 | return type.defaultValue;
|
7260 | }
|
7261 |
|
7262 | |
7263 |
|
7264 |
|
7265 |
|
7266 |
|
7267 |
|
7268 | Element.defaultFieldValue = mkDefault;
|
7269 |
|
7270 | |
7271 |
|
7272 |
|
7273 |
|
7274 |
|
7275 |
|
7276 |
|
7277 |
|
7278 |
|
7279 | function mkLong(value, unsigned) {
|
7280 | if (value && typeof value.low === 'number' && typeof value.high === 'number' && typeof value.unsigned === 'boolean'
|
7281 | && value.low === value.low && value.high === value.high)
|
7282 | return new ProtoBuf.Long(value.low, value.high, typeof unsigned === 'undefined' ? value.unsigned : unsigned);
|
7283 | if (typeof value === 'string')
|
7284 | return ProtoBuf.Long.fromString(value, unsigned || false, 10);
|
7285 | if (typeof value === 'number')
|
7286 | return ProtoBuf.Long.fromNumber(value, unsigned || false);
|
7287 | throw Error("not convertible to Long");
|
7288 | }
|
7289 |
|
7290 | ElementPrototype.toString = function() {
|
7291 | return (this.name || '') + (this.isMapKey ? 'map' : 'value') + ' element';
|
7292 | };
|
7293 |
|
7294 | |
7295 |
|
7296 |
|
7297 |
|
7298 |
|
7299 |
|
7300 |
|
7301 |
|
7302 | ElementPrototype.verifyValue = function(value) {
|
7303 | var self = this;
|
7304 | function fail(val, msg) {
|
7305 | throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
7306 | }
|
7307 | switch (this.type) {
|
7308 |
|
7309 | case ProtoBuf.TYPES["int32"]:
|
7310 | case ProtoBuf.TYPES["sint32"]:
|
7311 | case ProtoBuf.TYPES["sfixed32"]:
|
7312 |
|
7313 | if (typeof value !== 'number' || (value === value && value % 1 !== 0))
|
7314 | fail(typeof value, "not an integer");
|
7315 | return value > 4294967295 ? value | 0 : value;
|
7316 |
|
7317 |
|
7318 | case ProtoBuf.TYPES["uint32"]:
|
7319 | case ProtoBuf.TYPES["fixed32"]:
|
7320 | if (typeof value !== 'number' || (value === value && value % 1 !== 0))
|
7321 | fail(typeof value, "not an integer");
|
7322 | return value < 0 ? value >>> 0 : value;
|
7323 |
|
7324 |
|
7325 | case ProtoBuf.TYPES["int64"]:
|
7326 | case ProtoBuf.TYPES["sint64"]:
|
7327 | case ProtoBuf.TYPES["sfixed64"]: {
|
7328 | if (ProtoBuf.Long)
|
7329 | try {
|
7330 | return mkLong(value, false);
|
7331 | } catch (e) {
|
7332 | fail(typeof value, e.message);
|
7333 | }
|
7334 | else
|
7335 | fail(typeof value, "requires Long.js");
|
7336 | }
|
7337 |
|
7338 |
|
7339 | case ProtoBuf.TYPES["uint64"]:
|
7340 | case ProtoBuf.TYPES["fixed64"]: {
|
7341 | if (ProtoBuf.Long)
|
7342 | try {
|
7343 | return mkLong(value, true);
|
7344 | } catch (e) {
|
7345 | fail(typeof value, e.message);
|
7346 | }
|
7347 | else
|
7348 | fail(typeof value, "requires Long.js");
|
7349 | }
|
7350 |
|
7351 |
|
7352 | case ProtoBuf.TYPES["bool"]:
|
7353 | if (typeof value !== 'boolean')
|
7354 | fail(typeof value, "not a boolean");
|
7355 | return value;
|
7356 |
|
7357 |
|
7358 | case ProtoBuf.TYPES["float"]:
|
7359 | case ProtoBuf.TYPES["double"]:
|
7360 | if (typeof value !== 'number')
|
7361 | fail(typeof value, "not a number");
|
7362 | return value;
|
7363 |
|
7364 |
|
7365 | case ProtoBuf.TYPES["string"]:
|
7366 | if (typeof value !== 'string' && !(value && value instanceof String))
|
7367 | fail(typeof value, "not a string");
|
7368 | return ""+value;
|
7369 |
|
7370 |
|
7371 | case ProtoBuf.TYPES["bytes"]:
|
7372 | if (ByteBuffer.isByteBuffer(value))
|
7373 | return value;
|
7374 | return ByteBuffer.wrap(value, "base64");
|
7375 |
|
7376 |
|
7377 | case ProtoBuf.TYPES["enum"]: {
|
7378 | var values = this.resolvedType.getChildren(ProtoBuf.Reflect.Enum.Value);
|
7379 | for (i=0; i<values.length; i++)
|
7380 | if (values[i].name == value)
|
7381 | return values[i].id;
|
7382 | else if (values[i].id == value)
|
7383 | return values[i].id;
|
7384 |
|
7385 | if (this.syntax === 'proto3') {
|
7386 |
|
7387 | if (typeof value !== 'number' || (value === value && value % 1 !== 0))
|
7388 | fail(typeof value, "not an integer");
|
7389 | if (value > 4294967295 || value < 0)
|
7390 | fail(typeof value, "not in range for uint32");
|
7391 | return value;
|
7392 | } else {
|
7393 |
|
7394 | fail(value, "not a valid enum value");
|
7395 | }
|
7396 | }
|
7397 |
|
7398 | case ProtoBuf.TYPES["group"]:
|
7399 | case ProtoBuf.TYPES["message"]: {
|
7400 | if (!value || typeof value !== 'object')
|
7401 | fail(typeof value, "object expected");
|
7402 | if (value instanceof this.resolvedType.clazz)
|
7403 | return value;
|
7404 | if (value instanceof ProtoBuf.Builder.Message) {
|
7405 |
|
7406 | var obj = {};
|
7407 | for (var i in value)
|
7408 | if (value.hasOwnProperty(i))
|
7409 | obj[i] = value[i];
|
7410 | value = obj;
|
7411 | }
|
7412 |
|
7413 | return new (this.resolvedType.clazz)(value);
|
7414 | }
|
7415 | }
|
7416 |
|
7417 |
|
7418 | throw Error("[INTERNAL] Illegal value for "+this.toString(true)+": "+value+" (undefined type "+this.type+")");
|
7419 | };
|
7420 |
|
7421 | |
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 |
|
7428 |
|
7429 | ElementPrototype.calculateLength = function(id, value) {
|
7430 | if (value === null) return 0;
|
7431 |
|
7432 | var n;
|
7433 | switch (this.type) {
|
7434 | case ProtoBuf.TYPES["int32"]:
|
7435 | return value < 0 ? ByteBuffer.calculateVarint64(value) : ByteBuffer.calculateVarint32(value);
|
7436 | case ProtoBuf.TYPES["uint32"]:
|
7437 | return ByteBuffer.calculateVarint32(value);
|
7438 | case ProtoBuf.TYPES["sint32"]:
|
7439 | return ByteBuffer.calculateVarint32(ByteBuffer.zigZagEncode32(value));
|
7440 | case ProtoBuf.TYPES["fixed32"]:
|
7441 | case ProtoBuf.TYPES["sfixed32"]:
|
7442 | case ProtoBuf.TYPES["float"]:
|
7443 | return 4;
|
7444 | case ProtoBuf.TYPES["int64"]:
|
7445 | case ProtoBuf.TYPES["uint64"]:
|
7446 | return ByteBuffer.calculateVarint64(value);
|
7447 | case ProtoBuf.TYPES["sint64"]:
|
7448 | return ByteBuffer.calculateVarint64(ByteBuffer.zigZagEncode64(value));
|
7449 | case ProtoBuf.TYPES["fixed64"]:
|
7450 | case ProtoBuf.TYPES["sfixed64"]:
|
7451 | return 8;
|
7452 | case ProtoBuf.TYPES["bool"]:
|
7453 | return 1;
|
7454 | case ProtoBuf.TYPES["enum"]:
|
7455 | return ByteBuffer.calculateVarint32(value);
|
7456 | case ProtoBuf.TYPES["double"]:
|
7457 | return 8;
|
7458 | case ProtoBuf.TYPES["string"]:
|
7459 | n = ByteBuffer.calculateUTF8Bytes(value);
|
7460 | return ByteBuffer.calculateVarint32(n) + n;
|
7461 | case ProtoBuf.TYPES["bytes"]:
|
7462 | if (value.remaining() < 0)
|
7463 | throw Error("Illegal value for "+this.toString(true)+": "+value.remaining()+" bytes remaining");
|
7464 | return ByteBuffer.calculateVarint32(value.remaining()) + value.remaining();
|
7465 | case ProtoBuf.TYPES["message"]:
|
7466 | n = this.resolvedType.calculate(value);
|
7467 | return ByteBuffer.calculateVarint32(n) + n;
|
7468 | case ProtoBuf.TYPES["group"]:
|
7469 | n = this.resolvedType.calculate(value);
|
7470 | return n + ByteBuffer.calculateVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP);
|
7471 | }
|
7472 |
|
7473 | throw Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)");
|
7474 | };
|
7475 |
|
7476 | |
7477 |
|
7478 |
|
7479 |
|
7480 |
|
7481 |
|
7482 |
|
7483 |
|
7484 |
|
7485 | ElementPrototype.encodeValue = function(id, value, buffer) {
|
7486 | if (value === null) return buffer;
|
7487 |
|
7488 |
|
7489 | switch (this.type) {
|
7490 |
|
7491 | case ProtoBuf.TYPES["int32"]:
|
7492 |
|
7493 |
|
7494 | if (value < 0)
|
7495 | buffer.writeVarint64(value);
|
7496 | else
|
7497 | buffer.writeVarint32(value);
|
7498 | break;
|
7499 |
|
7500 |
|
7501 | case ProtoBuf.TYPES["uint32"]:
|
7502 | buffer.writeVarint32(value);
|
7503 | break;
|
7504 |
|
7505 |
|
7506 | case ProtoBuf.TYPES["sint32"]:
|
7507 | buffer.writeVarint32ZigZag(value);
|
7508 | break;
|
7509 |
|
7510 |
|
7511 | case ProtoBuf.TYPES["fixed32"]:
|
7512 | buffer.writeUint32(value);
|
7513 | break;
|
7514 |
|
7515 |
|
7516 | case ProtoBuf.TYPES["sfixed32"]:
|
7517 | buffer.writeInt32(value);
|
7518 | break;
|
7519 |
|
7520 |
|
7521 | case ProtoBuf.TYPES["int64"]:
|
7522 | case ProtoBuf.TYPES["uint64"]:
|
7523 | buffer.writeVarint64(value);
|
7524 | break;
|
7525 |
|
7526 |
|
7527 | case ProtoBuf.TYPES["sint64"]:
|
7528 | buffer.writeVarint64ZigZag(value);
|
7529 | break;
|
7530 |
|
7531 |
|
7532 | case ProtoBuf.TYPES["fixed64"]:
|
7533 | buffer.writeUint64(value);
|
7534 | break;
|
7535 |
|
7536 |
|
7537 | case ProtoBuf.TYPES["sfixed64"]:
|
7538 | buffer.writeInt64(value);
|
7539 | break;
|
7540 |
|
7541 |
|
7542 | case ProtoBuf.TYPES["bool"]:
|
7543 | if (typeof value === 'string')
|
7544 | buffer.writeVarint32(value.toLowerCase() === 'false' ? 0 : !!value);
|
7545 | else
|
7546 | buffer.writeVarint32(value ? 1 : 0);
|
7547 | break;
|
7548 |
|
7549 |
|
7550 | case ProtoBuf.TYPES["enum"]:
|
7551 | buffer.writeVarint32(value);
|
7552 | break;
|
7553 |
|
7554 |
|
7555 | case ProtoBuf.TYPES["float"]:
|
7556 | buffer.writeFloat32(value);
|
7557 | break;
|
7558 |
|
7559 |
|
7560 | case ProtoBuf.TYPES["double"]:
|
7561 | buffer.writeFloat64(value);
|
7562 | break;
|
7563 |
|
7564 |
|
7565 | case ProtoBuf.TYPES["string"]:
|
7566 | buffer.writeVString(value);
|
7567 | break;
|
7568 |
|
7569 |
|
7570 | case ProtoBuf.TYPES["bytes"]:
|
7571 | if (value.remaining() < 0)
|
7572 | throw Error("Illegal value for "+this.toString(true)+": "+value.remaining()+" bytes remaining");
|
7573 | var prevOffset = value.offset;
|
7574 | buffer.writeVarint32(value.remaining());
|
7575 | buffer.append(value);
|
7576 | value.offset = prevOffset;
|
7577 | break;
|
7578 |
|
7579 |
|
7580 | case ProtoBuf.TYPES["message"]:
|
7581 | var bb = new ByteBuffer().LE();
|
7582 | this.resolvedType.encode(value, bb);
|
7583 | buffer.writeVarint32(bb.offset);
|
7584 | buffer.append(bb.flip());
|
7585 | break;
|
7586 |
|
7587 |
|
7588 | case ProtoBuf.TYPES["group"]:
|
7589 | this.resolvedType.encode(value, buffer);
|
7590 | buffer.writeVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP);
|
7591 | break;
|
7592 |
|
7593 | default:
|
7594 |
|
7595 | throw Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)");
|
7596 | }
|
7597 | return buffer;
|
7598 | };
|
7599 |
|
7600 | |
7601 |
|
7602 |
|
7603 |
|
7604 |
|
7605 |
|
7606 |
|
7607 |
|
7608 |
|
7609 | ElementPrototype.decode = function(buffer, wireType, id) {
|
7610 | if (wireType != this.type.wireType)
|
7611 | throw Error("Unexpected wire type for element");
|
7612 |
|
7613 | var value, nBytes;
|
7614 | switch (this.type) {
|
7615 |
|
7616 | case ProtoBuf.TYPES["int32"]:
|
7617 | return buffer.readVarint32() | 0;
|
7618 |
|
7619 |
|
7620 | case ProtoBuf.TYPES["uint32"]:
|
7621 | return buffer.readVarint32() >>> 0;
|
7622 |
|
7623 |
|
7624 | case ProtoBuf.TYPES["sint32"]:
|
7625 | return buffer.readVarint32ZigZag() | 0;
|
7626 |
|
7627 |
|
7628 | case ProtoBuf.TYPES["fixed32"]:
|
7629 | return buffer.readUint32() >>> 0;
|
7630 |
|
7631 | case ProtoBuf.TYPES["sfixed32"]:
|
7632 | return buffer.readInt32() | 0;
|
7633 |
|
7634 |
|
7635 | case ProtoBuf.TYPES["int64"]:
|
7636 | return buffer.readVarint64();
|
7637 |
|
7638 |
|
7639 | case ProtoBuf.TYPES["uint64"]:
|
7640 | return buffer.readVarint64().toUnsigned();
|
7641 |
|
7642 |
|
7643 | case ProtoBuf.TYPES["sint64"]:
|
7644 | return buffer.readVarint64ZigZag();
|
7645 |
|
7646 |
|
7647 | case ProtoBuf.TYPES["fixed64"]:
|
7648 | return buffer.readUint64();
|
7649 |
|
7650 |
|
7651 | case ProtoBuf.TYPES["sfixed64"]:
|
7652 | return buffer.readInt64();
|
7653 |
|
7654 |
|
7655 | case ProtoBuf.TYPES["bool"]:
|
7656 | return !!buffer.readVarint32();
|
7657 |
|
7658 |
|
7659 | case ProtoBuf.TYPES["enum"]:
|
7660 |
|
7661 | return buffer.readVarint32();
|
7662 |
|
7663 |
|
7664 | case ProtoBuf.TYPES["float"]:
|
7665 | return buffer.readFloat();
|
7666 |
|
7667 |
|
7668 | case ProtoBuf.TYPES["double"]:
|
7669 | return buffer.readDouble();
|
7670 |
|
7671 |
|
7672 | case ProtoBuf.TYPES["string"]:
|
7673 | return buffer.readVString();
|
7674 |
|
7675 |
|
7676 | case ProtoBuf.TYPES["bytes"]: {
|
7677 | nBytes = buffer.readVarint32();
|
7678 | if (buffer.remaining() < nBytes)
|
7679 | throw Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining());
|
7680 | value = buffer.clone();
|
7681 | value.limit = value.offset+nBytes;
|
7682 | buffer.offset += nBytes;
|
7683 | return value;
|
7684 | }
|
7685 |
|
7686 |
|
7687 | case ProtoBuf.TYPES["message"]: {
|
7688 | nBytes = buffer.readVarint32();
|
7689 | return this.resolvedType.decode(buffer, nBytes);
|
7690 | }
|
7691 |
|
7692 |
|
7693 | case ProtoBuf.TYPES["group"]:
|
7694 | return this.resolvedType.decode(buffer, -1, id);
|
7695 | }
|
7696 |
|
7697 |
|
7698 | throw Error("[INTERNAL] Illegal decode type");
|
7699 | };
|
7700 |
|
7701 | |
7702 |
|
7703 |
|
7704 |
|
7705 |
|
7706 |
|
7707 |
|
7708 |
|
7709 | ElementPrototype.valueFromString = function(str) {
|
7710 | if (!this.isMapKey) {
|
7711 | throw Error("valueFromString() called on non-map-key element");
|
7712 | }
|
7713 |
|
7714 | switch (this.type) {
|
7715 | case ProtoBuf.TYPES["int32"]:
|
7716 | case ProtoBuf.TYPES["sint32"]:
|
7717 | case ProtoBuf.TYPES["sfixed32"]:
|
7718 | case ProtoBuf.TYPES["uint32"]:
|
7719 | case ProtoBuf.TYPES["fixed32"]:
|
7720 | return this.verifyValue(parseInt(str));
|
7721 |
|
7722 | case ProtoBuf.TYPES["int64"]:
|
7723 | case ProtoBuf.TYPES["sint64"]:
|
7724 | case ProtoBuf.TYPES["sfixed64"]:
|
7725 | case ProtoBuf.TYPES["uint64"]:
|
7726 | case ProtoBuf.TYPES["fixed64"]:
|
7727 |
|
7728 | return this.verifyValue(str);
|
7729 |
|
7730 | case ProtoBuf.TYPES["bool"]:
|
7731 | return str === "true";
|
7732 |
|
7733 | case ProtoBuf.TYPES["string"]:
|
7734 | return this.verifyValue(str);
|
7735 |
|
7736 | case ProtoBuf.TYPES["bytes"]:
|
7737 | return ByteBuffer.fromBinary(str);
|
7738 | }
|
7739 | };
|
7740 |
|
7741 | |
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 |
|
7747 |
|
7748 |
|
7749 |
|
7750 |
|
7751 |
|
7752 |
|
7753 |
|
7754 |
|
7755 |
|
7756 | ElementPrototype.valueToString = function(value) {
|
7757 | if (!this.isMapKey) {
|
7758 | throw Error("valueToString() called on non-map-key element");
|
7759 | }
|
7760 |
|
7761 | if (this.type === ProtoBuf.TYPES["bytes"]) {
|
7762 | return value.toString("binary");
|
7763 | } else {
|
7764 | return value.toString();
|
7765 | }
|
7766 | };
|
7767 |
|
7768 | |
7769 |
|
7770 |
|
7771 |
|
7772 | Reflect.Element = Element;
|
7773 |
|
7774 | |
7775 |
|
7776 |
|
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 |
|
7782 |
|
7783 |
|
7784 |
|
7785 |
|
7786 | var Message = function(builder, parent, name, options, isGroup, syntax) {
|
7787 | Namespace.call(this, builder, parent, name, options, syntax);
|
7788 |
|
7789 | |
7790 |
|
7791 |
|
7792 | this.className = "Message";
|
7793 |
|
7794 | |
7795 |
|
7796 |
|
7797 |
|
7798 |
|
7799 | this.extensions = undefined;
|
7800 |
|
7801 | |
7802 |
|
7803 |
|
7804 |
|
7805 |
|
7806 | this.clazz = null;
|
7807 |
|
7808 | |
7809 |
|
7810 |
|
7811 |
|
7812 |
|
7813 | this.isGroup = !!isGroup;
|
7814 |
|
7815 |
|
7816 |
|
7817 | |
7818 |
|
7819 |
|
7820 |
|
7821 |
|
7822 | this._fields = null;
|
7823 |
|
7824 | |
7825 |
|
7826 |
|
7827 |
|
7828 |
|
7829 | this._fieldsById = null;
|
7830 |
|
7831 | |
7832 |
|
7833 |
|
7834 |
|
7835 |
|
7836 | this._fieldsByName = null;
|
7837 | };
|
7838 |
|
7839 | |
7840 |
|
7841 |
|
7842 |
|
7843 | var MessagePrototype = Message.prototype = Object.create(Namespace.prototype);
|
7844 |
|
7845 | |
7846 |
|
7847 |
|
7848 |
|
7849 |
|
7850 |
|
7851 |
|
7852 |
|
7853 | MessagePrototype.build = function(rebuild) {
|
7854 | if (this.clazz && !rebuild)
|
7855 | return this.clazz;
|
7856 |
|
7857 |
|
7858 | var clazz = (function(ProtoBuf, T) {
|
7859 |
|
7860 | var fields = T.getChildren(ProtoBuf.Reflect.Message.Field),
|
7861 | oneofs = T.getChildren(ProtoBuf.Reflect.Message.OneOf);
|
7862 |
|
7863 | |
7864 |
|
7865 |
|
7866 |
|
7867 |
|
7868 |
|
7869 |
|
7870 |
|
7871 |
|
7872 | var Message = function(values, var_args) {
|
7873 | ProtoBuf.Builder.Message.call(this);
|
7874 |
|
7875 |
|
7876 | for (var i=0, k=oneofs.length; i<k; ++i)
|
7877 | this[oneofs[i].name] = null;
|
7878 |
|
7879 | for (i=0, k=fields.length; i<k; ++i) {
|
7880 | var field = fields[i];
|
7881 | this[field.name] =
|
7882 | field.repeated ? [] :
|
7883 | (field.map ? new ProtoBuf.Map(field) : null);
|
7884 | if ((field.required || T.syntax === 'proto3') &&
|
7885 | field.defaultValue !== null)
|
7886 | this[field.name] = field.defaultValue;
|
7887 | }
|
7888 |
|
7889 | if (arguments.length > 0) {
|
7890 | var value;
|
7891 |
|
7892 | if (arguments.length === 1 && values !== null && typeof values === 'object' &&
|
7893 | (typeof values.encode !== 'function' || values instanceof Message) &&
|
7894 | !Array.isArray(values) &&
|
7895 | !(values instanceof ProtoBuf.Map) &&
|
7896 | !ByteBuffer.isByteBuffer(values) &&
|
7897 | !(values instanceof ArrayBuffer) &&
|
7898 | !(ProtoBuf.Long && values instanceof ProtoBuf.Long)) {
|
7899 | this.$set(values);
|
7900 | } else // Set field values from arguments, in declaration order
|
7901 | for (i=0, k=arguments.length; i<k; ++i)
|
7902 | if (typeof (value = arguments[i]) !== 'undefined')
|
7903 | this.$set(fields[i].name, value); // May throw
|
7904 | }
|
7905 | };
|
7906 |
|
7907 | /**
|
7908 | * @alias ProtoBuf.Builder.Message.prototype
|
7909 | * @inner
|
7910 | */
|
7911 | var MessagePrototype = Message.prototype = Object.create(ProtoBuf.Builder.Message.prototype);
|
7912 |
|
7913 | /**
|
7914 | * Adds a value to a repeated field.
|
7915 | * @name ProtoBuf.Builder.Message#add
|
7916 | * @function
|
7917 | * @param {string} key Field name
|
7918 | * @param {*} value Value to add
|
7919 | * @param {boolean=} noAssert Whether to assert the value or not (asserts by default)
|
7920 | * @returns {!ProtoBuf.Builder.Message} this
|
7921 | * @throws {Error} If the value cannot be added
|
7922 | * @expose
|
7923 | */
|
7924 | MessagePrototype.add = function(key, value, noAssert) {
|
7925 | var field = T._fieldsByName[key];
|
7926 | if (!noAssert) {
|
7927 | if (!field)
|
7928 | throw Error(this+"#"+key+" is undefined");
|
7929 | if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
7930 | throw Error(this+"#"+key+" is not a field: "+field.toString(true));
|
7931 | if (!field.repeated)
|
7932 | throw Error(this+"#"+key+" is not a repeated field");
|
7933 | value = field.verifyValue(value, true);
|
7934 | }
|
7935 | if (this[key] === null)
|
7936 | this[key] = [];
|
7937 | this[key].push(value);
|
7938 | return this;
|
7939 | };
|
7940 |
|
7941 | |
7942 |
|
7943 |
|
7944 |
|
7945 |
|
7946 |
|
7947 |
|
7948 |
|
7949 |
|
7950 |
|
7951 |
|
7952 | MessagePrototype.$add = MessagePrototype.add;
|
7953 |
|
7954 | |
7955 |
|
7956 |
|
7957 |
|
7958 |
|
7959 |
|
7960 |
|
7961 |
|
7962 |
|
7963 |
|
7964 |
|
7965 | MessagePrototype.set = function(keyOrObj, value, noAssert) {
|
7966 | if (keyOrObj && typeof keyOrObj === 'object') {
|
7967 | noAssert = value;
|
7968 | for (var ikey in keyOrObj) {
|
7969 |
|
7970 | if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined' && T._oneofsByName[ikey] === undefined)
|
7971 | this.$set(ikey, value, noAssert);
|
7972 | }
|
7973 | return this;
|
7974 | }
|
7975 | var field = T._fieldsByName[keyOrObj];
|
7976 | if (!noAssert) {
|
7977 | if (!field)
|
7978 | throw Error(this+"#"+keyOrObj+" is not a field: undefined");
|
7979 | if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
7980 | throw Error(this+"#"+keyOrObj+" is not a field: "+field.toString(true));
|
7981 | this[field.name] = (value = field.verifyValue(value));
|
7982 | } else
|
7983 | this[keyOrObj] = value;
|
7984 | if (field && field.oneof) {
|
7985 | var currentField = this[field.oneof.name];
|
7986 | if (value !== null) {
|
7987 | if (currentField !== null && currentField !== field.name)
|
7988 | this[currentField] = null;
|
7989 | this[field.oneof.name] = field.name;
|
7990 | } else if (currentField === keyOrObj)
|
7991 | this[field.oneof.name] = null;
|
7992 | }
|
7993 | return this;
|
7994 | };
|
7995 |
|
7996 | |
7997 |
|
7998 |
|
7999 |
|
8000 |
|
8001 |
|
8002 |
|
8003 |
|
8004 |
|
8005 |
|
8006 | MessagePrototype.$set = MessagePrototype.set;
|
8007 |
|
8008 | /**
|
8009 | * Gets a field's value.
|
8010 | * @name ProtoBuf.Builder.Message#get
|
8011 | * @function
|
8012 | * @param {string} key Key
|
8013 | * @param {boolean=} noAssert Whether to not assert for an actual field, defaults to `false`
|
8014 | * @return {*} Value
|
8015 | * @throws {Error} If there is no such field
|
8016 | * @expose
|
8017 | */
|
8018 | MessagePrototype.get = function(key, noAssert) {
|
8019 | if (noAssert)
|
8020 | return this[key];
|
8021 | var field = T._fieldsByName[key];
|
8022 | if (!field || !(field instanceof ProtoBuf.Reflect.Message.Field))
|
8023 | throw Error(this+"#"+key+" is not a field: undefined");
|
8024 | if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
8025 | throw Error(this+"#"+key+" is not a field: "+field.toString(true));
|
8026 | return this[field.name];
|
8027 | };
|
8028 |
|
8029 | |
8030 |
|
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 |
|
8036 |
|
8037 |
|
8038 | MessagePrototype.$get = MessagePrototype.get;
|
8039 |
|
8040 | // Getters and setters
|
8041 |
|
8042 | for (var i=0; i<fields.length; i++) {
|
8043 | var field = fields[i];
|
8044 |
|
8045 | if (field instanceof ProtoBuf.Reflect.Message.ExtensionField)
|
8046 | continue;
|
8047 |
|
8048 | if (T.builder.options['populateAccessors'])
|
8049 | (function(field) {
|
8050 |
|
8051 | var Name = field.originalName.replace(/(_[a-zA-Z])/g, function(match) {
|
8052 | return match.toUpperCase().replace('_','');
|
8053 | });
|
8054 | Name = Name.substring(0,1).toUpperCase() + Name.substring(1);
|
8055 |
|
8056 |
|
8057 | var name = field.originalName.replace(/([A-Z])/g, function(match) {
|
8058 | return "_"+match;
|
8059 | });
|
8060 |
|
8061 | |
8062 |
|
8063 |
|
8064 |
|
8065 |
|
8066 |
|
8067 |
|
8068 |
|
8069 | var setter = function(value, noAssert) {
|
8070 | this[field.name] = noAssert ? value : field.verifyValue(value);
|
8071 | return this;
|
8072 | };
|
8073 |
|
8074 | |
8075 |
|
8076 |
|
8077 |
|
8078 |
|
8079 |
|
8080 | var getter = function() {
|
8081 | return this[field.name];
|
8082 | };
|
8083 |
|
8084 | if (T.getChild("set"+Name) === null)
|
8085 | |
8086 |
|
8087 |
|
8088 |
|
8089 |
|
8090 |
|
8091 |
|
8092 |
|
8093 |
|
8094 |
|
8095 |
|
8096 | MessagePrototype["set"+Name] = setter;
|
8097 |
|
8098 | if (T.getChild("set_"+name) === null)
|
8099 | |
8100 |
|
8101 |
|
8102 |
|
8103 |
|
8104 |
|
8105 |
|
8106 |
|
8107 |
|
8108 |
|
8109 |
|
8110 | MessagePrototype["set_"+name] = setter;
|
8111 |
|
8112 | if (T.getChild("get"+Name) === null)
|
8113 | |
8114 |
|
8115 |
|
8116 |
|
8117 |
|
8118 |
|
8119 |
|
8120 |
|
8121 | MessagePrototype["get"+Name] = getter;
|
8122 |
|
8123 | if (T.getChild("get_"+name) === null)
|
8124 | |
8125 |
|
8126 |
|
8127 |
|
8128 |
|
8129 |
|
8130 |
|
8131 |
|
8132 | MessagePrototype["get_"+name] = getter;
|
8133 |
|
8134 | })(field);
|
8135 | }
|
8136 |
|
8137 |
|
8138 |
|
8139 | |
8140 |
|
8141 |
|
8142 |
|
8143 |
|
8144 |
|
8145 |
|
8146 |
|
8147 |
|
8148 |
|
8149 |
|
8150 |
|
8151 |
|
8152 |
|
8153 | MessagePrototype.encode = function(buffer, noVerify) {
|
8154 | if (typeof buffer === 'boolean')
|
8155 | noVerify = buffer,
|
8156 | buffer = undefined;
|
8157 | var isNew = false;
|
8158 | if (!buffer)
|
8159 | buffer = new ByteBuffer(),
|
8160 | isNew = true;
|
8161 | var le = buffer.littleEndian;
|
8162 | try {
|
8163 | T.encode(this, buffer.LE(), noVerify);
|
8164 | return (isNew ? buffer.flip() : buffer).LE(le);
|
8165 | } catch (e) {
|
8166 | buffer.LE(le);
|
8167 | throw(e);
|
8168 | }
|
8169 | };
|
8170 |
|
8171 | |
8172 |
|
8173 |
|
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 |
|
8179 | Message.encode = function(data, buffer, noVerify) {
|
8180 | return new Message(data).encode(buffer, noVerify);
|
8181 | };
|
8182 |
|
8183 | |
8184 |
|
8185 |
|
8186 |
|
8187 |
|
8188 |
|
8189 |
|
8190 |
|
8191 | MessagePrototype.calculate = function() {
|
8192 | return T.calculate(this);
|
8193 | };
|
8194 |
|
8195 | |
8196 |
|
8197 |
|
8198 |
|
8199 |
|
8200 |
|
8201 |
|
8202 |
|
8203 |
|
8204 |
|
8205 |
|
8206 | MessagePrototype.encodeDelimited = function(buffer, noVerify) {
|
8207 | var isNew = false;
|
8208 | if (!buffer)
|
8209 | buffer = new ByteBuffer(),
|
8210 | isNew = true;
|
8211 | var enc = new ByteBuffer().LE();
|
8212 | T.encode(this, enc, noVerify).flip();
|
8213 | buffer.writeVarint32(enc.remaining());
|
8214 | buffer.append(enc);
|
8215 | return isNew ? buffer.flip() : buffer;
|
8216 | };
|
8217 |
|
8218 | |
8219 |
|
8220 |
|
8221 |
|
8222 |
|
8223 |
|
8224 |
|
8225 |
|
8226 |
|
8227 | MessagePrototype.encodeAB = function() {
|
8228 | try {
|
8229 | return this.encode().toArrayBuffer();
|
8230 | } catch (e) {
|
8231 | if (e["encoded"]) e["encoded"] = e["encoded"].toArrayBuffer();
|
8232 | throw(e);
|
8233 | }
|
8234 | };
|
8235 |
|
8236 | |
8237 |
|
8238 |
|
8239 |
|
8240 |
|
8241 |
|
8242 |
|
8243 |
|
8244 |
|
8245 | MessagePrototype.toArrayBuffer = MessagePrototype.encodeAB;
|
8246 |
|
8247 | |
8248 |
|
8249 |
|
8250 |
|
8251 |
|
8252 |
|
8253 |
|
8254 |
|
8255 |
|
8256 | MessagePrototype.encodeNB = function() {
|
8257 | try {
|
8258 | return this.encode().toBuffer();
|
8259 | } catch (e) {
|
8260 | if (e["encoded"]) e["encoded"] = e["encoded"].toBuffer();
|
8261 | throw(e);
|
8262 | }
|
8263 | };
|
8264 |
|
8265 | |
8266 |
|
8267 |
|
8268 |
|
8269 |
|
8270 |
|
8271 |
|
8272 |
|
8273 |
|
8274 | MessagePrototype.toBuffer = MessagePrototype.encodeNB;
|
8275 |
|
8276 | |
8277 |
|
8278 |
|
8279 |
|
8280 |
|
8281 |
|
8282 |
|
8283 |
|
8284 |
|
8285 | MessagePrototype.encode64 = function() {
|
8286 | try {
|
8287 | return this.encode().toBase64();
|
8288 | } catch (e) {
|
8289 | if (e["encoded"]) e["encoded"] = e["encoded"].toBase64();
|
8290 | throw(e);
|
8291 | }
|
8292 | };
|
8293 |
|
8294 | |
8295 |
|
8296 |
|
8297 |
|
8298 |
|
8299 |
|
8300 |
|
8301 |
|
8302 |
|
8303 | MessagePrototype.toBase64 = MessagePrototype.encode64;
|
8304 |
|
8305 | |
8306 |
|
8307 |
|
8308 |
|
8309 |
|
8310 |
|
8311 |
|
8312 |
|
8313 |
|
8314 | MessagePrototype.encodeHex = function() {
|
8315 | try {
|
8316 | return this.encode().toHex();
|
8317 | } catch (e) {
|
8318 | if (e["encoded"]) e["encoded"] = e["encoded"].toHex();
|
8319 | throw(e);
|
8320 | }
|
8321 | };
|
8322 |
|
8323 | |
8324 |
|
8325 |
|
8326 |
|
8327 |
|
8328 |
|
8329 |
|
8330 |
|
8331 |
|
8332 | MessagePrototype.toHex = MessagePrototype.encodeHex;
|
8333 |
|
8334 | |
8335 |
|
8336 |
|
8337 |
|
8338 |
|
8339 |
|
8340 |
|
8341 |
|
8342 |
|
8343 | function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) {
|
8344 | if (obj === null || typeof obj !== 'object') {
|
8345 |
|
8346 | if (resolvedType && resolvedType instanceof ProtoBuf.Reflect.Enum) {
|
8347 | var name = ProtoBuf.Reflect.Enum.getName(resolvedType.object, obj);
|
8348 | if (name !== null)
|
8349 | return name;
|
8350 | }
|
8351 |
|
8352 | return obj;
|
8353 | }
|
8354 |
|
8355 | if (ByteBuffer.isByteBuffer(obj))
|
8356 | return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();
|
8357 |
|
8358 | if (ProtoBuf.Long.isLong(obj))
|
8359 | return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);
|
8360 | var clone;
|
8361 |
|
8362 | if (Array.isArray(obj)) {
|
8363 | clone = [];
|
8364 | obj.forEach(function(v, k) {
|
8365 | clone[k] = cloneRaw(v, binaryAsBase64, longsAsStrings, resolvedType);
|
8366 | });
|
8367 | return clone;
|
8368 | }
|
8369 | clone = {};
|
8370 |
|
8371 | if (obj instanceof ProtoBuf.Map) {
|
8372 | var it = obj.entries();
|
8373 | for (var e = it.next(); !e.done; e = it.next())
|
8374 | clone[obj.keyElem.valueToString(e.value[0])] = cloneRaw(e.value[1], binaryAsBase64, longsAsStrings, obj.valueElem.resolvedType);
|
8375 | return clone;
|
8376 | }
|
8377 |
|
8378 | var type = obj.$type,
|
8379 | field = undefined;
|
8380 | for (var i in obj)
|
8381 | if (obj.hasOwnProperty(i)) {
|
8382 | if (type && (field = type.getChild(i)))
|
8383 | clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings, field.resolvedType);
|
8384 | else
|
8385 | clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings);
|
8386 | }
|
8387 | return clone;
|
8388 | }
|
8389 |
|
8390 | |
8391 |
|
8392 |
|
8393 |
|
8394 |
|
8395 |
|
8396 |
|
8397 | MessagePrototype.toRaw = function(binaryAsBase64, longsAsStrings) {
|
8398 | return cloneRaw(this, !!binaryAsBase64, !!longsAsStrings, this.$type);
|
8399 | };
|
8400 |
|
8401 | |
8402 |
|
8403 |
|
8404 |
|
8405 |
|
8406 | MessagePrototype.encodeJSON = function() {
|
8407 | return JSON.stringify(
|
8408 | cloneRaw(this,
|
8409 | true,
|
8410 | true,
|
8411 | this.$type
|
8412 | )
|
8413 | );
|
8414 | };
|
8415 |
|
8416 | |
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 |
|
8422 |
|
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 |
|
8429 |
|
8430 | Message.decode = function(buffer, length, enc) {
|
8431 | if (typeof length === 'string')
|
8432 | enc = length,
|
8433 | length = -1;
|
8434 | if (typeof buffer === 'string')
|
8435 | buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
8436 | else if (!ByteBuffer.isByteBuffer(buffer))
|
8437 | buffer = ByteBuffer.wrap(buffer);
|
8438 | var le = buffer.littleEndian;
|
8439 | try {
|
8440 | var msg = T.decode(buffer.LE(), length);
|
8441 | buffer.LE(le);
|
8442 | return msg;
|
8443 | } catch (e) {
|
8444 | buffer.LE(le);
|
8445 | throw(e);
|
8446 | }
|
8447 | };
|
8448 |
|
8449 | |
8450 |
|
8451 |
|
8452 |
|
8453 |
|
8454 |
|
8455 |
|
8456 |
|
8457 |
|
8458 |
|
8459 |
|
8460 | Message.decodeDelimited = function(buffer, enc) {
|
8461 | if (typeof buffer === 'string')
|
8462 | buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
8463 | else if (!ByteBuffer.isByteBuffer(buffer))
|
8464 | buffer = ByteBuffer.wrap(buffer);
|
8465 | if (buffer.remaining() < 1)
|
8466 | return null;
|
8467 | var off = buffer.offset,
|
8468 | len = buffer.readVarint32();
|
8469 | if (buffer.remaining() < len) {
|
8470 | buffer.offset = off;
|
8471 | return null;
|
8472 | }
|
8473 | try {
|
8474 | var msg = T.decode(buffer.slice(buffer.offset, buffer.offset + len).LE());
|
8475 | buffer.offset += len;
|
8476 | return msg;
|
8477 | } catch (err) {
|
8478 | buffer.offset += len;
|
8479 | throw err;
|
8480 | }
|
8481 | };
|
8482 |
|
8483 | |
8484 |
|
8485 |
|
8486 |
|
8487 |
|
8488 |
|
8489 |
|
8490 |
|
8491 |
|
8492 |
|
8493 | Message.decode64 = function(str) {
|
8494 | return Message.decode(str, "base64");
|
8495 | };
|
8496 |
|
8497 | |
8498 |
|
8499 |
|
8500 |
|
8501 |
|
8502 |
|
8503 |
|
8504 |
|
8505 |
|
8506 |
|
8507 | Message.decodeHex = function(str) {
|
8508 | return Message.decode(str, "hex");
|
8509 | };
|
8510 |
|
8511 | |
8512 |
|
8513 |
|
8514 |
|
8515 |
|
8516 |
|
8517 |
|
8518 |
|
8519 |
|
8520 |
|
8521 | Message.decodeJSON = function(str) {
|
8522 | return new Message(JSON.parse(str));
|
8523 | };
|
8524 |
|
8525 |
|
8526 |
|
8527 | |
8528 |
|
8529 |
|
8530 |
|
8531 |
|
8532 |
|
8533 |
|
8534 | MessagePrototype.toString = function() {
|
8535 | return T.toString();
|
8536 | };
|
8537 |
|
8538 | if (Object.defineProperty)
|
8539 | Object.defineProperty(Message, '$options', { "value": T.buildOpt() }),
|
8540 | Object.defineProperty(MessagePrototype, "$options", { "value": Message["$options"] }),
|
8541 | Object.defineProperty(Message, "$type", { "value": T }),
|
8542 | Object.defineProperty(MessagePrototype, "$type", { "value": T });
|
8543 |
|
8544 | return Message;
|
8545 |
|
8546 | })(ProtoBuf, this);
|
8547 |
|
8548 |
|
8549 | this._fields = [];
|
8550 | this._fieldsById = {};
|
8551 | this._fieldsByName = {};
|
8552 | this._oneofsByName = {};
|
8553 | for (var i=0, k=this.children.length, child; i<k; i++) {
|
8554 | child = this.children[i];
|
8555 | if (child instanceof Enum || child instanceof Message || child instanceof Service) {
|
8556 | if (clazz.hasOwnProperty(child.name))
|
8557 | throw Error("Illegal reflect child of "+this.toString(true)+": "+child.toString(true)+" cannot override static property '"+child.name+"'");
|
8558 | clazz[child.name] = child.build();
|
8559 | } else if (child instanceof Message.Field)
|
8560 | child.build(),
|
8561 | this._fields.push(child),
|
8562 | this._fieldsById[child.id] = child,
|
8563 | this._fieldsByName[child.name] = child;
|
8564 | else if (child instanceof Message.OneOf) {
|
8565 | this._oneofsByName[child.name] = child;
|
8566 | }
|
8567 | else if (!(child instanceof Message.OneOf) && !(child instanceof Extension))
|
8568 | throw Error("Illegal reflect child of "+this.toString(true)+": "+this.children[i].toString(true));
|
8569 | }
|
8570 |
|
8571 | return this.clazz = clazz;
|
8572 | };
|
8573 |
|
8574 | |
8575 |
|
8576 |
|
8577 |
|
8578 |
|
8579 |
|
8580 |
|
8581 |
|
8582 |
|
8583 | MessagePrototype.encode = function(message, buffer, noVerify) {
|
8584 | var fieldMissing = null,
|
8585 | field;
|
8586 | for (var i=0, k=this._fields.length, val; i<k; ++i) {
|
8587 | field = this._fields[i];
|
8588 | val = message[field.name];
|
8589 | if (field.required && val === null) {
|
8590 | if (fieldMissing === null)
|
8591 | fieldMissing = field;
|
8592 | } else
|
8593 | field.encode(noVerify ? val : field.verifyValue(val), buffer, message);
|
8594 | }
|
8595 | if (fieldMissing !== null) {
|
8596 | var err = Error("Missing at least one required field for "+this.toString(true)+": "+fieldMissing);
|
8597 | err["encoded"] = buffer;
|
8598 | throw(err);
|
8599 | }
|
8600 | return buffer;
|
8601 | };
|
8602 |
|
8603 | |
8604 |
|
8605 |
|
8606 |
|
8607 |
|
8608 |
|
8609 |
|
8610 | MessagePrototype.calculate = function(message) {
|
8611 | for (var n=0, i=0, k=this._fields.length, field, val; i<k; ++i) {
|
8612 | field = this._fields[i];
|
8613 | val = message[field.name];
|
8614 | if (field.required && val === null)
|
8615 | throw Error("Missing at least one required field for "+this.toString(true)+": "+field);
|
8616 | else
|
8617 | n += field.calculate(val, message);
|
8618 | }
|
8619 | return n;
|
8620 | };
|
8621 |
|
8622 | |
8623 |
|
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 |
|
8629 |
|
8630 | function skipTillGroupEnd(expectedId, buf) {
|
8631 | var tag = buf.readVarint32(),
|
8632 | wireType = tag & 0x07,
|
8633 | id = tag >>> 3;
|
8634 | switch (wireType) {
|
8635 | case ProtoBuf.WIRE_TYPES.VARINT:
|
8636 | do tag = buf.readUint8();
|
8637 | while ((tag & 0x80) === 0x80);
|
8638 | break;
|
8639 | case ProtoBuf.WIRE_TYPES.BITS64:
|
8640 | buf.offset += 8;
|
8641 | break;
|
8642 | case ProtoBuf.WIRE_TYPES.LDELIM:
|
8643 | tag = buf.readVarint32();
|
8644 | buf.offset += tag;
|
8645 | break;
|
8646 | case ProtoBuf.WIRE_TYPES.STARTGROUP:
|
8647 | skipTillGroupEnd(id, buf);
|
8648 | break;
|
8649 | case ProtoBuf.WIRE_TYPES.ENDGROUP:
|
8650 | if (id === expectedId)
|
8651 | return false;
|
8652 | else
|
8653 | throw Error("Illegal GROUPEND after unknown group: "+id+" ("+expectedId+" expected)");
|
8654 | case ProtoBuf.WIRE_TYPES.BITS32:
|
8655 | buf.offset += 4;
|
8656 | break;
|
8657 | default:
|
8658 | throw Error("Illegal wire type in unknown group "+expectedId+": "+wireType);
|
8659 | }
|
8660 | return true;
|
8661 | }
|
8662 |
|
8663 | |
8664 |
|
8665 |
|
8666 |
|
8667 |
|
8668 |
|
8669 |
|
8670 |
|
8671 |
|
8672 | MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
|
8673 | if (typeof length !== 'number')
|
8674 | length = -1;
|
8675 | var start = buffer.offset,
|
8676 | msg = new (this.clazz)(),
|
8677 | tag, wireType, id, field;
|
8678 | while (buffer.offset < start+length || (length === -1 && buffer.remaining() > 0)) {
|
8679 | tag = buffer.readVarint32();
|
8680 | wireType = tag & 0x07;
|
8681 | id = tag >>> 3;
|
8682 | if (wireType === ProtoBuf.WIRE_TYPES.ENDGROUP) {
|
8683 | if (id !== expectedGroupEndId)
|
8684 | throw Error("Illegal group end indicator for "+this.toString(true)+": "+id+" ("+(expectedGroupEndId ? expectedGroupEndId+" expected" : "not a group")+")");
|
8685 | break;
|
8686 | }
|
8687 | if (!(field = this._fieldsById[id])) {
|
8688 |
|
8689 | switch (wireType) {
|
8690 | case ProtoBuf.WIRE_TYPES.VARINT:
|
8691 | buffer.readVarint32();
|
8692 | break;
|
8693 | case ProtoBuf.WIRE_TYPES.BITS32:
|
8694 | buffer.offset += 4;
|
8695 | break;
|
8696 | case ProtoBuf.WIRE_TYPES.BITS64:
|
8697 | buffer.offset += 8;
|
8698 | break;
|
8699 | case ProtoBuf.WIRE_TYPES.LDELIM:
|
8700 | var len = buffer.readVarint32();
|
8701 | buffer.offset += len;
|
8702 | break;
|
8703 | case ProtoBuf.WIRE_TYPES.STARTGROUP:
|
8704 | while (skipTillGroupEnd(id, buffer)) {}
|
8705 | break;
|
8706 | default:
|
8707 | throw Error("Illegal wire type for unknown field "+id+" in "+this.toString(true)+"#decode: "+wireType);
|
8708 | }
|
8709 | continue;
|
8710 | }
|
8711 | if (field.repeated && !field.options["packed"]) {
|
8712 | msg[field.name].push(field.decode(wireType, buffer));
|
8713 | } else if (field.map) {
|
8714 | var keyval = field.decode(wireType, buffer);
|
8715 | msg[field.name].set(keyval[0], keyval[1]);
|
8716 | } else {
|
8717 | msg[field.name] = field.decode(wireType, buffer);
|
8718 | if (field.oneof) {
|
8719 | var currentField = msg[field.oneof.name];
|
8720 | if (currentField !== null && currentField !== field.name)
|
8721 | msg[currentField] = null;
|
8722 | msg[field.oneof.name] = field.name;
|
8723 | }
|
8724 | }
|
8725 | }
|
8726 |
|
8727 |
|
8728 | for (var i=0, k=this._fields.length; i<k; ++i) {
|
8729 | field = this._fields[i];
|
8730 | if (msg[field.name] === null) {
|
8731 | if (this.syntax === "proto3") {
|
8732 | msg[field.name] = field.defaultValue;
|
8733 | } else if (field.required) {
|
8734 | var err = Error("Missing at least one required field for " + this.toString(true) + ": " + field.name);
|
8735 | err["decoded"] = msg;
|
8736 | throw(err);
|
8737 | } else if (ProtoBuf.populateDefaults && field.defaultValue !== null)
|
8738 | msg[field.name] = field.defaultValue;
|
8739 | }
|
8740 | }
|
8741 | return msg;
|
8742 | };
|
8743 |
|
8744 | |
8745 |
|
8746 |
|
8747 |
|
8748 | Reflect.Message = Message;
|
8749 |
|
8750 | |
8751 |
|
8752 |
|
8753 |
|
8754 |
|
8755 |
|
8756 |
|
8757 |
|
8758 |
|
8759 |
|
8760 |
|
8761 |
|
8762 |
|
8763 |
|
8764 |
|
8765 |
|
8766 | var Field = function(builder, message, rule, keytype, type, name, id, options, oneof, syntax) {
|
8767 | T.call(this, builder, message, name);
|
8768 |
|
8769 | |
8770 |
|
8771 |
|
8772 | this.className = "Message.Field";
|
8773 |
|
8774 | |
8775 |
|
8776 |
|
8777 |
|
8778 |
|
8779 | this.required = rule === "required";
|
8780 |
|
8781 | |
8782 |
|
8783 |
|
8784 |
|
8785 |
|
8786 | this.repeated = rule === "repeated";
|
8787 |
|
8788 | |
8789 |
|
8790 |
|
8791 |
|
8792 |
|
8793 | this.map = rule === "map";
|
8794 |
|
8795 | |
8796 |
|
8797 |
|
8798 |
|
8799 |
|
8800 |
|
8801 | this.keyType = keytype || null;
|
8802 |
|
8803 | |
8804 |
|
8805 |
|
8806 |
|
8807 |
|
8808 |
|
8809 | this.type = type;
|
8810 |
|
8811 | |
8812 |
|
8813 |
|
8814 |
|
8815 |
|
8816 | this.resolvedType = null;
|
8817 |
|
8818 | |
8819 |
|
8820 |
|
8821 |
|
8822 |
|
8823 | this.id = id;
|
8824 |
|
8825 | |
8826 |
|
8827 |
|
8828 |
|
8829 |
|
8830 |
|
8831 | this.options = options || {};
|
8832 |
|
8833 | |
8834 |
|
8835 |
|
8836 |
|
8837 |
|
8838 | this.defaultValue = null;
|
8839 |
|
8840 | |
8841 |
|
8842 |
|
8843 |
|
8844 |
|
8845 | this.oneof = oneof || null;
|
8846 |
|
8847 | |
8848 |
|
8849 |
|
8850 |
|
8851 |
|
8852 | this.syntax = syntax || 'proto2';
|
8853 |
|
8854 | |
8855 |
|
8856 |
|
8857 |
|
8858 |
|
8859 | this.originalName = this.name;
|
8860 |
|
8861 | |
8862 |
|
8863 |
|
8864 |
|
8865 |
|
8866 | this.element = null;
|
8867 |
|
8868 | |
8869 |
|
8870 |
|
8871 |
|
8872 |
|
8873 |
|
8874 | this.keyElement = null;
|
8875 |
|
8876 |
|
8877 | if (this.builder.options['convertFieldsToCamelCase'] && !(this instanceof Message.ExtensionField))
|
8878 | this.name = ProtoBuf.Util.toCamelCase(this.name);
|
8879 | };
|
8880 |
|
8881 | |
8882 |
|
8883 |
|
8884 |
|
8885 | var FieldPrototype = Field.prototype = Object.create(T.prototype);
|
8886 |
|
8887 | |
8888 |
|
8889 |
|
8890 |
|
8891 |
|
8892 | FieldPrototype.build = function() {
|
8893 | this.element = new Element(this.type, this.resolvedType, false, this.syntax, this.name);
|
8894 | if (this.map)
|
8895 | this.keyElement = new Element(this.keyType, undefined, true, this.syntax, this.name);
|
8896 |
|
8897 |
|
8898 |
|
8899 | if (this.syntax === 'proto3' && !this.repeated && !this.map)
|
8900 | this.defaultValue = Element.defaultFieldValue(this.type);
|
8901 |
|
8902 |
|
8903 | else if (typeof this.options['default'] !== 'undefined')
|
8904 | this.defaultValue = this.verifyValue(this.options['default']);
|
8905 | };
|
8906 |
|
8907 | |
8908 |
|
8909 |
|
8910 |
|
8911 |
|
8912 |
|
8913 |
|
8914 |
|
8915 | FieldPrototype.verifyValue = function(value, skipRepeated) {
|
8916 | skipRepeated = skipRepeated || false;
|
8917 | var self = this;
|
8918 | function fail(val, msg) {
|
8919 | throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
8920 | }
|
8921 | if (value === null) {
|
8922 | if (this.required)
|
8923 | fail(typeof value, "required");
|
8924 | if (this.syntax === 'proto3' && this.type !== ProtoBuf.TYPES["message"])
|
8925 | fail(typeof value, "proto3 field without field presence cannot be null");
|
8926 | return null;
|
8927 | }
|
8928 | var i;
|
8929 | if (this.repeated && !skipRepeated) {
|
8930 | if (!Array.isArray(value))
|
8931 | value = [value];
|
8932 | var res = [];
|
8933 | for (i=0; i<value.length; i++)
|
8934 | res.push(this.element.verifyValue(value[i]));
|
8935 | return res;
|
8936 | }
|
8937 | if (this.map && !skipRepeated) {
|
8938 | if (!(value instanceof ProtoBuf.Map)) {
|
8939 |
|
8940 | if (!(value instanceof Object)) {
|
8941 | fail(typeof value,
|
8942 | "expected ProtoBuf.Map or raw object for map field");
|
8943 | }
|
8944 | return new ProtoBuf.Map(this, value);
|
8945 | } else {
|
8946 | return value;
|
8947 | }
|
8948 | }
|
8949 |
|
8950 | if (!this.repeated && Array.isArray(value))
|
8951 | fail(typeof value, "no array expected");
|
8952 |
|
8953 | return this.element.verifyValue(value);
|
8954 | };
|
8955 |
|
8956 | |
8957 |
|
8958 |
|
8959 |
|
8960 |
|
8961 |
|
8962 |
|
8963 | FieldPrototype.hasWirePresence = function(value, message) {
|
8964 | if (this.syntax !== 'proto3')
|
8965 | return (value !== null);
|
8966 | if (this.oneof && message[this.oneof.name] === this.name)
|
8967 | return true;
|
8968 | switch (this.type) {
|
8969 | case ProtoBuf.TYPES["int32"]:
|
8970 | case ProtoBuf.TYPES["sint32"]:
|
8971 | case ProtoBuf.TYPES["sfixed32"]:
|
8972 | case ProtoBuf.TYPES["uint32"]:
|
8973 | case ProtoBuf.TYPES["fixed32"]:
|
8974 | return value !== 0;
|
8975 |
|
8976 | case ProtoBuf.TYPES["int64"]:
|
8977 | case ProtoBuf.TYPES["sint64"]:
|
8978 | case ProtoBuf.TYPES["sfixed64"]:
|
8979 | case ProtoBuf.TYPES["uint64"]:
|
8980 | case ProtoBuf.TYPES["fixed64"]:
|
8981 | return value.low !== 0 || value.high !== 0;
|
8982 |
|
8983 | case ProtoBuf.TYPES["bool"]:
|
8984 | return value;
|
8985 |
|
8986 | case ProtoBuf.TYPES["float"]:
|
8987 | case ProtoBuf.TYPES["double"]:
|
8988 | return value !== 0.0;
|
8989 |
|
8990 | case ProtoBuf.TYPES["string"]:
|
8991 | return value.length > 0;
|
8992 |
|
8993 | case ProtoBuf.TYPES["bytes"]:
|
8994 | return value.remaining() > 0;
|
8995 |
|
8996 | case ProtoBuf.TYPES["enum"]:
|
8997 | return value !== 0;
|
8998 |
|
8999 | case ProtoBuf.TYPES["message"]:
|
9000 | return value !== null;
|
9001 | default:
|
9002 | return true;
|
9003 | }
|
9004 | };
|
9005 |
|
9006 | |
9007 |
|
9008 |
|
9009 |
|
9010 |
|
9011 |
|
9012 |
|
9013 |
|
9014 |
|
9015 | FieldPrototype.encode = function(value, buffer, message) {
|
9016 | if (this.type === null || typeof this.type !== 'object')
|
9017 | throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type);
|
9018 | if (value === null || (this.repeated && value.length == 0))
|
9019 | return buffer;
|
9020 | try {
|
9021 | if (this.repeated) {
|
9022 | var i;
|
9023 |
|
9024 |
|
9025 | if (this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {
|
9026 |
|
9027 |
|
9028 |
|
9029 | buffer.writeVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9030 | buffer.ensureCapacity(buffer.offset += 1);
|
9031 | var start = buffer.offset;
|
9032 | for (i=0; i<value.length; i++)
|
9033 | this.element.encodeValue(this.id, value[i], buffer);
|
9034 | var len = buffer.offset-start,
|
9035 | varintLen = ByteBuffer.calculateVarint32(len);
|
9036 | if (varintLen > 1) {
|
9037 | var contents = buffer.slice(start, buffer.offset);
|
9038 | start += varintLen-1;
|
9039 | buffer.offset = start;
|
9040 | buffer.append(contents);
|
9041 | }
|
9042 | buffer.writeVarint32(len, start-varintLen);
|
9043 | } else {
|
9044 |
|
9045 |
|
9046 | for (i=0; i<value.length; i++)
|
9047 | buffer.writeVarint32((this.id << 3) | this.type.wireType),
|
9048 | this.element.encodeValue(this.id, value[i], buffer);
|
9049 | }
|
9050 | } else if (this.map) {
|
9051 |
|
9052 | value.forEach(function(val, key, m) {
|
9053 |
|
9054 | var length =
|
9055 | ByteBuffer.calculateVarint32((1 << 3) | this.keyType.wireType) +
|
9056 | this.keyElement.calculateLength(1, key) +
|
9057 | ByteBuffer.calculateVarint32((2 << 3) | this.type.wireType) +
|
9058 | this.element.calculateLength(2, val);
|
9059 |
|
9060 |
|
9061 | buffer.writeVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9062 | buffer.writeVarint32(length);
|
9063 |
|
9064 |
|
9065 | buffer.writeVarint32((1 << 3) | this.keyType.wireType);
|
9066 | this.keyElement.encodeValue(1, key, buffer);
|
9067 | buffer.writeVarint32((2 << 3) | this.type.wireType);
|
9068 | this.element.encodeValue(2, val, buffer);
|
9069 | }, this);
|
9070 | } else {
|
9071 | if (this.hasWirePresence(value, message)) {
|
9072 | buffer.writeVarint32((this.id << 3) | this.type.wireType);
|
9073 | this.element.encodeValue(this.id, value, buffer);
|
9074 | }
|
9075 | }
|
9076 | } catch (e) {
|
9077 | throw Error("Illegal value for "+this.toString(true)+": "+value+" ("+e+")");
|
9078 | }
|
9079 | return buffer;
|
9080 | };
|
9081 |
|
9082 | |
9083 |
|
9084 |
|
9085 |
|
9086 |
|
9087 |
|
9088 |
|
9089 | FieldPrototype.calculate = function(value, message) {
|
9090 | value = this.verifyValue(value);
|
9091 | if (this.type === null || typeof this.type !== 'object')
|
9092 | throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type);
|
9093 | if (value === null || (this.repeated && value.length == 0))
|
9094 | return 0;
|
9095 | var n = 0;
|
9096 | try {
|
9097 | if (this.repeated) {
|
9098 | var i, ni;
|
9099 | if (this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {
|
9100 | n += ByteBuffer.calculateVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9101 | ni = 0;
|
9102 | for (i=0; i<value.length; i++)
|
9103 | ni += this.element.calculateLength(this.id, value[i]);
|
9104 | n += ByteBuffer.calculateVarint32(ni);
|
9105 | n += ni;
|
9106 | } else {
|
9107 | for (i=0; i<value.length; i++)
|
9108 | n += ByteBuffer.calculateVarint32((this.id << 3) | this.type.wireType),
|
9109 | n += this.element.calculateLength(this.id, value[i]);
|
9110 | }
|
9111 | } else if (this.map) {
|
9112 |
|
9113 | value.forEach(function(val, key, m) {
|
9114 |
|
9115 | var length =
|
9116 | ByteBuffer.calculateVarint32((1 << 3) | this.keyType.wireType) +
|
9117 | this.keyElement.calculateLength(1, key) +
|
9118 | ByteBuffer.calculateVarint32((2 << 3) | this.type.wireType) +
|
9119 | this.element.calculateLength(2, val);
|
9120 |
|
9121 | n += ByteBuffer.calculateVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9122 | n += ByteBuffer.calculateVarint32(length);
|
9123 | n += length;
|
9124 | }, this);
|
9125 | } else {
|
9126 | if (this.hasWirePresence(value, message)) {
|
9127 | n += ByteBuffer.calculateVarint32((this.id << 3) | this.type.wireType);
|
9128 | n += this.element.calculateLength(this.id, value);
|
9129 | }
|
9130 | }
|
9131 | } catch (e) {
|
9132 | throw Error("Illegal value for "+this.toString(true)+": "+value+" ("+e+")");
|
9133 | }
|
9134 | return n;
|
9135 | };
|
9136 |
|
9137 | |
9138 |
|
9139 |
|
9140 |
|
9141 |
|
9142 |
|
9143 |
|
9144 |
|
9145 |
|
9146 |
|
9147 | FieldPrototype.decode = function(wireType, buffer, skipRepeated) {
|
9148 | var value, nBytes;
|
9149 |
|
9150 |
|
9151 |
|
9152 | var wireTypeOK =
|
9153 | (!this.map && wireType == this.type.wireType) ||
|
9154 | (!skipRepeated && this.repeated && this.options["packed"] &&
|
9155 | wireType == ProtoBuf.WIRE_TYPES.LDELIM) ||
|
9156 | (this.map && wireType == ProtoBuf.WIRE_TYPES.LDELIM);
|
9157 | if (!wireTypeOK)
|
9158 | throw Error("Illegal wire type for field "+this.toString(true)+": "+wireType+" ("+this.type.wireType+" expected)");
|
9159 |
|
9160 |
|
9161 | if (wireType == ProtoBuf.WIRE_TYPES.LDELIM && this.repeated && this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {
|
9162 | if (!skipRepeated) {
|
9163 | nBytes = buffer.readVarint32();
|
9164 | nBytes = buffer.offset + nBytes;
|
9165 | var values = [];
|
9166 | while (buffer.offset < nBytes)
|
9167 | values.push(this.decode(this.type.wireType, buffer, true));
|
9168 | return values;
|
9169 | }
|
9170 |
|
9171 | }
|
9172 |
|
9173 |
|
9174 | if (this.map) {
|
9175 |
|
9176 | var key = Element.defaultFieldValue(this.keyType);
|
9177 | value = Element.defaultFieldValue(this.type);
|
9178 |
|
9179 |
|
9180 | nBytes = buffer.readVarint32();
|
9181 | if (buffer.remaining() < nBytes)
|
9182 | throw Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining());
|
9183 |
|
9184 |
|
9185 | var msgbuf = buffer.clone();
|
9186 | msgbuf.limit = msgbuf.offset + nBytes;
|
9187 | buffer.offset += nBytes;
|
9188 |
|
9189 | while (msgbuf.remaining() > 0) {
|
9190 | var tag = msgbuf.readVarint32();
|
9191 | wireType = tag & 0x07;
|
9192 | var id = tag >>> 3;
|
9193 | if (id === 1) {
|
9194 | key = this.keyElement.decode(msgbuf, wireType, id);
|
9195 | } else if (id === 2) {
|
9196 | value = this.element.decode(msgbuf, wireType, id);
|
9197 | } else {
|
9198 | throw Error("Unexpected tag in map field key/value submessage");
|
9199 | }
|
9200 | }
|
9201 |
|
9202 | return [key, value];
|
9203 | }
|
9204 |
|
9205 |
|
9206 | return this.element.decode(buffer, wireType, this.id);
|
9207 | };
|
9208 |
|
9209 | |
9210 |
|
9211 |
|
9212 |
|
9213 | Reflect.Message.Field = Field;
|
9214 |
|
9215 | |
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 |
|
9226 |
|
9227 |
|
9228 | var ExtensionField = function(builder, message, rule, type, name, id, options) {
|
9229 | Field.call(this, builder, message, rule, null, type, name, id, options);
|
9230 |
|
9231 | |
9232 |
|
9233 |
|
9234 |
|
9235 |
|
9236 | this.extension;
|
9237 | };
|
9238 |
|
9239 |
|
9240 | ExtensionField.prototype = Object.create(Field.prototype);
|
9241 |
|
9242 | |
9243 |
|
9244 |
|
9245 |
|
9246 | Reflect.Message.ExtensionField = ExtensionField;
|
9247 |
|
9248 | |
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 |
|
9254 |
|
9255 |
|
9256 |
|
9257 | var OneOf = function(builder, message, name) {
|
9258 | T.call(this, builder, message, name);
|
9259 |
|
9260 | |
9261 |
|
9262 |
|
9263 |
|
9264 |
|
9265 | this.fields = [];
|
9266 | };
|
9267 |
|
9268 | |
9269 |
|
9270 |
|
9271 |
|
9272 | Reflect.Message.OneOf = OneOf;
|
9273 |
|
9274 | |
9275 |
|
9276 |
|
9277 |
|
9278 |
|
9279 |
|
9280 |
|
9281 |
|
9282 |
|
9283 |
|
9284 |
|
9285 | var Enum = function(builder, parent, name, options, syntax) {
|
9286 | Namespace.call(this, builder, parent, name, options, syntax);
|
9287 |
|
9288 | |
9289 |
|
9290 |
|
9291 | this.className = "Enum";
|
9292 |
|
9293 | |
9294 |
|
9295 |
|
9296 |
|
9297 |
|
9298 | this.object = null;
|
9299 | };
|
9300 |
|
9301 | |
9302 |
|
9303 |
|
9304 |
|
9305 |
|
9306 |
|
9307 |
|
9308 | Enum.getName = function(enm, value) {
|
9309 | var keys = Object.keys(enm);
|
9310 | for (var i=0, key; i<keys.length; ++i)
|
9311 | if (enm[key = keys[i]] === value)
|
9312 | return key;
|
9313 | return null;
|
9314 | };
|
9315 |
|
9316 | |
9317 |
|
9318 |
|
9319 |
|
9320 | var EnumPrototype = Enum.prototype = Object.create(Namespace.prototype);
|
9321 |
|
9322 | |
9323 |
|
9324 |
|
9325 |
|
9326 |
|
9327 |
|
9328 | EnumPrototype.build = function(rebuild) {
|
9329 | if (this.object && !rebuild)
|
9330 | return this.object;
|
9331 | var enm = new ProtoBuf.Builder.Enum(),
|
9332 | values = this.getChildren(Enum.Value);
|
9333 | for (var i=0, k=values.length; i<k; ++i)
|
9334 | enm[values[i]['name']] = values[i]['id'];
|
9335 | if (Object.defineProperty)
|
9336 | Object.defineProperty(enm, '$options', {
|
9337 | "value": this.buildOpt(),
|
9338 | "enumerable": false
|
9339 | });
|
9340 | return this.object = enm;
|
9341 | };
|
9342 |
|
9343 | |
9344 |
|
9345 |
|
9346 |
|
9347 | Reflect.Enum = Enum;
|
9348 |
|
9349 | |
9350 |
|
9351 |
|
9352 |
|
9353 |
|
9354 |
|
9355 |
|
9356 |
|
9357 |
|
9358 |
|
9359 | var Value = function(builder, enm, name, id) {
|
9360 | T.call(this, builder, enm, name);
|
9361 |
|
9362 | |
9363 |
|
9364 |
|
9365 | this.className = "Enum.Value";
|
9366 |
|
9367 | |
9368 |
|
9369 |
|
9370 |
|
9371 |
|
9372 | this.id = id;
|
9373 | };
|
9374 |
|
9375 |
|
9376 | Value.prototype = Object.create(T.prototype);
|
9377 |
|
9378 | |
9379 |
|
9380 |
|
9381 |
|
9382 | Reflect.Enum.Value = Value;
|
9383 |
|
9384 | |
9385 |
|
9386 |
|
9387 |
|
9388 |
|
9389 |
|
9390 |
|
9391 |
|
9392 |
|
9393 | var Extension = function(builder, parent, name, field) {
|
9394 | T.call(this, builder, parent, name);
|
9395 |
|
9396 | |
9397 |
|
9398 |
|
9399 |
|
9400 |
|
9401 | this.field = field;
|
9402 | };
|
9403 |
|
9404 |
|
9405 | Extension.prototype = Object.create(T.prototype);
|
9406 |
|
9407 | |
9408 |
|
9409 |
|
9410 |
|
9411 | Reflect.Extension = Extension;
|
9412 |
|
9413 | |
9414 |
|
9415 |
|
9416 |
|
9417 |
|
9418 |
|
9419 |
|
9420 |
|
9421 |
|
9422 |
|
9423 | var Service = function(builder, root, name, options) {
|
9424 | Namespace.call(this, builder, root, name, options);
|
9425 |
|
9426 | |
9427 |
|
9428 |
|
9429 | this.className = "Service";
|
9430 |
|
9431 | |
9432 |
|
9433 |
|
9434 |
|
9435 | this.clazz = null;
|
9436 | };
|
9437 |
|
9438 | |
9439 |
|
9440 |
|
9441 |
|
9442 | var ServicePrototype = Service.prototype = Object.create(Namespace.prototype);
|
9443 |
|
9444 | |
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 |
|
9452 | ServicePrototype.build = function(rebuild) {
|
9453 | if (this.clazz && !rebuild)
|
9454 | return this.clazz;
|
9455 |
|
9456 |
|
9457 | return this.clazz = (function(ProtoBuf, T) {
|
9458 |
|
9459 | |
9460 |
|
9461 |
|
9462 |
|
9463 |
|
9464 |
|
9465 |
|
9466 |
|
9467 | var Service = function(rpcImpl) {
|
9468 | ProtoBuf.Builder.Service.call(this);
|
9469 |
|
9470 | |
9471 |
|
9472 |
|
9473 |
|
9474 |
|
9475 |
|
9476 | this.rpcImpl = rpcImpl || function(name, msg, callback) {
|
9477 |
|
9478 |
|
9479 |
|
9480 | setTimeout(callback.bind(this, Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), 0);
|
9481 | };
|
9482 | };
|
9483 |
|
9484 | |
9485 |
|
9486 |
|
9487 |
|
9488 | var ServicePrototype = Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype);
|
9489 |
|
9490 | |
9491 |
|
9492 |
|
9493 |
|
9494 |
|
9495 |
|
9496 |
|
9497 |
|
9498 |
|
9499 |
|
9500 |
|
9501 | |
9502 |
|
9503 |
|
9504 |
|
9505 |
|
9506 |
|
9507 |
|
9508 |
|
9509 |
|
9510 |
|
9511 | var rpc = T.getChildren(ProtoBuf.Reflect.Service.RPCMethod);
|
9512 | for (var i=0; i<rpc.length; i++) {
|
9513 | (function(method) {
|
9514 |
|
9515 |
|
9516 | ServicePrototype[method.name] = function(req, callback) {
|
9517 | try {
|
9518 | try {
|
9519 |
|
9520 | req = method.resolvedRequestType.clazz.decode(ByteBuffer.wrap(req));
|
9521 | } catch (err) {
|
9522 | if (!(err instanceof TypeError))
|
9523 | throw err;
|
9524 | }
|
9525 | if (req === null || typeof req !== 'object')
|
9526 | throw Error("Illegal arguments");
|
9527 | if (!(req instanceof method.resolvedRequestType.clazz))
|
9528 | req = new method.resolvedRequestType.clazz(req);
|
9529 | this.rpcImpl(method.fqn(), req, function(err, res) {
|
9530 | if (err) {
|
9531 | callback(err);
|
9532 | return;
|
9533 | }
|
9534 |
|
9535 | if (res === null)
|
9536 | res = '';
|
9537 | try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
|
9538 | if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
|
9539 | callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
|
9540 | return;
|
9541 | }
|
9542 | callback(null, res);
|
9543 | });
|
9544 | } catch (err) {
|
9545 | setTimeout(callback.bind(this, err), 0);
|
9546 | }
|
9547 | };
|
9548 |
|
9549 |
|
9550 | Service[method.name] = function(rpcImpl, req, callback) {
|
9551 | new Service(rpcImpl)[method.name](req, callback);
|
9552 | };
|
9553 |
|
9554 | if (Object.defineProperty)
|
9555 | Object.defineProperty(Service[method.name], "$options", { "value": method.buildOpt() }),
|
9556 | Object.defineProperty(ServicePrototype[method.name], "$options", { "value": Service[method.name]["$options"] });
|
9557 | })(rpc[i]);
|
9558 | }
|
9559 |
|
9560 | if (Object.defineProperty)
|
9561 | Object.defineProperty(Service, "$options", { "value": T.buildOpt() }),
|
9562 | Object.defineProperty(ServicePrototype, "$options", { "value": Service["$options"] }),
|
9563 | Object.defineProperty(Service, "$type", { "value": T }),
|
9564 | Object.defineProperty(ServicePrototype, "$type", { "value": T });
|
9565 |
|
9566 | return Service;
|
9567 |
|
9568 | })(ProtoBuf, this);
|
9569 | };
|
9570 |
|
9571 | |
9572 |
|
9573 |
|
9574 |
|
9575 | Reflect.Service = Service;
|
9576 |
|
9577 | |
9578 |
|
9579 |
|
9580 |
|
9581 |
|
9582 |
|
9583 |
|
9584 |
|
9585 |
|
9586 |
|
9587 | var Method = function(builder, svc, name, options) {
|
9588 | T.call(this, builder, svc, name);
|
9589 |
|
9590 | |
9591 |
|
9592 |
|
9593 | this.className = "Service.Method";
|
9594 |
|
9595 | |
9596 |
|
9597 |
|
9598 |
|
9599 |
|
9600 | this.options = options || {};
|
9601 | };
|
9602 |
|
9603 | |
9604 |
|
9605 |
|
9606 |
|
9607 | var MethodPrototype = Method.prototype = Object.create(T.prototype);
|
9608 |
|
9609 | |
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 |
|
9615 | MethodPrototype.buildOpt = NamespacePrototype.buildOpt;
|
9616 |
|
9617 | |
9618 |
|
9619 |
|
9620 |
|
9621 | Reflect.Service.Method = Method;
|
9622 |
|
9623 | |
9624 |
|
9625 |
|
9626 |
|
9627 |
|
9628 |
|
9629 |
|
9630 |
|
9631 |
|
9632 |
|
9633 |
|
9634 |
|
9635 |
|
9636 |
|
9637 | var RPCMethod = function(builder, svc, name, request, response, request_stream, response_stream, options) {
|
9638 | Method.call(this, builder, svc, name, options);
|
9639 |
|
9640 | |
9641 |
|
9642 |
|
9643 | this.className = "Service.RPCMethod";
|
9644 |
|
9645 | |
9646 |
|
9647 |
|
9648 |
|
9649 |
|
9650 | this.requestName = request;
|
9651 |
|
9652 | |
9653 |
|
9654 |
|
9655 |
|
9656 |
|
9657 | this.responseName = response;
|
9658 |
|
9659 | |
9660 |
|
9661 |
|
9662 |
|
9663 |
|
9664 | this.requestStream = request_stream;
|
9665 |
|
9666 | |
9667 |
|
9668 |
|
9669 |
|
9670 |
|
9671 | this.responseStream = response_stream;
|
9672 |
|
9673 | |
9674 |
|
9675 |
|
9676 |
|
9677 |
|
9678 | this.resolvedRequestType = null;
|
9679 |
|
9680 | |
9681 |
|
9682 |
|
9683 |
|
9684 |
|
9685 | this.resolvedResponseType = null;
|
9686 | };
|
9687 |
|
9688 |
|
9689 | RPCMethod.prototype = Object.create(Method.prototype);
|
9690 |
|
9691 | |
9692 |
|
9693 |
|
9694 |
|
9695 | Reflect.Service.RPCMethod = RPCMethod;
|
9696 |
|
9697 | return Reflect;
|
9698 |
|
9699 | })(ProtoBuf);
|
9700 |
|
9701 | |
9702 |
|
9703 |
|
9704 |
|
9705 | ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
|
9706 |
|
9707 | |
9708 |
|
9709 |
|
9710 |
|
9711 |
|
9712 |
|
9713 |
|
9714 | var Builder = function(options) {
|
9715 |
|
9716 | |
9717 |
|
9718 |
|
9719 |
|
9720 |
|
9721 | this.ns = new Reflect.Namespace(this, null, "");
|
9722 |
|
9723 | |
9724 |
|
9725 |
|
9726 |
|
9727 |
|
9728 | this.ptr = this.ns;
|
9729 |
|
9730 | |
9731 |
|
9732 |
|
9733 |
|
9734 |
|
9735 | this.resolved = false;
|
9736 |
|
9737 | |
9738 |
|
9739 |
|
9740 |
|
9741 |
|
9742 | this.result = null;
|
9743 |
|
9744 | |
9745 |
|
9746 |
|
9747 |
|
9748 |
|
9749 | this.files = {};
|
9750 |
|
9751 | |
9752 |
|
9753 |
|
9754 |
|
9755 |
|
9756 | this.importRoot = null;
|
9757 |
|
9758 | |
9759 |
|
9760 |
|
9761 |
|
9762 |
|
9763 | this.options = options || {};
|
9764 | };
|
9765 |
|
9766 | |
9767 |
|
9768 |
|
9769 |
|
9770 | var BuilderPrototype = Builder.prototype;
|
9771 |
|
9772 |
|
9773 |
|
9774 | |
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 | Builder.isMessage = function(def) {
|
9781 |
|
9782 | if (typeof def["name"] !== 'string')
|
9783 | return false;
|
9784 |
|
9785 | if (typeof def["values"] !== 'undefined' || typeof def["rpc"] !== 'undefined')
|
9786 | return false;
|
9787 | return true;
|
9788 | };
|
9789 |
|
9790 | |
9791 |
|
9792 |
|
9793 |
|
9794 |
|
9795 |
|
9796 | Builder.isMessageField = function(def) {
|
9797 |
|
9798 | if (typeof def["rule"] !== 'string' || typeof def["name"] !== 'string' || typeof def["type"] !== 'string' || typeof def["id"] === 'undefined')
|
9799 | return false;
|
9800 | return true;
|
9801 | };
|
9802 |
|
9803 | |
9804 |
|
9805 |
|
9806 |
|
9807 |
|
9808 |
|
9809 | Builder.isEnum = function(def) {
|
9810 |
|
9811 | if (typeof def["name"] !== 'string')
|
9812 | return false;
|
9813 |
|
9814 | if (typeof def["values"] === 'undefined' || !Array.isArray(def["values"]) || def["values"].length === 0)
|
9815 | return false;
|
9816 | return true;
|
9817 | };
|
9818 |
|
9819 | |
9820 |
|
9821 |
|
9822 |
|
9823 |
|
9824 |
|
9825 | Builder.isService = function(def) {
|
9826 |
|
9827 | if (typeof def["name"] !== 'string' || typeof def["rpc"] !== 'object' || !def["rpc"])
|
9828 | return false;
|
9829 | return true;
|
9830 | };
|
9831 |
|
9832 | |
9833 |
|
9834 |
|
9835 |
|
9836 |
|
9837 |
|
9838 | Builder.isExtend = function(def) {
|
9839 |
|
9840 | if (typeof def["ref"] !== 'string')
|
9841 | return false;
|
9842 | return true;
|
9843 | };
|
9844 |
|
9845 |
|
9846 |
|
9847 | |
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 | BuilderPrototype.reset = function() {
|
9853 | this.ptr = this.ns;
|
9854 | return this;
|
9855 | };
|
9856 |
|
9857 | |
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 | BuilderPrototype.define = function(namespace) {
|
9864 | if (typeof namespace !== 'string' || !Lang.TYPEREF.test(namespace))
|
9865 | throw Error("illegal namespace: "+namespace);
|
9866 | namespace.split(".").forEach(function(part) {
|
9867 | var ns = this.ptr.getChild(part);
|
9868 | if (ns === null)
|
9869 | this.ptr.addChild(ns = new Reflect.Namespace(this, this.ptr, part));
|
9870 | this.ptr = ns;
|
9871 | }, this);
|
9872 | return this;
|
9873 | };
|
9874 |
|
9875 | |
9876 |
|
9877 |
|
9878 |
|
9879 |
|
9880 |
|
9881 |
|
9882 | BuilderPrototype.create = function(defs) {
|
9883 | if (!defs)
|
9884 | return this;
|
9885 | if (!Array.isArray(defs))
|
9886 | defs = [defs];
|
9887 | else {
|
9888 | if (defs.length === 0)
|
9889 | return this;
|
9890 | defs = defs.slice();
|
9891 | }
|
9892 |
|
9893 |
|
9894 | var stack = [defs];
|
9895 | while (stack.length > 0) {
|
9896 | defs = stack.pop();
|
9897 |
|
9898 | if (!Array.isArray(defs))
|
9899 | throw Error("not a valid namespace: "+JSON.stringify(defs));
|
9900 |
|
9901 | while (defs.length > 0) {
|
9902 | var def = defs.shift();
|
9903 |
|
9904 | if (Builder.isMessage(def)) {
|
9905 | var obj = new Reflect.Message(this, this.ptr, def["name"], def["options"], def["isGroup"], def["syntax"]);
|
9906 |
|
9907 |
|
9908 | var oneofs = {};
|
9909 | if (def["oneofs"])
|
9910 | Object.keys(def["oneofs"]).forEach(function(name) {
|
9911 | obj.addChild(oneofs[name] = new Reflect.Message.OneOf(this, obj, name));
|
9912 | }, this);
|
9913 |
|
9914 |
|
9915 | if (def["fields"])
|
9916 | def["fields"].forEach(function(fld) {
|
9917 | if (obj.getChild(fld["id"]|0) !== null)
|
9918 | throw Error("duplicate or invalid field id in "+obj.name+": "+fld['id']);
|
9919 | if (fld["options"] && typeof fld["options"] !== 'object')
|
9920 | throw Error("illegal field options in "+obj.name+"#"+fld["name"]);
|
9921 | var oneof = null;
|
9922 | if (typeof fld["oneof"] === 'string' && !(oneof = oneofs[fld["oneof"]]))
|
9923 | throw Error("illegal oneof in "+obj.name+"#"+fld["name"]+": "+fld["oneof"]);
|
9924 | fld = new Reflect.Message.Field(this, obj, fld["rule"], fld["keytype"], fld["type"], fld["name"], fld["id"], fld["options"], oneof, def["syntax"]);
|
9925 | if (oneof)
|
9926 | oneof.fields.push(fld);
|
9927 | obj.addChild(fld);
|
9928 | }, this);
|
9929 |
|
9930 |
|
9931 | var subObj = [];
|
9932 | if (def["enums"])
|
9933 | def["enums"].forEach(function(enm) {
|
9934 | subObj.push(enm);
|
9935 | });
|
9936 | if (def["messages"])
|
9937 | def["messages"].forEach(function(msg) {
|
9938 | subObj.push(msg);
|
9939 | });
|
9940 | if (def["services"])
|
9941 | def["services"].forEach(function(svc) {
|
9942 | subObj.push(svc);
|
9943 | });
|
9944 |
|
9945 |
|
9946 | if (def["extensions"]) {
|
9947 | if (typeof def["extensions"][0] === 'number')
|
9948 | obj.extensions = [ def["extensions"] ];
|
9949 | else
|
9950 | obj.extensions = def["extensions"];
|
9951 | }
|
9952 |
|
9953 |
|
9954 | this.ptr.addChild(obj);
|
9955 | if (subObj.length > 0) {
|
9956 | stack.push(defs);
|
9957 | defs = subObj;
|
9958 | subObj = null;
|
9959 | this.ptr = obj;
|
9960 | obj = null;
|
9961 | continue;
|
9962 | }
|
9963 | subObj = null;
|
9964 |
|
9965 | } else if (Builder.isEnum(def)) {
|
9966 |
|
9967 | obj = new Reflect.Enum(this, this.ptr, def["name"], def["options"], def["syntax"]);
|
9968 | def["values"].forEach(function(val) {
|
9969 | obj.addChild(new Reflect.Enum.Value(this, obj, val["name"], val["id"]));
|
9970 | }, this);
|
9971 | this.ptr.addChild(obj);
|
9972 |
|
9973 | } else if (Builder.isService(def)) {
|
9974 |
|
9975 | obj = new Reflect.Service(this, this.ptr, def["name"], def["options"]);
|
9976 | Object.keys(def["rpc"]).forEach(function(name) {
|
9977 | var mtd = def["rpc"][name];
|
9978 | obj.addChild(new Reflect.Service.RPCMethod(this, obj, name, mtd["request"], mtd["response"], !!mtd["request_stream"], !!mtd["response_stream"], mtd["options"]));
|
9979 | }, this);
|
9980 | this.ptr.addChild(obj);
|
9981 |
|
9982 | } else if (Builder.isExtend(def)) {
|
9983 |
|
9984 | obj = this.ptr.resolve(def["ref"], true);
|
9985 | if (obj) {
|
9986 | def["fields"].forEach(function(fld) {
|
9987 | if (obj.getChild(fld['id']|0) !== null)
|
9988 | throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
|
9989 |
|
9990 | if (obj.extensions) {
|
9991 | var valid = false;
|
9992 | obj.extensions.forEach(function(range) {
|
9993 | if (fld["id"] >= range[0] && fld["id"] <= range[1])
|
9994 | valid = true;
|
9995 | });
|
9996 | if (!valid)
|
9997 | throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
|
9998 | }
|
9999 |
|
10000 | var name = fld["name"];
|
10001 | if (this.options['convertFieldsToCamelCase'])
|
10002 | name = ProtoBuf.Util.toCamelCase(name);
|
10003 |
|
10004 | var field = new Reflect.Message.ExtensionField(this, obj, fld["rule"], fld["type"], this.ptr.fqn()+'.'+name, fld["id"], fld["options"]);
|
10005 |
|
10006 |
|
10007 |
|
10008 | var ext = new Reflect.Extension(this, this.ptr, fld["name"], field);
|
10009 | field.extension = ext;
|
10010 | this.ptr.addChild(ext);
|
10011 | obj.addChild(field);
|
10012 | }, this);
|
10013 |
|
10014 | } else if (!/\.?google\.protobuf\./.test(def["ref"]))
|
10015 | throw Error("extended message "+def["ref"]+" is not defined");
|
10016 |
|
10017 | } else
|
10018 | throw Error("not a valid definition: "+JSON.stringify(def));
|
10019 |
|
10020 | def = null;
|
10021 | obj = null;
|
10022 | }
|
10023 |
|
10024 | defs = null;
|
10025 | this.ptr = this.ptr.parent;
|
10026 | }
|
10027 | this.resolved = false;
|
10028 | this.result = null;
|
10029 | return this;
|
10030 | };
|
10031 |
|
10032 | |
10033 |
|
10034 |
|
10035 |
|
10036 |
|
10037 | function propagateSyntax(parent) {
|
10038 | if (parent['messages']) {
|
10039 | parent['messages'].forEach(function(child) {
|
10040 | child["syntax"] = parent["syntax"];
|
10041 | propagateSyntax(child);
|
10042 | });
|
10043 | }
|
10044 | if (parent['enums']) {
|
10045 | parent['enums'].forEach(function(child) {
|
10046 | child["syntax"] = parent["syntax"];
|
10047 | });
|
10048 | }
|
10049 | }
|
10050 |
|
10051 | |
10052 |
|
10053 |
|
10054 |
|
10055 |
|
10056 |
|
10057 |
|
10058 |
|
10059 | BuilderPrototype["import"] = function(json, filename) {
|
10060 | var delim = '/';
|
10061 |
|
10062 |
|
10063 |
|
10064 | if (typeof filename === 'string') {
|
10065 |
|
10066 | if (ProtoBuf.Util.IS_NODE)
|
10067 | filename = require$$2['resolve'](filename);
|
10068 | if (this.files[filename] === true)
|
10069 | return this.reset();
|
10070 | this.files[filename] = true;
|
10071 |
|
10072 | } else if (typeof filename === 'object') {
|
10073 |
|
10074 | var root = filename.root;
|
10075 | if (ProtoBuf.Util.IS_NODE)
|
10076 | root = require$$2['resolve'](root);
|
10077 | if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
|
10078 | delim = '\\';
|
10079 | var fname;
|
10080 | if (ProtoBuf.Util.IS_NODE)
|
10081 | fname = require$$2['join'](root, filename.file);
|
10082 | else
|
10083 | fname = root + delim + filename.file;
|
10084 | if (this.files[fname] === true)
|
10085 | return this.reset();
|
10086 | this.files[fname] = true;
|
10087 | }
|
10088 |
|
10089 |
|
10090 |
|
10091 | if (json['imports'] && json['imports'].length > 0) {
|
10092 | var importRoot,
|
10093 | resetRoot = false;
|
10094 |
|
10095 | if (typeof filename === 'object') {
|
10096 |
|
10097 | this.importRoot = filename["root"]; resetRoot = true;
|
10098 | importRoot = this.importRoot;
|
10099 | filename = filename["file"];
|
10100 | if (importRoot.indexOf("\\") >= 0 || filename.indexOf("\\") >= 0)
|
10101 | delim = '\\';
|
10102 |
|
10103 | } else if (typeof filename === 'string') {
|
10104 |
|
10105 | if (this.importRoot)
|
10106 | importRoot = this.importRoot;
|
10107 | else {
|
10108 | if (filename.indexOf("/") >= 0) {
|
10109 | importRoot = filename.replace(/\/[^\/]*$/, "");
|
10110 | if ( importRoot === "")
|
10111 | importRoot = "/";
|
10112 | } else if (filename.indexOf("\\") >= 0) {
|
10113 | importRoot = filename.replace(/\\[^\\]*$/, "");
|
10114 | delim = '\\';
|
10115 | } else
|
10116 | importRoot = ".";
|
10117 | }
|
10118 |
|
10119 | } else
|
10120 | importRoot = null;
|
10121 |
|
10122 | for (var i=0; i<json['imports'].length; i++) {
|
10123 | if (typeof json['imports'][i] === 'string') {
|
10124 | if (!importRoot)
|
10125 | throw Error("cannot determine import root");
|
10126 | var importFilename = json['imports'][i];
|
10127 | if (importFilename === "google/protobuf/descriptor.proto")
|
10128 | continue;
|
10129 | if (ProtoBuf.Util.IS_NODE)
|
10130 | importFilename = require$$2['join'](importRoot, importFilename);
|
10131 | else
|
10132 | importFilename = importRoot + delim + importFilename;
|
10133 | if (this.files[importFilename] === true)
|
10134 | continue;
|
10135 | if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto)
|
10136 | importFilename = importFilename.replace(/\.proto$/, ".json");
|
10137 | var contents = ProtoBuf.Util.fetch(importFilename);
|
10138 | if (contents === null)
|
10139 | throw Error("failed to import '"+importFilename+"' in '"+filename+"': file not found");
|
10140 | if (/\.json$/i.test(importFilename))
|
10141 | this["import"](JSON.parse(contents+""), importFilename);
|
10142 | else
|
10143 | this["import"](ProtoBuf.DotProto.Parser.parse(contents), importFilename);
|
10144 | } else
|
10145 | if (!filename)
|
10146 | this["import"](json['imports'][i]);
|
10147 | else if (/\.(\w+)$/.test(filename))
|
10148 | this["import"](json['imports'][i], filename.replace(/^(.+)\.(\w+)$/, function($0, $1, $2) { return $1+"_import"+i+"."+$2; }));
|
10149 | else
|
10150 | this["import"](json['imports'][i], filename+"_import"+i);
|
10151 | }
|
10152 | if (resetRoot)
|
10153 | this.importRoot = null;
|
10154 | }
|
10155 |
|
10156 |
|
10157 |
|
10158 | if (json['package'])
|
10159 | this.define(json['package']);
|
10160 | if (json['syntax'])
|
10161 | propagateSyntax(json);
|
10162 | var base = this.ptr;
|
10163 | if (json['options'])
|
10164 | Object.keys(json['options']).forEach(function(key) {
|
10165 | base.options[key] = json['options'][key];
|
10166 | });
|
10167 | if (json['messages'])
|
10168 | this.create(json['messages']),
|
10169 | this.ptr = base;
|
10170 | if (json['enums'])
|
10171 | this.create(json['enums']),
|
10172 | this.ptr = base;
|
10173 | if (json['services'])
|
10174 | this.create(json['services']),
|
10175 | this.ptr = base;
|
10176 | if (json['extends'])
|
10177 | this.create(json['extends']);
|
10178 |
|
10179 | return this.reset();
|
10180 | };
|
10181 |
|
10182 | |
10183 |
|
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 | BuilderPrototype.resolveAll = function() {
|
10189 |
|
10190 | var res;
|
10191 | if (this.ptr == null || typeof this.ptr.type === 'object')
|
10192 | return this;
|
10193 |
|
10194 | if (this.ptr instanceof Reflect.Namespace) {
|
10195 |
|
10196 | this.ptr.children.forEach(function(child) {
|
10197 | this.ptr = child;
|
10198 | this.resolveAll();
|
10199 | }, this);
|
10200 |
|
10201 | } else if (this.ptr instanceof Reflect.Message.Field) {
|
10202 |
|
10203 | if (!Lang.TYPE.test(this.ptr.type)) {
|
10204 | if (!Lang.TYPEREF.test(this.ptr.type))
|
10205 | throw Error("illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
|
10206 | res = (this.ptr instanceof Reflect.Message.ExtensionField ? this.ptr.extension.parent : this.ptr.parent).resolve(this.ptr.type, true);
|
10207 | if (!res)
|
10208 | throw Error("unresolvable type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
|
10209 | this.ptr.resolvedType = res;
|
10210 | if (res instanceof Reflect.Enum) {
|
10211 | this.ptr.type = ProtoBuf.TYPES["enum"];
|
10212 | if (this.ptr.syntax === 'proto3' && res.syntax !== 'proto3')
|
10213 | throw Error("proto3 message cannot reference proto2 enum");
|
10214 | }
|
10215 | else if (res instanceof Reflect.Message)
|
10216 | this.ptr.type = res.isGroup ? ProtoBuf.TYPES["group"] : ProtoBuf.TYPES["message"];
|
10217 | else
|
10218 | throw Error("illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
|
10219 | } else
|
10220 | this.ptr.type = ProtoBuf.TYPES[this.ptr.type];
|
10221 |
|
10222 |
|
10223 |
|
10224 | if (this.ptr.map) {
|
10225 | if (!Lang.TYPE.test(this.ptr.keyType))
|
10226 | throw Error("illegal key type for map field in "+this.ptr.toString(true)+": "+this.ptr.keyType);
|
10227 | this.ptr.keyType = ProtoBuf.TYPES[this.ptr.keyType];
|
10228 | }
|
10229 |
|
10230 |
|
10231 |
|
10232 | if (
|
10233 | this.ptr.syntax === 'proto3' &&
|
10234 | this.ptr.repeated && this.ptr.options.packed === undefined &&
|
10235 | ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType) !== -1
|
10236 | ) {
|
10237 | this.ptr.options.packed = true;
|
10238 | }
|
10239 |
|
10240 | } else if (this.ptr instanceof ProtoBuf.Reflect.Service.Method) {
|
10241 |
|
10242 | if (this.ptr instanceof ProtoBuf.Reflect.Service.RPCMethod) {
|
10243 | res = this.ptr.parent.resolve(this.ptr.requestName, true);
|
10244 | if (!res || !(res instanceof ProtoBuf.Reflect.Message))
|
10245 | throw Error("Illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.requestName);
|
10246 | this.ptr.resolvedRequestType = res;
|
10247 | res = this.ptr.parent.resolve(this.ptr.responseName, true);
|
10248 | if (!res || !(res instanceof ProtoBuf.Reflect.Message))
|
10249 | throw Error("Illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.responseName);
|
10250 | this.ptr.resolvedResponseType = res;
|
10251 | } else
|
10252 | throw Error("illegal service type in "+this.ptr.toString(true));
|
10253 |
|
10254 | } else if (
|
10255 | !(this.ptr instanceof ProtoBuf.Reflect.Message.OneOf) &&
|
10256 | !(this.ptr instanceof ProtoBuf.Reflect.Extension) &&
|
10257 | !(this.ptr instanceof ProtoBuf.Reflect.Enum.Value)
|
10258 | )
|
10259 | throw Error("illegal object in namespace: "+typeof(this.ptr)+": "+this.ptr);
|
10260 |
|
10261 | return this.reset();
|
10262 | };
|
10263 |
|
10264 | |
10265 |
|
10266 |
|
10267 |
|
10268 |
|
10269 |
|
10270 |
|
10271 |
|
10272 | BuilderPrototype.build = function(path) {
|
10273 | this.reset();
|
10274 | if (!this.resolved)
|
10275 | this.resolveAll(),
|
10276 | this.resolved = true,
|
10277 | this.result = null;
|
10278 | if (this.result === null)
|
10279 | this.result = this.ns.build();
|
10280 | if (!path)
|
10281 | return this.result;
|
10282 | var part = typeof path === 'string' ? path.split(".") : path,
|
10283 | ptr = this.result;
|
10284 | for (var i=0; i<part.length; i++)
|
10285 | if (ptr[part[i]])
|
10286 | ptr = ptr[part[i]];
|
10287 | else {
|
10288 | ptr = null;
|
10289 | break;
|
10290 | }
|
10291 | return ptr;
|
10292 | };
|
10293 |
|
10294 | |
10295 |
|
10296 |
|
10297 |
|
10298 |
|
10299 |
|
10300 | BuilderPrototype.lookup = function(path, excludeNonNamespace) {
|
10301 | return path ? this.ns.resolve(path, excludeNonNamespace) : this.ns;
|
10302 | };
|
10303 |
|
10304 | |
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 | BuilderPrototype.toString = function() {
|
10310 | return "Builder";
|
10311 | };
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 | |
10317 |
|
10318 |
|
10319 | Builder.Message = function() {};
|
10320 |
|
10321 | |
10322 |
|
10323 |
|
10324 | Builder.Enum = function() {};
|
10325 |
|
10326 | |
10327 |
|
10328 |
|
10329 | Builder.Service = function() {};
|
10330 |
|
10331 | return Builder;
|
10332 |
|
10333 | })(ProtoBuf, ProtoBuf.Lang, ProtoBuf.Reflect);
|
10334 |
|
10335 | |
10336 |
|
10337 |
|
10338 |
|
10339 | ProtoBuf.Map = (function(ProtoBuf, Reflect) {
|
10340 |
|
10341 | |
10342 |
|
10343 |
|
10344 |
|
10345 |
|
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 |
|
10351 |
|
10352 | var Map = function(field, contents) {
|
10353 | if (!field.map)
|
10354 | throw Error("field is not a map");
|
10355 |
|
10356 | |
10357 |
|
10358 |
|
10359 |
|
10360 | this.field = field;
|
10361 |
|
10362 | |
10363 |
|
10364 |
|
10365 |
|
10366 | this.keyElem = new Reflect.Element(field.keyType, null, true, field.syntax);
|
10367 |
|
10368 | |
10369 |
|
10370 |
|
10371 |
|
10372 | this.valueElem = new Reflect.Element(field.type, field.resolvedType, false, field.syntax);
|
10373 |
|
10374 | |
10375 |
|
10376 |
|
10377 |
|
10378 |
|
10379 |
|
10380 |
|
10381 |
|
10382 |
|
10383 |
|
10384 |
|
10385 |
|
10386 |
|
10387 |
|
10388 | this.map = {};
|
10389 |
|
10390 | |
10391 |
|
10392 |
|
10393 | Object.defineProperty(this, "size", {
|
10394 | get: function() { return Object.keys(this.map).length; }
|
10395 | });
|
10396 |
|
10397 |
|
10398 | if (contents) {
|
10399 | var keys = Object.keys(contents);
|
10400 | for (var i = 0; i < keys.length; i++) {
|
10401 | var key = this.keyElem.valueFromString(keys[i]);
|
10402 | var val = this.valueElem.verifyValue(contents[keys[i]]);
|
10403 | this.map[this.keyElem.valueToString(key)] =
|
10404 | { key: key, value: val };
|
10405 | }
|
10406 | }
|
10407 | };
|
10408 |
|
10409 | var MapPrototype = Map.prototype;
|
10410 |
|
10411 | |
10412 |
|
10413 |
|
10414 |
|
10415 |
|
10416 |
|
10417 | function arrayIterator(arr) {
|
10418 | var idx = 0;
|
10419 | return {
|
10420 | next: function() {
|
10421 | if (idx < arr.length)
|
10422 | return { done: false, value: arr[idx++] };
|
10423 | return { done: true };
|
10424 | }
|
10425 | }
|
10426 | }
|
10427 |
|
10428 | |
10429 |
|
10430 |
|
10431 | MapPrototype.clear = function() {
|
10432 | this.map = {};
|
10433 | };
|
10434 |
|
10435 | |
10436 |
|
10437 |
|
10438 |
|
10439 | MapPrototype["delete"] = function(key) {
|
10440 | var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));
|
10441 | var hadKey = keyValue in this.map;
|
10442 | delete this.map[keyValue];
|
10443 | return hadKey;
|
10444 | };
|
10445 |
|
10446 | |
10447 |
|
10448 |
|
10449 |
|
10450 | MapPrototype.entries = function() {
|
10451 | var entries = [];
|
10452 | var strKeys = Object.keys(this.map);
|
10453 | for (var i = 0, entry; i < strKeys.length; i++)
|
10454 | entries.push([(entry=this.map[strKeys[i]]).key, entry.value]);
|
10455 | return arrayIterator(entries);
|
10456 | };
|
10457 |
|
10458 | |
10459 |
|
10460 |
|
10461 |
|
10462 | MapPrototype.keys = function() {
|
10463 | var keys = [];
|
10464 | var strKeys = Object.keys(this.map);
|
10465 | for (var i = 0; i < strKeys.length; i++)
|
10466 | keys.push(this.map[strKeys[i]].key);
|
10467 | return arrayIterator(keys);
|
10468 | };
|
10469 |
|
10470 | |
10471 |
|
10472 |
|
10473 |
|
10474 | MapPrototype.values = function() {
|
10475 | var values = [];
|
10476 | var strKeys = Object.keys(this.map);
|
10477 | for (var i = 0; i < strKeys.length; i++)
|
10478 | values.push(this.map[strKeys[i]].value);
|
10479 | return arrayIterator(values);
|
10480 | };
|
10481 |
|
10482 | |
10483 |
|
10484 |
|
10485 |
|
10486 |
|
10487 | MapPrototype.forEach = function(cb, thisArg) {
|
10488 | var strKeys = Object.keys(this.map);
|
10489 | for (var i = 0, entry; i < strKeys.length; i++)
|
10490 | cb.call(thisArg, (entry=this.map[strKeys[i]]).value, entry.key, this);
|
10491 | };
|
10492 |
|
10493 | |
10494 |
|
10495 |
|
10496 |
|
10497 |
|
10498 |
|
10499 | MapPrototype.set = function(key, value) {
|
10500 | var keyValue = this.keyElem.verifyValue(key);
|
10501 | var valValue = this.valueElem.verifyValue(value);
|
10502 | this.map[this.keyElem.valueToString(keyValue)] =
|
10503 | { key: keyValue, value: valValue };
|
10504 | return this;
|
10505 | };
|
10506 |
|
10507 | |
10508 |
|
10509 |
|
10510 |
|
10511 |
|
10512 | MapPrototype.get = function(key) {
|
10513 | var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));
|
10514 | if (!(keyValue in this.map))
|
10515 | return undefined;
|
10516 | return this.map[keyValue].value;
|
10517 | };
|
10518 |
|
10519 | |
10520 |
|
10521 |
|
10522 |
|
10523 |
|
10524 | MapPrototype.has = function(key) {
|
10525 | var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));
|
10526 | return (keyValue in this.map);
|
10527 | };
|
10528 |
|
10529 | return Map;
|
10530 | })(ProtoBuf, ProtoBuf.Reflect);
|
10531 |
|
10532 |
|
10533 | |
10534 |
|
10535 |
|
10536 |
|
10537 |
|
10538 |
|
10539 | ProtoBuf.newBuilder = function(options) {
|
10540 | options = options || {};
|
10541 | if (typeof options['convertFieldsToCamelCase'] === 'undefined')
|
10542 | options['convertFieldsToCamelCase'] = ProtoBuf.convertFieldsToCamelCase;
|
10543 | if (typeof options['populateAccessors'] === 'undefined')
|
10544 | options['populateAccessors'] = ProtoBuf.populateAccessors;
|
10545 | return new ProtoBuf.Builder(options);
|
10546 | };
|
10547 |
|
10548 | |
10549 |
|
10550 |
|
10551 |
|
10552 |
|
10553 |
|
10554 |
|
10555 |
|
10556 |
|
10557 | ProtoBuf.loadJson = function(json, builder, filename) {
|
10558 | if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string'))
|
10559 | filename = builder,
|
10560 | builder = null;
|
10561 | if (!builder || typeof builder !== 'object')
|
10562 | builder = ProtoBuf.newBuilder();
|
10563 | if (typeof json === 'string')
|
10564 | json = JSON.parse(json);
|
10565 | builder["import"](json, filename);
|
10566 | builder.resolveAll();
|
10567 | return builder;
|
10568 | };
|
10569 |
|
10570 | |
10571 |
|
10572 |
|
10573 |
|
10574 |
|
10575 |
|
10576 |
|
10577 |
|
10578 |
|
10579 |
|
10580 |
|
10581 |
|
10582 | ProtoBuf.loadJsonFile = function(filename, callback, builder) {
|
10583 | if (callback && typeof callback === 'object')
|
10584 | builder = callback,
|
10585 | callback = null;
|
10586 | else if (!callback || typeof callback !== 'function')
|
10587 | callback = null;
|
10588 | if (callback)
|
10589 | return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename["root"]+"/"+filename["file"], function(contents) {
|
10590 | if (contents === null) {
|
10591 | callback(Error("Failed to fetch file"));
|
10592 | return;
|
10593 | }
|
10594 | try {
|
10595 | callback(null, ProtoBuf.loadJson(JSON.parse(contents), builder, filename));
|
10596 | } catch (e) {
|
10597 | callback(e);
|
10598 | }
|
10599 | });
|
10600 | var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename);
|
10601 | return contents === null ? null : ProtoBuf.loadJson(JSON.parse(contents), builder, filename);
|
10602 | };
|
10603 |
|
10604 | return ProtoBuf;
|
10605 | });
|
10606 | });
|
10607 |
|
10608 | var messageCompiled = protobufLight.newBuilder({})['import']({
|
10609 | package: 'push_server.messages2',
|
10610 | syntax: 'proto2',
|
10611 | options: {
|
10612 | objc_class_prefix: 'AVIM'
|
10613 | },
|
10614 | messages: [{
|
10615 | name: 'JsonObjectMessage',
|
10616 | syntax: 'proto2',
|
10617 | fields: [{
|
10618 | rule: 'required',
|
10619 | type: 'string',
|
10620 | name: 'data',
|
10621 | id: 1
|
10622 | }]
|
10623 | }, {
|
10624 | name: 'UnreadTuple',
|
10625 | syntax: 'proto2',
|
10626 | fields: [{
|
10627 | rule: 'required',
|
10628 | type: 'string',
|
10629 | name: 'cid',
|
10630 | id: 1
|
10631 | }, {
|
10632 | rule: 'required',
|
10633 | type: 'int32',
|
10634 | name: 'unread',
|
10635 | id: 2
|
10636 | }, {
|
10637 | rule: 'optional',
|
10638 | type: 'string',
|
10639 | name: 'mid',
|
10640 | id: 3
|
10641 | }, {
|
10642 | rule: 'optional',
|
10643 | type: 'int64',
|
10644 | name: 'timestamp',
|
10645 | id: 4
|
10646 | }, {
|
10647 | rule: 'optional',
|
10648 | type: 'string',
|
10649 | name: 'from',
|
10650 | id: 5
|
10651 | }, {
|
10652 | rule: 'optional',
|
10653 | type: 'string',
|
10654 | name: 'data',
|
10655 | id: 6
|
10656 | }, {
|
10657 | rule: 'optional',
|
10658 | type: 'int64',
|
10659 | name: 'patchTimestamp',
|
10660 | id: 7
|
10661 | }, {
|
10662 | rule: 'optional',
|
10663 | type: 'bool',
|
10664 | name: 'mentioned',
|
10665 | id: 8
|
10666 | }, {
|
10667 | rule: 'optional',
|
10668 | type: 'bytes',
|
10669 | name: 'binaryMsg',
|
10670 | id: 9
|
10671 | }, {
|
10672 | rule: 'optional',
|
10673 | type: 'int32',
|
10674 | name: 'convType',
|
10675 | id: 10
|
10676 | }]
|
10677 | }, {
|
10678 | name: 'LogItem',
|
10679 | syntax: 'proto2',
|
10680 | fields: [{
|
10681 | rule: 'optional',
|
10682 | type: 'string',
|
10683 | name: 'from',
|
10684 | id: 1
|
10685 | }, {
|
10686 | rule: 'optional',
|
10687 | type: 'string',
|
10688 | name: 'data',
|
10689 | id: 2
|
10690 | }, {
|
10691 | rule: 'optional',
|
10692 | type: 'int64',
|
10693 | name: 'timestamp',
|
10694 | id: 3
|
10695 | }, {
|
10696 | rule: 'optional',
|
10697 | type: 'string',
|
10698 | name: 'msgId',
|
10699 | id: 4
|
10700 | }, {
|
10701 | rule: 'optional',
|
10702 | type: 'int64',
|
10703 | name: 'ackAt',
|
10704 | id: 5
|
10705 | }, {
|
10706 | rule: 'optional',
|
10707 | type: 'int64',
|
10708 | name: 'readAt',
|
10709 | id: 6
|
10710 | }, {
|
10711 | rule: 'optional',
|
10712 | type: 'int64',
|
10713 | name: 'patchTimestamp',
|
10714 | id: 7
|
10715 | }, {
|
10716 | rule: 'optional',
|
10717 | type: 'bool',
|
10718 | name: 'mentionAll',
|
10719 | id: 8
|
10720 | }, {
|
10721 | rule: 'repeated',
|
10722 | type: 'string',
|
10723 | name: 'mentionPids',
|
10724 | id: 9
|
10725 | }, {
|
10726 | rule: 'optional',
|
10727 | type: 'bool',
|
10728 | name: 'bin',
|
10729 | id: 10
|
10730 | }, {
|
10731 | rule: 'optional',
|
10732 | type: 'int32',
|
10733 | name: 'convType',
|
10734 | id: 11
|
10735 | }]
|
10736 | }, {
|
10737 | name: 'ConvMemberInfo',
|
10738 | syntax: 'proto2',
|
10739 | fields: [{
|
10740 | rule: 'optional',
|
10741 | type: 'string',
|
10742 | name: 'pid',
|
10743 | id: 1
|
10744 | }, {
|
10745 | rule: 'optional',
|
10746 | type: 'string',
|
10747 | name: 'role',
|
10748 | id: 2
|
10749 | }, {
|
10750 | rule: 'optional',
|
10751 | type: 'string',
|
10752 | name: 'infoId',
|
10753 | id: 3
|
10754 | }]
|
10755 | }, {
|
10756 | name: 'DataCommand',
|
10757 | syntax: 'proto2',
|
10758 | fields: [{
|
10759 | rule: 'repeated',
|
10760 | type: 'string',
|
10761 | name: 'ids',
|
10762 | id: 1
|
10763 | }, {
|
10764 | rule: 'repeated',
|
10765 | type: 'JsonObjectMessage',
|
10766 | name: 'msg',
|
10767 | id: 2
|
10768 | }, {
|
10769 | rule: 'optional',
|
10770 | type: 'bool',
|
10771 | name: 'offline',
|
10772 | id: 3
|
10773 | }]
|
10774 | }, {
|
10775 | name: 'SessionCommand',
|
10776 | syntax: 'proto2',
|
10777 | fields: [{
|
10778 | rule: 'optional',
|
10779 | type: 'int64',
|
10780 | name: 't',
|
10781 | id: 1
|
10782 | }, {
|
10783 | rule: 'optional',
|
10784 | type: 'string',
|
10785 | name: 'n',
|
10786 | id: 2
|
10787 | }, {
|
10788 | rule: 'optional',
|
10789 | type: 'string',
|
10790 | name: 's',
|
10791 | id: 3
|
10792 | }, {
|
10793 | rule: 'optional',
|
10794 | type: 'string',
|
10795 | name: 'ua',
|
10796 | id: 4
|
10797 | }, {
|
10798 | rule: 'optional',
|
10799 | type: 'bool',
|
10800 | name: 'r',
|
10801 | id: 5
|
10802 | }, {
|
10803 | rule: 'optional',
|
10804 | type: 'string',
|
10805 | name: 'tag',
|
10806 | id: 6
|
10807 | }, {
|
10808 | rule: 'optional',
|
10809 | type: 'string',
|
10810 | name: 'deviceId',
|
10811 | id: 7
|
10812 | }, {
|
10813 | rule: 'repeated',
|
10814 | type: 'string',
|
10815 | name: 'sessionPeerIds',
|
10816 | id: 8
|
10817 | }, {
|
10818 | rule: 'repeated',
|
10819 | type: 'string',
|
10820 | name: 'onlineSessionPeerIds',
|
10821 | id: 9
|
10822 | }, {
|
10823 | rule: 'optional',
|
10824 | type: 'string',
|
10825 | name: 'st',
|
10826 | id: 10
|
10827 | }, {
|
10828 | rule: 'optional',
|
10829 | type: 'int32',
|
10830 | name: 'stTtl',
|
10831 | id: 11
|
10832 | }, {
|
10833 | rule: 'optional',
|
10834 | type: 'int32',
|
10835 | name: 'code',
|
10836 | id: 12
|
10837 | }, {
|
10838 | rule: 'optional',
|
10839 | type: 'string',
|
10840 | name: 'reason',
|
10841 | id: 13
|
10842 | }, {
|
10843 | rule: 'optional',
|
10844 | type: 'string',
|
10845 | name: 'deviceToken',
|
10846 | id: 14
|
10847 | }, {
|
10848 | rule: 'optional',
|
10849 | type: 'bool',
|
10850 | name: 'sp',
|
10851 | id: 15
|
10852 | }, {
|
10853 | rule: 'optional',
|
10854 | type: 'string',
|
10855 | name: 'detail',
|
10856 | id: 16
|
10857 | }, {
|
10858 | rule: 'optional',
|
10859 | type: 'int64',
|
10860 | name: 'lastUnreadNotifTime',
|
10861 | id: 17
|
10862 | }, {
|
10863 | rule: 'optional',
|
10864 | type: 'int64',
|
10865 | name: 'lastPatchTime',
|
10866 | id: 18
|
10867 | }, {
|
10868 | rule: 'optional',
|
10869 | type: 'int64',
|
10870 | name: 'configBitmap',
|
10871 | id: 19
|
10872 | }]
|
10873 | }, {
|
10874 | name: 'ErrorCommand',
|
10875 | syntax: 'proto2',
|
10876 | fields: [{
|
10877 | rule: 'required',
|
10878 | type: 'int32',
|
10879 | name: 'code',
|
10880 | id: 1
|
10881 | }, {
|
10882 | rule: 'required',
|
10883 | type: 'string',
|
10884 | name: 'reason',
|
10885 | id: 2
|
10886 | }, {
|
10887 | rule: 'optional',
|
10888 | type: 'int32',
|
10889 | name: 'appCode',
|
10890 | id: 3
|
10891 | }, {
|
10892 | rule: 'optional',
|
10893 | type: 'string',
|
10894 | name: 'detail',
|
10895 | id: 4
|
10896 | }, {
|
10897 | rule: 'repeated',
|
10898 | type: 'string',
|
10899 | name: 'pids',
|
10900 | id: 5
|
10901 | }, {
|
10902 | rule: 'optional',
|
10903 | type: 'string',
|
10904 | name: 'appMsg',
|
10905 | id: 6
|
10906 | }]
|
10907 | }, {
|
10908 | name: 'DirectCommand',
|
10909 | syntax: 'proto2',
|
10910 | fields: [{
|
10911 | rule: 'optional',
|
10912 | type: 'string',
|
10913 | name: 'msg',
|
10914 | id: 1
|
10915 | }, {
|
10916 | rule: 'optional',
|
10917 | type: 'string',
|
10918 | name: 'uid',
|
10919 | id: 2
|
10920 | }, {
|
10921 | rule: 'optional',
|
10922 | type: 'string',
|
10923 | name: 'fromPeerId',
|
10924 | id: 3
|
10925 | }, {
|
10926 | rule: 'optional',
|
10927 | type: 'int64',
|
10928 | name: 'timestamp',
|
10929 | id: 4
|
10930 | }, {
|
10931 | rule: 'optional',
|
10932 | type: 'bool',
|
10933 | name: 'offline',
|
10934 | id: 5
|
10935 | }, {
|
10936 | rule: 'optional',
|
10937 | type: 'bool',
|
10938 | name: 'hasMore',
|
10939 | id: 6
|
10940 | }, {
|
10941 | rule: 'repeated',
|
10942 | type: 'string',
|
10943 | name: 'toPeerIds',
|
10944 | id: 7
|
10945 | }, {
|
10946 | rule: 'optional',
|
10947 | type: 'bool',
|
10948 | name: 'r',
|
10949 | id: 10
|
10950 | }, {
|
10951 | rule: 'optional',
|
10952 | type: 'string',
|
10953 | name: 'cid',
|
10954 | id: 11
|
10955 | }, {
|
10956 | rule: 'optional',
|
10957 | type: 'string',
|
10958 | name: 'id',
|
10959 | id: 12
|
10960 | }, {
|
10961 | rule: 'optional',
|
10962 | type: 'bool',
|
10963 | name: 'transient',
|
10964 | id: 13
|
10965 | }, {
|
10966 | rule: 'optional',
|
10967 | type: 'string',
|
10968 | name: 'dt',
|
10969 | id: 14
|
10970 | }, {
|
10971 | rule: 'optional',
|
10972 | type: 'string',
|
10973 | name: 'roomId',
|
10974 | id: 15
|
10975 | }, {
|
10976 | rule: 'optional',
|
10977 | type: 'string',
|
10978 | name: 'pushData',
|
10979 | id: 16
|
10980 | }, {
|
10981 | rule: 'optional',
|
10982 | type: 'bool',
|
10983 | name: 'will',
|
10984 | id: 17
|
10985 | }, {
|
10986 | rule: 'optional',
|
10987 | type: 'int64',
|
10988 | name: 'patchTimestamp',
|
10989 | id: 18
|
10990 | }, {
|
10991 | rule: 'optional',
|
10992 | type: 'bytes',
|
10993 | name: 'binaryMsg',
|
10994 | id: 19
|
10995 | }, {
|
10996 | rule: 'repeated',
|
10997 | type: 'string',
|
10998 | name: 'mentionPids',
|
10999 | id: 20
|
11000 | }, {
|
11001 | rule: 'optional',
|
11002 | type: 'bool',
|
11003 | name: 'mentionAll',
|
11004 | id: 21
|
11005 | }, {
|
11006 | rule: 'optional',
|
11007 | type: 'int32',
|
11008 | name: 'convType',
|
11009 | id: 22
|
11010 | }]
|
11011 | }, {
|
11012 | name: 'AckCommand',
|
11013 | syntax: 'proto2',
|
11014 | fields: [{
|
11015 | rule: 'optional',
|
11016 | type: 'int32',
|
11017 | name: 'code',
|
11018 | id: 1
|
11019 | }, {
|
11020 | rule: 'optional',
|
11021 | type: 'string',
|
11022 | name: 'reason',
|
11023 | id: 2
|
11024 | }, {
|
11025 | rule: 'optional',
|
11026 | type: 'string',
|
11027 | name: 'mid',
|
11028 | id: 3
|
11029 | }, {
|
11030 | rule: 'optional',
|
11031 | type: 'string',
|
11032 | name: 'cid',
|
11033 | id: 4
|
11034 | }, {
|
11035 | rule: 'optional',
|
11036 | type: 'int64',
|
11037 | name: 't',
|
11038 | id: 5
|
11039 | }, {
|
11040 | rule: 'optional',
|
11041 | type: 'string',
|
11042 | name: 'uid',
|
11043 | id: 6
|
11044 | }, {
|
11045 | rule: 'optional',
|
11046 | type: 'int64',
|
11047 | name: 'fromts',
|
11048 | id: 7
|
11049 | }, {
|
11050 | rule: 'optional',
|
11051 | type: 'int64',
|
11052 | name: 'tots',
|
11053 | id: 8
|
11054 | }, {
|
11055 | rule: 'optional',
|
11056 | type: 'string',
|
11057 | name: 'type',
|
11058 | id: 9
|
11059 | }, {
|
11060 | rule: 'repeated',
|
11061 | type: 'string',
|
11062 | name: 'ids',
|
11063 | id: 10
|
11064 | }, {
|
11065 | rule: 'optional',
|
11066 | type: 'int32',
|
11067 | name: 'appCode',
|
11068 | id: 11
|
11069 | }, {
|
11070 | rule: 'optional',
|
11071 | type: 'string',
|
11072 | name: 'appMsg',
|
11073 | id: 12
|
11074 | }]
|
11075 | }, {
|
11076 | name: 'UnreadCommand',
|
11077 | syntax: 'proto2',
|
11078 | fields: [{
|
11079 | rule: 'repeated',
|
11080 | type: 'UnreadTuple',
|
11081 | name: 'convs',
|
11082 | id: 1
|
11083 | }, {
|
11084 | rule: 'optional',
|
11085 | type: 'int64',
|
11086 | name: 'notifTime',
|
11087 | id: 2
|
11088 | }]
|
11089 | }, {
|
11090 | name: 'ConvCommand',
|
11091 | syntax: 'proto2',
|
11092 | fields: [{
|
11093 | rule: 'repeated',
|
11094 | type: 'string',
|
11095 | name: 'm',
|
11096 | id: 1
|
11097 | }, {
|
11098 | rule: 'optional',
|
11099 | type: 'bool',
|
11100 | name: 'transient',
|
11101 | id: 2
|
11102 | }, {
|
11103 | rule: 'optional',
|
11104 | type: 'bool',
|
11105 | name: 'unique',
|
11106 | id: 3
|
11107 | }, {
|
11108 | rule: 'optional',
|
11109 | type: 'string',
|
11110 | name: 'cid',
|
11111 | id: 4
|
11112 | }, {
|
11113 | rule: 'optional',
|
11114 | type: 'string',
|
11115 | name: 'cdate',
|
11116 | id: 5
|
11117 | }, {
|
11118 | rule: 'optional',
|
11119 | type: 'string',
|
11120 | name: 'initBy',
|
11121 | id: 6
|
11122 | }, {
|
11123 | rule: 'optional',
|
11124 | type: 'string',
|
11125 | name: 'sort',
|
11126 | id: 7
|
11127 | }, {
|
11128 | rule: 'optional',
|
11129 | type: 'int32',
|
11130 | name: 'limit',
|
11131 | id: 8
|
11132 | }, {
|
11133 | rule: 'optional',
|
11134 | type: 'int32',
|
11135 | name: 'skip',
|
11136 | id: 9
|
11137 | }, {
|
11138 | rule: 'optional',
|
11139 | type: 'int32',
|
11140 | name: 'flag',
|
11141 | id: 10
|
11142 | }, {
|
11143 | rule: 'optional',
|
11144 | type: 'int32',
|
11145 | name: 'count',
|
11146 | id: 11
|
11147 | }, {
|
11148 | rule: 'optional',
|
11149 | type: 'string',
|
11150 | name: 'udate',
|
11151 | id: 12
|
11152 | }, {
|
11153 | rule: 'optional',
|
11154 | type: 'int64',
|
11155 | name: 't',
|
11156 | id: 13
|
11157 | }, {
|
11158 | rule: 'optional',
|
11159 | type: 'string',
|
11160 | name: 'n',
|
11161 | id: 14
|
11162 | }, {
|
11163 | rule: 'optional',
|
11164 | type: 'string',
|
11165 | name: 's',
|
11166 | id: 15
|
11167 | }, {
|
11168 | rule: 'optional',
|
11169 | type: 'bool',
|
11170 | name: 'statusSub',
|
11171 | id: 16
|
11172 | }, {
|
11173 | rule: 'optional',
|
11174 | type: 'bool',
|
11175 | name: 'statusPub',
|
11176 | id: 17
|
11177 | }, {
|
11178 | rule: 'optional',
|
11179 | type: 'int32',
|
11180 | name: 'statusTTL',
|
11181 | id: 18
|
11182 | }, {
|
11183 | rule: 'optional',
|
11184 | type: 'string',
|
11185 | name: 'uniqueId',
|
11186 | id: 19
|
11187 | }, {
|
11188 | rule: 'optional',
|
11189 | type: 'string',
|
11190 | name: 'targetClientId',
|
11191 | id: 20
|
11192 | }, {
|
11193 | rule: 'optional',
|
11194 | type: 'int64',
|
11195 | name: 'maxReadTimestamp',
|
11196 | id: 21
|
11197 | }, {
|
11198 | rule: 'optional',
|
11199 | type: 'int64',
|
11200 | name: 'maxAckTimestamp',
|
11201 | id: 22
|
11202 | }, {
|
11203 | rule: 'optional',
|
11204 | type: 'bool',
|
11205 | name: 'queryAllMembers',
|
11206 | id: 23
|
11207 | }, {
|
11208 | rule: 'repeated',
|
11209 | type: 'MaxReadTuple',
|
11210 | name: 'maxReadTuples',
|
11211 | id: 24
|
11212 | }, {
|
11213 | rule: 'repeated',
|
11214 | type: 'string',
|
11215 | name: 'cids',
|
11216 | id: 25
|
11217 | }, {
|
11218 | rule: 'optional',
|
11219 | type: 'ConvMemberInfo',
|
11220 | name: 'info',
|
11221 | id: 26
|
11222 | }, {
|
11223 | rule: 'optional',
|
11224 | type: 'bool',
|
11225 | name: 'tempConv',
|
11226 | id: 27
|
11227 | }, {
|
11228 | rule: 'optional',
|
11229 | type: 'int32',
|
11230 | name: 'tempConvTTL',
|
11231 | id: 28
|
11232 | }, {
|
11233 | rule: 'repeated',
|
11234 | type: 'string',
|
11235 | name: 'tempConvIds',
|
11236 | id: 29
|
11237 | }, {
|
11238 | rule: 'repeated',
|
11239 | type: 'string',
|
11240 | name: 'allowedPids',
|
11241 | id: 30
|
11242 | }, {
|
11243 | rule: 'repeated',
|
11244 | type: 'ErrorCommand',
|
11245 | name: 'failedPids',
|
11246 | id: 31
|
11247 | }, {
|
11248 | rule: 'optional',
|
11249 | type: 'string',
|
11250 | name: 'next',
|
11251 | id: 40
|
11252 | }, {
|
11253 | rule: 'optional',
|
11254 | type: 'JsonObjectMessage',
|
11255 | name: 'results',
|
11256 | id: 100
|
11257 | }, {
|
11258 | rule: 'optional',
|
11259 | type: 'JsonObjectMessage',
|
11260 | name: 'where',
|
11261 | id: 101
|
11262 | }, {
|
11263 | rule: 'optional',
|
11264 | type: 'JsonObjectMessage',
|
11265 | name: 'attr',
|
11266 | id: 103
|
11267 | }, {
|
11268 | rule: 'optional',
|
11269 | type: 'JsonObjectMessage',
|
11270 | name: 'attrModified',
|
11271 | id: 104
|
11272 | }]
|
11273 | }, {
|
11274 | name: 'RoomCommand',
|
11275 | syntax: 'proto2',
|
11276 | fields: [{
|
11277 | rule: 'optional',
|
11278 | type: 'string',
|
11279 | name: 'roomId',
|
11280 | id: 1
|
11281 | }, {
|
11282 | rule: 'optional',
|
11283 | type: 'string',
|
11284 | name: 's',
|
11285 | id: 2
|
11286 | }, {
|
11287 | rule: 'optional',
|
11288 | type: 'int64',
|
11289 | name: 't',
|
11290 | id: 3
|
11291 | }, {
|
11292 | rule: 'optional',
|
11293 | type: 'string',
|
11294 | name: 'n',
|
11295 | id: 4
|
11296 | }, {
|
11297 | rule: 'optional',
|
11298 | type: 'bool',
|
11299 | name: 'transient',
|
11300 | id: 5
|
11301 | }, {
|
11302 | rule: 'repeated',
|
11303 | type: 'string',
|
11304 | name: 'roomPeerIds',
|
11305 | id: 6
|
11306 | }, {
|
11307 | rule: 'optional',
|
11308 | type: 'string',
|
11309 | name: 'byPeerId',
|
11310 | id: 7
|
11311 | }]
|
11312 | }, {
|
11313 | name: 'LogsCommand',
|
11314 | syntax: 'proto2',
|
11315 | fields: [{
|
11316 | rule: 'optional',
|
11317 | type: 'string',
|
11318 | name: 'cid',
|
11319 | id: 1
|
11320 | }, {
|
11321 | rule: 'optional',
|
11322 | type: 'int32',
|
11323 | name: 'l',
|
11324 | id: 2
|
11325 | }, {
|
11326 | rule: 'optional',
|
11327 | type: 'int32',
|
11328 | name: 'limit',
|
11329 | id: 3
|
11330 | }, {
|
11331 | rule: 'optional',
|
11332 | type: 'int64',
|
11333 | name: 't',
|
11334 | id: 4
|
11335 | }, {
|
11336 | rule: 'optional',
|
11337 | type: 'int64',
|
11338 | name: 'tt',
|
11339 | id: 5
|
11340 | }, {
|
11341 | rule: 'optional',
|
11342 | type: 'string',
|
11343 | name: 'tmid',
|
11344 | id: 6
|
11345 | }, {
|
11346 | rule: 'optional',
|
11347 | type: 'string',
|
11348 | name: 'mid',
|
11349 | id: 7
|
11350 | }, {
|
11351 | rule: 'optional',
|
11352 | type: 'string',
|
11353 | name: 'checksum',
|
11354 | id: 8
|
11355 | }, {
|
11356 | rule: 'optional',
|
11357 | type: 'bool',
|
11358 | name: 'stored',
|
11359 | id: 9
|
11360 | }, {
|
11361 | rule: 'optional',
|
11362 | type: 'QueryDirection',
|
11363 | name: 'direction',
|
11364 | id: 10,
|
11365 | options: {
|
11366 | default: 'OLD'
|
11367 | }
|
11368 | }, {
|
11369 | rule: 'optional',
|
11370 | type: 'bool',
|
11371 | name: 'tIncluded',
|
11372 | id: 11
|
11373 | }, {
|
11374 | rule: 'optional',
|
11375 | type: 'bool',
|
11376 | name: 'ttIncluded',
|
11377 | id: 12
|
11378 | }, {
|
11379 | rule: 'optional',
|
11380 | type: 'int32',
|
11381 | name: 'lctype',
|
11382 | id: 13
|
11383 | }, {
|
11384 | rule: 'repeated',
|
11385 | type: 'LogItem',
|
11386 | name: 'logs',
|
11387 | id: 105
|
11388 | }],
|
11389 | enums: [{
|
11390 | name: 'QueryDirection',
|
11391 | syntax: 'proto2',
|
11392 | values: [{
|
11393 | name: 'OLD',
|
11394 | id: 1
|
11395 | }, {
|
11396 | name: 'NEW',
|
11397 | id: 2
|
11398 | }]
|
11399 | }]
|
11400 | }, {
|
11401 | name: 'RcpCommand',
|
11402 | syntax: 'proto2',
|
11403 | fields: [{
|
11404 | rule: 'optional',
|
11405 | type: 'string',
|
11406 | name: 'id',
|
11407 | id: 1
|
11408 | }, {
|
11409 | rule: 'optional',
|
11410 | type: 'string',
|
11411 | name: 'cid',
|
11412 | id: 2
|
11413 | }, {
|
11414 | rule: 'optional',
|
11415 | type: 'int64',
|
11416 | name: 't',
|
11417 | id: 3
|
11418 | }, {
|
11419 | rule: 'optional',
|
11420 | type: 'bool',
|
11421 | name: 'read',
|
11422 | id: 4
|
11423 | }, {
|
11424 | rule: 'optional',
|
11425 | type: 'string',
|
11426 | name: 'from',
|
11427 | id: 5
|
11428 | }]
|
11429 | }, {
|
11430 | name: 'ReadTuple',
|
11431 | syntax: 'proto2',
|
11432 | fields: [{
|
11433 | rule: 'required',
|
11434 | type: 'string',
|
11435 | name: 'cid',
|
11436 | id: 1
|
11437 | }, {
|
11438 | rule: 'optional',
|
11439 | type: 'int64',
|
11440 | name: 'timestamp',
|
11441 | id: 2
|
11442 | }, {
|
11443 | rule: 'optional',
|
11444 | type: 'string',
|
11445 | name: 'mid',
|
11446 | id: 3
|
11447 | }]
|
11448 | }, {
|
11449 | name: 'MaxReadTuple',
|
11450 | syntax: 'proto2',
|
11451 | fields: [{
|
11452 | rule: 'optional',
|
11453 | type: 'string',
|
11454 | name: 'pid',
|
11455 | id: 1
|
11456 | }, {
|
11457 | rule: 'optional',
|
11458 | type: 'int64',
|
11459 | name: 'maxAckTimestamp',
|
11460 | id: 2
|
11461 | }, {
|
11462 | rule: 'optional',
|
11463 | type: 'int64',
|
11464 | name: 'maxReadTimestamp',
|
11465 | id: 3
|
11466 | }]
|
11467 | }, {
|
11468 | name: 'ReadCommand',
|
11469 | syntax: 'proto2',
|
11470 | fields: [{
|
11471 | rule: 'optional',
|
11472 | type: 'string',
|
11473 | name: 'cid',
|
11474 | id: 1
|
11475 | }, {
|
11476 | rule: 'repeated',
|
11477 | type: 'string',
|
11478 | name: 'cids',
|
11479 | id: 2
|
11480 | }, {
|
11481 | rule: 'repeated',
|
11482 | type: 'ReadTuple',
|
11483 | name: 'convs',
|
11484 | id: 3
|
11485 | }]
|
11486 | }, {
|
11487 | name: 'PresenceCommand',
|
11488 | syntax: 'proto2',
|
11489 | fields: [{
|
11490 | rule: 'optional',
|
11491 | type: 'StatusType',
|
11492 | name: 'status',
|
11493 | id: 1
|
11494 | }, {
|
11495 | rule: 'repeated',
|
11496 | type: 'string',
|
11497 | name: 'sessionPeerIds',
|
11498 | id: 2
|
11499 | }, {
|
11500 | rule: 'optional',
|
11501 | type: 'string',
|
11502 | name: 'cid',
|
11503 | id: 3
|
11504 | }]
|
11505 | }, {
|
11506 | name: 'ReportCommand',
|
11507 | syntax: 'proto2',
|
11508 | fields: [{
|
11509 | rule: 'optional',
|
11510 | type: 'bool',
|
11511 | name: 'initiative',
|
11512 | id: 1
|
11513 | }, {
|
11514 | rule: 'optional',
|
11515 | type: 'string',
|
11516 | name: 'type',
|
11517 | id: 2
|
11518 | }, {
|
11519 | rule: 'optional',
|
11520 | type: 'string',
|
11521 | name: 'data',
|
11522 | id: 3
|
11523 | }]
|
11524 | }, {
|
11525 | name: 'PatchItem',
|
11526 | syntax: 'proto2',
|
11527 | fields: [{
|
11528 | rule: 'optional',
|
11529 | type: 'string',
|
11530 | name: 'cid',
|
11531 | id: 1
|
11532 | }, {
|
11533 | rule: 'optional',
|
11534 | type: 'string',
|
11535 | name: 'mid',
|
11536 | id: 2
|
11537 | }, {
|
11538 | rule: 'optional',
|
11539 | type: 'int64',
|
11540 | name: 'timestamp',
|
11541 | id: 3
|
11542 | }, {
|
11543 | rule: 'optional',
|
11544 | type: 'bool',
|
11545 | name: 'recall',
|
11546 | id: 4
|
11547 | }, {
|
11548 | rule: 'optional',
|
11549 | type: 'string',
|
11550 | name: 'data',
|
11551 | id: 5
|
11552 | }, {
|
11553 | rule: 'optional',
|
11554 | type: 'int64',
|
11555 | name: 'patchTimestamp',
|
11556 | id: 6
|
11557 | }, {
|
11558 | rule: 'optional',
|
11559 | type: 'string',
|
11560 | name: 'from',
|
11561 | id: 7
|
11562 | }, {
|
11563 | rule: 'optional',
|
11564 | type: 'bytes',
|
11565 | name: 'binaryMsg',
|
11566 | id: 8
|
11567 | }, {
|
11568 | rule: 'optional',
|
11569 | type: 'bool',
|
11570 | name: 'mentionAll',
|
11571 | id: 9
|
11572 | }, {
|
11573 | rule: 'repeated',
|
11574 | type: 'string',
|
11575 | name: 'mentionPids',
|
11576 | id: 10
|
11577 | }, {
|
11578 | rule: 'optional',
|
11579 | type: 'int64',
|
11580 | name: 'patchCode',
|
11581 | id: 11
|
11582 | }, {
|
11583 | rule: 'optional',
|
11584 | type: 'string',
|
11585 | name: 'patchReason',
|
11586 | id: 12
|
11587 | }]
|
11588 | }, {
|
11589 | name: 'PatchCommand',
|
11590 | syntax: 'proto2',
|
11591 | fields: [{
|
11592 | rule: 'repeated',
|
11593 | type: 'PatchItem',
|
11594 | name: 'patches',
|
11595 | id: 1
|
11596 | }, {
|
11597 | rule: 'optional',
|
11598 | type: 'int64',
|
11599 | name: 'lastPatchTime',
|
11600 | id: 2
|
11601 | }]
|
11602 | }, {
|
11603 | name: 'PubsubCommand',
|
11604 | syntax: 'proto2',
|
11605 | fields: [{
|
11606 | rule: 'optional',
|
11607 | type: 'string',
|
11608 | name: 'cid',
|
11609 | id: 1
|
11610 | }, {
|
11611 | rule: 'repeated',
|
11612 | type: 'string',
|
11613 | name: 'cids',
|
11614 | id: 2
|
11615 | }, {
|
11616 | rule: 'optional',
|
11617 | type: 'string',
|
11618 | name: 'topic',
|
11619 | id: 3
|
11620 | }, {
|
11621 | rule: 'optional',
|
11622 | type: 'string',
|
11623 | name: 'subtopic',
|
11624 | id: 4
|
11625 | }, {
|
11626 | rule: 'repeated',
|
11627 | type: 'string',
|
11628 | name: 'topics',
|
11629 | id: 5
|
11630 | }, {
|
11631 | rule: 'repeated',
|
11632 | type: 'string',
|
11633 | name: 'subtopics',
|
11634 | id: 6
|
11635 | }, {
|
11636 | rule: 'optional',
|
11637 | type: 'JsonObjectMessage',
|
11638 | name: 'results',
|
11639 | id: 7
|
11640 | }]
|
11641 | }, {
|
11642 | name: 'BlacklistCommand',
|
11643 | syntax: 'proto2',
|
11644 | fields: [{
|
11645 | rule: 'optional',
|
11646 | type: 'string',
|
11647 | name: 'srcCid',
|
11648 | id: 1
|
11649 | }, {
|
11650 | rule: 'repeated',
|
11651 | type: 'string',
|
11652 | name: 'toPids',
|
11653 | id: 2
|
11654 | }, {
|
11655 | rule: 'optional',
|
11656 | type: 'string',
|
11657 | name: 'srcPid',
|
11658 | id: 3
|
11659 | }, {
|
11660 | rule: 'repeated',
|
11661 | type: 'string',
|
11662 | name: 'toCids',
|
11663 | id: 4
|
11664 | }, {
|
11665 | rule: 'optional',
|
11666 | type: 'int32',
|
11667 | name: 'limit',
|
11668 | id: 5
|
11669 | }, {
|
11670 | rule: 'optional',
|
11671 | type: 'string',
|
11672 | name: 'next',
|
11673 | id: 6
|
11674 | }, {
|
11675 | rule: 'repeated',
|
11676 | type: 'string',
|
11677 | name: 'blockedPids',
|
11678 | id: 8
|
11679 | }, {
|
11680 | rule: 'repeated',
|
11681 | type: 'string',
|
11682 | name: 'blockedCids',
|
11683 | id: 9
|
11684 | }, {
|
11685 | rule: 'repeated',
|
11686 | type: 'string',
|
11687 | name: 'allowedPids',
|
11688 | id: 10
|
11689 | }, {
|
11690 | rule: 'repeated',
|
11691 | type: 'ErrorCommand',
|
11692 | name: 'failedPids',
|
11693 | id: 11
|
11694 | }, {
|
11695 | rule: 'optional',
|
11696 | type: 'int64',
|
11697 | name: 't',
|
11698 | id: 12
|
11699 | }, {
|
11700 | rule: 'optional',
|
11701 | type: 'string',
|
11702 | name: 'n',
|
11703 | id: 13
|
11704 | }, {
|
11705 | rule: 'optional',
|
11706 | type: 'string',
|
11707 | name: 's',
|
11708 | id: 14
|
11709 | }]
|
11710 | }, {
|
11711 | name: 'GenericCommand',
|
11712 | syntax: 'proto2',
|
11713 | fields: [{
|
11714 | rule: 'optional',
|
11715 | type: 'CommandType',
|
11716 | name: 'cmd',
|
11717 | id: 1
|
11718 | }, {
|
11719 | rule: 'optional',
|
11720 | type: 'OpType',
|
11721 | name: 'op',
|
11722 | id: 2
|
11723 | }, {
|
11724 | rule: 'optional',
|
11725 | type: 'string',
|
11726 | name: 'appId',
|
11727 | id: 3
|
11728 | }, {
|
11729 | rule: 'optional',
|
11730 | type: 'string',
|
11731 | name: 'peerId',
|
11732 | id: 4
|
11733 | }, {
|
11734 | rule: 'optional',
|
11735 | type: 'int32',
|
11736 | name: 'i',
|
11737 | id: 5
|
11738 | }, {
|
11739 | rule: 'optional',
|
11740 | type: 'string',
|
11741 | name: 'installationId',
|
11742 | id: 6
|
11743 | }, {
|
11744 | rule: 'optional',
|
11745 | type: 'int32',
|
11746 | name: 'priority',
|
11747 | id: 7
|
11748 | }, {
|
11749 | rule: 'optional',
|
11750 | type: 'int32',
|
11751 | name: 'service',
|
11752 | id: 8
|
11753 | }, {
|
11754 | rule: 'optional',
|
11755 | type: 'int64',
|
11756 | name: 'serverTs',
|
11757 | id: 9
|
11758 | }, {
|
11759 | rule: 'optional',
|
11760 | type: 'int64',
|
11761 | name: 'clientTs',
|
11762 | id: 10
|
11763 | }, {
|
11764 | rule: 'optional',
|
11765 | type: 'int32',
|
11766 | name: 'notificationType',
|
11767 | id: 11
|
11768 | }, {
|
11769 | rule: 'optional',
|
11770 | type: 'DataCommand',
|
11771 | name: 'dataMessage',
|
11772 | id: 101
|
11773 | }, {
|
11774 | rule: 'optional',
|
11775 | type: 'SessionCommand',
|
11776 | name: 'sessionMessage',
|
11777 | id: 102
|
11778 | }, {
|
11779 | rule: 'optional',
|
11780 | type: 'ErrorCommand',
|
11781 | name: 'errorMessage',
|
11782 | id: 103
|
11783 | }, {
|
11784 | rule: 'optional',
|
11785 | type: 'DirectCommand',
|
11786 | name: 'directMessage',
|
11787 | id: 104
|
11788 | }, {
|
11789 | rule: 'optional',
|
11790 | type: 'AckCommand',
|
11791 | name: 'ackMessage',
|
11792 | id: 105
|
11793 | }, {
|
11794 | rule: 'optional',
|
11795 | type: 'UnreadCommand',
|
11796 | name: 'unreadMessage',
|
11797 | id: 106
|
11798 | }, {
|
11799 | rule: 'optional',
|
11800 | type: 'ReadCommand',
|
11801 | name: 'readMessage',
|
11802 | id: 107
|
11803 | }, {
|
11804 | rule: 'optional',
|
11805 | type: 'RcpCommand',
|
11806 | name: 'rcpMessage',
|
11807 | id: 108
|
11808 | }, {
|
11809 | rule: 'optional',
|
11810 | type: 'LogsCommand',
|
11811 | name: 'logsMessage',
|
11812 | id: 109
|
11813 | }, {
|
11814 | rule: 'optional',
|
11815 | type: 'ConvCommand',
|
11816 | name: 'convMessage',
|
11817 | id: 110
|
11818 | }, {
|
11819 | rule: 'optional',
|
11820 | type: 'RoomCommand',
|
11821 | name: 'roomMessage',
|
11822 | id: 111
|
11823 | }, {
|
11824 | rule: 'optional',
|
11825 | type: 'PresenceCommand',
|
11826 | name: 'presenceMessage',
|
11827 | id: 112
|
11828 | }, {
|
11829 | rule: 'optional',
|
11830 | type: 'ReportCommand',
|
11831 | name: 'reportMessage',
|
11832 | id: 113
|
11833 | }, {
|
11834 | rule: 'optional',
|
11835 | type: 'PatchCommand',
|
11836 | name: 'patchMessage',
|
11837 | id: 114
|
11838 | }, {
|
11839 | rule: 'optional',
|
11840 | type: 'PubsubCommand',
|
11841 | name: 'pubsubMessage',
|
11842 | id: 115
|
11843 | }, {
|
11844 | rule: 'optional',
|
11845 | type: 'BlacklistCommand',
|
11846 | name: 'blacklistMessage',
|
11847 | id: 116
|
11848 | }]
|
11849 | }],
|
11850 | enums: [{
|
11851 | name: 'CommandType',
|
11852 | syntax: 'proto2',
|
11853 | values: [{
|
11854 | name: 'session',
|
11855 | id: 0
|
11856 | }, {
|
11857 | name: 'conv',
|
11858 | id: 1
|
11859 | }, {
|
11860 | name: 'direct',
|
11861 | id: 2
|
11862 | }, {
|
11863 | name: 'ack',
|
11864 | id: 3
|
11865 | }, {
|
11866 | name: 'rcp',
|
11867 | id: 4
|
11868 | }, {
|
11869 | name: 'unread',
|
11870 | id: 5
|
11871 | }, {
|
11872 | name: 'logs',
|
11873 | id: 6
|
11874 | }, {
|
11875 | name: 'error',
|
11876 | id: 7
|
11877 | }, {
|
11878 | name: 'login',
|
11879 | id: 8
|
11880 | }, {
|
11881 | name: 'data',
|
11882 | id: 9
|
11883 | }, {
|
11884 | name: 'room',
|
11885 | id: 10
|
11886 | }, {
|
11887 | name: 'read',
|
11888 | id: 11
|
11889 | }, {
|
11890 | name: 'presence',
|
11891 | id: 12
|
11892 | }, {
|
11893 | name: 'report',
|
11894 | id: 13
|
11895 | }, {
|
11896 | name: 'echo',
|
11897 | id: 14
|
11898 | }, {
|
11899 | name: 'loggedin',
|
11900 | id: 15
|
11901 | }, {
|
11902 | name: 'logout',
|
11903 | id: 16
|
11904 | }, {
|
11905 | name: 'loggedout',
|
11906 | id: 17
|
11907 | }, {
|
11908 | name: 'patch',
|
11909 | id: 18
|
11910 | }, {
|
11911 | name: 'pubsub',
|
11912 | id: 19
|
11913 | }, {
|
11914 | name: 'blacklist',
|
11915 | id: 20
|
11916 | }, {
|
11917 | name: 'goaway',
|
11918 | id: 21
|
11919 | }]
|
11920 | }, {
|
11921 | name: 'OpType',
|
11922 | syntax: 'proto2',
|
11923 | values: [{
|
11924 | name: 'open',
|
11925 | id: 1
|
11926 | }, {
|
11927 | name: 'add',
|
11928 | id: 2
|
11929 | }, {
|
11930 | name: 'remove',
|
11931 | id: 3
|
11932 | }, {
|
11933 | name: 'close',
|
11934 | id: 4
|
11935 | }, {
|
11936 | name: 'opened',
|
11937 | id: 5
|
11938 | }, {
|
11939 | name: 'closed',
|
11940 | id: 6
|
11941 | }, {
|
11942 | name: 'query',
|
11943 | id: 7
|
11944 | }, {
|
11945 | name: 'query_result',
|
11946 | id: 8
|
11947 | }, {
|
11948 | name: 'conflict',
|
11949 | id: 9
|
11950 | }, {
|
11951 | name: 'added',
|
11952 | id: 10
|
11953 | }, {
|
11954 | name: 'removed',
|
11955 | id: 11
|
11956 | }, {
|
11957 | name: 'refresh',
|
11958 | id: 12
|
11959 | }, {
|
11960 | name: 'refreshed',
|
11961 | id: 13
|
11962 | }, {
|
11963 | name: 'start',
|
11964 | id: 30
|
11965 | }, {
|
11966 | name: 'started',
|
11967 | id: 31
|
11968 | }, {
|
11969 | name: 'joined',
|
11970 | id: 32
|
11971 | }, {
|
11972 | name: 'members_joined',
|
11973 | id: 33
|
11974 | }, {
|
11975 | name: 'left',
|
11976 | id: 39
|
11977 | }, {
|
11978 | name: 'members_left',
|
11979 | id: 40
|
11980 | }, {
|
11981 | name: 'results',
|
11982 | id: 42
|
11983 | }, {
|
11984 | name: 'count',
|
11985 | id: 43
|
11986 | }, {
|
11987 | name: 'result',
|
11988 | id: 44
|
11989 | }, {
|
11990 | name: 'update',
|
11991 | id: 45
|
11992 | }, {
|
11993 | name: 'updated',
|
11994 | id: 46
|
11995 | }, {
|
11996 | name: 'mute',
|
11997 | id: 47
|
11998 | }, {
|
11999 | name: 'unmute',
|
12000 | id: 48
|
12001 | }, {
|
12002 | name: 'status',
|
12003 | id: 49
|
12004 | }, {
|
12005 | name: 'members',
|
12006 | id: 50
|
12007 | }, {
|
12008 | name: 'max_read',
|
12009 | id: 51
|
12010 | }, {
|
12011 | name: 'is_member',
|
12012 | id: 52
|
12013 | }, {
|
12014 | name: 'member_info_update',
|
12015 | id: 53
|
12016 | }, {
|
12017 | name: 'member_info_updated',
|
12018 | id: 54
|
12019 | }, {
|
12020 | name: 'member_info_changed',
|
12021 | id: 55
|
12022 | }, {
|
12023 | name: 'join',
|
12024 | id: 80
|
12025 | }, {
|
12026 | name: 'invite',
|
12027 | id: 81
|
12028 | }, {
|
12029 | name: 'leave',
|
12030 | id: 82
|
12031 | }, {
|
12032 | name: 'kick',
|
12033 | id: 83
|
12034 | }, {
|
12035 | name: 'reject',
|
12036 | id: 84
|
12037 | }, {
|
12038 | name: 'invited',
|
12039 | id: 85
|
12040 | }, {
|
12041 | name: 'kicked',
|
12042 | id: 86
|
12043 | }, {
|
12044 | name: 'upload',
|
12045 | id: 100
|
12046 | }, {
|
12047 | name: 'uploaded',
|
12048 | id: 101
|
12049 | }, {
|
12050 | name: 'subscribe',
|
12051 | id: 120
|
12052 | }, {
|
12053 | name: 'subscribed',
|
12054 | id: 121
|
12055 | }, {
|
12056 | name: 'unsubscribe',
|
12057 | id: 122
|
12058 | }, {
|
12059 | name: 'unsubscribed',
|
12060 | id: 123
|
12061 | }, {
|
12062 | name: 'is_subscribed',
|
12063 | id: 124
|
12064 | }, {
|
12065 | name: 'modify',
|
12066 | id: 150
|
12067 | }, {
|
12068 | name: 'modified',
|
12069 | id: 151
|
12070 | }, {
|
12071 | name: 'block',
|
12072 | id: 170
|
12073 | }, {
|
12074 | name: 'unblock',
|
12075 | id: 171
|
12076 | }, {
|
12077 | name: 'blocked',
|
12078 | id: 172
|
12079 | }, {
|
12080 | name: 'unblocked',
|
12081 | id: 173
|
12082 | }, {
|
12083 | name: 'members_blocked',
|
12084 | id: 174
|
12085 | }, {
|
12086 | name: 'members_unblocked',
|
12087 | id: 175
|
12088 | }, {
|
12089 | name: 'check_block',
|
12090 | id: 176
|
12091 | }, {
|
12092 | name: 'check_result',
|
12093 | id: 177
|
12094 | }, {
|
12095 | name: 'add_shutup',
|
12096 | id: 180
|
12097 | }, {
|
12098 | name: 'remove_shutup',
|
12099 | id: 181
|
12100 | }, {
|
12101 | name: 'query_shutup',
|
12102 | id: 182
|
12103 | }, {
|
12104 | name: 'shutup_added',
|
12105 | id: 183
|
12106 | }, {
|
12107 | name: 'shutup_removed',
|
12108 | id: 184
|
12109 | }, {
|
12110 | name: 'shutup_result',
|
12111 | id: 185
|
12112 | }, {
|
12113 | name: 'shutuped',
|
12114 | id: 186
|
12115 | }, {
|
12116 | name: 'unshutuped',
|
12117 | id: 187
|
12118 | }, {
|
12119 | name: 'members_shutuped',
|
12120 | id: 188
|
12121 | }, {
|
12122 | name: 'members_unshutuped',
|
12123 | id: 189
|
12124 | }, {
|
12125 | name: 'check_shutup',
|
12126 | id: 190
|
12127 | }]
|
12128 | }, {
|
12129 | name: 'StatusType',
|
12130 | syntax: 'proto2',
|
12131 | values: [{
|
12132 | name: 'on',
|
12133 | id: 1
|
12134 | }, {
|
12135 | name: 'off',
|
12136 | id: 2
|
12137 | }]
|
12138 | }],
|
12139 | isNamespace: true
|
12140 | }).build();
|
12141 |
|
12142 | var _messages$push_server = messageCompiled.push_server.messages2,
|
12143 | JsonObjectMessage = _messages$push_server.JsonObjectMessage,
|
12144 | UnreadTuple = _messages$push_server.UnreadTuple,
|
12145 | LogItem = _messages$push_server.LogItem,
|
12146 | DataCommand = _messages$push_server.DataCommand,
|
12147 | SessionCommand = _messages$push_server.SessionCommand,
|
12148 | ErrorCommand = _messages$push_server.ErrorCommand,
|
12149 | DirectCommand = _messages$push_server.DirectCommand,
|
12150 | AckCommand = _messages$push_server.AckCommand,
|
12151 | UnreadCommand = _messages$push_server.UnreadCommand,
|
12152 | ConvCommand = _messages$push_server.ConvCommand,
|
12153 | RoomCommand = _messages$push_server.RoomCommand,
|
12154 | LogsCommand = _messages$push_server.LogsCommand,
|
12155 | RcpCommand = _messages$push_server.RcpCommand,
|
12156 | ReadTuple = _messages$push_server.ReadTuple,
|
12157 | MaxReadTuple = _messages$push_server.MaxReadTuple,
|
12158 | ReadCommand = _messages$push_server.ReadCommand,
|
12159 | PresenceCommand = _messages$push_server.PresenceCommand,
|
12160 | ReportCommand = _messages$push_server.ReportCommand,
|
12161 | GenericCommand = _messages$push_server.GenericCommand,
|
12162 | BlacklistCommand = _messages$push_server.BlacklistCommand,
|
12163 | PatchCommand = _messages$push_server.PatchCommand,
|
12164 | PatchItem = _messages$push_server.PatchItem,
|
12165 | ConvMemberInfo = _messages$push_server.ConvMemberInfo,
|
12166 | CommandType = _messages$push_server.CommandType,
|
12167 | OpType = _messages$push_server.OpType,
|
12168 | StatusType = _messages$push_server.StatusType;
|
12169 |
|
12170 | var message = Object.freeze({
|
12171 | JsonObjectMessage: JsonObjectMessage,
|
12172 | UnreadTuple: UnreadTuple,
|
12173 | LogItem: LogItem,
|
12174 | DataCommand: DataCommand,
|
12175 | SessionCommand: SessionCommand,
|
12176 | ErrorCommand: ErrorCommand,
|
12177 | DirectCommand: DirectCommand,
|
12178 | AckCommand: AckCommand,
|
12179 | UnreadCommand: UnreadCommand,
|
12180 | ConvCommand: ConvCommand,
|
12181 | RoomCommand: RoomCommand,
|
12182 | LogsCommand: LogsCommand,
|
12183 | RcpCommand: RcpCommand,
|
12184 | ReadTuple: ReadTuple,
|
12185 | MaxReadTuple: MaxReadTuple,
|
12186 | ReadCommand: ReadCommand,
|
12187 | PresenceCommand: PresenceCommand,
|
12188 | ReportCommand: ReportCommand,
|
12189 | GenericCommand: GenericCommand,
|
12190 | BlacklistCommand: BlacklistCommand,
|
12191 | PatchCommand: PatchCommand,
|
12192 | PatchItem: PatchItem,
|
12193 | ConvMemberInfo: ConvMemberInfo,
|
12194 | CommandType: CommandType,
|
12195 | OpType: OpType,
|
12196 | StatusType: StatusType
|
12197 | });
|
12198 |
|
12199 | var eventemitter3 = createCommonjsModule(function (module) {
|
12200 |
|
12201 | var has = Object.prototype.hasOwnProperty
|
12202 | , prefix = '~';
|
12203 |
|
12204 | |
12205 |
|
12206 |
|
12207 |
|
12208 |
|
12209 |
|
12210 |
|
12211 | function Events() {}
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 |
|
12217 |
|
12218 |
|
12219 |
|
12220 | if (Object.create) {
|
12221 | Events.prototype = Object.create(null);
|
12222 |
|
12223 |
|
12224 |
|
12225 |
|
12226 |
|
12227 | if (!new Events().__proto__) prefix = false;
|
12228 | }
|
12229 |
|
12230 | |
12231 |
|
12232 |
|
12233 |
|
12234 |
|
12235 |
|
12236 |
|
12237 |
|
12238 |
|
12239 | function EE(fn, context, once) {
|
12240 | this.fn = fn;
|
12241 | this.context = context;
|
12242 | this.once = once || false;
|
12243 | }
|
12244 |
|
12245 | |
12246 |
|
12247 |
|
12248 |
|
12249 |
|
12250 |
|
12251 |
|
12252 |
|
12253 |
|
12254 |
|
12255 |
|
12256 | function addListener(emitter, event, fn, context, once) {
|
12257 | if (typeof fn !== 'function') {
|
12258 | throw new TypeError('The listener must be a function');
|
12259 | }
|
12260 |
|
12261 | var listener = new EE(fn, context || emitter, once)
|
12262 | , evt = prefix ? prefix + event : event;
|
12263 |
|
12264 | if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
12265 | else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
12266 | else emitter._events[evt] = [emitter._events[evt], listener];
|
12267 |
|
12268 | return emitter;
|
12269 | }
|
12270 |
|
12271 | |
12272 |
|
12273 |
|
12274 |
|
12275 |
|
12276 |
|
12277 |
|
12278 | function clearEvent(emitter, evt) {
|
12279 | if (--emitter._eventsCount === 0) emitter._events = new Events();
|
12280 | else delete emitter._events[evt];
|
12281 | }
|
12282 |
|
12283 | |
12284 |
|
12285 |
|
12286 |
|
12287 |
|
12288 |
|
12289 |
|
12290 | function EventEmitter() {
|
12291 | this._events = new Events();
|
12292 | this._eventsCount = 0;
|
12293 | }
|
12294 |
|
12295 | |
12296 |
|
12297 |
|
12298 |
|
12299 |
|
12300 |
|
12301 |
|
12302 | EventEmitter.prototype.eventNames = function eventNames() {
|
12303 | var names = []
|
12304 | , events
|
12305 | , name;
|
12306 |
|
12307 | if (this._eventsCount === 0) return names;
|
12308 |
|
12309 | for (name in (events = this._events)) {
|
12310 | if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
12311 | }
|
12312 |
|
12313 | if (Object.getOwnPropertySymbols) {
|
12314 | return names.concat(Object.getOwnPropertySymbols(events));
|
12315 | }
|
12316 |
|
12317 | return names;
|
12318 | };
|
12319 |
|
12320 | |
12321 |
|
12322 |
|
12323 |
|
12324 |
|
12325 |
|
12326 |
|
12327 | EventEmitter.prototype.listeners = function listeners(event) {
|
12328 | var evt = prefix ? prefix + event : event
|
12329 | , handlers = this._events[evt];
|
12330 |
|
12331 | if (!handlers) return [];
|
12332 | if (handlers.fn) return [handlers.fn];
|
12333 |
|
12334 | for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
12335 | ee[i] = handlers[i].fn;
|
12336 | }
|
12337 |
|
12338 | return ee;
|
12339 | };
|
12340 |
|
12341 | |
12342 |
|
12343 |
|
12344 |
|
12345 |
|
12346 |
|
12347 |
|
12348 | EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
12349 | var evt = prefix ? prefix + event : event
|
12350 | , listeners = this._events[evt];
|
12351 |
|
12352 | if (!listeners) return 0;
|
12353 | if (listeners.fn) return 1;
|
12354 | return listeners.length;
|
12355 | };
|
12356 |
|
12357 | |
12358 |
|
12359 |
|
12360 |
|
12361 |
|
12362 |
|
12363 |
|
12364 | EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
12365 | var evt = prefix ? prefix + event : event;
|
12366 |
|
12367 | if (!this._events[evt]) return false;
|
12368 |
|
12369 | var listeners = this._events[evt]
|
12370 | , len = arguments.length
|
12371 | , args
|
12372 | , i;
|
12373 |
|
12374 | if (listeners.fn) {
|
12375 | if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
12376 |
|
12377 | switch (len) {
|
12378 | case 1: return listeners.fn.call(listeners.context), true;
|
12379 | case 2: return listeners.fn.call(listeners.context, a1), true;
|
12380 | case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
12381 | case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
12382 | case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
12383 | case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
12384 | }
|
12385 |
|
12386 | for (i = 1, args = new Array(len -1); i < len; i++) {
|
12387 | args[i - 1] = arguments[i];
|
12388 | }
|
12389 |
|
12390 | listeners.fn.apply(listeners.context, args);
|
12391 | } else {
|
12392 | var length = listeners.length
|
12393 | , j;
|
12394 |
|
12395 | for (i = 0; i < length; i++) {
|
12396 | if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
12397 |
|
12398 | switch (len) {
|
12399 | case 1: listeners[i].fn.call(listeners[i].context); break;
|
12400 | case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
12401 | case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
12402 | case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
12403 | default:
|
12404 | if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
12405 | args[j - 1] = arguments[j];
|
12406 | }
|
12407 |
|
12408 | listeners[i].fn.apply(listeners[i].context, args);
|
12409 | }
|
12410 | }
|
12411 | }
|
12412 |
|
12413 | return true;
|
12414 | };
|
12415 |
|
12416 | |
12417 |
|
12418 |
|
12419 |
|
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 |
|
12425 | EventEmitter.prototype.on = function on(event, fn, context) {
|
12426 | return addListener(this, event, fn, context, false);
|
12427 | };
|
12428 |
|
12429 | |
12430 |
|
12431 |
|
12432 |
|
12433 |
|
12434 |
|
12435 |
|
12436 |
|
12437 |
|
12438 | EventEmitter.prototype.once = function once(event, fn, context) {
|
12439 | return addListener(this, event, fn, context, true);
|
12440 | };
|
12441 |
|
12442 | |
12443 |
|
12444 |
|
12445 |
|
12446 |
|
12447 |
|
12448 |
|
12449 |
|
12450 |
|
12451 |
|
12452 | EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
12453 | var evt = prefix ? prefix + event : event;
|
12454 |
|
12455 | if (!this._events[evt]) return this;
|
12456 | if (!fn) {
|
12457 | clearEvent(this, evt);
|
12458 | return this;
|
12459 | }
|
12460 |
|
12461 | var listeners = this._events[evt];
|
12462 |
|
12463 | if (listeners.fn) {
|
12464 | if (
|
12465 | listeners.fn === fn &&
|
12466 | (!once || listeners.once) &&
|
12467 | (!context || listeners.context === context)
|
12468 | ) {
|
12469 | clearEvent(this, evt);
|
12470 | }
|
12471 | } else {
|
12472 | for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
12473 | if (
|
12474 | listeners[i].fn !== fn ||
|
12475 | (once && !listeners[i].once) ||
|
12476 | (context && listeners[i].context !== context)
|
12477 | ) {
|
12478 | events.push(listeners[i]);
|
12479 | }
|
12480 | }
|
12481 |
|
12482 |
|
12483 |
|
12484 |
|
12485 | if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
12486 | else clearEvent(this, evt);
|
12487 | }
|
12488 |
|
12489 | return this;
|
12490 | };
|
12491 |
|
12492 | |
12493 |
|
12494 |
|
12495 |
|
12496 |
|
12497 |
|
12498 |
|
12499 | EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
12500 | var evt;
|
12501 |
|
12502 | if (event) {
|
12503 | evt = prefix ? prefix + event : event;
|
12504 | if (this._events[evt]) clearEvent(this, evt);
|
12505 | } else {
|
12506 | this._events = new Events();
|
12507 | this._eventsCount = 0;
|
12508 | }
|
12509 |
|
12510 | return this;
|
12511 | };
|
12512 |
|
12513 |
|
12514 |
|
12515 |
|
12516 | EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
12517 | EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
12518 |
|
12519 |
|
12520 |
|
12521 |
|
12522 | EventEmitter.prefixed = prefix;
|
12523 |
|
12524 |
|
12525 |
|
12526 |
|
12527 | EventEmitter.EventEmitter = EventEmitter;
|
12528 |
|
12529 |
|
12530 |
|
12531 |
|
12532 | {
|
12533 | module.exports = EventEmitter;
|
12534 | }
|
12535 | });
|
12536 |
|
12537 | var runtime = createCommonjsModule(function (module) {
|
12538 | |
12539 |
|
12540 |
|
12541 |
|
12542 |
|
12543 |
|
12544 |
|
12545 | !(function(global) {
|
12546 |
|
12547 | var Op = Object.prototype;
|
12548 | var hasOwn = Op.hasOwnProperty;
|
12549 | var undefined$1;
|
12550 | var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
12551 | var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
12552 | var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
12553 | var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
12554 | var runtime = global.regeneratorRuntime;
|
12555 | if (runtime) {
|
12556 | {
|
12557 |
|
12558 |
|
12559 | module.exports = runtime;
|
12560 | }
|
12561 |
|
12562 |
|
12563 | return;
|
12564 | }
|
12565 |
|
12566 |
|
12567 |
|
12568 | runtime = global.regeneratorRuntime = module.exports;
|
12569 |
|
12570 | function wrap(innerFn, outerFn, self, tryLocsList) {
|
12571 |
|
12572 | var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
12573 | var generator = Object.create(protoGenerator.prototype);
|
12574 | var context = new Context(tryLocsList || []);
|
12575 |
|
12576 |
|
12577 |
|
12578 | generator._invoke = makeInvokeMethod(innerFn, self, context);
|
12579 |
|
12580 | return generator;
|
12581 | }
|
12582 | runtime.wrap = wrap;
|
12583 |
|
12584 |
|
12585 |
|
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 |
|
12591 |
|
12592 |
|
12593 |
|
12594 | function tryCatch(fn, obj, arg) {
|
12595 | try {
|
12596 | return { type: "normal", arg: fn.call(obj, arg) };
|
12597 | } catch (err) {
|
12598 | return { type: "throw", arg: err };
|
12599 | }
|
12600 | }
|
12601 |
|
12602 | var GenStateSuspendedStart = "suspendedStart";
|
12603 | var GenStateSuspendedYield = "suspendedYield";
|
12604 | var GenStateExecuting = "executing";
|
12605 | var GenStateCompleted = "completed";
|
12606 |
|
12607 |
|
12608 |
|
12609 | var ContinueSentinel = {};
|
12610 |
|
12611 |
|
12612 |
|
12613 |
|
12614 |
|
12615 | function Generator() {}
|
12616 | function GeneratorFunction() {}
|
12617 | function GeneratorFunctionPrototype() {}
|
12618 |
|
12619 |
|
12620 |
|
12621 | var IteratorPrototype = {};
|
12622 | IteratorPrototype[iteratorSymbol] = function () {
|
12623 | return this;
|
12624 | };
|
12625 |
|
12626 | var getProto = Object.getPrototypeOf;
|
12627 | var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
12628 | if (NativeIteratorPrototype &&
|
12629 | NativeIteratorPrototype !== Op &&
|
12630 | hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
12631 |
|
12632 |
|
12633 | IteratorPrototype = NativeIteratorPrototype;
|
12634 | }
|
12635 |
|
12636 | var Gp = GeneratorFunctionPrototype.prototype =
|
12637 | Generator.prototype = Object.create(IteratorPrototype);
|
12638 | GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
|
12639 | GeneratorFunctionPrototype.constructor = GeneratorFunction;
|
12640 | GeneratorFunctionPrototype[toStringTagSymbol] =
|
12641 | GeneratorFunction.displayName = "GeneratorFunction";
|
12642 |
|
12643 |
|
12644 |
|
12645 | function defineIteratorMethods(prototype) {
|
12646 | ["next", "throw", "return"].forEach(function(method) {
|
12647 | prototype[method] = function(arg) {
|
12648 | return this._invoke(method, arg);
|
12649 | };
|
12650 | });
|
12651 | }
|
12652 |
|
12653 | runtime.isGeneratorFunction = function(genFun) {
|
12654 | var ctor = typeof genFun === "function" && genFun.constructor;
|
12655 | return ctor
|
12656 | ? ctor === GeneratorFunction ||
|
12657 |
|
12658 |
|
12659 | (ctor.displayName || ctor.name) === "GeneratorFunction"
|
12660 | : false;
|
12661 | };
|
12662 |
|
12663 | runtime.mark = function(genFun) {
|
12664 | if (Object.setPrototypeOf) {
|
12665 | Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
12666 | } else {
|
12667 | genFun.__proto__ = GeneratorFunctionPrototype;
|
12668 | if (!(toStringTagSymbol in genFun)) {
|
12669 | genFun[toStringTagSymbol] = "GeneratorFunction";
|
12670 | }
|
12671 | }
|
12672 | genFun.prototype = Object.create(Gp);
|
12673 | return genFun;
|
12674 | };
|
12675 |
|
12676 |
|
12677 |
|
12678 |
|
12679 |
|
12680 | runtime.awrap = function(arg) {
|
12681 | return { __await: arg };
|
12682 | };
|
12683 |
|
12684 | function AsyncIterator(generator) {
|
12685 | function invoke(method, arg, resolve, reject) {
|
12686 | var record = tryCatch(generator[method], generator, arg);
|
12687 | if (record.type === "throw") {
|
12688 | reject(record.arg);
|
12689 | } else {
|
12690 | var result = record.arg;
|
12691 | var value = result.value;
|
12692 | if (value &&
|
12693 | typeof value === "object" &&
|
12694 | hasOwn.call(value, "__await")) {
|
12695 | return Promise.resolve(value.__await).then(function(value) {
|
12696 | invoke("next", value, resolve, reject);
|
12697 | }, function(err) {
|
12698 | invoke("throw", err, resolve, reject);
|
12699 | });
|
12700 | }
|
12701 |
|
12702 | return Promise.resolve(value).then(function(unwrapped) {
|
12703 |
|
12704 |
|
12705 |
|
12706 | result.value = unwrapped;
|
12707 | resolve(result);
|
12708 | }, function(error) {
|
12709 |
|
12710 |
|
12711 | return invoke("throw", error, resolve, reject);
|
12712 | });
|
12713 | }
|
12714 | }
|
12715 |
|
12716 | var previousPromise;
|
12717 |
|
12718 | function enqueue(method, arg) {
|
12719 | function callInvokeWithMethodAndArg() {
|
12720 | return new Promise(function(resolve, reject) {
|
12721 | invoke(method, arg, resolve, reject);
|
12722 | });
|
12723 | }
|
12724 |
|
12725 | return previousPromise =
|
12726 |
|
12727 |
|
12728 |
|
12729 |
|
12730 |
|
12731 |
|
12732 |
|
12733 |
|
12734 |
|
12735 |
|
12736 |
|
12737 |
|
12738 | previousPromise ? previousPromise.then(
|
12739 | callInvokeWithMethodAndArg,
|
12740 |
|
12741 |
|
12742 | callInvokeWithMethodAndArg
|
12743 | ) : callInvokeWithMethodAndArg();
|
12744 | }
|
12745 |
|
12746 |
|
12747 |
|
12748 | this._invoke = enqueue;
|
12749 | }
|
12750 |
|
12751 | defineIteratorMethods(AsyncIterator.prototype);
|
12752 | AsyncIterator.prototype[asyncIteratorSymbol] = function () {
|
12753 | return this;
|
12754 | };
|
12755 | runtime.AsyncIterator = AsyncIterator;
|
12756 |
|
12757 |
|
12758 |
|
12759 |
|
12760 | runtime.async = function(innerFn, outerFn, self, tryLocsList) {
|
12761 | var iter = new AsyncIterator(
|
12762 | wrap(innerFn, outerFn, self, tryLocsList)
|
12763 | );
|
12764 |
|
12765 | return runtime.isGeneratorFunction(outerFn)
|
12766 | ? iter
|
12767 | : iter.next().then(function(result) {
|
12768 | return result.done ? result.value : iter.next();
|
12769 | });
|
12770 | };
|
12771 |
|
12772 | function makeInvokeMethod(innerFn, self, context) {
|
12773 | var state = GenStateSuspendedStart;
|
12774 |
|
12775 | return function invoke(method, arg) {
|
12776 | if (state === GenStateExecuting) {
|
12777 | throw new Error("Generator is already running");
|
12778 | }
|
12779 |
|
12780 | if (state === GenStateCompleted) {
|
12781 | if (method === "throw") {
|
12782 | throw arg;
|
12783 | }
|
12784 |
|
12785 |
|
12786 |
|
12787 | return doneResult();
|
12788 | }
|
12789 |
|
12790 | context.method = method;
|
12791 | context.arg = arg;
|
12792 |
|
12793 | while (true) {
|
12794 | var delegate = context.delegate;
|
12795 | if (delegate) {
|
12796 | var delegateResult = maybeInvokeDelegate(delegate, context);
|
12797 | if (delegateResult) {
|
12798 | if (delegateResult === ContinueSentinel) continue;
|
12799 | return delegateResult;
|
12800 | }
|
12801 | }
|
12802 |
|
12803 | if (context.method === "next") {
|
12804 |
|
12805 |
|
12806 | context.sent = context._sent = context.arg;
|
12807 |
|
12808 | } else if (context.method === "throw") {
|
12809 | if (state === GenStateSuspendedStart) {
|
12810 | state = GenStateCompleted;
|
12811 | throw context.arg;
|
12812 | }
|
12813 |
|
12814 | context.dispatchException(context.arg);
|
12815 |
|
12816 | } else if (context.method === "return") {
|
12817 | context.abrupt("return", context.arg);
|
12818 | }
|
12819 |
|
12820 | state = GenStateExecuting;
|
12821 |
|
12822 | var record = tryCatch(innerFn, self, context);
|
12823 | if (record.type === "normal") {
|
12824 |
|
12825 |
|
12826 | state = context.done
|
12827 | ? GenStateCompleted
|
12828 | : GenStateSuspendedYield;
|
12829 |
|
12830 | if (record.arg === ContinueSentinel) {
|
12831 | continue;
|
12832 | }
|
12833 |
|
12834 | return {
|
12835 | value: record.arg,
|
12836 | done: context.done
|
12837 | };
|
12838 |
|
12839 | } else if (record.type === "throw") {
|
12840 | state = GenStateCompleted;
|
12841 |
|
12842 |
|
12843 | context.method = "throw";
|
12844 | context.arg = record.arg;
|
12845 | }
|
12846 | }
|
12847 | };
|
12848 | }
|
12849 |
|
12850 |
|
12851 |
|
12852 |
|
12853 |
|
12854 | function maybeInvokeDelegate(delegate, context) {
|
12855 | var method = delegate.iterator[context.method];
|
12856 | if (method === undefined$1) {
|
12857 |
|
12858 |
|
12859 | context.delegate = null;
|
12860 |
|
12861 | if (context.method === "throw") {
|
12862 | if (delegate.iterator.return) {
|
12863 |
|
12864 |
|
12865 | context.method = "return";
|
12866 | context.arg = undefined$1;
|
12867 | maybeInvokeDelegate(delegate, context);
|
12868 |
|
12869 | if (context.method === "throw") {
|
12870 |
|
12871 |
|
12872 | return ContinueSentinel;
|
12873 | }
|
12874 | }
|
12875 |
|
12876 | context.method = "throw";
|
12877 | context.arg = new TypeError(
|
12878 | "The iterator does not provide a 'throw' method");
|
12879 | }
|
12880 |
|
12881 | return ContinueSentinel;
|
12882 | }
|
12883 |
|
12884 | var record = tryCatch(method, delegate.iterator, context.arg);
|
12885 |
|
12886 | if (record.type === "throw") {
|
12887 | context.method = "throw";
|
12888 | context.arg = record.arg;
|
12889 | context.delegate = null;
|
12890 | return ContinueSentinel;
|
12891 | }
|
12892 |
|
12893 | var info = record.arg;
|
12894 |
|
12895 | if (! info) {
|
12896 | context.method = "throw";
|
12897 | context.arg = new TypeError("iterator result is not an object");
|
12898 | context.delegate = null;
|
12899 | return ContinueSentinel;
|
12900 | }
|
12901 |
|
12902 | if (info.done) {
|
12903 |
|
12904 |
|
12905 | context[delegate.resultName] = info.value;
|
12906 |
|
12907 |
|
12908 | context.next = delegate.nextLoc;
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 | if (context.method !== "return") {
|
12917 | context.method = "next";
|
12918 | context.arg = undefined$1;
|
12919 | }
|
12920 |
|
12921 | } else {
|
12922 |
|
12923 | return info;
|
12924 | }
|
12925 |
|
12926 |
|
12927 |
|
12928 | context.delegate = null;
|
12929 | return ContinueSentinel;
|
12930 | }
|
12931 |
|
12932 |
|
12933 |
|
12934 | defineIteratorMethods(Gp);
|
12935 |
|
12936 | Gp[toStringTagSymbol] = "Generator";
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 | Gp[iteratorSymbol] = function() {
|
12944 | return this;
|
12945 | };
|
12946 |
|
12947 | Gp.toString = function() {
|
12948 | return "[object Generator]";
|
12949 | };
|
12950 |
|
12951 | function pushTryEntry(locs) {
|
12952 | var entry = { tryLoc: locs[0] };
|
12953 |
|
12954 | if (1 in locs) {
|
12955 | entry.catchLoc = locs[1];
|
12956 | }
|
12957 |
|
12958 | if (2 in locs) {
|
12959 | entry.finallyLoc = locs[2];
|
12960 | entry.afterLoc = locs[3];
|
12961 | }
|
12962 |
|
12963 | this.tryEntries.push(entry);
|
12964 | }
|
12965 |
|
12966 | function resetTryEntry(entry) {
|
12967 | var record = entry.completion || {};
|
12968 | record.type = "normal";
|
12969 | delete record.arg;
|
12970 | entry.completion = record;
|
12971 | }
|
12972 |
|
12973 | function Context(tryLocsList) {
|
12974 |
|
12975 |
|
12976 |
|
12977 | this.tryEntries = [{ tryLoc: "root" }];
|
12978 | tryLocsList.forEach(pushTryEntry, this);
|
12979 | this.reset(true);
|
12980 | }
|
12981 |
|
12982 | runtime.keys = function(object) {
|
12983 | var keys = [];
|
12984 | for (var key in object) {
|
12985 | keys.push(key);
|
12986 | }
|
12987 | keys.reverse();
|
12988 |
|
12989 |
|
12990 |
|
12991 | return function next() {
|
12992 | while (keys.length) {
|
12993 | var key = keys.pop();
|
12994 | if (key in object) {
|
12995 | next.value = key;
|
12996 | next.done = false;
|
12997 | return next;
|
12998 | }
|
12999 | }
|
13000 |
|
13001 |
|
13002 |
|
13003 |
|
13004 | next.done = true;
|
13005 | return next;
|
13006 | };
|
13007 | };
|
13008 |
|
13009 | function values(iterable) {
|
13010 | if (iterable) {
|
13011 | var iteratorMethod = iterable[iteratorSymbol];
|
13012 | if (iteratorMethod) {
|
13013 | return iteratorMethod.call(iterable);
|
13014 | }
|
13015 |
|
13016 | if (typeof iterable.next === "function") {
|
13017 | return iterable;
|
13018 | }
|
13019 |
|
13020 | if (!isNaN(iterable.length)) {
|
13021 | var i = -1, next = function next() {
|
13022 | while (++i < iterable.length) {
|
13023 | if (hasOwn.call(iterable, i)) {
|
13024 | next.value = iterable[i];
|
13025 | next.done = false;
|
13026 | return next;
|
13027 | }
|
13028 | }
|
13029 |
|
13030 | next.value = undefined$1;
|
13031 | next.done = true;
|
13032 |
|
13033 | return next;
|
13034 | };
|
13035 |
|
13036 | return next.next = next;
|
13037 | }
|
13038 | }
|
13039 |
|
13040 |
|
13041 | return { next: doneResult };
|
13042 | }
|
13043 | runtime.values = values;
|
13044 |
|
13045 | function doneResult() {
|
13046 | return { value: undefined$1, done: true };
|
13047 | }
|
13048 |
|
13049 | Context.prototype = {
|
13050 | constructor: Context,
|
13051 |
|
13052 | reset: function(skipTempReset) {
|
13053 | this.prev = 0;
|
13054 | this.next = 0;
|
13055 |
|
13056 |
|
13057 | this.sent = this._sent = undefined$1;
|
13058 | this.done = false;
|
13059 | this.delegate = null;
|
13060 |
|
13061 | this.method = "next";
|
13062 | this.arg = undefined$1;
|
13063 |
|
13064 | this.tryEntries.forEach(resetTryEntry);
|
13065 |
|
13066 | if (!skipTempReset) {
|
13067 | for (var name in this) {
|
13068 |
|
13069 | if (name.charAt(0) === "t" &&
|
13070 | hasOwn.call(this, name) &&
|
13071 | !isNaN(+name.slice(1))) {
|
13072 | this[name] = undefined$1;
|
13073 | }
|
13074 | }
|
13075 | }
|
13076 | },
|
13077 |
|
13078 | stop: function() {
|
13079 | this.done = true;
|
13080 |
|
13081 | var rootEntry = this.tryEntries[0];
|
13082 | var rootRecord = rootEntry.completion;
|
13083 | if (rootRecord.type === "throw") {
|
13084 | throw rootRecord.arg;
|
13085 | }
|
13086 |
|
13087 | return this.rval;
|
13088 | },
|
13089 |
|
13090 | dispatchException: function(exception) {
|
13091 | if (this.done) {
|
13092 | throw exception;
|
13093 | }
|
13094 |
|
13095 | var context = this;
|
13096 | function handle(loc, caught) {
|
13097 | record.type = "throw";
|
13098 | record.arg = exception;
|
13099 | context.next = loc;
|
13100 |
|
13101 | if (caught) {
|
13102 |
|
13103 |
|
13104 | context.method = "next";
|
13105 | context.arg = undefined$1;
|
13106 | }
|
13107 |
|
13108 | return !! caught;
|
13109 | }
|
13110 |
|
13111 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13112 | var entry = this.tryEntries[i];
|
13113 | var record = entry.completion;
|
13114 |
|
13115 | if (entry.tryLoc === "root") {
|
13116 |
|
13117 |
|
13118 |
|
13119 | return handle("end");
|
13120 | }
|
13121 |
|
13122 | if (entry.tryLoc <= this.prev) {
|
13123 | var hasCatch = hasOwn.call(entry, "catchLoc");
|
13124 | var hasFinally = hasOwn.call(entry, "finallyLoc");
|
13125 |
|
13126 | if (hasCatch && hasFinally) {
|
13127 | if (this.prev < entry.catchLoc) {
|
13128 | return handle(entry.catchLoc, true);
|
13129 | } else if (this.prev < entry.finallyLoc) {
|
13130 | return handle(entry.finallyLoc);
|
13131 | }
|
13132 |
|
13133 | } else if (hasCatch) {
|
13134 | if (this.prev < entry.catchLoc) {
|
13135 | return handle(entry.catchLoc, true);
|
13136 | }
|
13137 |
|
13138 | } else if (hasFinally) {
|
13139 | if (this.prev < entry.finallyLoc) {
|
13140 | return handle(entry.finallyLoc);
|
13141 | }
|
13142 |
|
13143 | } else {
|
13144 | throw new Error("try statement without catch or finally");
|
13145 | }
|
13146 | }
|
13147 | }
|
13148 | },
|
13149 |
|
13150 | abrupt: function(type, arg) {
|
13151 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13152 | var entry = this.tryEntries[i];
|
13153 | if (entry.tryLoc <= this.prev &&
|
13154 | hasOwn.call(entry, "finallyLoc") &&
|
13155 | this.prev < entry.finallyLoc) {
|
13156 | var finallyEntry = entry;
|
13157 | break;
|
13158 | }
|
13159 | }
|
13160 |
|
13161 | if (finallyEntry &&
|
13162 | (type === "break" ||
|
13163 | type === "continue") &&
|
13164 | finallyEntry.tryLoc <= arg &&
|
13165 | arg <= finallyEntry.finallyLoc) {
|
13166 |
|
13167 |
|
13168 | finallyEntry = null;
|
13169 | }
|
13170 |
|
13171 | var record = finallyEntry ? finallyEntry.completion : {};
|
13172 | record.type = type;
|
13173 | record.arg = arg;
|
13174 |
|
13175 | if (finallyEntry) {
|
13176 | this.method = "next";
|
13177 | this.next = finallyEntry.finallyLoc;
|
13178 | return ContinueSentinel;
|
13179 | }
|
13180 |
|
13181 | return this.complete(record);
|
13182 | },
|
13183 |
|
13184 | complete: function(record, afterLoc) {
|
13185 | if (record.type === "throw") {
|
13186 | throw record.arg;
|
13187 | }
|
13188 |
|
13189 | if (record.type === "break" ||
|
13190 | record.type === "continue") {
|
13191 | this.next = record.arg;
|
13192 | } else if (record.type === "return") {
|
13193 | this.rval = this.arg = record.arg;
|
13194 | this.method = "return";
|
13195 | this.next = "end";
|
13196 | } else if (record.type === "normal" && afterLoc) {
|
13197 | this.next = afterLoc;
|
13198 | }
|
13199 |
|
13200 | return ContinueSentinel;
|
13201 | },
|
13202 |
|
13203 | finish: function(finallyLoc) {
|
13204 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13205 | var entry = this.tryEntries[i];
|
13206 | if (entry.finallyLoc === finallyLoc) {
|
13207 | this.complete(entry.completion, entry.afterLoc);
|
13208 | resetTryEntry(entry);
|
13209 | return ContinueSentinel;
|
13210 | }
|
13211 | }
|
13212 | },
|
13213 |
|
13214 | "catch": function(tryLoc) {
|
13215 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13216 | var entry = this.tryEntries[i];
|
13217 | if (entry.tryLoc === tryLoc) {
|
13218 | var record = entry.completion;
|
13219 | if (record.type === "throw") {
|
13220 | var thrown = record.arg;
|
13221 | resetTryEntry(entry);
|
13222 | }
|
13223 | return thrown;
|
13224 | }
|
13225 | }
|
13226 |
|
13227 |
|
13228 |
|
13229 | throw new Error("illegal catch attempt");
|
13230 | },
|
13231 |
|
13232 | delegateYield: function(iterable, resultName, nextLoc) {
|
13233 | this.delegate = {
|
13234 | iterator: values(iterable),
|
13235 | resultName: resultName,
|
13236 | nextLoc: nextLoc
|
13237 | };
|
13238 |
|
13239 | if (this.method === "next") {
|
13240 |
|
13241 |
|
13242 | this.arg = undefined$1;
|
13243 | }
|
13244 |
|
13245 | return ContinueSentinel;
|
13246 | }
|
13247 | };
|
13248 | })(
|
13249 |
|
13250 |
|
13251 |
|
13252 | (function() {
|
13253 | return this || (typeof self === "object" && self);
|
13254 | })() || Function("return this")()
|
13255 | );
|
13256 | });
|
13257 |
|
13258 | |
13259 |
|
13260 |
|
13261 |
|
13262 |
|
13263 |
|
13264 |
|
13265 |
|
13266 |
|
13267 | var g = (function() {
|
13268 | return this || (typeof self === "object" && self);
|
13269 | })() || Function("return this")();
|
13270 |
|
13271 |
|
13272 |
|
13273 | var hadRuntime = g.regeneratorRuntime &&
|
13274 | Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0;
|
13275 |
|
13276 |
|
13277 | var oldRuntime = hadRuntime && g.regeneratorRuntime;
|
13278 |
|
13279 |
|
13280 | g.regeneratorRuntime = undefined;
|
13281 |
|
13282 | var runtimeModule = runtime;
|
13283 |
|
13284 | if (hadRuntime) {
|
13285 |
|
13286 | g.regeneratorRuntime = oldRuntime;
|
13287 | } else {
|
13288 |
|
13289 | try {
|
13290 | delete g.regeneratorRuntime;
|
13291 | } catch(e) {
|
13292 | g.regeneratorRuntime = undefined;
|
13293 | }
|
13294 | }
|
13295 |
|
13296 | var regenerator = runtimeModule;
|
13297 |
|
13298 | |
13299 |
|
13300 |
|
13301 |
|
13302 | var s = 1000;
|
13303 | var m = s * 60;
|
13304 | var h = m * 60;
|
13305 | var d = h * 24;
|
13306 | var w = d * 7;
|
13307 | var y = d * 365.25;
|
13308 |
|
13309 | |
13310 |
|
13311 |
|
13312 |
|
13313 |
|
13314 |
|
13315 |
|
13316 |
|
13317 |
|
13318 |
|
13319 |
|
13320 |
|
13321 |
|
13322 |
|
13323 | var ms = function(val, options) {
|
13324 | options = options || {};
|
13325 | var type = typeof val;
|
13326 | if (type === 'string' && val.length > 0) {
|
13327 | return parse(val);
|
13328 | } else if (type === 'number' && isNaN(val) === false) {
|
13329 | return options.long ? fmtLong(val) : fmtShort(val);
|
13330 | }
|
13331 | throw new Error(
|
13332 | 'val is not a non-empty string or a valid number. val=' +
|
13333 | JSON.stringify(val)
|
13334 | );
|
13335 | };
|
13336 |
|
13337 | |
13338 |
|
13339 |
|
13340 |
|
13341 |
|
13342 |
|
13343 |
|
13344 |
|
13345 | function parse(str) {
|
13346 | str = String(str);
|
13347 | if (str.length > 100) {
|
13348 | return;
|
13349 | }
|
13350 | var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
13351 | str
|
13352 | );
|
13353 | if (!match) {
|
13354 | return;
|
13355 | }
|
13356 | var n = parseFloat(match[1]);
|
13357 | var type = (match[2] || 'ms').toLowerCase();
|
13358 | switch (type) {
|
13359 | case 'years':
|
13360 | case 'year':
|
13361 | case 'yrs':
|
13362 | case 'yr':
|
13363 | case 'y':
|
13364 | return n * y;
|
13365 | case 'weeks':
|
13366 | case 'week':
|
13367 | case 'w':
|
13368 | return n * w;
|
13369 | case 'days':
|
13370 | case 'day':
|
13371 | case 'd':
|
13372 | return n * d;
|
13373 | case 'hours':
|
13374 | case 'hour':
|
13375 | case 'hrs':
|
13376 | case 'hr':
|
13377 | case 'h':
|
13378 | return n * h;
|
13379 | case 'minutes':
|
13380 | case 'minute':
|
13381 | case 'mins':
|
13382 | case 'min':
|
13383 | case 'm':
|
13384 | return n * m;
|
13385 | case 'seconds':
|
13386 | case 'second':
|
13387 | case 'secs':
|
13388 | case 'sec':
|
13389 | case 's':
|
13390 | return n * s;
|
13391 | case 'milliseconds':
|
13392 | case 'millisecond':
|
13393 | case 'msecs':
|
13394 | case 'msec':
|
13395 | case 'ms':
|
13396 | return n;
|
13397 | default:
|
13398 | return undefined;
|
13399 | }
|
13400 | }
|
13401 |
|
13402 | |
13403 |
|
13404 |
|
13405 |
|
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 | function fmtShort(ms) {
|
13411 | var msAbs = Math.abs(ms);
|
13412 | if (msAbs >= d) {
|
13413 | return Math.round(ms / d) + 'd';
|
13414 | }
|
13415 | if (msAbs >= h) {
|
13416 | return Math.round(ms / h) + 'h';
|
13417 | }
|
13418 | if (msAbs >= m) {
|
13419 | return Math.round(ms / m) + 'm';
|
13420 | }
|
13421 | if (msAbs >= s) {
|
13422 | return Math.round(ms / s) + 's';
|
13423 | }
|
13424 | return ms + 'ms';
|
13425 | }
|
13426 |
|
13427 | |
13428 |
|
13429 |
|
13430 |
|
13431 |
|
13432 |
|
13433 |
|
13434 |
|
13435 | function fmtLong(ms) {
|
13436 | var msAbs = Math.abs(ms);
|
13437 | if (msAbs >= d) {
|
13438 | return plural(ms, msAbs, d, 'day');
|
13439 | }
|
13440 | if (msAbs >= h) {
|
13441 | return plural(ms, msAbs, h, 'hour');
|
13442 | }
|
13443 | if (msAbs >= m) {
|
13444 | return plural(ms, msAbs, m, 'minute');
|
13445 | }
|
13446 | if (msAbs >= s) {
|
13447 | return plural(ms, msAbs, s, 'second');
|
13448 | }
|
13449 | return ms + ' ms';
|
13450 | }
|
13451 |
|
13452 | |
13453 |
|
13454 |
|
13455 |
|
13456 | function plural(ms, msAbs, n, name) {
|
13457 | var isPlural = msAbs >= n * 1.5;
|
13458 | return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
13459 | }
|
13460 |
|
13461 | |
13462 |
|
13463 |
|
13464 |
|
13465 | function setup(env) {
|
13466 | createDebug.debug = createDebug;
|
13467 | createDebug.default = createDebug;
|
13468 | createDebug.coerce = coerce;
|
13469 | createDebug.disable = disable;
|
13470 | createDebug.enable = enable;
|
13471 | createDebug.enabled = enabled;
|
13472 | createDebug.humanize = ms;
|
13473 | Object.keys(env).forEach(function (key) {
|
13474 | createDebug[key] = env[key];
|
13475 | });
|
13476 | |
13477 |
|
13478 |
|
13479 |
|
13480 | createDebug.instances = [];
|
13481 | |
13482 |
|
13483 |
|
13484 |
|
13485 | createDebug.names = [];
|
13486 | createDebug.skips = [];
|
13487 | |
13488 |
|
13489 |
|
13490 |
|
13491 |
|
13492 |
|
13493 | createDebug.formatters = {};
|
13494 | |
13495 |
|
13496 |
|
13497 |
|
13498 |
|
13499 |
|
13500 |
|
13501 | function selectColor(namespace) {
|
13502 | var hash = 0;
|
13503 |
|
13504 | for (var i = 0; i < namespace.length; i++) {
|
13505 | hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
13506 | hash |= 0;
|
13507 | }
|
13508 |
|
13509 | return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
13510 | }
|
13511 |
|
13512 | createDebug.selectColor = selectColor;
|
13513 | |
13514 |
|
13515 |
|
13516 |
|
13517 |
|
13518 |
|
13519 |
|
13520 |
|
13521 | function createDebug(namespace) {
|
13522 | var prevTime;
|
13523 |
|
13524 | function debug() {
|
13525 |
|
13526 | if (!debug.enabled) {
|
13527 | return;
|
13528 | }
|
13529 |
|
13530 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
13531 | args[_key] = arguments[_key];
|
13532 | }
|
13533 |
|
13534 | var self = debug;
|
13535 |
|
13536 | var curr = Number(new Date());
|
13537 | var ms = curr - (prevTime || curr);
|
13538 | self.diff = ms;
|
13539 | self.prev = prevTime;
|
13540 | self.curr = curr;
|
13541 | prevTime = curr;
|
13542 | args[0] = createDebug.coerce(args[0]);
|
13543 |
|
13544 | if (typeof args[0] !== 'string') {
|
13545 |
|
13546 | args.unshift('%O');
|
13547 | }
|
13548 |
|
13549 |
|
13550 | var index = 0;
|
13551 | args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
13552 |
|
13553 | if (match === '%%') {
|
13554 | return match;
|
13555 | }
|
13556 |
|
13557 | index++;
|
13558 | var formatter = createDebug.formatters[format];
|
13559 |
|
13560 | if (typeof formatter === 'function') {
|
13561 | var val = args[index];
|
13562 | match = formatter.call(self, val);
|
13563 |
|
13564 | args.splice(index, 1);
|
13565 | index--;
|
13566 | }
|
13567 |
|
13568 | return match;
|
13569 | });
|
13570 |
|
13571 | createDebug.formatArgs.call(self, args);
|
13572 | var logFn = self.log || createDebug.log;
|
13573 | logFn.apply(self, args);
|
13574 | }
|
13575 |
|
13576 | debug.namespace = namespace;
|
13577 | debug.enabled = createDebug.enabled(namespace);
|
13578 | debug.useColors = createDebug.useColors();
|
13579 | debug.color = selectColor(namespace);
|
13580 | debug.destroy = destroy;
|
13581 | debug.extend = extend;
|
13582 |
|
13583 |
|
13584 |
|
13585 | if (typeof createDebug.init === 'function') {
|
13586 | createDebug.init(debug);
|
13587 | }
|
13588 |
|
13589 | createDebug.instances.push(debug);
|
13590 | return debug;
|
13591 | }
|
13592 |
|
13593 | function destroy() {
|
13594 | var index = createDebug.instances.indexOf(this);
|
13595 |
|
13596 | if (index !== -1) {
|
13597 | createDebug.instances.splice(index, 1);
|
13598 | return true;
|
13599 | }
|
13600 |
|
13601 | return false;
|
13602 | }
|
13603 |
|
13604 | function extend(namespace, delimiter) {
|
13605 | return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
13606 | }
|
13607 | |
13608 |
|
13609 |
|
13610 |
|
13611 |
|
13612 |
|
13613 |
|
13614 |
|
13615 |
|
13616 | function enable(namespaces) {
|
13617 | createDebug.save(namespaces);
|
13618 | createDebug.names = [];
|
13619 | createDebug.skips = [];
|
13620 | var i;
|
13621 | var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
13622 | var len = split.length;
|
13623 |
|
13624 | for (i = 0; i < len; i++) {
|
13625 | if (!split[i]) {
|
13626 |
|
13627 | continue;
|
13628 | }
|
13629 |
|
13630 | namespaces = split[i].replace(/\*/g, '.*?');
|
13631 |
|
13632 | if (namespaces[0] === '-') {
|
13633 | createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
13634 | } else {
|
13635 | createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
13636 | }
|
13637 | }
|
13638 |
|
13639 | for (i = 0; i < createDebug.instances.length; i++) {
|
13640 | var instance = createDebug.instances[i];
|
13641 | instance.enabled = createDebug.enabled(instance.namespace);
|
13642 | }
|
13643 | }
|
13644 | |
13645 |
|
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 |
|
13651 | function disable() {
|
13652 | createDebug.enable('');
|
13653 | }
|
13654 | |
13655 |
|
13656 |
|
13657 |
|
13658 |
|
13659 |
|
13660 |
|
13661 |
|
13662 |
|
13663 | function enabled(name) {
|
13664 | if (name[name.length - 1] === '*') {
|
13665 | return true;
|
13666 | }
|
13667 |
|
13668 | var i;
|
13669 | var len;
|
13670 |
|
13671 | for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
13672 | if (createDebug.skips[i].test(name)) {
|
13673 | return false;
|
13674 | }
|
13675 | }
|
13676 |
|
13677 | for (i = 0, len = createDebug.names.length; i < len; i++) {
|
13678 | if (createDebug.names[i].test(name)) {
|
13679 | return true;
|
13680 | }
|
13681 | }
|
13682 |
|
13683 | return false;
|
13684 | }
|
13685 | |
13686 |
|
13687 |
|
13688 |
|
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 | function coerce(val) {
|
13695 | if (val instanceof Error) {
|
13696 | return val.stack || val.message;
|
13697 | }
|
13698 |
|
13699 | return val;
|
13700 | }
|
13701 |
|
13702 | createDebug.enable(createDebug.load());
|
13703 | return createDebug;
|
13704 | }
|
13705 |
|
13706 | var common = setup;
|
13707 |
|
13708 | var browser = createCommonjsModule(function (module, exports) {
|
13709 |
|
13710 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
13711 |
|
13712 |
|
13713 |
|
13714 | |
13715 |
|
13716 |
|
13717 | exports.log = log;
|
13718 | exports.formatArgs = formatArgs;
|
13719 | exports.save = save;
|
13720 | exports.load = load;
|
13721 | exports.useColors = useColors;
|
13722 | exports.storage = localstorage();
|
13723 | |
13724 |
|
13725 |
|
13726 |
|
13727 | exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
13728 | |
13729 |
|
13730 |
|
13731 |
|
13732 |
|
13733 |
|
13734 |
|
13735 |
|
13736 |
|
13737 | function useColors() {
|
13738 |
|
13739 |
|
13740 |
|
13741 | if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
13742 | return true;
|
13743 | }
|
13744 |
|
13745 |
|
13746 | if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
13747 | return false;
|
13748 | }
|
13749 |
|
13750 |
|
13751 |
|
13752 | return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
|
13753 | typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
|
13754 |
|
13755 | typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 ||
|
13756 | typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
13757 | }
|
13758 | |
13759 |
|
13760 |
|
13761 |
|
13762 |
|
13763 |
|
13764 |
|
13765 | function formatArgs(args) {
|
13766 | args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
13767 |
|
13768 | if (!this.useColors) {
|
13769 | return;
|
13770 | }
|
13771 |
|
13772 | var c = 'color: ' + this.color;
|
13773 | args.splice(1, 0, c, 'color: inherit');
|
13774 |
|
13775 |
|
13776 |
|
13777 | var index = 0;
|
13778 | var lastC = 0;
|
13779 | args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
13780 | if (match === '%%') {
|
13781 | return;
|
13782 | }
|
13783 |
|
13784 | index++;
|
13785 |
|
13786 | if (match === '%c') {
|
13787 |
|
13788 |
|
13789 | lastC = index;
|
13790 | }
|
13791 | });
|
13792 | args.splice(lastC, 0, c);
|
13793 | }
|
13794 | |
13795 |
|
13796 |
|
13797 |
|
13798 |
|
13799 |
|
13800 |
|
13801 |
|
13802 | function log() {
|
13803 | var _console;
|
13804 |
|
13805 |
|
13806 |
|
13807 | return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
13808 | }
|
13809 | |
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 | function save(namespaces) {
|
13818 | try {
|
13819 | if (namespaces) {
|
13820 | exports.storage.setItem('debug', namespaces);
|
13821 | } else {
|
13822 | exports.storage.removeItem('debug');
|
13823 | }
|
13824 | } catch (error) {
|
13825 |
|
13826 | }
|
13827 | }
|
13828 | |
13829 |
|
13830 |
|
13831 |
|
13832 |
|
13833 |
|
13834 |
|
13835 |
|
13836 | function load() {
|
13837 | var r;
|
13838 |
|
13839 | try {
|
13840 | r = exports.storage.getItem('debug');
|
13841 | } catch (error) {}
|
13842 |
|
13843 |
|
13844 |
|
13845 |
|
13846 | if (!r && typeof process !== 'undefined' && 'env' in process) {
|
13847 | r = process.env.DEBUG;
|
13848 | }
|
13849 |
|
13850 | return r;
|
13851 | }
|
13852 | |
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 | function localstorage() {
|
13865 | try {
|
13866 |
|
13867 |
|
13868 | return localStorage;
|
13869 | } catch (error) {
|
13870 |
|
13871 | }
|
13872 | }
|
13873 |
|
13874 | module.exports = common(exports);
|
13875 | var formatters = module.exports.formatters;
|
13876 | |
13877 |
|
13878 |
|
13879 |
|
13880 | formatters.j = function (v) {
|
13881 | try {
|
13882 | return JSON.stringify(v);
|
13883 | } catch (error) {
|
13884 | return '[UnexpectedJSONParseError]: ' + error.message;
|
13885 | }
|
13886 | };
|
13887 | });
|
13888 | var browser_1 = browser.log;
|
13889 | var browser_2 = browser.formatArgs;
|
13890 | var browser_3 = browser.save;
|
13891 | var browser_4 = browser.load;
|
13892 | var browser_5 = browser.useColors;
|
13893 | var browser_6 = browser.storage;
|
13894 | var browser_7 = browser.colors;
|
13895 |
|
13896 | var componentEmitter = createCommonjsModule(function (module) {
|
13897 | |
13898 |
|
13899 |
|
13900 | {
|
13901 | module.exports = Emitter;
|
13902 | }
|
13903 | |
13904 |
|
13905 |
|
13906 |
|
13907 |
|
13908 |
|
13909 |
|
13910 | function Emitter(obj) {
|
13911 | if (obj) return mixin(obj);
|
13912 | }
|
13913 | |
13914 |
|
13915 |
|
13916 |
|
13917 |
|
13918 |
|
13919 |
|
13920 |
|
13921 | function mixin(obj) {
|
13922 | for (var key in Emitter.prototype) {
|
13923 | obj[key] = Emitter.prototype[key];
|
13924 | }
|
13925 |
|
13926 | return obj;
|
13927 | }
|
13928 | |
13929 |
|
13930 |
|
13931 |
|
13932 |
|
13933 |
|
13934 |
|
13935 |
|
13936 |
|
13937 |
|
13938 | Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
|
13939 | this._callbacks = this._callbacks || {};
|
13940 | (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
|
13941 | return this;
|
13942 | };
|
13943 | |
13944 |
|
13945 |
|
13946 |
|
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 |
|
13952 |
|
13953 |
|
13954 | Emitter.prototype.once = function (event, fn) {
|
13955 | function on() {
|
13956 | this.off(event, on);
|
13957 | fn.apply(this, arguments);
|
13958 | }
|
13959 |
|
13960 | on.fn = fn;
|
13961 | this.on(event, on);
|
13962 | return this;
|
13963 | };
|
13964 | |
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 |
|
13973 |
|
13974 |
|
13975 | Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
|
13976 | this._callbacks = this._callbacks || {};
|
13977 |
|
13978 | if (0 == arguments.length) {
|
13979 | this._callbacks = {};
|
13980 | return this;
|
13981 | }
|
13982 |
|
13983 |
|
13984 | var callbacks = this._callbacks['$' + event];
|
13985 | if (!callbacks) return this;
|
13986 |
|
13987 | if (1 == arguments.length) {
|
13988 | delete this._callbacks['$' + event];
|
13989 | return this;
|
13990 | }
|
13991 |
|
13992 |
|
13993 | var cb;
|
13994 |
|
13995 | for (var i = 0; i < callbacks.length; i++) {
|
13996 | cb = callbacks[i];
|
13997 |
|
13998 | if (cb === fn || cb.fn === fn) {
|
13999 | callbacks.splice(i, 1);
|
14000 | break;
|
14001 | }
|
14002 | }
|
14003 |
|
14004 |
|
14005 |
|
14006 | if (callbacks.length === 0) {
|
14007 | delete this._callbacks['$' + event];
|
14008 | }
|
14009 |
|
14010 | return this;
|
14011 | };
|
14012 | |
14013 |
|
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 | Emitter.prototype.emit = function (event) {
|
14022 | this._callbacks = this._callbacks || {};
|
14023 | var args = new Array(arguments.length - 1),
|
14024 | callbacks = this._callbacks['$' + event];
|
14025 |
|
14026 | for (var i = 1; i < arguments.length; i++) {
|
14027 | args[i - 1] = arguments[i];
|
14028 | }
|
14029 |
|
14030 | if (callbacks) {
|
14031 | callbacks = callbacks.slice(0);
|
14032 |
|
14033 | for (var i = 0, len = callbacks.length; i < len; ++i) {
|
14034 | callbacks[i].apply(this, args);
|
14035 | }
|
14036 | }
|
14037 |
|
14038 | return this;
|
14039 | };
|
14040 | |
14041 |
|
14042 |
|
14043 |
|
14044 |
|
14045 |
|
14046 |
|
14047 |
|
14048 |
|
14049 | Emitter.prototype.listeners = function (event) {
|
14050 | this._callbacks = this._callbacks || {};
|
14051 | return this._callbacks['$' + event] || [];
|
14052 | };
|
14053 | |
14054 |
|
14055 |
|
14056 |
|
14057 |
|
14058 |
|
14059 |
|
14060 |
|
14061 |
|
14062 | Emitter.prototype.hasListeners = function (event) {
|
14063 | return !!this.listeners(event).length;
|
14064 | };
|
14065 | });
|
14066 |
|
14067 | var fastSafeStringify = stringify;
|
14068 | stringify.default = stringify;
|
14069 | stringify.stable = deterministicStringify;
|
14070 | stringify.stableStringify = deterministicStringify;
|
14071 |
|
14072 | var arr = [];
|
14073 | var replacerStack = [];
|
14074 |
|
14075 |
|
14076 | function stringify (obj, replacer, spacer) {
|
14077 | decirc(obj, '', [], undefined);
|
14078 | var res;
|
14079 | if (replacerStack.length === 0) {
|
14080 | res = JSON.stringify(obj, replacer, spacer);
|
14081 | } else {
|
14082 | res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
|
14083 | }
|
14084 | while (arr.length !== 0) {
|
14085 | var part = arr.pop();
|
14086 | if (part.length === 4) {
|
14087 | Object.defineProperty(part[0], part[1], part[3]);
|
14088 | } else {
|
14089 | part[0][part[1]] = part[2];
|
14090 | }
|
14091 | }
|
14092 | return res
|
14093 | }
|
14094 | function decirc (val, k, stack, parent) {
|
14095 | var i;
|
14096 | if (typeof val === 'object' && val !== null) {
|
14097 | for (i = 0; i < stack.length; i++) {
|
14098 | if (stack[i] === val) {
|
14099 | var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
|
14100 | if (propertyDescriptor.get !== undefined) {
|
14101 | if (propertyDescriptor.configurable) {
|
14102 | Object.defineProperty(parent, k, { value: '[Circular]' });
|
14103 | arr.push([parent, k, val, propertyDescriptor]);
|
14104 | } else {
|
14105 | replacerStack.push([val, k]);
|
14106 | }
|
14107 | } else {
|
14108 | parent[k] = '[Circular]';
|
14109 | arr.push([parent, k, val]);
|
14110 | }
|
14111 | return
|
14112 | }
|
14113 | }
|
14114 | stack.push(val);
|
14115 |
|
14116 | if (Array.isArray(val)) {
|
14117 | for (i = 0; i < val.length; i++) {
|
14118 | decirc(val[i], i, stack, val);
|
14119 | }
|
14120 | } else {
|
14121 | var keys = Object.keys(val);
|
14122 | for (i = 0; i < keys.length; i++) {
|
14123 | var key = keys[i];
|
14124 | decirc(val[key], key, stack, val);
|
14125 | }
|
14126 | }
|
14127 | stack.pop();
|
14128 | }
|
14129 | }
|
14130 |
|
14131 |
|
14132 | function compareFunction (a, b) {
|
14133 | if (a < b) {
|
14134 | return -1
|
14135 | }
|
14136 | if (a > b) {
|
14137 | return 1
|
14138 | }
|
14139 | return 0
|
14140 | }
|
14141 |
|
14142 | function deterministicStringify (obj, replacer, spacer) {
|
14143 | var tmp = deterministicDecirc(obj, '', [], undefined) || obj;
|
14144 | var res;
|
14145 | if (replacerStack.length === 0) {
|
14146 | res = JSON.stringify(tmp, replacer, spacer);
|
14147 | } else {
|
14148 | res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
|
14149 | }
|
14150 | while (arr.length !== 0) {
|
14151 | var part = arr.pop();
|
14152 | if (part.length === 4) {
|
14153 | Object.defineProperty(part[0], part[1], part[3]);
|
14154 | } else {
|
14155 | part[0][part[1]] = part[2];
|
14156 | }
|
14157 | }
|
14158 | return res
|
14159 | }
|
14160 |
|
14161 | function deterministicDecirc (val, k, stack, parent) {
|
14162 | var i;
|
14163 | if (typeof val === 'object' && val !== null) {
|
14164 | for (i = 0; i < stack.length; i++) {
|
14165 | if (stack[i] === val) {
|
14166 | var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
|
14167 | if (propertyDescriptor.get !== undefined) {
|
14168 | if (propertyDescriptor.configurable) {
|
14169 | Object.defineProperty(parent, k, { value: '[Circular]' });
|
14170 | arr.push([parent, k, val, propertyDescriptor]);
|
14171 | } else {
|
14172 | replacerStack.push([val, k]);
|
14173 | }
|
14174 | } else {
|
14175 | parent[k] = '[Circular]';
|
14176 | arr.push([parent, k, val]);
|
14177 | }
|
14178 | return
|
14179 | }
|
14180 | }
|
14181 | if (typeof val.toJSON === 'function') {
|
14182 | return
|
14183 | }
|
14184 | stack.push(val);
|
14185 |
|
14186 | if (Array.isArray(val)) {
|
14187 | for (i = 0; i < val.length; i++) {
|
14188 | deterministicDecirc(val[i], i, stack, val);
|
14189 | }
|
14190 | } else {
|
14191 |
|
14192 | var tmp = {};
|
14193 | var keys = Object.keys(val).sort(compareFunction);
|
14194 | for (i = 0; i < keys.length; i++) {
|
14195 | var key = keys[i];
|
14196 | deterministicDecirc(val[key], key, stack, val);
|
14197 | tmp[key] = val[key];
|
14198 | }
|
14199 | if (parent !== undefined) {
|
14200 | arr.push([parent, k, val]);
|
14201 | parent[k] = tmp;
|
14202 | } else {
|
14203 | return tmp
|
14204 | }
|
14205 | }
|
14206 | stack.pop();
|
14207 | }
|
14208 | }
|
14209 |
|
14210 |
|
14211 |
|
14212 | function replaceGetterValues (replacer) {
|
14213 | replacer = replacer !== undefined ? replacer : function (k, v) { return v };
|
14214 | return function (key, val) {
|
14215 | if (replacerStack.length > 0) {
|
14216 | for (var i = 0; i < replacerStack.length; i++) {
|
14217 | var part = replacerStack[i];
|
14218 | if (part[1] === key && part[0] === val) {
|
14219 | val = '[Circular]';
|
14220 | replacerStack.splice(i, 1);
|
14221 | break
|
14222 | }
|
14223 | }
|
14224 | }
|
14225 | return replacer.call(this, key, val)
|
14226 | }
|
14227 | }
|
14228 |
|
14229 | function _typeof$1(obj) {
|
14230 | if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
|
14231 | _typeof$1 = function _typeof$1(obj) {
|
14232 | return _typeof(obj);
|
14233 | };
|
14234 | } else {
|
14235 | _typeof$1 = function _typeof$1(obj) {
|
14236 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
|
14237 | };
|
14238 | }
|
14239 |
|
14240 | return _typeof$1(obj);
|
14241 | }
|
14242 | |
14243 |
|
14244 |
|
14245 |
|
14246 |
|
14247 |
|
14248 |
|
14249 |
|
14250 |
|
14251 | function isObject(obj) {
|
14252 | return obj !== null && _typeof$1(obj) === 'object';
|
14253 | }
|
14254 |
|
14255 | var isObject_1 = isObject;
|
14256 |
|
14257 | function _typeof$2(obj) {
|
14258 | if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
|
14259 | _typeof$2 = function _typeof$1(obj) {
|
14260 | return _typeof(obj);
|
14261 | };
|
14262 | } else {
|
14263 | _typeof$2 = function _typeof$1(obj) {
|
14264 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
|
14265 | };
|
14266 | }
|
14267 |
|
14268 | return _typeof$2(obj);
|
14269 | }
|
14270 | |
14271 |
|
14272 |
|
14273 |
|
14274 | |
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 | var requestBase = RequestBase;
|
14280 | |
14281 |
|
14282 |
|
14283 |
|
14284 |
|
14285 |
|
14286 | function RequestBase(obj) {
|
14287 | if (obj) return mixin(obj);
|
14288 | }
|
14289 | |
14290 |
|
14291 |
|
14292 |
|
14293 |
|
14294 |
|
14295 |
|
14296 |
|
14297 |
|
14298 | function mixin(obj) {
|
14299 | for (var key in RequestBase.prototype) {
|
14300 | if (Object.prototype.hasOwnProperty.call(RequestBase.prototype, key)) obj[key] = RequestBase.prototype[key];
|
14301 | }
|
14302 |
|
14303 | return obj;
|
14304 | }
|
14305 | |
14306 |
|
14307 |
|
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 | RequestBase.prototype.clearTimeout = function () {
|
14314 | clearTimeout(this._timer);
|
14315 | clearTimeout(this._responseTimeoutTimer);
|
14316 | clearTimeout(this._uploadTimeoutTimer);
|
14317 | delete this._timer;
|
14318 | delete this._responseTimeoutTimer;
|
14319 | delete this._uploadTimeoutTimer;
|
14320 | return this;
|
14321 | };
|
14322 | |
14323 |
|
14324 |
|
14325 |
|
14326 |
|
14327 |
|
14328 |
|
14329 |
|
14330 |
|
14331 |
|
14332 | RequestBase.prototype.parse = function (fn) {
|
14333 | this._parser = fn;
|
14334 | return this;
|
14335 | };
|
14336 | |
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 |
|
14346 |
|
14347 |
|
14348 |
|
14349 |
|
14350 |
|
14351 |
|
14352 |
|
14353 |
|
14354 |
|
14355 | RequestBase.prototype.responseType = function (val) {
|
14356 | this._responseType = val;
|
14357 | return this;
|
14358 | };
|
14359 | |
14360 |
|
14361 |
|
14362 |
|
14363 |
|
14364 |
|
14365 |
|
14366 |
|
14367 |
|
14368 |
|
14369 | RequestBase.prototype.serialize = function (fn) {
|
14370 | this._serializer = fn;
|
14371 | return this;
|
14372 | };
|
14373 | |
14374 |
|
14375 |
|
14376 |
|
14377 |
|
14378 |
|
14379 |
|
14380 |
|
14381 |
|
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 |
|
14388 | RequestBase.prototype.timeout = function (options) {
|
14389 | if (!options || _typeof$2(options) !== 'object') {
|
14390 | this._timeout = options;
|
14391 | this._responseTimeout = 0;
|
14392 | this._uploadTimeout = 0;
|
14393 | return this;
|
14394 | }
|
14395 |
|
14396 | for (var option in options) {
|
14397 | if (Object.prototype.hasOwnProperty.call(options, option)) {
|
14398 | switch (option) {
|
14399 | case 'deadline':
|
14400 | this._timeout = options.deadline;
|
14401 | break;
|
14402 |
|
14403 | case 'response':
|
14404 | this._responseTimeout = options.response;
|
14405 | break;
|
14406 |
|
14407 | case 'upload':
|
14408 | this._uploadTimeout = options.upload;
|
14409 | break;
|
14410 |
|
14411 | default:
|
14412 | console.warn('Unknown timeout option', option);
|
14413 | }
|
14414 | }
|
14415 | }
|
14416 |
|
14417 | return this;
|
14418 | };
|
14419 | |
14420 |
|
14421 |
|
14422 |
|
14423 |
|
14424 |
|
14425 |
|
14426 |
|
14427 |
|
14428 |
|
14429 |
|
14430 |
|
14431 | RequestBase.prototype.retry = function (count, fn) {
|
14432 |
|
14433 | if (arguments.length === 0 || count === true) count = 1;
|
14434 | if (count <= 0) count = 0;
|
14435 | this._maxRetries = count;
|
14436 | this._retries = 0;
|
14437 | this._retryCallback = fn;
|
14438 | return this;
|
14439 | };
|
14440 |
|
14441 | var ERROR_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EADDRINFO', 'ESOCKETTIMEDOUT'];
|
14442 | |
14443 |
|
14444 |
|
14445 |
|
14446 |
|
14447 |
|
14448 |
|
14449 |
|
14450 |
|
14451 | RequestBase.prototype._shouldRetry = function (err, res) {
|
14452 | if (!this._maxRetries || this._retries++ >= this._maxRetries) {
|
14453 | return false;
|
14454 | }
|
14455 |
|
14456 | if (this._retryCallback) {
|
14457 | try {
|
14458 | var override = this._retryCallback(err, res);
|
14459 |
|
14460 | if (override === true) return true;
|
14461 | if (override === false) return false;
|
14462 | } catch (err2) {
|
14463 | console.error(err2);
|
14464 | }
|
14465 | }
|
14466 |
|
14467 | if (res && res.status && res.status >= 500 && res.status !== 501) return true;
|
14468 |
|
14469 | if (err) {
|
14470 | if (err.code && ERROR_CODES.indexOf(err.code) !== -1) return true;
|
14471 |
|
14472 | if (err.timeout && err.code === 'ECONNABORTED') return true;
|
14473 | if (err.crossDomain) return true;
|
14474 | }
|
14475 |
|
14476 | return false;
|
14477 | };
|
14478 | |
14479 |
|
14480 |
|
14481 |
|
14482 |
|
14483 |
|
14484 |
|
14485 |
|
14486 | RequestBase.prototype._retry = function () {
|
14487 | this.clearTimeout();
|
14488 |
|
14489 | if (this.req) {
|
14490 | this.req = null;
|
14491 | this.req = this.request();
|
14492 | }
|
14493 |
|
14494 | this._aborted = false;
|
14495 | this.timedout = false;
|
14496 | return this._end();
|
14497 | };
|
14498 | |
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 |
|
14504 |
|
14505 |
|
14506 |
|
14507 | RequestBase.prototype.then = function (resolve, reject) {
|
14508 | var _this = this;
|
14509 |
|
14510 | if (!this._fullfilledPromise) {
|
14511 | var self = this;
|
14512 |
|
14513 | if (this._endCalled) {
|
14514 | console.warn('Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises');
|
14515 | }
|
14516 |
|
14517 | this._fullfilledPromise = new Promise(function (resolve, reject) {
|
14518 | self.on('abort', function () {
|
14519 | var err = new Error('Aborted');
|
14520 | err.code = 'ABORTED';
|
14521 | err.status = _this.status;
|
14522 | err.method = _this.method;
|
14523 | err.url = _this.url;
|
14524 | reject(err);
|
14525 | });
|
14526 | self.end(function (err, res) {
|
14527 | if (err) reject(err);else resolve(res);
|
14528 | });
|
14529 | });
|
14530 | }
|
14531 |
|
14532 | return this._fullfilledPromise.then(resolve, reject);
|
14533 | };
|
14534 |
|
14535 | RequestBase.prototype.catch = function (cb) {
|
14536 | return this.then(undefined, cb);
|
14537 | };
|
14538 | |
14539 |
|
14540 |
|
14541 |
|
14542 |
|
14543 | RequestBase.prototype.use = function (fn) {
|
14544 | fn(this);
|
14545 | return this;
|
14546 | };
|
14547 |
|
14548 | RequestBase.prototype.ok = function (cb) {
|
14549 | if (typeof cb !== 'function') throw new Error('Callback required');
|
14550 | this._okCallback = cb;
|
14551 | return this;
|
14552 | };
|
14553 |
|
14554 | RequestBase.prototype._isResponseOK = function (res) {
|
14555 | if (!res) {
|
14556 | return false;
|
14557 | }
|
14558 |
|
14559 | if (this._okCallback) {
|
14560 | return this._okCallback(res);
|
14561 | }
|
14562 |
|
14563 | return res.status >= 200 && res.status < 300;
|
14564 | };
|
14565 | |
14566 |
|
14567 |
|
14568 |
|
14569 |
|
14570 |
|
14571 |
|
14572 |
|
14573 |
|
14574 |
|
14575 | RequestBase.prototype.get = function (field) {
|
14576 | return this._header[field.toLowerCase()];
|
14577 | };
|
14578 | |
14579 |
|
14580 |
|
14581 |
|
14582 |
|
14583 |
|
14584 |
|
14585 |
|
14586 |
|
14587 |
|
14588 |
|
14589 |
|
14590 |
|
14591 | RequestBase.prototype.getHeader = RequestBase.prototype.get;
|
14592 | |
14593 |
|
14594 |
|
14595 |
|
14596 |
|
14597 |
|
14598 |
|
14599 |
|
14600 |
|
14601 |
|
14602 |
|
14603 |
|
14604 |
|
14605 |
|
14606 |
|
14607 |
|
14608 |
|
14609 |
|
14610 |
|
14611 |
|
14612 |
|
14613 | RequestBase.prototype.set = function (field, val) {
|
14614 | if (isObject_1(field)) {
|
14615 | for (var key in field) {
|
14616 | if (Object.prototype.hasOwnProperty.call(field, key)) this.set(key, field[key]);
|
14617 | }
|
14618 |
|
14619 | return this;
|
14620 | }
|
14621 |
|
14622 | this._header[field.toLowerCase()] = val;
|
14623 | this.header[field] = val;
|
14624 | return this;
|
14625 | };
|
14626 |
|
14627 | |
14628 |
|
14629 |
|
14630 |
|
14631 |
|
14632 |
|
14633 |
|
14634 |
|
14635 |
|
14636 |
|
14637 |
|
14638 |
|
14639 |
|
14640 |
|
14641 | RequestBase.prototype.unset = function (field) {
|
14642 | delete this._header[field.toLowerCase()];
|
14643 | delete this.header[field];
|
14644 | return this;
|
14645 | };
|
14646 | |
14647 |
|
14648 |
|
14649 |
|
14650 |
|
14651 |
|
14652 |
|
14653 |
|
14654 |
|
14655 |
|
14656 |
|
14657 |
|
14658 |
|
14659 |
|
14660 |
|
14661 |
|
14662 |
|
14663 |
|
14664 |
|
14665 |
|
14666 |
|
14667 | RequestBase.prototype.field = function (name, val) {
|
14668 |
|
14669 | if (name === null || undefined === name) {
|
14670 | throw new Error('.field(name, val) name can not be empty');
|
14671 | }
|
14672 |
|
14673 | if (this._data) {
|
14674 | throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");
|
14675 | }
|
14676 |
|
14677 | if (isObject_1(name)) {
|
14678 | for (var key in name) {
|
14679 | if (Object.prototype.hasOwnProperty.call(name, key)) this.field(key, name[key]);
|
14680 | }
|
14681 |
|
14682 | return this;
|
14683 | }
|
14684 |
|
14685 | if (Array.isArray(val)) {
|
14686 | for (var i in val) {
|
14687 | if (Object.prototype.hasOwnProperty.call(val, i)) this.field(name, val[i]);
|
14688 | }
|
14689 |
|
14690 | return this;
|
14691 | }
|
14692 |
|
14693 |
|
14694 | if (val === null || undefined === val) {
|
14695 | throw new Error('.field(name, val) val can not be empty');
|
14696 | }
|
14697 |
|
14698 | if (typeof val === 'boolean') {
|
14699 | val = String(val);
|
14700 | }
|
14701 |
|
14702 | this._getFormData().append(name, val);
|
14703 |
|
14704 | return this;
|
14705 | };
|
14706 | |
14707 |
|
14708 |
|
14709 |
|
14710 |
|
14711 |
|
14712 |
|
14713 |
|
14714 | RequestBase.prototype.abort = function () {
|
14715 | if (this._aborted) {
|
14716 | return this;
|
14717 | }
|
14718 |
|
14719 | this._aborted = true;
|
14720 | if (this.xhr) this.xhr.abort();
|
14721 |
|
14722 | if (this.req) this.req.abort();
|
14723 |
|
14724 | this.clearTimeout();
|
14725 | this.emit('abort');
|
14726 | return this;
|
14727 | };
|
14728 |
|
14729 | RequestBase.prototype._auth = function (user, pass, options, base64Encoder) {
|
14730 | switch (options.type) {
|
14731 | case 'basic':
|
14732 | this.set('Authorization', "Basic ".concat(base64Encoder("".concat(user, ":").concat(pass))));
|
14733 | break;
|
14734 |
|
14735 | case 'auto':
|
14736 | this.username = user;
|
14737 | this.password = pass;
|
14738 | break;
|
14739 |
|
14740 | case 'bearer':
|
14741 |
|
14742 | this.set('Authorization', "Bearer ".concat(user));
|
14743 | break;
|
14744 |
|
14745 | default:
|
14746 | break;
|
14747 | }
|
14748 |
|
14749 | return this;
|
14750 | };
|
14751 | |
14752 |
|
14753 |
|
14754 |
|
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 |
|
14760 |
|
14761 |
|
14762 |
|
14763 | RequestBase.prototype.withCredentials = function (on) {
|
14764 |
|
14765 | if (on === undefined) on = true;
|
14766 | this._withCredentials = on;
|
14767 | return this;
|
14768 | };
|
14769 | |
14770 |
|
14771 |
|
14772 |
|
14773 |
|
14774 |
|
14775 |
|
14776 |
|
14777 |
|
14778 | RequestBase.prototype.redirects = function (n) {
|
14779 | this._maxRedirects = n;
|
14780 | return this;
|
14781 | };
|
14782 | |
14783 |
|
14784 |
|
14785 |
|
14786 |
|
14787 |
|
14788 |
|
14789 |
|
14790 |
|
14791 | RequestBase.prototype.maxResponseSize = function (n) {
|
14792 | if (typeof n !== 'number') {
|
14793 | throw new TypeError('Invalid argument');
|
14794 | }
|
14795 |
|
14796 | this._maxResponseSize = n;
|
14797 | return this;
|
14798 | };
|
14799 | |
14800 |
|
14801 |
|
14802 |
|
14803 |
|
14804 |
|
14805 |
|
14806 |
|
14807 |
|
14808 |
|
14809 | RequestBase.prototype.toJSON = function () {
|
14810 | return {
|
14811 | method: this.method,
|
14812 | url: this.url,
|
14813 | data: this._data,
|
14814 | headers: this._header
|
14815 | };
|
14816 | };
|
14817 | |
14818 |
|
14819 |
|
14820 |
|
14821 |
|
14822 |
|
14823 |
|
14824 |
|
14825 |
|
14826 |
|
14827 |
|
14828 |
|
14829 |
|
14830 |
|
14831 |
|
14832 |
|
14833 |
|
14834 |
|
14835 |
|
14836 |
|
14837 |
|
14838 |
|
14839 |
|
14840 |
|
14841 |
|
14842 |
|
14843 |
|
14844 |
|
14845 |
|
14846 |
|
14847 |
|
14848 |
|
14849 |
|
14850 |
|
14851 |
|
14852 |
|
14853 |
|
14854 |
|
14855 |
|
14856 |
|
14857 |
|
14858 |
|
14859 | RequestBase.prototype.send = function (data) {
|
14860 | var isObj = isObject_1(data);
|
14861 | var type = this._header['content-type'];
|
14862 |
|
14863 | if (this._formData) {
|
14864 | throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");
|
14865 | }
|
14866 |
|
14867 | if (isObj && !this._data) {
|
14868 | if (Array.isArray(data)) {
|
14869 | this._data = [];
|
14870 | } else if (!this._isHost(data)) {
|
14871 | this._data = {};
|
14872 | }
|
14873 | } else if (data && this._data && this._isHost(this._data)) {
|
14874 | throw new Error("Can't merge these send calls");
|
14875 | }
|
14876 |
|
14877 |
|
14878 | if (isObj && isObject_1(this._data)) {
|
14879 | for (var key in data) {
|
14880 | if (Object.prototype.hasOwnProperty.call(data, key)) this._data[key] = data[key];
|
14881 | }
|
14882 | } else if (typeof data === 'string') {
|
14883 |
|
14884 | if (!type) this.type('form');
|
14885 | type = this._header['content-type'];
|
14886 |
|
14887 | if (type === 'application/x-www-form-urlencoded') {
|
14888 | this._data = this._data ? "".concat(this._data, "&").concat(data) : data;
|
14889 | } else {
|
14890 | this._data = (this._data || '') + data;
|
14891 | }
|
14892 | } else {
|
14893 | this._data = data;
|
14894 | }
|
14895 |
|
14896 | if (!isObj || this._isHost(data)) {
|
14897 | return this;
|
14898 | }
|
14899 |
|
14900 |
|
14901 | if (!type) this.type('json');
|
14902 | return this;
|
14903 | };
|
14904 | |
14905 |
|
14906 |
|
14907 |
|
14908 |
|
14909 |
|
14910 |
|
14911 |
|
14912 |
|
14913 |
|
14914 |
|
14915 |
|
14916 |
|
14917 |
|
14918 |
|
14919 |
|
14920 |
|
14921 |
|
14922 |
|
14923 |
|
14924 |
|
14925 |
|
14926 |
|
14927 |
|
14928 |
|
14929 |
|
14930 |
|
14931 |
|
14932 |
|
14933 | RequestBase.prototype.sortQuery = function (sort) {
|
14934 |
|
14935 | this._sort = typeof sort === 'undefined' ? true : sort;
|
14936 | return this;
|
14937 | };
|
14938 | |
14939 |
|
14940 |
|
14941 |
|
14942 |
|
14943 |
|
14944 |
|
14945 | RequestBase.prototype._finalizeQueryString = function () {
|
14946 | var query = this._query.join('&');
|
14947 |
|
14948 | if (query) {
|
14949 | this.url += (this.url.indexOf('?') >= 0 ? '&' : '?') + query;
|
14950 | }
|
14951 |
|
14952 | this._query.length = 0;
|
14953 |
|
14954 | if (this._sort) {
|
14955 | var index = this.url.indexOf('?');
|
14956 |
|
14957 | if (index >= 0) {
|
14958 | var queryArr = this.url.substring(index + 1).split('&');
|
14959 |
|
14960 | if (typeof this._sort === 'function') {
|
14961 | queryArr.sort(this._sort);
|
14962 | } else {
|
14963 | queryArr.sort();
|
14964 | }
|
14965 |
|
14966 | this.url = this.url.substring(0, index) + '?' + queryArr.join('&');
|
14967 | }
|
14968 | }
|
14969 | };
|
14970 |
|
14971 |
|
14972 | RequestBase.prototype._appendQueryString = function () {
|
14973 | console.warn('Unsupported');
|
14974 | };
|
14975 | |
14976 |
|
14977 |
|
14978 |
|
14979 |
|
14980 |
|
14981 |
|
14982 | RequestBase.prototype._timeoutError = function (reason, timeout, errno) {
|
14983 | if (this._aborted) {
|
14984 | return;
|
14985 | }
|
14986 |
|
14987 | var err = new Error("".concat(reason + timeout, "ms exceeded"));
|
14988 | err.timeout = timeout;
|
14989 | err.code = 'ECONNABORTED';
|
14990 | err.errno = errno;
|
14991 | this.timedout = true;
|
14992 | this.abort();
|
14993 | this.callback(err);
|
14994 | };
|
14995 |
|
14996 | RequestBase.prototype._setTimeouts = function () {
|
14997 | var self = this;
|
14998 |
|
14999 | if (this._timeout && !this._timer) {
|
15000 | this._timer = setTimeout(function () {
|
15001 | self._timeoutError('Timeout of ', self._timeout, 'ETIME');
|
15002 | }, this._timeout);
|
15003 | }
|
15004 |
|
15005 |
|
15006 | if (this._responseTimeout && !this._responseTimeoutTimer) {
|
15007 | this._responseTimeoutTimer = setTimeout(function () {
|
15008 | self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT');
|
15009 | }, this._responseTimeout);
|
15010 | }
|
15011 | };
|
15012 |
|
15013 | |
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 |
|
15021 | var type = function type(str) {
|
15022 | return str.split(/ *; */).shift();
|
15023 | };
|
15024 | |
15025 |
|
15026 |
|
15027 |
|
15028 |
|
15029 |
|
15030 |
|
15031 |
|
15032 |
|
15033 | var params = function params(str) {
|
15034 | return str.split(/ *; */).reduce(function (obj, str) {
|
15035 | var parts = str.split(/ *= */);
|
15036 | var key = parts.shift();
|
15037 | var val = parts.shift();
|
15038 | if (key && val) obj[key] = val;
|
15039 | return obj;
|
15040 | }, {});
|
15041 | };
|
15042 | |
15043 |
|
15044 |
|
15045 |
|
15046 |
|
15047 |
|
15048 |
|
15049 |
|
15050 |
|
15051 | var parseLinks = function parseLinks(str) {
|
15052 | return str.split(/ *, */).reduce(function (obj, str) {
|
15053 | var parts = str.split(/ *; */);
|
15054 | var url = parts[0].slice(1, -1);
|
15055 | var rel = parts[1].split(/ *= */)[1].slice(1, -1);
|
15056 | obj[rel] = url;
|
15057 | return obj;
|
15058 | }, {});
|
15059 | };
|
15060 | |
15061 |
|
15062 |
|
15063 |
|
15064 |
|
15065 |
|
15066 |
|
15067 |
|
15068 |
|
15069 | var cleanHeader = function cleanHeader(header, changesOrigin) {
|
15070 | delete header['content-type'];
|
15071 | delete header['content-length'];
|
15072 | delete header['transfer-encoding'];
|
15073 | delete header.host;
|
15074 |
|
15075 | if (changesOrigin) {
|
15076 | delete header.authorization;
|
15077 | delete header.cookie;
|
15078 | }
|
15079 |
|
15080 | return header;
|
15081 | };
|
15082 |
|
15083 | var utils = {
|
15084 | type: type,
|
15085 | params: params,
|
15086 | parseLinks: parseLinks,
|
15087 | cleanHeader: cleanHeader
|
15088 | };
|
15089 |
|
15090 | |
15091 |
|
15092 |
|
15093 |
|
15094 | |
15095 |
|
15096 |
|
15097 |
|
15098 |
|
15099 | var responseBase = ResponseBase;
|
15100 | |
15101 |
|
15102 |
|
15103 |
|
15104 |
|
15105 |
|
15106 | function ResponseBase(obj) {
|
15107 | if (obj) return mixin$1(obj);
|
15108 | }
|
15109 | |
15110 |
|
15111 |
|
15112 |
|
15113 |
|
15114 |
|
15115 |
|
15116 |
|
15117 |
|
15118 | function mixin$1(obj) {
|
15119 | for (var key in ResponseBase.prototype) {
|
15120 | if (Object.prototype.hasOwnProperty.call(ResponseBase.prototype, key)) obj[key] = ResponseBase.prototype[key];
|
15121 | }
|
15122 |
|
15123 | return obj;
|
15124 | }
|
15125 | |
15126 |
|
15127 |
|
15128 |
|
15129 |
|
15130 |
|
15131 |
|
15132 |
|
15133 |
|
15134 | ResponseBase.prototype.get = function (field) {
|
15135 | return this.header[field.toLowerCase()];
|
15136 | };
|
15137 | |
15138 |
|
15139 |
|
15140 |
|
15141 |
|
15142 |
|
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 |
|
15150 | ResponseBase.prototype._setHeaderProperties = function (header) {
|
15151 |
|
15152 |
|
15153 |
|
15154 | var ct = header['content-type'] || '';
|
15155 | this.type = utils.type(ct);
|
15156 |
|
15157 | var params = utils.params(ct);
|
15158 |
|
15159 | for (var key in params) {
|
15160 | if (Object.prototype.hasOwnProperty.call(params, key)) this[key] = params[key];
|
15161 | }
|
15162 |
|
15163 | this.links = {};
|
15164 |
|
15165 | try {
|
15166 | if (header.link) {
|
15167 | this.links = utils.parseLinks(header.link);
|
15168 | }
|
15169 | } catch (err) {
|
15170 | }
|
15171 | };
|
15172 | |
15173 |
|
15174 |
|
15175 |
|
15176 |
|
15177 |
|
15178 |
|
15179 |
|
15180 |
|
15181 |
|
15182 |
|
15183 |
|
15184 |
|
15185 |
|
15186 |
|
15187 |
|
15188 |
|
15189 |
|
15190 |
|
15191 |
|
15192 |
|
15193 |
|
15194 | ResponseBase.prototype._setStatusProperties = function (status) {
|
15195 | var type = status / 100 | 0;
|
15196 |
|
15197 | this.statusCode = status;
|
15198 | this.status = this.statusCode;
|
15199 | this.statusType = type;
|
15200 |
|
15201 | this.info = type === 1;
|
15202 | this.ok = type === 2;
|
15203 | this.redirect = type === 3;
|
15204 | this.clientError = type === 4;
|
15205 | this.serverError = type === 5;
|
15206 | this.error = type === 4 || type === 5 ? this.toError() : false;
|
15207 |
|
15208 | this.created = status === 201;
|
15209 | this.accepted = status === 202;
|
15210 | this.noContent = status === 204;
|
15211 | this.badRequest = status === 400;
|
15212 | this.unauthorized = status === 401;
|
15213 | this.notAcceptable = status === 406;
|
15214 | this.forbidden = status === 403;
|
15215 | this.notFound = status === 404;
|
15216 | this.unprocessableEntity = status === 422;
|
15217 | };
|
15218 |
|
15219 | function _toConsumableArray$1(arr) {
|
15220 | return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
|
15221 | }
|
15222 |
|
15223 | function _nonIterableSpread$1() {
|
15224 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
15225 | }
|
15226 |
|
15227 | function _iterableToArray$1(iter) {
|
15228 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
15229 | }
|
15230 |
|
15231 | function _arrayWithoutHoles$1(arr) {
|
15232 | if (Array.isArray(arr)) {
|
15233 | for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
|
15234 | arr2[i] = arr[i];
|
15235 | }
|
15236 |
|
15237 | return arr2;
|
15238 | }
|
15239 | }
|
15240 |
|
15241 | function Agent() {
|
15242 | this._defaults = [];
|
15243 | }
|
15244 |
|
15245 | ['use', 'on', 'once', 'set', 'query', 'type', 'accept', 'auth', 'withCredentials', 'sortQuery', 'retry', 'ok', 'redirects', 'timeout', 'buffer', 'serialize', 'parse', 'ca', 'key', 'pfx', 'cert'].forEach(function (fn) {
|
15246 |
|
15247 | Agent.prototype[fn] = function () {
|
15248 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
15249 | args[_key] = arguments[_key];
|
15250 | }
|
15251 |
|
15252 | this._defaults.push({
|
15253 | fn: fn,
|
15254 | args: args
|
15255 | });
|
15256 |
|
15257 | return this;
|
15258 | };
|
15259 | });
|
15260 |
|
15261 | Agent.prototype._setDefaults = function (req) {
|
15262 | this._defaults.forEach(function (def) {
|
15263 | req[def.fn].apply(req, _toConsumableArray$1(def.args));
|
15264 | });
|
15265 | };
|
15266 |
|
15267 | var agentBase = Agent;
|
15268 |
|
15269 | var client = createCommonjsModule(function (module, exports) {
|
15270 |
|
15271 | function _typeof$1(obj) {
|
15272 | if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
|
15273 | _typeof$1 = function _typeof$1(obj) {
|
15274 | return _typeof(obj);
|
15275 | };
|
15276 | } else {
|
15277 | _typeof$1 = function _typeof$1(obj) {
|
15278 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
|
15279 | };
|
15280 | }
|
15281 |
|
15282 | return _typeof$1(obj);
|
15283 | }
|
15284 | |
15285 |
|
15286 |
|
15287 |
|
15288 |
|
15289 | var root;
|
15290 |
|
15291 | if (typeof window !== 'undefined') {
|
15292 |
|
15293 | root = window;
|
15294 | } else if (typeof self === 'undefined') {
|
15295 |
|
15296 | console.warn('Using browser-only version of superagent in non-browser environment');
|
15297 | root = void 0;
|
15298 | } else {
|
15299 |
|
15300 | root = self;
|
15301 | }
|
15302 | |
15303 |
|
15304 |
|
15305 |
|
15306 |
|
15307 | function noop() {}
|
15308 | |
15309 |
|
15310 |
|
15311 |
|
15312 |
|
15313 | module.exports = function (method, url) {
|
15314 |
|
15315 | if (typeof url === 'function') {
|
15316 | return new exports.Request('GET', method).end(url);
|
15317 | }
|
15318 |
|
15319 |
|
15320 | if (arguments.length === 1) {
|
15321 | return new exports.Request('GET', method);
|
15322 | }
|
15323 |
|
15324 | return new exports.Request(method, url);
|
15325 | };
|
15326 |
|
15327 | exports = module.exports;
|
15328 | var request = exports;
|
15329 | exports.Request = Request;
|
15330 | |
15331 |
|
15332 |
|
15333 |
|
15334 | request.getXHR = function () {
|
15335 | if (root.XMLHttpRequest && (!root.location || root.location.protocol !== 'file:' || !root.ActiveXObject)) {
|
15336 | return new XMLHttpRequest();
|
15337 | }
|
15338 |
|
15339 | try {
|
15340 | return new ActiveXObject('Microsoft.XMLHTTP');
|
15341 | } catch (err) {}
|
15342 |
|
15343 | try {
|
15344 | return new ActiveXObject('Msxml2.XMLHTTP.6.0');
|
15345 | } catch (err) {}
|
15346 |
|
15347 | try {
|
15348 | return new ActiveXObject('Msxml2.XMLHTTP.3.0');
|
15349 | } catch (err) {}
|
15350 |
|
15351 | try {
|
15352 | return new ActiveXObject('Msxml2.XMLHTTP');
|
15353 | } catch (err) {}
|
15354 |
|
15355 | throw new Error('Browser-only version of superagent could not find XHR');
|
15356 | };
|
15357 | |
15358 |
|
15359 |
|
15360 |
|
15361 |
|
15362 |
|
15363 |
|
15364 |
|
15365 |
|
15366 | var trim = ''.trim ? function (s) {
|
15367 | return s.trim();
|
15368 | } : function (s) {
|
15369 | return s.replace(/(^\s*|\s*$)/g, '');
|
15370 | };
|
15371 | |
15372 |
|
15373 |
|
15374 |
|
15375 |
|
15376 |
|
15377 |
|
15378 |
|
15379 | function serialize(obj) {
|
15380 | if (!isObject_1(obj)) return obj;
|
15381 | var pairs = [];
|
15382 |
|
15383 | for (var key in obj) {
|
15384 | if (Object.prototype.hasOwnProperty.call(obj, key)) pushEncodedKeyValuePair(pairs, key, obj[key]);
|
15385 | }
|
15386 |
|
15387 | return pairs.join('&');
|
15388 | }
|
15389 | |
15390 |
|
15391 |
|
15392 |
|
15393 |
|
15394 |
|
15395 |
|
15396 |
|
15397 |
|
15398 |
|
15399 | function pushEncodedKeyValuePair(pairs, key, val) {
|
15400 | if (val === undefined) return;
|
15401 |
|
15402 | if (val === null) {
|
15403 | pairs.push(encodeURIComponent(key));
|
15404 | return;
|
15405 | }
|
15406 |
|
15407 | if (Array.isArray(val)) {
|
15408 | val.forEach(function (v) {
|
15409 | pushEncodedKeyValuePair(pairs, key, v);
|
15410 | });
|
15411 | } else if (isObject_1(val)) {
|
15412 | for (var subkey in val) {
|
15413 | if (Object.prototype.hasOwnProperty.call(val, subkey)) pushEncodedKeyValuePair(pairs, "".concat(key, "[").concat(subkey, "]"), val[subkey]);
|
15414 | }
|
15415 | } else {
|
15416 | pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
|
15417 | }
|
15418 | }
|
15419 | |
15420 |
|
15421 |
|
15422 |
|
15423 |
|
15424 | request.serializeObject = serialize;
|
15425 | |
15426 |
|
15427 |
|
15428 |
|
15429 |
|
15430 |
|
15431 |
|
15432 |
|
15433 | function parseString(str) {
|
15434 | var obj = {};
|
15435 | var pairs = str.split('&');
|
15436 | var pair;
|
15437 | var pos;
|
15438 |
|
15439 | for (var i = 0, len = pairs.length; i < len; ++i) {
|
15440 | pair = pairs[i];
|
15441 | pos = pair.indexOf('=');
|
15442 |
|
15443 | if (pos === -1) {
|
15444 | obj[decodeURIComponent(pair)] = '';
|
15445 | } else {
|
15446 | obj[decodeURIComponent(pair.slice(0, pos))] = decodeURIComponent(pair.slice(pos + 1));
|
15447 | }
|
15448 | }
|
15449 |
|
15450 | return obj;
|
15451 | }
|
15452 | |
15453 |
|
15454 |
|
15455 |
|
15456 |
|
15457 | request.parseString = parseString;
|
15458 | |
15459 |
|
15460 |
|
15461 |
|
15462 |
|
15463 |
|
15464 |
|
15465 | request.types = {
|
15466 | html: 'text/html',
|
15467 | json: 'application/json',
|
15468 | xml: 'text/xml',
|
15469 | urlencoded: 'application/x-www-form-urlencoded',
|
15470 | form: 'application/x-www-form-urlencoded',
|
15471 | 'form-data': 'application/x-www-form-urlencoded'
|
15472 | };
|
15473 | |
15474 |
|
15475 |
|
15476 |
|
15477 |
|
15478 |
|
15479 |
|
15480 |
|
15481 |
|
15482 | request.serialize = {
|
15483 | 'application/x-www-form-urlencoded': serialize,
|
15484 | 'application/json': fastSafeStringify
|
15485 | };
|
15486 | |
15487 |
|
15488 |
|
15489 |
|
15490 |
|
15491 |
|
15492 |
|
15493 |
|
15494 |
|
15495 | request.parse = {
|
15496 | 'application/x-www-form-urlencoded': parseString,
|
15497 | 'application/json': JSON.parse
|
15498 | };
|
15499 | |
15500 |
|
15501 |
|
15502 |
|
15503 |
|
15504 |
|
15505 |
|
15506 |
|
15507 |
|
15508 | function parseHeader(str) {
|
15509 | var lines = str.split(/\r?\n/);
|
15510 | var fields = {};
|
15511 | var index;
|
15512 | var line;
|
15513 | var field;
|
15514 | var val;
|
15515 |
|
15516 | for (var i = 0, len = lines.length; i < len; ++i) {
|
15517 | line = lines[i];
|
15518 | index = line.indexOf(':');
|
15519 |
|
15520 | if (index === -1) {
|
15521 |
|
15522 | continue;
|
15523 | }
|
15524 |
|
15525 | field = line.slice(0, index).toLowerCase();
|
15526 | val = trim(line.slice(index + 1));
|
15527 | fields[field] = val;
|
15528 | }
|
15529 |
|
15530 | return fields;
|
15531 | }
|
15532 | |
15533 |
|
15534 |
|
15535 |
|
15536 |
|
15537 |
|
15538 |
|
15539 |
|
15540 |
|
15541 | function isJSON(mime) {
|
15542 |
|
15543 |
|
15544 | return /[/+]json($|[^-\w])/.test(mime);
|
15545 | }
|
15546 | |
15547 |
|
15548 |
|
15549 |
|
15550 |
|
15551 |
|
15552 |
|
15553 |
|
15554 |
|
15555 |
|
15556 |
|
15557 |
|
15558 |
|
15559 |
|
15560 |
|
15561 |
|
15562 |
|
15563 |
|
15564 |
|
15565 |
|
15566 |
|
15567 |
|
15568 |
|
15569 |
|
15570 |
|
15571 |
|
15572 |
|
15573 |
|
15574 |
|
15575 |
|
15576 |
|
15577 |
|
15578 |
|
15579 |
|
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 |
|
15585 |
|
15586 |
|
15587 |
|
15588 |
|
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 | function Response(req) {
|
15594 | this.req = req;
|
15595 | this.xhr = this.req.xhr;
|
15596 |
|
15597 | this.text = this.req.method !== 'HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text') || typeof this.xhr.responseType === 'undefined' ? this.xhr.responseText : null;
|
15598 | this.statusText = this.req.xhr.statusText;
|
15599 | var status = this.xhr.status;
|
15600 |
|
15601 | if (status === 1223) {
|
15602 | status = 204;
|
15603 | }
|
15604 |
|
15605 | this._setStatusProperties(status);
|
15606 |
|
15607 | this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
15608 | this.header = this.headers;
|
15609 |
|
15610 |
|
15611 |
|
15612 | this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
15613 |
|
15614 | this._setHeaderProperties(this.header);
|
15615 |
|
15616 | if (this.text === null && req._responseType) {
|
15617 | this.body = this.xhr.response;
|
15618 | } else {
|
15619 | this.body = this.req.method === 'HEAD' ? null : this._parseBody(this.text ? this.text : this.xhr.response);
|
15620 | }
|
15621 | }
|
15622 |
|
15623 |
|
15624 | responseBase(Response.prototype);
|
15625 | |
15626 |
|
15627 |
|
15628 |
|
15629 |
|
15630 |
|
15631 |
|
15632 |
|
15633 |
|
15634 |
|
15635 |
|
15636 | Response.prototype._parseBody = function (str) {
|
15637 | var parse = request.parse[this.type];
|
15638 |
|
15639 | if (this.req._parser) {
|
15640 | return this.req._parser(this, str);
|
15641 | }
|
15642 |
|
15643 | if (!parse && isJSON(this.type)) {
|
15644 | parse = request.parse['application/json'];
|
15645 | }
|
15646 |
|
15647 | return parse && str && (str.length > 0 || str instanceof Object) ? parse(str) : null;
|
15648 | };
|
15649 | |
15650 |
|
15651 |
|
15652 |
|
15653 |
|
15654 |
|
15655 |
|
15656 |
|
15657 | Response.prototype.toError = function () {
|
15658 | var req = this.req;
|
15659 | var method = req.method;
|
15660 | var url = req.url;
|
15661 | var msg = "cannot ".concat(method, " ").concat(url, " (").concat(this.status, ")");
|
15662 | var err = new Error(msg);
|
15663 | err.status = this.status;
|
15664 | err.method = method;
|
15665 | err.url = url;
|
15666 | return err;
|
15667 | };
|
15668 | |
15669 |
|
15670 |
|
15671 |
|
15672 |
|
15673 | request.Response = Response;
|
15674 | |
15675 |
|
15676 |
|
15677 |
|
15678 |
|
15679 |
|
15680 |
|
15681 |
|
15682 | function Request(method, url) {
|
15683 | var self = this;
|
15684 | this._query = this._query || [];
|
15685 | this.method = method;
|
15686 | this.url = url;
|
15687 | this.header = {};
|
15688 |
|
15689 | this._header = {};
|
15690 |
|
15691 | this.on('end', function () {
|
15692 | var err = null;
|
15693 | var res = null;
|
15694 |
|
15695 | try {
|
15696 | res = new Response(self);
|
15697 | } catch (err2) {
|
15698 | err = new Error('Parser is unable to parse the response');
|
15699 | err.parse = true;
|
15700 | err.original = err2;
|
15701 |
|
15702 | if (self.xhr) {
|
15703 |
|
15704 | err.rawResponse = typeof self.xhr.responseType === 'undefined' ? self.xhr.responseText : self.xhr.response;
|
15705 |
|
15706 | err.status = self.xhr.status ? self.xhr.status : null;
|
15707 | err.statusCode = err.status;
|
15708 | } else {
|
15709 | err.rawResponse = null;
|
15710 | err.status = null;
|
15711 | }
|
15712 |
|
15713 | return self.callback(err);
|
15714 | }
|
15715 |
|
15716 | self.emit('response', res);
|
15717 | var new_err;
|
15718 |
|
15719 | try {
|
15720 | if (!self._isResponseOK(res)) {
|
15721 | new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
15722 | }
|
15723 | } catch (err2) {
|
15724 | new_err = err2;
|
15725 | }
|
15726 |
|
15727 |
|
15728 | if (new_err) {
|
15729 | new_err.original = err;
|
15730 | new_err.response = res;
|
15731 | new_err.status = res.status;
|
15732 | self.callback(new_err, res);
|
15733 | } else {
|
15734 | self.callback(null, res);
|
15735 | }
|
15736 | });
|
15737 | }
|
15738 | |
15739 |
|
15740 |
|
15741 |
|
15742 |
|
15743 |
|
15744 | componentEmitter(Request.prototype);
|
15745 |
|
15746 | requestBase(Request.prototype);
|
15747 | |
15748 |
|
15749 |
|
15750 |
|
15751 |
|
15752 |
|
15753 |
|
15754 |
|
15755 |
|
15756 |
|
15757 |
|
15758 |
|
15759 |
|
15760 |
|
15761 |
|
15762 |
|
15763 |
|
15764 |
|
15765 |
|
15766 |
|
15767 |
|
15768 |
|
15769 | Request.prototype.type = function (type) {
|
15770 | this.set('Content-Type', request.types[type] || type);
|
15771 | return this;
|
15772 | };
|
15773 | |
15774 |
|
15775 |
|
15776 |
|
15777 |
|
15778 |
|
15779 |
|
15780 |
|
15781 |
|
15782 |
|
15783 |
|
15784 |
|
15785 |
|
15786 |
|
15787 |
|
15788 |
|
15789 |
|
15790 |
|
15791 |
|
15792 |
|
15793 |
|
15794 | Request.prototype.accept = function (type) {
|
15795 | this.set('Accept', request.types[type] || type);
|
15796 | return this;
|
15797 | };
|
15798 | |
15799 |
|
15800 |
|
15801 |
|
15802 |
|
15803 |
|
15804 |
|
15805 |
|
15806 |
|
15807 |
|
15808 |
|
15809 | Request.prototype.auth = function (user, pass, options) {
|
15810 | if (arguments.length === 1) pass = '';
|
15811 |
|
15812 | if (_typeof$1(pass) === 'object' && pass !== null) {
|
15813 |
|
15814 | options = pass;
|
15815 | pass = '';
|
15816 | }
|
15817 |
|
15818 | if (!options) {
|
15819 | options = {
|
15820 | type: typeof btoa === 'function' ? 'basic' : 'auto'
|
15821 | };
|
15822 | }
|
15823 |
|
15824 | var encoder = function encoder(string) {
|
15825 | if (typeof btoa === 'function') {
|
15826 | return btoa(string);
|
15827 | }
|
15828 |
|
15829 | throw new Error('Cannot use basic auth, btoa is not a function');
|
15830 | };
|
15831 |
|
15832 | return this._auth(user, pass, options, encoder);
|
15833 | };
|
15834 | |
15835 |
|
15836 |
|
15837 |
|
15838 |
|
15839 |
|
15840 |
|
15841 |
|
15842 |
|
15843 |
|
15844 |
|
15845 |
|
15846 |
|
15847 |
|
15848 |
|
15849 | Request.prototype.query = function (val) {
|
15850 | if (typeof val !== 'string') val = serialize(val);
|
15851 | if (val) this._query.push(val);
|
15852 | return this;
|
15853 | };
|
15854 | |
15855 |
|
15856 |
|
15857 |
|
15858 |
|
15859 |
|
15860 |
|
15861 |
|
15862 |
|
15863 |
|
15864 |
|
15865 |
|
15866 |
|
15867 |
|
15868 |
|
15869 |
|
15870 |
|
15871 |
|
15872 | Request.prototype.attach = function (field, file, options) {
|
15873 | if (file) {
|
15874 | if (this._data) {
|
15875 | throw new Error("superagent can't mix .send() and .attach()");
|
15876 | }
|
15877 |
|
15878 | this._getFormData().append(field, file, options || file.name);
|
15879 | }
|
15880 |
|
15881 | return this;
|
15882 | };
|
15883 |
|
15884 | Request.prototype._getFormData = function () {
|
15885 | if (!this._formData) {
|
15886 | this._formData = new root.FormData();
|
15887 | }
|
15888 |
|
15889 | return this._formData;
|
15890 | };
|
15891 | |
15892 |
|
15893 |
|
15894 |
|
15895 |
|
15896 |
|
15897 |
|
15898 |
|
15899 |
|
15900 |
|
15901 | Request.prototype.callback = function (err, res) {
|
15902 | if (this._shouldRetry(err, res)) {
|
15903 | return this._retry();
|
15904 | }
|
15905 |
|
15906 | var fn = this._callback;
|
15907 | this.clearTimeout();
|
15908 |
|
15909 | if (err) {
|
15910 | if (this._maxRetries) err.retries = this._retries - 1;
|
15911 | this.emit('error', err);
|
15912 | }
|
15913 |
|
15914 | fn(err, res);
|
15915 | };
|
15916 | |
15917 |
|
15918 |
|
15919 |
|
15920 |
|
15921 |
|
15922 |
|
15923 | Request.prototype.crossDomainError = function () {
|
15924 | var err = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
|
15925 | err.crossDomain = true;
|
15926 | err.status = this.status;
|
15927 | err.method = this.method;
|
15928 | err.url = this.url;
|
15929 | this.callback(err);
|
15930 | };
|
15931 |
|
15932 |
|
15933 | Request.prototype.agent = function () {
|
15934 | console.warn('This is not supported in browser version of superagent');
|
15935 | return this;
|
15936 | };
|
15937 |
|
15938 | Request.prototype.buffer = Request.prototype.ca;
|
15939 | Request.prototype.ca = Request.prototype.agent;
|
15940 |
|
15941 | Request.prototype.write = function () {
|
15942 | throw new Error('Streaming is not supported in browser version of superagent');
|
15943 | };
|
15944 |
|
15945 | Request.prototype.pipe = Request.prototype.write;
|
15946 | |
15947 |
|
15948 |
|
15949 |
|
15950 |
|
15951 |
|
15952 |
|
15953 |
|
15954 |
|
15955 | Request.prototype._isHost = function (obj) {
|
15956 |
|
15957 | return obj && _typeof$1(obj) === 'object' && !Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]';
|
15958 | };
|
15959 | |
15960 |
|
15961 |
|
15962 |
|
15963 |
|
15964 |
|
15965 |
|
15966 |
|
15967 |
|
15968 |
|
15969 | Request.prototype.end = function (fn) {
|
15970 | if (this._endCalled) {
|
15971 | console.warn('Warning: .end() was called twice. This is not supported in superagent');
|
15972 | }
|
15973 |
|
15974 | this._endCalled = true;
|
15975 |
|
15976 | this._callback = fn || noop;
|
15977 |
|
15978 | this._finalizeQueryString();
|
15979 |
|
15980 | this._end();
|
15981 | };
|
15982 |
|
15983 | Request.prototype._setUploadTimeout = function () {
|
15984 | var self = this;
|
15985 |
|
15986 | if (this._uploadTimeout && !this._uploadTimeoutTimer) {
|
15987 | this._uploadTimeoutTimer = setTimeout(function () {
|
15988 | self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
|
15989 | }, this._uploadTimeout);
|
15990 | }
|
15991 | };
|
15992 |
|
15993 |
|
15994 | Request.prototype._end = function () {
|
15995 | if (this._aborted) return this.callback(new Error('The request has been aborted even before .end() was called'));
|
15996 | var self = this;
|
15997 | this.xhr = request.getXHR();
|
15998 | var xhr = this.xhr;
|
15999 | var data = this._formData || this._data;
|
16000 |
|
16001 | this._setTimeouts();
|
16002 |
|
16003 |
|
16004 | xhr.onreadystatechange = function () {
|
16005 | var readyState = xhr.readyState;
|
16006 |
|
16007 | if (readyState >= 2 && self._responseTimeoutTimer) {
|
16008 | clearTimeout(self._responseTimeoutTimer);
|
16009 | }
|
16010 |
|
16011 | if (readyState !== 4) {
|
16012 | return;
|
16013 | }
|
16014 |
|
16015 |
|
16016 |
|
16017 | var status;
|
16018 |
|
16019 | try {
|
16020 | status = xhr.status;
|
16021 | } catch (err) {
|
16022 | status = 0;
|
16023 | }
|
16024 |
|
16025 | if (!status) {
|
16026 | if (self.timedout || self._aborted) return;
|
16027 | return self.crossDomainError();
|
16028 | }
|
16029 |
|
16030 | self.emit('end');
|
16031 | };
|
16032 |
|
16033 |
|
16034 | var handleProgress = function handleProgress(direction, e) {
|
16035 | if (e.total > 0) {
|
16036 | e.percent = e.loaded / e.total * 100;
|
16037 |
|
16038 | if (e.percent === 100) {
|
16039 | clearTimeout(self._uploadTimeoutTimer);
|
16040 | }
|
16041 | }
|
16042 |
|
16043 | e.direction = direction;
|
16044 | self.emit('progress', e);
|
16045 | };
|
16046 |
|
16047 | if (this.hasListeners('progress')) {
|
16048 | try {
|
16049 | xhr.addEventListener('progress', handleProgress.bind(null, 'download'));
|
16050 |
|
16051 | if (xhr.upload) {
|
16052 | xhr.upload.addEventListener('progress', handleProgress.bind(null, 'upload'));
|
16053 | }
|
16054 | } catch (err) {
|
16055 |
|
16056 |
|
16057 | }
|
16058 | }
|
16059 |
|
16060 | if (xhr.upload) {
|
16061 | this._setUploadTimeout();
|
16062 | }
|
16063 |
|
16064 |
|
16065 | try {
|
16066 | if (this.username && this.password) {
|
16067 | xhr.open(this.method, this.url, true, this.username, this.password);
|
16068 | } else {
|
16069 | xhr.open(this.method, this.url, true);
|
16070 | }
|
16071 | } catch (err) {
|
16072 |
|
16073 | return this.callback(err);
|
16074 | }
|
16075 |
|
16076 |
|
16077 | if (this._withCredentials) xhr.withCredentials = true;
|
16078 |
|
16079 | if (!this._formData && this.method !== 'GET' && this.method !== 'HEAD' && typeof data !== 'string' && !this._isHost(data)) {
|
16080 |
|
16081 | var contentType = this._header['content-type'];
|
16082 |
|
16083 | var _serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
16084 |
|
16085 | if (!_serialize && isJSON(contentType)) {
|
16086 | _serialize = request.serialize['application/json'];
|
16087 | }
|
16088 |
|
16089 | if (_serialize) data = _serialize(data);
|
16090 | }
|
16091 |
|
16092 |
|
16093 | for (var field in this.header) {
|
16094 | if (this.header[field] === null) continue;
|
16095 | if (Object.prototype.hasOwnProperty.call(this.header, field)) xhr.setRequestHeader(field, this.header[field]);
|
16096 | }
|
16097 |
|
16098 | if (this._responseType) {
|
16099 | xhr.responseType = this._responseType;
|
16100 | }
|
16101 |
|
16102 |
|
16103 | this.emit('request', this);
|
16104 |
|
16105 |
|
16106 | xhr.send(typeof data === 'undefined' ? null : data);
|
16107 | };
|
16108 |
|
16109 | request.agent = function () {
|
16110 | return new agentBase();
|
16111 | };
|
16112 |
|
16113 | ['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach(function (method) {
|
16114 | agentBase.prototype[method.toLowerCase()] = function (url, fn) {
|
16115 | var req = new request.Request(method, url);
|
16116 |
|
16117 | this._setDefaults(req);
|
16118 |
|
16119 | if (fn) {
|
16120 | req.end(fn);
|
16121 | }
|
16122 |
|
16123 | return req;
|
16124 | };
|
16125 | });
|
16126 | agentBase.prototype.del = agentBase.prototype.delete;
|
16127 | |
16128 |
|
16129 |
|
16130 |
|
16131 |
|
16132 |
|
16133 |
|
16134 |
|
16135 |
|
16136 |
|
16137 | request.get = function (url, data, fn) {
|
16138 | var req = request('GET', url);
|
16139 |
|
16140 | if (typeof data === 'function') {
|
16141 | fn = data;
|
16142 | data = null;
|
16143 | }
|
16144 |
|
16145 | if (data) req.query(data);
|
16146 | if (fn) req.end(fn);
|
16147 | return req;
|
16148 | };
|
16149 | |
16150 |
|
16151 |
|
16152 |
|
16153 |
|
16154 |
|
16155 |
|
16156 |
|
16157 |
|
16158 |
|
16159 |
|
16160 | request.head = function (url, data, fn) {
|
16161 | var req = request('HEAD', url);
|
16162 |
|
16163 | if (typeof data === 'function') {
|
16164 | fn = data;
|
16165 | data = null;
|
16166 | }
|
16167 |
|
16168 | if (data) req.query(data);
|
16169 | if (fn) req.end(fn);
|
16170 | return req;
|
16171 | };
|
16172 | |
16173 |
|
16174 |
|
16175 |
|
16176 |
|
16177 |
|
16178 |
|
16179 |
|
16180 |
|
16181 |
|
16182 |
|
16183 | request.options = function (url, data, fn) {
|
16184 | var req = request('OPTIONS', url);
|
16185 |
|
16186 | if (typeof data === 'function') {
|
16187 | fn = data;
|
16188 | data = null;
|
16189 | }
|
16190 |
|
16191 | if (data) req.send(data);
|
16192 | if (fn) req.end(fn);
|
16193 | return req;
|
16194 | };
|
16195 | |
16196 |
|
16197 |
|
16198 |
|
16199 |
|
16200 |
|
16201 |
|
16202 |
|
16203 |
|
16204 |
|
16205 |
|
16206 | function del(url, data, fn) {
|
16207 | var req = request('DELETE', url);
|
16208 |
|
16209 | if (typeof data === 'function') {
|
16210 | fn = data;
|
16211 | data = null;
|
16212 | }
|
16213 |
|
16214 | if (data) req.send(data);
|
16215 | if (fn) req.end(fn);
|
16216 | return req;
|
16217 | }
|
16218 |
|
16219 | request.del = del;
|
16220 | request.delete = del;
|
16221 | |
16222 |
|
16223 |
|
16224 |
|
16225 |
|
16226 |
|
16227 |
|
16228 |
|
16229 |
|
16230 |
|
16231 | request.patch = function (url, data, fn) {
|
16232 | var req = request('PATCH', url);
|
16233 |
|
16234 | if (typeof data === 'function') {
|
16235 | fn = data;
|
16236 | data = null;
|
16237 | }
|
16238 |
|
16239 | if (data) req.send(data);
|
16240 | if (fn) req.end(fn);
|
16241 | return req;
|
16242 | };
|
16243 | |
16244 |
|
16245 |
|
16246 |
|
16247 |
|
16248 |
|
16249 |
|
16250 |
|
16251 |
|
16252 |
|
16253 |
|
16254 | request.post = function (url, data, fn) {
|
16255 | var req = request('POST', url);
|
16256 |
|
16257 | if (typeof data === 'function') {
|
16258 | fn = data;
|
16259 | data = null;
|
16260 | }
|
16261 |
|
16262 | if (data) req.send(data);
|
16263 | if (fn) req.end(fn);
|
16264 | return req;
|
16265 | };
|
16266 | |
16267 |
|
16268 |
|
16269 |
|
16270 |
|
16271 |
|
16272 |
|
16273 |
|
16274 |
|
16275 |
|
16276 |
|
16277 | request.put = function (url, data, fn) {
|
16278 | var req = request('PUT', url);
|
16279 |
|
16280 | if (typeof data === 'function') {
|
16281 | fn = data;
|
16282 | data = null;
|
16283 | }
|
16284 |
|
16285 | if (data) req.send(data);
|
16286 | if (fn) req.end(fn);
|
16287 | return req;
|
16288 | };
|
16289 | });
|
16290 | var client_1 = client.Request;
|
16291 |
|
16292 | |
16293 |
|
16294 |
|
16295 |
|
16296 |
|
16297 |
|
16298 |
|
16299 |
|
16300 | function copyArray(source, array) {
|
16301 | var index = -1,
|
16302 | length = source.length;
|
16303 |
|
16304 | array || (array = Array(length));
|
16305 | while (++index < length) {
|
16306 | array[index] = source[index];
|
16307 | }
|
16308 | return array;
|
16309 | }
|
16310 |
|
16311 | var _copyArray = copyArray;
|
16312 |
|
16313 |
|
16314 | var nativeFloor = Math.floor,
|
16315 | nativeRandom = Math.random;
|
16316 |
|
16317 | |
16318 |
|
16319 |
|
16320 |
|
16321 |
|
16322 |
|
16323 |
|
16324 |
|
16325 |
|
16326 | function baseRandom(lower, upper) {
|
16327 | return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
|
16328 | }
|
16329 |
|
16330 | var _baseRandom = baseRandom;
|
16331 |
|
16332 | |
16333 |
|
16334 |
|
16335 |
|
16336 |
|
16337 |
|
16338 |
|
16339 |
|
16340 | function shuffleSelf(array, size) {
|
16341 | var index = -1,
|
16342 | length = array.length,
|
16343 | lastIndex = length - 1;
|
16344 |
|
16345 | size = size === undefined ? length : size;
|
16346 | while (++index < size) {
|
16347 | var rand = _baseRandom(index, lastIndex),
|
16348 | value = array[rand];
|
16349 |
|
16350 | array[rand] = array[index];
|
16351 | array[index] = value;
|
16352 | }
|
16353 | array.length = size;
|
16354 | return array;
|
16355 | }
|
16356 |
|
16357 | var _shuffleSelf = shuffleSelf;
|
16358 |
|
16359 | |
16360 |
|
16361 |
|
16362 |
|
16363 |
|
16364 |
|
16365 |
|
16366 | function arrayShuffle(array) {
|
16367 | return _shuffleSelf(_copyArray(array));
|
16368 | }
|
16369 |
|
16370 | var _arrayShuffle = arrayShuffle;
|
16371 |
|
16372 | |
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 |
|
16380 |
|
16381 | function arrayMap(array, iteratee) {
|
16382 | var index = -1,
|
16383 | length = array == null ? 0 : array.length,
|
16384 | result = Array(length);
|
16385 |
|
16386 | while (++index < length) {
|
16387 | result[index] = iteratee(array[index], index, array);
|
16388 | }
|
16389 | return result;
|
16390 | }
|
16391 |
|
16392 | var _arrayMap = arrayMap;
|
16393 |
|
16394 | |
16395 |
|
16396 |
|
16397 |
|
16398 |
|
16399 |
|
16400 |
|
16401 |
|
16402 |
|
16403 |
|
16404 | function baseValues(object, props) {
|
16405 | return _arrayMap(props, function(key) {
|
16406 | return object[key];
|
16407 | });
|
16408 | }
|
16409 |
|
16410 | var _baseValues = baseValues;
|
16411 |
|
16412 | |
16413 |
|
16414 |
|
16415 |
|
16416 |
|
16417 |
|
16418 |
|
16419 |
|
16420 |
|
16421 | function baseTimes(n, iteratee) {
|
16422 | var index = -1,
|
16423 | result = Array(n);
|
16424 |
|
16425 | while (++index < n) {
|
16426 | result[index] = iteratee(index);
|
16427 | }
|
16428 | return result;
|
16429 | }
|
16430 |
|
16431 | var _baseTimes = baseTimes;
|
16432 |
|
16433 |
|
16434 | var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
16435 |
|
16436 | var _freeGlobal = freeGlobal;
|
16437 |
|
16438 |
|
16439 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
16440 |
|
16441 |
|
16442 | var root = _freeGlobal || freeSelf || Function('return this')();
|
16443 |
|
16444 | var _root = root;
|
16445 |
|
16446 |
|
16447 | var Symbol$1 = _root.Symbol;
|
16448 |
|
16449 | var _Symbol = Symbol$1;
|
16450 |
|
16451 |
|
16452 | var objectProto = Object.prototype;
|
16453 |
|
16454 |
|
16455 | var hasOwnProperty$1 = objectProto.hasOwnProperty;
|
16456 |
|
16457 | |
16458 |
|
16459 |
|
16460 |
|
16461 |
|
16462 | var nativeObjectToString = objectProto.toString;
|
16463 |
|
16464 |
|
16465 | var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
|
16466 |
|
16467 | |
16468 |
|
16469 |
|
16470 |
|
16471 |
|
16472 |
|
16473 |
|
16474 | function getRawTag(value) {
|
16475 | var isOwn = hasOwnProperty$1.call(value, symToStringTag),
|
16476 | tag = value[symToStringTag];
|
16477 |
|
16478 | try {
|
16479 | value[symToStringTag] = undefined;
|
16480 | var unmasked = true;
|
16481 | } catch (e) {}
|
16482 |
|
16483 | var result = nativeObjectToString.call(value);
|
16484 | if (unmasked) {
|
16485 | if (isOwn) {
|
16486 | value[symToStringTag] = tag;
|
16487 | } else {
|
16488 | delete value[symToStringTag];
|
16489 | }
|
16490 | }
|
16491 | return result;
|
16492 | }
|
16493 |
|
16494 | var _getRawTag = getRawTag;
|
16495 |
|
16496 |
|
16497 | var objectProto$1 = Object.prototype;
|
16498 |
|
16499 | |
16500 |
|
16501 |
|
16502 |
|
16503 |
|
16504 | var nativeObjectToString$1 = objectProto$1.toString;
|
16505 |
|
16506 | |
16507 |
|
16508 |
|
16509 |
|
16510 |
|
16511 |
|
16512 |
|
16513 | function objectToString(value) {
|
16514 | return nativeObjectToString$1.call(value);
|
16515 | }
|
16516 |
|
16517 | var _objectToString = objectToString;
|
16518 |
|
16519 |
|
16520 | var nullTag = '[object Null]',
|
16521 | undefinedTag = '[object Undefined]';
|
16522 |
|
16523 |
|
16524 | var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
|
16525 |
|
16526 | |
16527 |
|
16528 |
|
16529 |
|
16530 |
|
16531 |
|
16532 |
|
16533 | function baseGetTag(value) {
|
16534 | if (value == null) {
|
16535 | return value === undefined ? undefinedTag : nullTag;
|
16536 | }
|
16537 | return (symToStringTag$1 && symToStringTag$1 in Object(value))
|
16538 | ? _getRawTag(value)
|
16539 | : _objectToString(value);
|
16540 | }
|
16541 |
|
16542 | var _baseGetTag = baseGetTag;
|
16543 |
|
16544 | |
16545 |
|
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 |
|
16552 |
|
16553 |
|
16554 |
|
16555 |
|
16556 |
|
16557 |
|
16558 |
|
16559 |
|
16560 |
|
16561 |
|
16562 |
|
16563 |
|
16564 |
|
16565 |
|
16566 |
|
16567 |
|
16568 | function isObjectLike(value) {
|
16569 | return value != null && typeof value == 'object';
|
16570 | }
|
16571 |
|
16572 | var isObjectLike_1 = isObjectLike;
|
16573 |
|
16574 |
|
16575 | var argsTag = '[object Arguments]';
|
16576 |
|
16577 | |
16578 |
|
16579 |
|
16580 |
|
16581 |
|
16582 |
|
16583 |
|
16584 | function baseIsArguments(value) {
|
16585 | return isObjectLike_1(value) && _baseGetTag(value) == argsTag;
|
16586 | }
|
16587 |
|
16588 | var _baseIsArguments = baseIsArguments;
|
16589 |
|
16590 |
|
16591 | var objectProto$2 = Object.prototype;
|
16592 |
|
16593 |
|
16594 | var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
|
16595 |
|
16596 |
|
16597 | var propertyIsEnumerable = objectProto$2.propertyIsEnumerable;
|
16598 |
|
16599 | |
16600 |
|
16601 |
|
16602 |
|
16603 |
|
16604 |
|
16605 |
|
16606 |
|
16607 |
|
16608 |
|
16609 |
|
16610 |
|
16611 |
|
16612 |
|
16613 |
|
16614 |
|
16615 |
|
16616 |
|
16617 | var isArguments = _baseIsArguments(function() { return arguments; }()) ? _baseIsArguments : function(value) {
|
16618 | return isObjectLike_1(value) && hasOwnProperty$2.call(value, 'callee') &&
|
16619 | !propertyIsEnumerable.call(value, 'callee');
|
16620 | };
|
16621 |
|
16622 | var isArguments_1 = isArguments;
|
16623 |
|
16624 | |
16625 |
|
16626 |
|
16627 |
|
16628 |
|
16629 |
|
16630 |
|
16631 |
|
16632 |
|
16633 |
|
16634 |
|
16635 |
|
16636 |
|
16637 |
|
16638 |
|
16639 |
|
16640 |
|
16641 |
|
16642 |
|
16643 |
|
16644 |
|
16645 |
|
16646 |
|
16647 | var isArray = Array.isArray;
|
16648 |
|
16649 | var isArray_1 = isArray;
|
16650 |
|
16651 | |
16652 |
|
16653 |
|
16654 |
|
16655 |
|
16656 |
|
16657 |
|
16658 |
|
16659 |
|
16660 |
|
16661 |
|
16662 |
|
16663 |
|
16664 | function stubFalse() {
|
16665 | return false;
|
16666 | }
|
16667 |
|
16668 | var stubFalse_1 = stubFalse;
|
16669 |
|
16670 | var isBuffer_1 = createCommonjsModule(function (module, exports) {
|
16671 |
|
16672 | var freeExports = exports && !exports.nodeType && exports;
|
16673 |
|
16674 |
|
16675 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
16676 |
|
16677 |
|
16678 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
16679 |
|
16680 |
|
16681 | var Buffer = moduleExports ? _root.Buffer : undefined;
|
16682 |
|
16683 |
|
16684 | var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
16685 |
|
16686 | |
16687 |
|
16688 |
|
16689 |
|
16690 |
|
16691 |
|
16692 |
|
16693 |
|
16694 |
|
16695 |
|
16696 |
|
16697 |
|
16698 |
|
16699 |
|
16700 |
|
16701 |
|
16702 |
|
16703 | var isBuffer = nativeIsBuffer || stubFalse_1;
|
16704 |
|
16705 | module.exports = isBuffer;
|
16706 | });
|
16707 |
|
16708 |
|
16709 | var MAX_SAFE_INTEGER = 9007199254740991;
|
16710 |
|
16711 |
|
16712 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
16713 |
|
16714 | |
16715 |
|
16716 |
|
16717 |
|
16718 |
|
16719 |
|
16720 |
|
16721 |
|
16722 | function isIndex(value, length) {
|
16723 | var type = typeof value;
|
16724 | length = length == null ? MAX_SAFE_INTEGER : length;
|
16725 |
|
16726 | return !!length &&
|
16727 | (type == 'number' ||
|
16728 | (type != 'symbol' && reIsUint.test(value))) &&
|
16729 | (value > -1 && value % 1 == 0 && value < length);
|
16730 | }
|
16731 |
|
16732 | var _isIndex = isIndex;
|
16733 |
|
16734 |
|
16735 | var MAX_SAFE_INTEGER$1 = 9007199254740991;
|
16736 |
|
16737 | |
16738 |
|
16739 |
|
16740 |
|
16741 |
|
16742 |
|
16743 |
|
16744 |
|
16745 |
|
16746 |
|
16747 |
|
16748 |
|
16749 |
|
16750 |
|
16751 |
|
16752 |
|
16753 |
|
16754 |
|
16755 |
|
16756 |
|
16757 |
|
16758 |
|
16759 |
|
16760 |
|
16761 |
|
16762 |
|
16763 | function isLength(value) {
|
16764 | return typeof value == 'number' &&
|
16765 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$1;
|
16766 | }
|
16767 |
|
16768 | var isLength_1 = isLength;
|
16769 |
|
16770 |
|
16771 | var argsTag$1 = '[object Arguments]',
|
16772 | arrayTag = '[object Array]',
|
16773 | boolTag = '[object Boolean]',
|
16774 | dateTag = '[object Date]',
|
16775 | errorTag = '[object Error]',
|
16776 | funcTag = '[object Function]',
|
16777 | mapTag = '[object Map]',
|
16778 | numberTag = '[object Number]',
|
16779 | objectTag = '[object Object]',
|
16780 | regexpTag = '[object RegExp]',
|
16781 | setTag = '[object Set]',
|
16782 | stringTag = '[object String]',
|
16783 | weakMapTag = '[object WeakMap]';
|
16784 |
|
16785 | var arrayBufferTag = '[object ArrayBuffer]',
|
16786 | dataViewTag = '[object DataView]',
|
16787 | float32Tag = '[object Float32Array]',
|
16788 | float64Tag = '[object Float64Array]',
|
16789 | int8Tag = '[object Int8Array]',
|
16790 | int16Tag = '[object Int16Array]',
|
16791 | int32Tag = '[object Int32Array]',
|
16792 | uint8Tag = '[object Uint8Array]',
|
16793 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
16794 | uint16Tag = '[object Uint16Array]',
|
16795 | uint32Tag = '[object Uint32Array]';
|
16796 |
|
16797 |
|
16798 | var typedArrayTags = {};
|
16799 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
16800 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
16801 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
16802 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
16803 | typedArrayTags[uint32Tag] = true;
|
16804 | typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] =
|
16805 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
16806 | typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
|
16807 | typedArrayTags[errorTag] = typedArrayTags[funcTag] =
|
16808 | typedArrayTags[mapTag] = typedArrayTags[numberTag] =
|
16809 | typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
|
16810 | typedArrayTags[setTag] = typedArrayTags[stringTag] =
|
16811 | typedArrayTags[weakMapTag] = false;
|
16812 |
|
16813 | |
16814 |
|
16815 |
|
16816 |
|
16817 |
|
16818 |
|
16819 |
|
16820 | function baseIsTypedArray(value) {
|
16821 | return isObjectLike_1(value) &&
|
16822 | isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
|
16823 | }
|
16824 |
|
16825 | var _baseIsTypedArray = baseIsTypedArray;
|
16826 |
|
16827 | |
16828 |
|
16829 |
|
16830 |
|
16831 |
|
16832 |
|
16833 |
|
16834 | function baseUnary(func) {
|
16835 | return function(value) {
|
16836 | return func(value);
|
16837 | };
|
16838 | }
|
16839 |
|
16840 | var _baseUnary = baseUnary;
|
16841 |
|
16842 | var _nodeUtil = createCommonjsModule(function (module, exports) {
|
16843 |
|
16844 | var freeExports = exports && !exports.nodeType && exports;
|
16845 |
|
16846 |
|
16847 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
16848 |
|
16849 |
|
16850 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
16851 |
|
16852 |
|
16853 | var freeProcess = moduleExports && _freeGlobal.process;
|
16854 |
|
16855 |
|
16856 | var nodeUtil = (function() {
|
16857 | try {
|
16858 |
|
16859 | var types = freeModule && freeModule.require && freeModule.require('util').types;
|
16860 |
|
16861 | if (types) {
|
16862 | return types;
|
16863 | }
|
16864 |
|
16865 |
|
16866 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
16867 | } catch (e) {}
|
16868 | }());
|
16869 |
|
16870 | module.exports = nodeUtil;
|
16871 | });
|
16872 |
|
16873 |
|
16874 | var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
|
16875 |
|
16876 | |
16877 |
|
16878 |
|
16879 |
|
16880 |
|
16881 |
|
16882 |
|
16883 |
|
16884 |
|
16885 |
|
16886 |
|
16887 |
|
16888 |
|
16889 |
|
16890 |
|
16891 |
|
16892 |
|
16893 | var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
|
16894 |
|
16895 | var isTypedArray_1 = isTypedArray;
|
16896 |
|
16897 |
|
16898 | var objectProto$3 = Object.prototype;
|
16899 |
|
16900 |
|
16901 | var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
|
16902 |
|
16903 | |
16904 |
|
16905 |
|
16906 |
|
16907 |
|
16908 |
|
16909 |
|
16910 |
|
16911 | function arrayLikeKeys(value, inherited) {
|
16912 | var isArr = isArray_1(value),
|
16913 | isArg = !isArr && isArguments_1(value),
|
16914 | isBuff = !isArr && !isArg && isBuffer_1(value),
|
16915 | isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
|
16916 | skipIndexes = isArr || isArg || isBuff || isType,
|
16917 | result = skipIndexes ? _baseTimes(value.length, String) : [],
|
16918 | length = result.length;
|
16919 |
|
16920 | for (var key in value) {
|
16921 | if ((inherited || hasOwnProperty$3.call(value, key)) &&
|
16922 | !(skipIndexes && (
|
16923 |
|
16924 | key == 'length' ||
|
16925 |
|
16926 | (isBuff && (key == 'offset' || key == 'parent')) ||
|
16927 |
|
16928 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
16929 |
|
16930 | _isIndex(key, length)
|
16931 | ))) {
|
16932 | result.push(key);
|
16933 | }
|
16934 | }
|
16935 | return result;
|
16936 | }
|
16937 |
|
16938 | var _arrayLikeKeys = arrayLikeKeys;
|
16939 |
|
16940 |
|
16941 | var objectProto$4 = Object.prototype;
|
16942 |
|
16943 | |
16944 |
|
16945 |
|
16946 |
|
16947 |
|
16948 |
|
16949 |
|
16950 | function isPrototype(value) {
|
16951 | var Ctor = value && value.constructor,
|
16952 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$4;
|
16953 |
|
16954 | return value === proto;
|
16955 | }
|
16956 |
|
16957 | var _isPrototype = isPrototype;
|
16958 |
|
16959 | |
16960 |
|
16961 |
|
16962 |
|
16963 |
|
16964 |
|
16965 |
|
16966 |
|
16967 | function overArg(func, transform) {
|
16968 | return function(arg) {
|
16969 | return func(transform(arg));
|
16970 | };
|
16971 | }
|
16972 |
|
16973 | var _overArg = overArg;
|
16974 |
|
16975 |
|
16976 | var nativeKeys = _overArg(Object.keys, Object);
|
16977 |
|
16978 | var _nativeKeys = nativeKeys;
|
16979 |
|
16980 |
|
16981 | var objectProto$5 = Object.prototype;
|
16982 |
|
16983 |
|
16984 | var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
|
16985 |
|
16986 | |
16987 |
|
16988 |
|
16989 |
|
16990 |
|
16991 |
|
16992 |
|
16993 | function baseKeys(object) {
|
16994 | if (!_isPrototype(object)) {
|
16995 | return _nativeKeys(object);
|
16996 | }
|
16997 | var result = [];
|
16998 | for (var key in Object(object)) {
|
16999 | if (hasOwnProperty$4.call(object, key) && key != 'constructor') {
|
17000 | result.push(key);
|
17001 | }
|
17002 | }
|
17003 | return result;
|
17004 | }
|
17005 |
|
17006 | var _baseKeys = baseKeys;
|
17007 |
|
17008 | |
17009 |
|
17010 |
|
17011 |
|
17012 |
|
17013 |
|
17014 |
|
17015 |
|
17016 |
|
17017 |
|
17018 |
|
17019 |
|
17020 |
|
17021 |
|
17022 |
|
17023 |
|
17024 |
|
17025 |
|
17026 |
|
17027 |
|
17028 |
|
17029 |
|
17030 |
|
17031 |
|
17032 |
|
17033 | function isObject$1(value) {
|
17034 | var type = typeof value;
|
17035 | return value != null && (type == 'object' || type == 'function');
|
17036 | }
|
17037 |
|
17038 | var isObject_1$1 = isObject$1;
|
17039 |
|
17040 |
|
17041 | var asyncTag = '[object AsyncFunction]',
|
17042 | funcTag$1 = '[object Function]',
|
17043 | genTag = '[object GeneratorFunction]',
|
17044 | proxyTag = '[object Proxy]';
|
17045 |
|
17046 | |
17047 |
|
17048 |
|
17049 |
|
17050 |
|
17051 |
|
17052 |
|
17053 |
|
17054 |
|
17055 |
|
17056 |
|
17057 |
|
17058 |
|
17059 |
|
17060 |
|
17061 |
|
17062 |
|
17063 | function isFunction(value) {
|
17064 | if (!isObject_1$1(value)) {
|
17065 | return false;
|
17066 | }
|
17067 |
|
17068 |
|
17069 | var tag = _baseGetTag(value);
|
17070 | return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag;
|
17071 | }
|
17072 |
|
17073 | var isFunction_1 = isFunction;
|
17074 |
|
17075 | |
17076 |
|
17077 |
|
17078 |
|
17079 |
|
17080 |
|
17081 |
|
17082 |
|
17083 |
|
17084 |
|
17085 |
|
17086 |
|
17087 |
|
17088 |
|
17089 |
|
17090 |
|
17091 |
|
17092 |
|
17093 |
|
17094 |
|
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 | function isArrayLike(value) {
|
17101 | return value != null && isLength_1(value.length) && !isFunction_1(value);
|
17102 | }
|
17103 |
|
17104 | var isArrayLike_1 = isArrayLike;
|
17105 |
|
17106 | |
17107 |
|
17108 |
|
17109 |
|
17110 |
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 |
|
17118 |
|
17119 |
|
17120 |
|
17121 |
|
17122 |
|
17123 |
|
17124 |
|
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 |
|
17130 |
|
17131 |
|
17132 |
|
17133 |
|
17134 | function keys(object) {
|
17135 | return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
|
17136 | }
|
17137 |
|
17138 | var keys_1 = keys;
|
17139 |
|
17140 | |
17141 |
|
17142 |
|
17143 |
|
17144 |
|
17145 |
|
17146 |
|
17147 |
|
17148 |
|
17149 |
|
17150 |
|
17151 |
|
17152 |
|
17153 |
|
17154 |
|
17155 |
|
17156 |
|
17157 |
|
17158 |
|
17159 |
|
17160 |
|
17161 |
|
17162 |
|
17163 |
|
17164 |
|
17165 |
|
17166 | function values(object) {
|
17167 | return object == null ? [] : _baseValues(object, keys_1(object));
|
17168 | }
|
17169 |
|
17170 | var values_1 = values;
|
17171 |
|
17172 | |
17173 |
|
17174 |
|
17175 |
|
17176 |
|
17177 |
|
17178 |
|
17179 | function baseShuffle(collection) {
|
17180 | return _shuffleSelf(values_1(collection));
|
17181 | }
|
17182 |
|
17183 | var _baseShuffle = baseShuffle;
|
17184 |
|
17185 | |
17186 |
|
17187 |
|
17188 |
|
17189 |
|
17190 |
|
17191 |
|
17192 |
|
17193 |
|
17194 |
|
17195 |
|
17196 |
|
17197 |
|
17198 |
|
17199 |
|
17200 | function shuffle(collection) {
|
17201 | var func = isArray_1(collection) ? _arrayShuffle : _baseShuffle;
|
17202 | return func(collection);
|
17203 | }
|
17204 |
|
17205 | var shuffle_1 = shuffle;
|
17206 |
|
17207 | var stateMachine = createCommonjsModule(function (module, exports) {
|
17208 | |
17209 |
|
17210 |
|
17211 |
|
17212 |
|
17213 |
|
17214 |
|
17215 |
|
17216 |
|
17217 | (function () {
|
17218 |
|
17219 | var StateMachine = {
|
17220 |
|
17221 |
|
17222 |
|
17223 | VERSION: "2.4.0",
|
17224 |
|
17225 |
|
17226 |
|
17227 | Result: {
|
17228 | SUCCEEDED: 1,
|
17229 | NOTRANSITION: 2,
|
17230 | CANCELLED: 3,
|
17231 | PENDING: 4
|
17232 | },
|
17233 |
|
17234 | Error: {
|
17235 | INVALID_TRANSITION: 100,
|
17236 | PENDING_TRANSITION: 200,
|
17237 | INVALID_CALLBACK: 300
|
17238 | },
|
17239 |
|
17240 | WILDCARD: '*',
|
17241 | ASYNC: 'async',
|
17242 |
|
17243 |
|
17244 |
|
17245 | create: function(cfg, target) {
|
17246 |
|
17247 | var initial = (typeof cfg.initial == 'string') ? { state: cfg.initial } : cfg.initial;
|
17248 | var terminal = cfg.terminal || cfg['final'];
|
17249 | var fsm = target || cfg.target || {};
|
17250 | var events = cfg.events || [];
|
17251 | var callbacks = cfg.callbacks || {};
|
17252 | var map = {};
|
17253 | var transitions = {};
|
17254 |
|
17255 | var add = function(e) {
|
17256 | var from = Array.isArray(e.from) ? e.from : (e.from ? [e.from] : [StateMachine.WILDCARD]);
|
17257 | map[e.name] = map[e.name] || {};
|
17258 | for (var n = 0 ; n < from.length ; n++) {
|
17259 | transitions[from[n]] = transitions[from[n]] || [];
|
17260 | transitions[from[n]].push(e.name);
|
17261 |
|
17262 | map[e.name][from[n]] = e.to || from[n];
|
17263 | }
|
17264 | if (e.to)
|
17265 | transitions[e.to] = transitions[e.to] || [];
|
17266 | };
|
17267 |
|
17268 | if (initial) {
|
17269 | initial.event = initial.event || 'startup';
|
17270 | add({ name: initial.event, from: 'none', to: initial.state });
|
17271 | }
|
17272 |
|
17273 | for(var n = 0 ; n < events.length ; n++)
|
17274 | add(events[n]);
|
17275 |
|
17276 | for(var name in map) {
|
17277 | if (map.hasOwnProperty(name))
|
17278 | fsm[name] = StateMachine.buildEvent(name, map[name]);
|
17279 | }
|
17280 |
|
17281 | for(var name in callbacks) {
|
17282 | if (callbacks.hasOwnProperty(name))
|
17283 | fsm[name] = callbacks[name];
|
17284 | }
|
17285 |
|
17286 | fsm.current = 'none';
|
17287 | fsm.is = function(state) { return Array.isArray(state) ? (state.indexOf(this.current) >= 0) : (this.current === state); };
|
17288 | fsm.can = function(event) { return !this.transition && (map[event] !== undefined) && (map[event].hasOwnProperty(this.current) || map[event].hasOwnProperty(StateMachine.WILDCARD)); };
|
17289 | fsm.cannot = function(event) { return !this.can(event); };
|
17290 | fsm.transitions = function() { return (transitions[this.current] || []).concat(transitions[StateMachine.WILDCARD] || []); };
|
17291 | fsm.isFinished = function() { return this.is(terminal); };
|
17292 | fsm.error = cfg.error || function(name, from, to, args, error, msg, e) { throw e || msg; };
|
17293 | fsm.states = function() { return Object.keys(transitions).sort() };
|
17294 |
|
17295 | if (initial && !initial.defer)
|
17296 | fsm[initial.event]();
|
17297 |
|
17298 | return fsm;
|
17299 |
|
17300 | },
|
17301 |
|
17302 |
|
17303 |
|
17304 | doCallback: function(fsm, func, name, from, to, args) {
|
17305 | if (func) {
|
17306 | try {
|
17307 | return func.apply(fsm, [name, from, to].concat(args));
|
17308 | }
|
17309 | catch(e) {
|
17310 | return fsm.error(name, from, to, args, StateMachine.Error.INVALID_CALLBACK, "an exception occurred in a caller-provided callback function", e);
|
17311 | }
|
17312 | }
|
17313 | },
|
17314 |
|
17315 | beforeAnyEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onbeforeevent'], name, from, to, args); },
|
17316 | afterAnyEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onafterevent'] || fsm['onevent'], name, from, to, args); },
|
17317 | leaveAnyState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onleavestate'], name, from, to, args); },
|
17318 | enterAnyState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onenterstate'] || fsm['onstate'], name, from, to, args); },
|
17319 | changeState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onchangestate'], name, from, to, args); },
|
17320 |
|
17321 | beforeThisEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onbefore' + name], name, from, to, args); },
|
17322 | afterThisEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onafter' + name] || fsm['on' + name], name, from, to, args); },
|
17323 | leaveThisState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onleave' + from], name, from, to, args); },
|
17324 | enterThisState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onenter' + to] || fsm['on' + to], name, from, to, args); },
|
17325 |
|
17326 | beforeEvent: function(fsm, name, from, to, args) {
|
17327 | if ((false === StateMachine.beforeThisEvent(fsm, name, from, to, args)) ||
|
17328 | (false === StateMachine.beforeAnyEvent( fsm, name, from, to, args)))
|
17329 | return false;
|
17330 | },
|
17331 |
|
17332 | afterEvent: function(fsm, name, from, to, args) {
|
17333 | StateMachine.afterThisEvent(fsm, name, from, to, args);
|
17334 | StateMachine.afterAnyEvent( fsm, name, from, to, args);
|
17335 | },
|
17336 |
|
17337 | leaveState: function(fsm, name, from, to, args) {
|
17338 | var specific = StateMachine.leaveThisState(fsm, name, from, to, args),
|
17339 | general = StateMachine.leaveAnyState( fsm, name, from, to, args);
|
17340 | if ((false === specific) || (false === general))
|
17341 | return false;
|
17342 | else if ((StateMachine.ASYNC === specific) || (StateMachine.ASYNC === general))
|
17343 | return StateMachine.ASYNC;
|
17344 | },
|
17345 |
|
17346 | enterState: function(fsm, name, from, to, args) {
|
17347 | StateMachine.enterThisState(fsm, name, from, to, args);
|
17348 | StateMachine.enterAnyState( fsm, name, from, to, args);
|
17349 | },
|
17350 |
|
17351 |
|
17352 |
|
17353 | buildEvent: function(name, map) {
|
17354 | return function() {
|
17355 |
|
17356 | var from = this.current;
|
17357 | var to = map[from] || (map[StateMachine.WILDCARD] != StateMachine.WILDCARD ? map[StateMachine.WILDCARD] : from) || from;
|
17358 | var args = Array.prototype.slice.call(arguments);
|
17359 |
|
17360 | if (this.transition)
|
17361 | return this.error(name, from, to, args, StateMachine.Error.PENDING_TRANSITION, "event " + name + " inappropriate because previous transition did not complete");
|
17362 |
|
17363 | if (this.cannot(name))
|
17364 | return this.error(name, from, to, args, StateMachine.Error.INVALID_TRANSITION, "event " + name + " inappropriate in current state " + this.current);
|
17365 |
|
17366 | if (false === StateMachine.beforeEvent(this, name, from, to, args))
|
17367 | return StateMachine.Result.CANCELLED;
|
17368 |
|
17369 | if (from === to) {
|
17370 | StateMachine.afterEvent(this, name, from, to, args);
|
17371 | return StateMachine.Result.NOTRANSITION;
|
17372 | }
|
17373 |
|
17374 |
|
17375 | var fsm = this;
|
17376 | this.transition = function() {
|
17377 | fsm.transition = null;
|
17378 | fsm.current = to;
|
17379 | StateMachine.enterState( fsm, name, from, to, args);
|
17380 | StateMachine.changeState(fsm, name, from, to, args);
|
17381 | StateMachine.afterEvent( fsm, name, from, to, args);
|
17382 | return StateMachine.Result.SUCCEEDED;
|
17383 | };
|
17384 | this.transition.cancel = function() {
|
17385 | fsm.transition = null;
|
17386 | StateMachine.afterEvent(fsm, name, from, to, args);
|
17387 | };
|
17388 |
|
17389 | var leave = StateMachine.leaveState(this, name, from, to, args);
|
17390 | if (false === leave) {
|
17391 | this.transition = null;
|
17392 | return StateMachine.Result.CANCELLED;
|
17393 | }
|
17394 | else if (StateMachine.ASYNC === leave) {
|
17395 | return StateMachine.Result.PENDING;
|
17396 | }
|
17397 | else {
|
17398 | if (this.transition)
|
17399 | return this.transition();
|
17400 | }
|
17401 |
|
17402 | };
|
17403 | }
|
17404 |
|
17405 | };
|
17406 |
|
17407 |
|
17408 |
|
17409 |
|
17410 |
|
17411 |
|
17412 | {
|
17413 | if (module.exports) {
|
17414 | exports = module.exports = StateMachine;
|
17415 | }
|
17416 | exports.StateMachine = StateMachine;
|
17417 | }
|
17418 |
|
17419 | }());
|
17420 | });
|
17421 | var stateMachine_1 = stateMachine.StateMachine;
|
17422 |
|
17423 |
|
17424 | var getPrototype = _overArg(Object.getPrototypeOf, Object);
|
17425 |
|
17426 | var _getPrototype = getPrototype;
|
17427 |
|
17428 |
|
17429 | var objectTag$1 = '[object Object]';
|
17430 |
|
17431 |
|
17432 | var funcProto = Function.prototype,
|
17433 | objectProto$6 = Object.prototype;
|
17434 |
|
17435 |
|
17436 | var funcToString = funcProto.toString;
|
17437 |
|
17438 |
|
17439 | var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
|
17440 |
|
17441 |
|
17442 | var objectCtorString = funcToString.call(Object);
|
17443 |
|
17444 | |
17445 |
|
17446 |
|
17447 |
|
17448 |
|
17449 |
|
17450 |
|
17451 |
|
17452 |
|
17453 |
|
17454 |
|
17455 |
|
17456 |
|
17457 |
|
17458 |
|
17459 |
|
17460 |
|
17461 |
|
17462 |
|
17463 |
|
17464 |
|
17465 |
|
17466 |
|
17467 |
|
17468 |
|
17469 |
|
17470 |
|
17471 |
|
17472 | function isPlainObject(value) {
|
17473 | if (!isObjectLike_1(value) || _baseGetTag(value) != objectTag$1) {
|
17474 | return false;
|
17475 | }
|
17476 | var proto = _getPrototype(value);
|
17477 | if (proto === null) {
|
17478 | return true;
|
17479 | }
|
17480 | var Ctor = hasOwnProperty$5.call(proto, 'constructor') && proto.constructor;
|
17481 | return typeof Ctor == 'function' && Ctor instanceof Ctor &&
|
17482 | funcToString.call(Ctor) == objectCtorString;
|
17483 | }
|
17484 |
|
17485 | var isPlainObject_1 = isPlainObject;
|
17486 |
|
17487 |
|
17488 | var global$1 = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
|
17489 |
|
17490 | var EXPIRED = Symbol('expired');
|
17491 | var debug = browser('LC:Expirable');
|
17492 |
|
17493 | var Expirable =
|
17494 |
|
17495 | function () {
|
17496 | function Expirable(value, ttl) {
|
17497 | this.originalValue = value;
|
17498 |
|
17499 | if (typeof ttl === 'number') {
|
17500 | this.expiredAt = Date.now() + ttl;
|
17501 | }
|
17502 | }
|
17503 |
|
17504 | _createClass(Expirable, [{
|
17505 | key: "value",
|
17506 | get: function get() {
|
17507 | var expired = this.expiredAt && this.expiredAt <= Date.now();
|
17508 | if (expired) debug("expired: ".concat(this.originalValue));
|
17509 | return expired ? EXPIRED : this.originalValue;
|
17510 | }
|
17511 | }]);
|
17512 |
|
17513 | return Expirable;
|
17514 | }();
|
17515 | Expirable.EXPIRED = EXPIRED;
|
17516 |
|
17517 | var debug$1 = browser('LC:Cache');
|
17518 |
|
17519 | var Cache =
|
17520 |
|
17521 | function () {
|
17522 | function Cache() {
|
17523 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'anonymous';
|
17524 | this.name = name;
|
17525 | this._map = {};
|
17526 | }
|
17527 |
|
17528 | var _proto = Cache.prototype;
|
17529 |
|
17530 | _proto.get = function get(key) {
|
17531 | var cache = this._map[key];
|
17532 |
|
17533 | if (cache) {
|
17534 | var value = cache.value;
|
17535 |
|
17536 | if (value !== Expirable.EXPIRED) {
|
17537 | debug$1('[%s] hit: %s', this.name, key);
|
17538 | return value;
|
17539 | }
|
17540 |
|
17541 | delete this._map[key];
|
17542 | }
|
17543 |
|
17544 | debug$1("[".concat(this.name, "] missed: ").concat(key));
|
17545 | return null;
|
17546 | };
|
17547 |
|
17548 | _proto.set = function set(key, value, ttl) {
|
17549 | debug$1('[%s] set: %s %d', this.name, key, ttl);
|
17550 | this._map[key] = new Expirable(value, ttl);
|
17551 | };
|
17552 |
|
17553 | return Cache;
|
17554 | }();
|
17555 |
|
17556 | var debug$2 = {
|
17557 | enable: function enable() {
|
17558 | var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'LC*';
|
17559 | return browser.enable(namespaces);
|
17560 | },
|
17561 | disable: browser.disable
|
17562 | };
|
17563 | var tryAll = function tryAll(promiseConstructors) {
|
17564 | var promise = new Promise(promiseConstructors[0]);
|
17565 |
|
17566 | if (promiseConstructors.length === 1) {
|
17567 | return promise;
|
17568 | }
|
17569 |
|
17570 | return promise.catch(function () {
|
17571 | return tryAll(promiseConstructors.slice(1));
|
17572 | });
|
17573 | };
|
17574 |
|
17575 | var tap = function tap(interceptor) {
|
17576 | return function (value) {
|
17577 | return interceptor(value), value;
|
17578 | };
|
17579 | };
|
17580 | var finalize = function finalize(callback) {
|
17581 | return [
|
17582 | function (value) {
|
17583 | return callback(), value;
|
17584 | }, function (error) {
|
17585 | callback();
|
17586 | throw error;
|
17587 | }];
|
17588 | };
|
17589 | |
17590 |
|
17591 |
|
17592 |
|
17593 |
|
17594 |
|
17595 | var decodeDate = function decodeDate(date) {
|
17596 | if (!date) return date;
|
17597 |
|
17598 | if (typeof date === 'string' || typeof date === 'number') {
|
17599 | return new Date(date);
|
17600 | }
|
17601 |
|
17602 | if (date.__type === 'Date' && date.iso) {
|
17603 | return new Date(date.iso);
|
17604 | }
|
17605 |
|
17606 |
|
17607 | if (typeof date.toNumber === 'function') {
|
17608 | return new Date(date.toNumber());
|
17609 | }
|
17610 |
|
17611 | return date;
|
17612 | };
|
17613 | |
17614 |
|
17615 |
|
17616 |
|
17617 |
|
17618 | var getTime = function getTime(date) {
|
17619 | return date && date.getTime ? date.getTime() : undefined;
|
17620 | };
|
17621 | |
17622 |
|
17623 |
|
17624 |
|
17625 |
|
17626 |
|
17627 | var decode = function decode(value) {
|
17628 | if (!value) return value;
|
17629 |
|
17630 | if (value.__type === 'Date' && value.iso) {
|
17631 | return new Date(value.iso);
|
17632 | }
|
17633 |
|
17634 | if (Array.isArray(value)) {
|
17635 | return value.map(decode);
|
17636 | }
|
17637 |
|
17638 | if (isPlainObject_1(value)) {
|
17639 | return Object.keys(value).reduce(function (result, key) {
|
17640 | return _objectSpread({}, result, _defineProperty({}, key, decode(value[key])));
|
17641 | }, {});
|
17642 | }
|
17643 |
|
17644 | return value;
|
17645 | };
|
17646 | |
17647 |
|
17648 |
|
17649 |
|
17650 |
|
17651 |
|
17652 | var encode = function encode(value) {
|
17653 | if (value instanceof Date) return {
|
17654 | __type: 'Date',
|
17655 | iso: value.toJSON()
|
17656 | };
|
17657 |
|
17658 | if (Array.isArray(value)) {
|
17659 | return value.map(encode);
|
17660 | }
|
17661 |
|
17662 | if (isPlainObject_1(value)) {
|
17663 | return Object.keys(value).reduce(function (result, key) {
|
17664 | return _objectSpread({}, result, _defineProperty({}, key, encode(value[key])));
|
17665 | }, {});
|
17666 | }
|
17667 |
|
17668 | return value;
|
17669 | };
|
17670 | var keyRemap = function keyRemap(keymap, obj) {
|
17671 | return Object.keys(obj).reduce(function (newObj, key) {
|
17672 | var newKey = keymap[key] || key;
|
17673 | return Object.assign(newObj, _defineProperty({}, newKey, obj[key]));
|
17674 | }, {});
|
17675 | };
|
17676 | var isIE10 = global$1.navigator && global$1.navigator.userAgent && global$1.navigator.userAgent.indexOf('MSIE 10.') !== -1;
|
17677 |
|
17678 |
|
17679 | var getStaticProperty = function getStaticProperty(klass, property) {
|
17680 | return klass[property] || (klass.__proto__ ? getStaticProperty(klass.__proto__, property) : undefined);
|
17681 | };
|
17682 |
|
17683 |
|
17684 | var union = function union(a, b) {
|
17685 | return Array.from(new Set([].concat(_toConsumableArray(a), _toConsumableArray(b))));
|
17686 | };
|
17687 | var difference = function difference(a, b) {
|
17688 | return Array.from(function (bSet) {
|
17689 | return new Set(a.filter(function (x) {
|
17690 | return !bSet.has(x);
|
17691 | }));
|
17692 | }(new Set(b)));
|
17693 | };
|
17694 | var map = new WeakMap();
|
17695 |
|
17696 | var internal = function internal(object) {
|
17697 | if (!map.has(object)) {
|
17698 | map.set(object, {});
|
17699 | }
|
17700 |
|
17701 | return map.get(object);
|
17702 | };
|
17703 | var compact = function compact(obj, filter) {
|
17704 | if (!isPlainObject_1(obj)) return obj;
|
17705 | var object = Object.assign({}, obj);
|
17706 |
|
17707 | for (var prop in object) {
|
17708 | if ({}.hasOwnProperty.call(object, prop)) {
|
17709 | var value = object[prop];
|
17710 |
|
17711 | if (value === filter) {
|
17712 | delete object[prop];
|
17713 | } else {
|
17714 | object[prop] = compact(value, filter);
|
17715 | }
|
17716 | }
|
17717 | }
|
17718 |
|
17719 | return object;
|
17720 | };
|
17721 |
|
17722 | var removeNull = function removeNull(obj) {
|
17723 | return compact(obj, null);
|
17724 | };
|
17725 |
|
17726 | var trim = function trim(message) {
|
17727 | return removeNull(JSON.parse(JSON.stringify(message)));
|
17728 | };
|
17729 | var ensureArray = function ensureArray(target) {
|
17730 | if (Array.isArray(target)) {
|
17731 | return target;
|
17732 | }
|
17733 |
|
17734 | if (target === undefined || target === null) {
|
17735 | return [];
|
17736 | }
|
17737 |
|
17738 | return [target];
|
17739 | };
|
17740 | var setValue = function setValue(target, key, value) {
|
17741 |
|
17742 | var segs = key.split('.');
|
17743 | var lastSeg = segs.pop();
|
17744 | var currentTarget = target;
|
17745 | segs.forEach(function (seg) {
|
17746 | if (currentTarget[seg] === undefined) currentTarget[seg] = {};
|
17747 | currentTarget = currentTarget[seg];
|
17748 | });
|
17749 | currentTarget[lastSeg] = value;
|
17750 | return target;
|
17751 | };
|
17752 | var isWeapp =
|
17753 | (typeof wx === "undefined" ? "undefined" : _typeof(wx)) === 'object' && typeof wx.connectSocket === 'function';
|
17754 |
|
17755 | var throttle = function throttle(wait) {
|
17756 | return function (target, property, descriptor) {
|
17757 | var callback = descriptor.value;
|
17758 |
|
17759 | if (callback.length) {
|
17760 | throw new Error('throttled function should not accept any arguments');
|
17761 | }
|
17762 |
|
17763 | return _objectSpread({}, descriptor, {
|
17764 | value: function value() {
|
17765 | var _this = this;
|
17766 |
|
17767 | var _internal = internal(this),
|
17768 | throttleMeta = _internal.throttleMeta;
|
17769 |
|
17770 | if (!throttleMeta) {
|
17771 | throttleMeta = {};
|
17772 | internal(this).throttleMeta = throttleMeta;
|
17773 | }
|
17774 |
|
17775 | var _throttleMeta = throttleMeta,
|
17776 | propertyMeta = _throttleMeta[property];
|
17777 |
|
17778 | if (!propertyMeta) {
|
17779 | propertyMeta = {};
|
17780 | throttleMeta[property] = propertyMeta;
|
17781 | }
|
17782 |
|
17783 | var _propertyMeta = propertyMeta,
|
17784 | _propertyMeta$previou = _propertyMeta.previouseTimestamp,
|
17785 | previouseTimestamp = _propertyMeta$previou === void 0 ? 0 : _propertyMeta$previou,
|
17786 | timeout = _propertyMeta.timeout;
|
17787 | var now = Date.now();
|
17788 | var remainingTime = wait - (now - previouseTimestamp);
|
17789 |
|
17790 | if (remainingTime <= 0) {
|
17791 | throttleMeta[property].previouseTimestamp = now;
|
17792 | callback.apply(this);
|
17793 | } else if (!timeout) {
|
17794 | propertyMeta.timeout = setTimeout(function () {
|
17795 | propertyMeta.previouseTimestamp = Date.now();
|
17796 | delete propertyMeta.timeout;
|
17797 | callback.apply(_this);
|
17798 | }, remainingTime);
|
17799 | }
|
17800 | }
|
17801 | });
|
17802 | };
|
17803 | };
|
17804 | var isCNApp = function isCNApp(appId) {
|
17805 | return appId.slice(-9) !== '-MdYXbMMI';
|
17806 | };
|
17807 |
|
17808 | var _class;
|
17809 | var debug$3 = browser('LC:WebSocketPlus');
|
17810 | var OPEN$1 = 'open';
|
17811 | var DISCONNECT = 'disconnect';
|
17812 | var RECONNECT = 'reconnect';
|
17813 | var RETRY = 'retry';
|
17814 | var SCHEDULE = 'schedule';
|
17815 | var OFFLINE = 'offline';
|
17816 | var ONLINE = 'online';
|
17817 | var ERROR = 'error';
|
17818 | var MESSAGE = 'message';
|
17819 | var HEARTBEAT_TIME = 180000;
|
17820 | var TIMEOUT_TIME = 380000;
|
17821 |
|
17822 | var DEFAULT_RETRY_STRATEGY = function DEFAULT_RETRY_STRATEGY(attempt) {
|
17823 | return Math.min(1000 * Math.pow(2, attempt), 300000);
|
17824 | };
|
17825 |
|
17826 | var requireConnected = function requireConnected(target, name, descriptor) {
|
17827 | return Object.assign({}, descriptor, {
|
17828 | value: function requireConnectedWrapper() {
|
17829 | var _descriptor$value;
|
17830 |
|
17831 | this.checkConnectionAvailability(name);
|
17832 |
|
17833 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
17834 | args[_key] = arguments[_key];
|
17835 | }
|
17836 |
|
17837 | return (_descriptor$value = descriptor.value).call.apply(_descriptor$value, [this].concat(args));
|
17838 | }
|
17839 | });
|
17840 | };
|
17841 |
|
17842 | var WebSocketPlus = (_class =
|
17843 |
|
17844 | function (_EventEmitter) {
|
17845 | _inheritsLoose(WebSocketPlus, _EventEmitter);
|
17846 |
|
17847 | _createClass(WebSocketPlus, [{
|
17848 | key: "urls",
|
17849 | get: function get() {
|
17850 | return this._urls;
|
17851 | },
|
17852 | set: function set(urls) {
|
17853 | this._urls = ensureArray(urls);
|
17854 | }
|
17855 | }]);
|
17856 |
|
17857 | function WebSocketPlus(getUrls, protocol) {
|
17858 | var _this;
|
17859 |
|
17860 | if (typeof websocket === 'undefined') {
|
17861 | throw new Error('WebSocket is undefined. Polyfill is required in this runtime.');
|
17862 | }
|
17863 |
|
17864 | _this = _EventEmitter.call(this) || this;
|
17865 |
|
17866 | _this.init();
|
17867 |
|
17868 | _this._protocol = protocol;
|
17869 | Promise.resolve(typeof getUrls === 'function' ? getUrls() : getUrls).then(ensureArray).then(function (urls) {
|
17870 | _this._urls = urls;
|
17871 | return _this._open();
|
17872 | }).then(function () {
|
17873 | _this.__postponeTimeoutTimer = _this._postponeTimeoutTimer.bind(_assertThisInitialized(_this));
|
17874 |
|
17875 | if (global$1.addEventListener) {
|
17876 | _this.__pause = function () {
|
17877 | if (_this.can('pause')) _this.pause();
|
17878 | };
|
17879 |
|
17880 | _this.__resume = function () {
|
17881 | if (_this.can('resume')) _this.resume();
|
17882 | };
|
17883 |
|
17884 | global$1.addEventListener('offline', _this.__pause);
|
17885 | global$1.addEventListener('online', _this.__resume);
|
17886 | }
|
17887 |
|
17888 | _this.open();
|
17889 | }).catch(_this.throw.bind(_assertThisInitialized(_this)));
|
17890 | return _this;
|
17891 | }
|
17892 |
|
17893 | var _proto = WebSocketPlus.prototype;
|
17894 |
|
17895 | _proto._open = function _open() {
|
17896 | var _this2 = this;
|
17897 |
|
17898 | return this._createWs(this._urls, this._protocol).then(function (ws) {
|
17899 | var _this2$_urls = _toArray(_this2._urls),
|
17900 | first = _this2$_urls[0],
|
17901 | reset = _this2$_urls.slice(1);
|
17902 |
|
17903 | _this2._urls = [].concat(_toConsumableArray(reset), [first]);
|
17904 | return ws;
|
17905 | });
|
17906 | };
|
17907 |
|
17908 | _proto._createWs = function _createWs(urls, protocol) {
|
17909 | var _this3 = this;
|
17910 |
|
17911 | return tryAll(urls.map(function (url) {
|
17912 | return function (resolve, reject) {
|
17913 | debug$3("connect [".concat(url, "] ").concat(protocol));
|
17914 | var ws = protocol ? new websocket(url, protocol) : new websocket(url);
|
17915 | ws.binaryType = _this3.binaryType || 'arraybuffer';
|
17916 |
|
17917 | ws.onopen = function () {
|
17918 | return resolve(ws);
|
17919 | };
|
17920 |
|
17921 | ws.onclose = function (error) {
|
17922 | if (error instanceof Error) {
|
17923 | return reject(error);
|
17924 | }
|
17925 |
|
17926 |
|
17927 | return reject(new Error("Failed to connect [".concat(url, "]")));
|
17928 | };
|
17929 |
|
17930 | ws.onerror = ws.onclose;
|
17931 | };
|
17932 | })).then(function (ws) {
|
17933 | _this3._ws = ws;
|
17934 | _this3._ws.onclose = _this3._handleClose.bind(_this3);
|
17935 | _this3._ws.onmessage = _this3._handleMessage.bind(_this3);
|
17936 | return ws;
|
17937 | });
|
17938 | };
|
17939 |
|
17940 | _proto._destroyWs = function _destroyWs() {
|
17941 | var ws = this._ws;
|
17942 | if (!ws) return;
|
17943 | ws.onopen = null;
|
17944 | ws.onclose = null;
|
17945 | ws.onerror = null;
|
17946 | ws.onmessage = null;
|
17947 | this._ws = null;
|
17948 | ws.close();
|
17949 | }
|
17950 | ;
|
17951 |
|
17952 | _proto.onbeforeevent = function onbeforeevent(event, from, to) {
|
17953 | for (var _len2 = arguments.length, payload = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
17954 | payload[_key2 - 3] = arguments[_key2];
|
17955 | }
|
17956 |
|
17957 | debug$3("".concat(event, ": ").concat(from, " -> ").concat(to, " %o"), payload);
|
17958 | };
|
17959 |
|
17960 | _proto.onopen = function onopen() {
|
17961 | this.emit(OPEN$1);
|
17962 | };
|
17963 |
|
17964 | _proto.onconnected = function onconnected() {
|
17965 | this._startConnectionKeeper();
|
17966 | };
|
17967 |
|
17968 | _proto.onleaveconnected = function onleaveconnected(event, from, to) {
|
17969 | this._stopConnectionKeeper();
|
17970 |
|
17971 | this._destroyWs();
|
17972 |
|
17973 | if (to === 'offline' || to === 'disconnected') {
|
17974 | this.emit(DISCONNECT);
|
17975 | }
|
17976 | };
|
17977 |
|
17978 | _proto.onpause = function onpause() {
|
17979 | this.emit(OFFLINE);
|
17980 | };
|
17981 |
|
17982 | _proto.onbeforeresume = function onbeforeresume() {
|
17983 | this.emit(ONLINE);
|
17984 | };
|
17985 |
|
17986 | _proto.onreconnect = function onreconnect() {
|
17987 | this.emit(RECONNECT);
|
17988 | };
|
17989 |
|
17990 | _proto.ondisconnected = function ondisconnected(event, from, to) {
|
17991 | var _this4 = this;
|
17992 |
|
17993 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
17994 | var delay = DEFAULT_RETRY_STRATEGY.call(null, attempt);
|
17995 | debug$3("schedule attempt=".concat(attempt, " delay=").concat(delay));
|
17996 | this.emit(SCHEDULE, attempt, delay);
|
17997 |
|
17998 | if (this.__scheduledRetry) {
|
17999 | clearTimeout(this.__scheduledRetry);
|
18000 | }
|
18001 |
|
18002 | this.__scheduledRetry = setTimeout(function () {
|
18003 | if (_this4.is('disconnected')) {
|
18004 | _this4.retry(attempt);
|
18005 | }
|
18006 | }, delay);
|
18007 | };
|
18008 |
|
18009 | _proto.onretry = function onretry(event, from, to) {
|
18010 | var _this5 = this;
|
18011 |
|
18012 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
18013 | this.emit(RETRY, attempt);
|
18014 |
|
18015 | this._open().then(function () {
|
18016 | return _this5.can('reconnect') ? _this5.reconnect() : _this5._destroyWs();
|
18017 | }, function () {
|
18018 | return _this5.can('fail') && _this5.fail(attempt + 1);
|
18019 | });
|
18020 | };
|
18021 |
|
18022 | _proto.onerror = function onerror(event, from, to, error) {
|
18023 | this.emit(ERROR, error);
|
18024 | };
|
18025 |
|
18026 | _proto.onclose = function onclose() {
|
18027 | if (global$1.removeEventListener) {
|
18028 | if (this.__pause) global$1.removeEventListener('offline', this.__pause);
|
18029 | if (this.__resume) global$1.removeEventListener('online', this.__resume);
|
18030 | }
|
18031 | };
|
18032 |
|
18033 | _proto.checkConnectionAvailability = function checkConnectionAvailability() {
|
18034 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'API';
|
18035 |
|
18036 | if (!this.is('connected')) {
|
18037 | var currentState = this.current;
|
18038 | console.warn("".concat(name, " should not be called when the connection is ").concat(currentState));
|
18039 |
|
18040 | if (this.is('disconnected') || this.is('reconnecting')) {
|
18041 | console.warn('disconnect and reconnect event should be handled to avoid such calls.');
|
18042 | }
|
18043 |
|
18044 | throw new Error('Connection unavailable');
|
18045 | }
|
18046 | }
|
18047 | ;
|
18048 |
|
18049 | _proto.
|
18050 | _ping = function _ping() {
|
18051 | debug$3('ping');
|
18052 |
|
18053 | try {
|
18054 | this.ping();
|
18055 | } catch (error) {
|
18056 | console.warn("websocket ping error: ".concat(error.message));
|
18057 | }
|
18058 | };
|
18059 |
|
18060 | _proto.ping = function ping() {
|
18061 | if (this._ws.ping) {
|
18062 | this._ws.ping();
|
18063 | } else {
|
18064 | console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.");
|
18065 | }
|
18066 | };
|
18067 |
|
18068 | _proto._postponeTimeoutTimer = function _postponeTimeoutTimer() {
|
18069 | var _this6 = this;
|
18070 |
|
18071 | debug$3('_postponeTimeoutTimer');
|
18072 |
|
18073 | this._clearTimeoutTimers();
|
18074 |
|
18075 | this._timeoutTimer = setTimeout(function () {
|
18076 | debug$3('timeout');
|
18077 |
|
18078 | _this6.disconnect();
|
18079 | }, TIMEOUT_TIME);
|
18080 | };
|
18081 |
|
18082 | _proto._clearTimeoutTimers = function _clearTimeoutTimers() {
|
18083 | if (this._timeoutTimer) {
|
18084 | clearTimeout(this._timeoutTimer);
|
18085 | }
|
18086 | };
|
18087 |
|
18088 | _proto._startConnectionKeeper = function _startConnectionKeeper() {
|
18089 | debug$3('start connection keeper');
|
18090 | this._heartbeatTimer = setInterval(this._ping.bind(this), HEARTBEAT_TIME);
|
18091 | var addListener = this._ws.addListener || this._ws.addEventListener;
|
18092 |
|
18093 | if (!addListener) {
|
18094 | debug$3('connection keeper disabled due to the lack of #addEventListener.');
|
18095 | return;
|
18096 | }
|
18097 |
|
18098 | addListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
18099 | addListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
18100 |
|
18101 | this._postponeTimeoutTimer();
|
18102 | };
|
18103 |
|
18104 | _proto._stopConnectionKeeper = function _stopConnectionKeeper() {
|
18105 | debug$3('stop connection keeper');
|
18106 |
|
18107 | var removeListener = this._ws.removeListener || this._ws.removeEventListener;
|
18108 |
|
18109 | if (removeListener) {
|
18110 | removeListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
18111 | removeListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
18112 |
|
18113 | this._clearTimeoutTimers();
|
18114 | }
|
18115 |
|
18116 | if (this._heartbeatTimer) {
|
18117 | clearInterval(this._heartbeatTimer);
|
18118 | }
|
18119 | };
|
18120 |
|
18121 | _proto._handleClose = function _handleClose(event) {
|
18122 | debug$3("ws closed [".concat(event.code, "] ").concat(event.reason));
|
18123 |
|
18124 | if (this.isFinished()) return;
|
18125 | this.handleClose(event);
|
18126 | };
|
18127 |
|
18128 | _proto.handleClose = function handleClose() {
|
18129 |
|
18130 | this.disconnect();
|
18131 | }
|
18132 | ;
|
18133 |
|
18134 | _proto.
|
18135 | send = function send(data) {
|
18136 | debug$3('send', data);
|
18137 |
|
18138 | this._ws.send(data);
|
18139 | };
|
18140 |
|
18141 | _proto._handleMessage = function _handleMessage(event) {
|
18142 | debug$3('message', event.data);
|
18143 | this.handleMessage(event.data);
|
18144 | };
|
18145 |
|
18146 | _proto.handleMessage = function handleMessage(message) {
|
18147 | this.emit(MESSAGE, message);
|
18148 | };
|
18149 |
|
18150 | return WebSocketPlus;
|
18151 | }(eventemitter3), (_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);
|
18152 | stateMachine.create({
|
18153 | target: WebSocketPlus.prototype,
|
18154 | initial: {
|
18155 | state: 'initialized',
|
18156 | event: 'init',
|
18157 | defer: true
|
18158 | },
|
18159 | terminal: 'closed',
|
18160 | events: [{
|
18161 | name: 'open',
|
18162 | from: 'initialized',
|
18163 | to: 'connected'
|
18164 | }, {
|
18165 | name: 'disconnect',
|
18166 | from: 'connected',
|
18167 | to: 'disconnected'
|
18168 | }, {
|
18169 | name: 'retry',
|
18170 | from: 'disconnected',
|
18171 | to: 'reconnecting'
|
18172 | }, {
|
18173 | name: 'fail',
|
18174 | from: 'reconnecting',
|
18175 | to: 'disconnected'
|
18176 | }, {
|
18177 | name: 'reconnect',
|
18178 | from: 'reconnecting',
|
18179 | to: 'connected'
|
18180 | }, {
|
18181 | name: 'pause',
|
18182 | from: ['connected', 'disconnected', 'reconnecting'],
|
18183 | to: 'offline'
|
18184 | }, {}, {
|
18185 | name: 'resume',
|
18186 | from: 'offline',
|
18187 | to: 'disconnected'
|
18188 | }, {
|
18189 | name: 'close',
|
18190 | from: ['connected', 'disconnected', 'reconnecting', 'offline'],
|
18191 | to: 'closed'
|
18192 | }, {
|
18193 | name: 'throw',
|
18194 | from: '*',
|
18195 | to: 'error'
|
18196 | }]
|
18197 | });
|
18198 |
|
18199 | var error = Object.freeze({
|
18200 | 1000: {
|
18201 | name: 'CLOSE_NORMAL'
|
18202 | },
|
18203 | 1006: {
|
18204 | name: 'CLOSE_ABNORMAL'
|
18205 | },
|
18206 | 4100: {
|
18207 | name: 'APP_NOT_AVAILABLE',
|
18208 | message: 'App not exists or realtime message service is disabled.'
|
18209 | },
|
18210 | 4102: {
|
18211 | name: 'SIGNATURE_FAILED',
|
18212 | message: 'Login signature mismatch.'
|
18213 | },
|
18214 | 4103: {
|
18215 | name: 'INVALID_LOGIN',
|
18216 | message: 'Malformed clientId.'
|
18217 | },
|
18218 | 4105: {
|
18219 | name: 'SESSION_REQUIRED',
|
18220 | message: 'Message sent before session opened.'
|
18221 | },
|
18222 | 4107: {
|
18223 | name: 'READ_TIMEOUT'
|
18224 | },
|
18225 | 4108: {
|
18226 | name: 'LOGIN_TIMEOUT'
|
18227 | },
|
18228 | 4109: {
|
18229 | name: 'FRAME_TOO_LONG'
|
18230 | },
|
18231 | 4110: {
|
18232 | name: 'INVALID_ORIGIN',
|
18233 | message: 'Access denied by domain whitelist.'
|
18234 | },
|
18235 | 4111: {
|
18236 | name: 'SESSION_CONFLICT'
|
18237 | },
|
18238 | 4112: {
|
18239 | name: 'SESSION_TOKEN_EXPIRED'
|
18240 | },
|
18241 | 4113: {
|
18242 | name: 'APP_QUOTA_EXCEEDED',
|
18243 | message: 'The daily active users limit exceeded.'
|
18244 | },
|
18245 | 4116: {
|
18246 | name: 'MESSAGE_SENT_QUOTA_EXCEEDED',
|
18247 | message: 'Command sent too fast.'
|
18248 | },
|
18249 | 4200: {
|
18250 | name: 'INTERNAL_ERROR',
|
18251 | message: 'Internal error, please contact LeanCloud for support.'
|
18252 | },
|
18253 | 4301: {
|
18254 | name: 'CONVERSATION_API_FAILED',
|
18255 | message: 'Upstream Conversatoin API failed, see error.detail for details.'
|
18256 | },
|
18257 | 4302: {
|
18258 | name: 'CONVERSATION_SIGNATURE_FAILED',
|
18259 | message: 'Conversation action signature mismatch.'
|
18260 | },
|
18261 | 4303: {
|
18262 | name: 'CONVERSATION_NOT_FOUND'
|
18263 | },
|
18264 | 4304: {
|
18265 | name: 'CONVERSATION_FULL'
|
18266 | },
|
18267 | 4305: {
|
18268 | name: 'CONVERSATION_REJECTED_BY_APP',
|
18269 | message: 'Conversation action rejected by hook.'
|
18270 | },
|
18271 | 4306: {
|
18272 | name: 'CONVERSATION_UPDATE_FAILED'
|
18273 | },
|
18274 | 4307: {
|
18275 | name: 'CONVERSATION_READ_ONLY'
|
18276 | },
|
18277 | 4308: {
|
18278 | name: 'CONVERSATION_NOT_ALLOWED'
|
18279 | },
|
18280 | 4309: {
|
18281 | name: 'CONVERSATION_UPDATE_REJECTED',
|
18282 | message: 'Conversation update rejected because the client is not a member.'
|
18283 | },
|
18284 | 4310: {
|
18285 | name: 'CONVERSATION_QUERY_FAILED',
|
18286 | message: 'Conversation query failed because it is too expansive.'
|
18287 | },
|
18288 | 4311: {
|
18289 | name: 'CONVERSATION_LOG_FAILED'
|
18290 | },
|
18291 | 4312: {
|
18292 | name: 'CONVERSATION_LOG_REJECTED',
|
18293 | message: 'Message query rejected because the client is not a member of the conversation.'
|
18294 | },
|
18295 | 4313: {
|
18296 | name: 'SYSTEM_CONVERSATION_REQUIRED'
|
18297 | },
|
18298 | 4314: {
|
18299 | name: 'NORMAL_CONVERSATION_REQUIRED'
|
18300 | },
|
18301 | 4315: {
|
18302 | name: 'CONVERSATION_BLACKLISTED',
|
18303 | message: 'Blacklisted in the conversation.'
|
18304 | },
|
18305 | 4316: {
|
18306 | name: 'TRANSIENT_CONVERSATION_REQUIRED'
|
18307 | },
|
18308 | 4317: {
|
18309 | name: 'CONVERSATION_MEMBERSHIP_REQUIRED'
|
18310 | },
|
18311 | 4318: {
|
18312 | name: 'CONVERSATION_API_QUOTA_EXCEEDED',
|
18313 | message: 'LeanCloud API quota exceeded. You may upgrade your plan.'
|
18314 | },
|
18315 | 4323: {
|
18316 | name: 'TEMPORARY_CONVERSATION_EXPIRED',
|
18317 | message: 'Temporary conversation expired or does not exist.'
|
18318 | },
|
18319 | 4401: {
|
18320 | name: 'INVALID_MESSAGING_TARGET',
|
18321 | message: 'Conversation does not exist or client is not a member.'
|
18322 | },
|
18323 | 4402: {
|
18324 | name: 'MESSAGE_REJECTED_BY_APP',
|
18325 | message: 'Message rejected by hook.'
|
18326 | },
|
18327 | 4403: {
|
18328 | name: 'MESSAGE_OWNERSHIP_REQUIRED'
|
18329 | },
|
18330 | 4404: {
|
18331 | name: 'MESSAGE_NOT_FOUND'
|
18332 | },
|
18333 | 4405: {
|
18334 | name: 'MESSAGE_UPDATE_REJECTED_BY_APP',
|
18335 | message: 'Message update rejected by hook.'
|
18336 | },
|
18337 | 4406: {
|
18338 | name: 'MESSAGE_EDIT_DISABLED'
|
18339 | },
|
18340 | 4407: {
|
18341 | name: 'MESSAGE_RECALL_DISABLED'
|
18342 | },
|
18343 | 5130: {
|
18344 | name: 'OWNER_PROMOTION_NOT_ALLOWED',
|
18345 | message: "Updating a member's role to owner is not allowed."
|
18346 | }
|
18347 | });
|
18348 | var ErrorCode = Object.freeze(Object.keys(error).reduce(function (result, code) {
|
18349 | return Object.assign(result, _defineProperty({}, error[code].name, Number(code)));
|
18350 | }, {}));
|
18351 | var createError = function createError(_ref) {
|
18352 | var code = _ref.code,
|
18353 | reason = _ref.reason,
|
18354 | appCode = _ref.appCode,
|
18355 | detail = _ref.detail,
|
18356 | errorMessage = _ref.error;
|
18357 | var message = reason || detail || errorMessage;
|
18358 | var name = reason;
|
18359 |
|
18360 | if (!message && error[code]) {
|
18361 | name = error[code].name;
|
18362 | message = error[code].message || name;
|
18363 | }
|
18364 |
|
18365 | if (!message) {
|
18366 | message = "Unknow Error: ".concat(code);
|
18367 | }
|
18368 |
|
18369 | var err = new Error(message);
|
18370 | return Object.assign(err, {
|
18371 | code: code,
|
18372 | appCode: appCode,
|
18373 | detail: detail,
|
18374 | name: name
|
18375 | });
|
18376 | };
|
18377 |
|
18378 | var debug$4 = browser('LC:Connection');
|
18379 | var COMMAND_TIMEOUT = 20000;
|
18380 | var EXPIRE = Symbol('expire');
|
18381 |
|
18382 | var Connection =
|
18383 |
|
18384 | function (_WebSocketPlus) {
|
18385 | _inheritsLoose(Connection, _WebSocketPlus);
|
18386 |
|
18387 | function Connection(getUrl, _ref) {
|
18388 | var _this;
|
18389 |
|
18390 | var format = _ref.format,
|
18391 | version = _ref.version;
|
18392 | debug$4('initializing Connection');
|
18393 | var protocolString = "lc.".concat(format, ".").concat(version);
|
18394 |
|
18395 | if (!isWeapp) {
|
18396 | _this = _WebSocketPlus.call(this, getUrl, protocolString) || this;
|
18397 | } else {
|
18398 | _this = _WebSocketPlus.call(this, getUrl().then(function (urls) {
|
18399 | return urls.map(function (url) {
|
18400 | return "".concat(url).concat(url.indexOf('?') === -1 ? '?' : '&', "subprotocol=").concat(encodeURIComponent(protocolString));
|
18401 | });
|
18402 | })) || this;
|
18403 | }
|
18404 |
|
18405 | _this._protocalFormat = format;
|
18406 | _this._commands = {};
|
18407 | _this._serialId = 0;
|
18408 | return _assertThisInitialized(_this);
|
18409 | }
|
18410 |
|
18411 | var _proto = Connection.prototype;
|
18412 |
|
18413 | _proto.send =
|
18414 |
|
18415 | function () {
|
18416 | var _send = _asyncToGenerator(
|
18417 |
|
18418 | regenerator.mark(function _callee(command) {
|
18419 | var _this2 = this;
|
18420 |
|
18421 | var waitingForRespond,
|
18422 | serialId,
|
18423 | message,
|
18424 | _args = arguments;
|
18425 | return regenerator.wrap(function _callee$(_context) {
|
18426 | while (1) {
|
18427 | switch (_context.prev = _context.next) {
|
18428 | case 0:
|
18429 | waitingForRespond = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
|
18430 |
|
18431 | if (waitingForRespond) {
|
18432 | this._serialId += 1;
|
18433 | serialId = this._serialId;
|
18434 | command.i = serialId;
|
18435 | }
|
18436 |
|
18437 | if (debug$4.enabled) debug$4('↑ %O sent', trim(command));
|
18438 |
|
18439 | if (this._protocalFormat === 'proto2base64') {
|
18440 | message = command.toBase64();
|
18441 | } else if (command.toArrayBuffer) {
|
18442 | message = command.toArrayBuffer();
|
18443 | }
|
18444 |
|
18445 | if (message) {
|
18446 | _context.next = 6;
|
18447 | break;
|
18448 | }
|
18449 |
|
18450 | throw new TypeError("".concat(command, " is not a GenericCommand"));
|
18451 |
|
18452 | case 6:
|
18453 | _WebSocketPlus.prototype.send.call(this, message);
|
18454 |
|
18455 | if (waitingForRespond) {
|
18456 | _context.next = 9;
|
18457 | break;
|
18458 | }
|
18459 |
|
18460 | return _context.abrupt("return", undefined);
|
18461 |
|
18462 | case 9:
|
18463 | return _context.abrupt("return", new Promise(function (resolve, reject) {
|
18464 | _this2._commands[serialId] = {
|
18465 | resolve: resolve,
|
18466 | reject: reject,
|
18467 | timeout: setTimeout(function () {
|
18468 | if (_this2._commands[serialId]) {
|
18469 | if (debug$4.enabled) debug$4('✗ %O timeout', trim(command));
|
18470 | reject(createError({
|
18471 | error: "Command Timeout [cmd:".concat(command.cmd, " op:").concat(command.op, "]"),
|
18472 | name: 'COMMAND_TIMEOUT'
|
18473 | }));
|
18474 | delete _this2._commands[serialId];
|
18475 | }
|
18476 | }, COMMAND_TIMEOUT)
|
18477 | };
|
18478 | }));
|
18479 |
|
18480 | case 10:
|
18481 | case "end":
|
18482 | return _context.stop();
|
18483 | }
|
18484 | }
|
18485 | }, _callee, this);
|
18486 | }));
|
18487 |
|
18488 | function send(_x) {
|
18489 | return _send.apply(this, arguments);
|
18490 | }
|
18491 |
|
18492 | return send;
|
18493 | }();
|
18494 |
|
18495 | _proto.handleMessage = function handleMessage(msg) {
|
18496 | var message;
|
18497 |
|
18498 | try {
|
18499 | message = GenericCommand.decode(msg);
|
18500 | if (debug$4.enabled) debug$4('↓ %O received', trim(message));
|
18501 | } catch (e) {
|
18502 | console.warn('Decode message failed:', e.message, msg);
|
18503 | return;
|
18504 | }
|
18505 |
|
18506 | var serialId = message.i;
|
18507 |
|
18508 | if (serialId) {
|
18509 | if (this._commands[serialId]) {
|
18510 | clearTimeout(this._commands[serialId].timeout);
|
18511 |
|
18512 | if (message.cmd === CommandType.error) {
|
18513 | this._commands[serialId].reject(createError(message.errorMessage));
|
18514 | } else {
|
18515 | this._commands[serialId].resolve(message);
|
18516 | }
|
18517 |
|
18518 | delete this._commands[serialId];
|
18519 | } else {
|
18520 | console.warn("Unexpected command received with serialId [".concat(serialId, "],\n which have timed out or never been requested."));
|
18521 | }
|
18522 | } else {
|
18523 | switch (message.cmd) {
|
18524 | case CommandType.error:
|
18525 | {
|
18526 | this.emit(ERROR, createError(message.errorMessage));
|
18527 | return;
|
18528 | }
|
18529 |
|
18530 | case CommandType.goaway:
|
18531 | {
|
18532 | this.emit(EXPIRE);
|
18533 | return;
|
18534 | }
|
18535 |
|
18536 | default:
|
18537 | {
|
18538 | this.emit(MESSAGE, message);
|
18539 | }
|
18540 | }
|
18541 | }
|
18542 | };
|
18543 |
|
18544 | _proto.ping = function ping() {
|
18545 | return this.send(new GenericCommand({
|
18546 | cmd: CommandType.echo
|
18547 | })).catch(function (error) {
|
18548 | return debug$4('ping failed:', error);
|
18549 | });
|
18550 | };
|
18551 |
|
18552 | return Connection;
|
18553 | }(WebSocketPlus);
|
18554 |
|
18555 | var checkType = function checkType(middleware) {
|
18556 | return function (param) {
|
18557 | var constructor = param.constructor;
|
18558 | return Promise.resolve(param).then(middleware).then(tap(function (result) {
|
18559 | if (result === undefined || result === null) {
|
18560 |
|
18561 | return console.warn("Middleware[".concat(middleware._pluginName || 'anonymous plugin', ":").concat(middleware.name || 'anonymous middleware', "] param/return types not match. It returns ").concat(result, " while a ").concat(param.constructor.name, " expected."));
|
18562 | }
|
18563 |
|
18564 | if (!(result instanceof constructor)) {
|
18565 |
|
18566 | return console.warn("Middleware[".concat(middleware._pluginName || 'anonymous plugin', ":").concat(middleware.name || 'anonymous middleware', "] param/return types not match. It returns a ").concat(result.constructor.name, " while a ").concat(param.constructor.name, " expected."));
|
18567 | }
|
18568 |
|
18569 | return 0;
|
18570 | }));
|
18571 | };
|
18572 | };
|
18573 |
|
18574 | var applyDecorators = function applyDecorators(decorators, target) {
|
18575 | if (decorators) {
|
18576 | decorators.forEach(function (decorator) {
|
18577 | try {
|
18578 | decorator(target);
|
18579 | } catch (error) {
|
18580 | if (decorator._pluginName) {
|
18581 | error.message += "[".concat(decorator._pluginName, "]");
|
18582 | }
|
18583 |
|
18584 | throw error;
|
18585 | }
|
18586 | });
|
18587 | }
|
18588 | };
|
18589 | var applyMiddlewares = function applyMiddlewares(middlewares) {
|
18590 | return function (target) {
|
18591 | return ensureArray(middlewares).reduce(function (previousPromise, middleware) {
|
18592 | return previousPromise.then(checkType(middleware)).catch(function (error) {
|
18593 | if (middleware._pluginName) {
|
18594 |
|
18595 | error.message += "[".concat(middleware._pluginName, "]");
|
18596 | }
|
18597 |
|
18598 | throw error;
|
18599 | });
|
18600 | }, Promise.resolve(target));
|
18601 | };
|
18602 | };
|
18603 | var applyDispatcher = function applyDispatcher(dispatchers, payload) {
|
18604 | return ensureArray(dispatchers).reduce(function (resultPromise, dispatcher) {
|
18605 | return resultPromise.then(function (shouldDispatch) {
|
18606 | return shouldDispatch === false ? false : dispatcher.apply(void 0, _toConsumableArray(payload));
|
18607 | }).catch(function (error) {
|
18608 | if (dispatcher._pluginName) {
|
18609 |
|
18610 | error.message += "[".concat(dispatcher._pluginName, "]");
|
18611 | }
|
18612 |
|
18613 | throw error;
|
18614 | });
|
18615 | }, Promise.resolve(true));
|
18616 | };
|
18617 |
|
18618 | var version = "5.0.0-beta.0";
|
18619 |
|
18620 | var debug$5 = browser('LC:Realtime');
|
18621 | var debugRequest = browser('LC:request');
|
18622 | var routerCache = new Cache('push-router');
|
18623 |
|
18624 | var Realtime =
|
18625 |
|
18626 | function (_EventEmitter) {
|
18627 | _inheritsLoose(Realtime, _EventEmitter);
|
18628 |
|
18629 | |
18630 |
|
18631 |
|
18632 |
|
18633 |
|
18634 |
|
18635 |
|
18636 |
|
18637 |
|
18638 |
|
18639 |
|
18640 |
|
18641 |
|
18642 | function Realtime(_ref) {
|
18643 | var _this2;
|
18644 |
|
18645 | var plugins = _ref.plugins,
|
18646 | options = _objectWithoutProperties(_ref, ["plugins"]);
|
18647 |
|
18648 | debug$5('initializing Realtime %s %O', version, options);
|
18649 | _this2 = _EventEmitter.call(this) || this;
|
18650 |
|
18651 | if (typeof options.appId !== 'string') {
|
18652 | throw new TypeError("appId [".concat(options.appId, "] is not a string"));
|
18653 | }
|
18654 |
|
18655 | if (typeof options.appKey !== 'string') {
|
18656 | throw new TypeError("appKey [".concat(options.appKey, "] is not a string"));
|
18657 | }
|
18658 |
|
18659 | if (isCNApp(options.appId)) {
|
18660 | if (!options.server) {
|
18661 | throw new TypeError("server option is required for apps from CN region");
|
18662 | }
|
18663 | }
|
18664 |
|
18665 | _this2._options = Object.assign({
|
18666 | appId: undefined,
|
18667 | appKey: undefined,
|
18668 | pushOfflineMessages: false,
|
18669 | noBinary: false,
|
18670 | ssl: true,
|
18671 | RTMServerName: process.env.RTM_SERVER_NAME
|
18672 |
|
18673 | }, options);
|
18674 | _this2._cache = new Cache('endpoints');
|
18675 |
|
18676 | var _this = internal(_assertThisInitialized(_this2));
|
18677 |
|
18678 | _this.clients = new Set();
|
18679 | _this.pendingClients = new Set();
|
18680 | var mergedPlugins = [].concat(_toConsumableArray(ensureArray(Realtime.__preRegisteredPlugins)), _toConsumableArray(ensureArray(plugins)));
|
18681 | debug$5('Using plugins %o', mergedPlugins.map(function (plugin) {
|
18682 | return plugin.name;
|
18683 | }));
|
18684 | _this2._plugins = mergedPlugins.reduce(function (result, plugin) {
|
18685 |
|
18686 | for (var hook in plugin) {
|
18687 | if ({}.hasOwnProperty.call(plugin, hook) && hook !== 'name') {
|
18688 | if (plugin.name) {
|
18689 | ensureArray(plugin[hook]).forEach(function (value) {
|
18690 |
|
18691 | value._pluginName = plugin.name;
|
18692 | });
|
18693 | }
|
18694 |
|
18695 |
|
18696 | result[hook] = ensureArray(result[hook]).concat(plugin[hook]);
|
18697 | }
|
18698 | }
|
18699 |
|
18700 | return result;
|
18701 | }, {});
|
18702 |
|
18703 | applyDecorators(_this2._plugins.onRealtimeCreate, _assertThisInitialized(_this2));
|
18704 | return _this2;
|
18705 | }
|
18706 |
|
18707 | var _proto = Realtime.prototype;
|
18708 |
|
18709 | _proto._request =
|
18710 |
|
18711 | function () {
|
18712 | var _request2 = _asyncToGenerator(
|
18713 |
|
18714 | regenerator.mark(function _callee(_ref2) {
|
18715 | var method, _ref2$version, version, path, query, headers, _ref2$data, data, _this$_options, appId, server, _ref3, api, url;
|
18716 |
|
18717 | return regenerator.wrap(function _callee$(_context) {
|
18718 | while (1) {
|
18719 | switch (_context.prev = _context.next) {
|
18720 | case 0:
|
18721 | method = _ref2.method, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1.1' : _ref2$version, path = _ref2.path, query = _ref2.query, headers = _ref2.headers, _ref2$data = _ref2.data, data = _ref2$data === void 0 ? {} : _ref2$data;
|
18722 | _this$_options = this._options, appId = _this$_options.appId, server = _this$_options.server;
|
18723 | _context.next = 4;
|
18724 | return this.constructor._getServerUrls({
|
18725 | appId: appId,
|
18726 | server: server
|
18727 | });
|
18728 |
|
18729 | case 4:
|
18730 | _ref3 = _context.sent;
|
18731 | api = _ref3.api;
|
18732 | url = "".concat(api, "/").concat(version).concat(path);
|
18733 | debugRequest('Req: %O %O %O', method, url, {
|
18734 | query: query,
|
18735 | headers: headers,
|
18736 | data: data
|
18737 | });
|
18738 | return _context.abrupt("return", client(method, url).set(_objectSpread({
|
18739 | 'X-LC-Id': this._options.appId,
|
18740 | 'X-LC-Key': this._options.appKey
|
18741 | }, headers)).query(query).send(data).then(function (response) {
|
18742 | debugRequest('Res: %O %O %O', url, response.status, response.body);
|
18743 | return response.body;
|
18744 | }, function (error) {
|
18745 | debugRequest('Error: %O %O %O', url, error.response.status, error.response.body);
|
18746 |
|
18747 | if (error.response && error.response.body && error.response.body.code) {
|
18748 | throw createError(error.response.body);
|
18749 | }
|
18750 |
|
18751 | throw error;
|
18752 | }));
|
18753 |
|
18754 | case 9:
|
18755 | case "end":
|
18756 | return _context.stop();
|
18757 | }
|
18758 | }
|
18759 | }, _callee, this);
|
18760 | }));
|
18761 |
|
18762 | function _request(_x) {
|
18763 | return _request2.apply(this, arguments);
|
18764 | }
|
18765 |
|
18766 | return _request;
|
18767 | }();
|
18768 |
|
18769 | _proto._open = function _open() {
|
18770 | var _this3 = this;
|
18771 |
|
18772 | if (this._openPromise) return this._openPromise;
|
18773 | var format = 'protobuf2';
|
18774 |
|
18775 | if (this._options.noBinary) {
|
18776 |
|
18777 | format = 'proto2base64';
|
18778 | }
|
18779 |
|
18780 | var version = 3;
|
18781 |
|
18782 | if (this._options.pushOfflineMessages) {
|
18783 |
|
18784 | version = 1;
|
18785 | }
|
18786 |
|
18787 | var protocol = {
|
18788 | format: format,
|
18789 | version: version
|
18790 | };
|
18791 | this._openPromise = new Promise(function (resolve, reject) {
|
18792 | debug$5('No connection established, create a new one.');
|
18793 | var connection = new Connection(function () {
|
18794 | return _this3._getRTMServers(_this3._options);
|
18795 | }, protocol);
|
18796 | connection.on(OPEN$1, function () {
|
18797 | return resolve(connection);
|
18798 | }).on(ERROR, reject).on(EXPIRE,
|
18799 |
|
18800 | _asyncToGenerator(
|
18801 |
|
18802 | regenerator.mark(function _callee2() {
|
18803 | return regenerator.wrap(function _callee2$(_context2) {
|
18804 | while (1) {
|
18805 | switch (_context2.prev = _context2.next) {
|
18806 | case 0:
|
18807 | debug$5('Connection expired. Refresh endpoints.');
|
18808 |
|
18809 | _this3._cache.set('endpoints', null, 0);
|
18810 |
|
18811 | _context2.next = 4;
|
18812 | return _this3._getRTMServers(_this3._options);
|
18813 |
|
18814 | case 4:
|
18815 | connection.urls = _context2.sent;
|
18816 | connection.disconnect();
|
18817 |
|
18818 | case 6:
|
18819 | case "end":
|
18820 | return _context2.stop();
|
18821 | }
|
18822 | }
|
18823 | }, _callee2, this);
|
18824 | }))).on(MESSAGE, _this3._dispatchCommand.bind(_this3));
|
18825 | |
18826 |
|
18827 |
|
18828 |
|
18829 |
|
18830 |
|
18831 |
|
18832 | |
18833 |
|
18834 |
|
18835 |
|
18836 |
|
18837 |
|
18838 |
|
18839 | |
18840 |
|
18841 |
|
18842 |
|
18843 |
|
18844 |
|
18845 | |
18846 |
|
18847 |
|
18848 |
|
18849 |
|
18850 |
|
18851 | |
18852 |
|
18853 |
|
18854 |
|
18855 |
|
18856 |
|
18857 |
|
18858 | |
18859 |
|
18860 |
|
18861 |
|
18862 |
|
18863 |
|
18864 |
|
18865 |
|
18866 | |
18867 |
|
18868 |
|
18869 |
|
18870 |
|
18871 |
|
18872 |
|
18873 | |
18874 |
|
18875 |
|
18876 |
|
18877 |
|
18878 |
|
18879 |
|
18880 | |
18881 |
|
18882 |
|
18883 |
|
18884 |
|
18885 |
|
18886 |
|
18887 | |
18888 |
|
18889 |
|
18890 |
|
18891 |
|
18892 |
|
18893 |
|
18894 | |
18895 |
|
18896 |
|
18897 |
|
18898 |
|
18899 |
|
18900 |
|
18901 |
|
18902 | [DISCONNECT, RECONNECT, RETRY, SCHEDULE, OFFLINE, ONLINE].forEach(function (event) {
|
18903 | return connection.on(event, function () {
|
18904 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
18905 | payload[_key] = arguments[_key];
|
18906 | }
|
18907 |
|
18908 | debug$5("".concat(event, " event emitted. %o"), payload);
|
18909 |
|
18910 | _this3.emit.apply(_this3, [event].concat(payload));
|
18911 |
|
18912 | if (event !== RECONNECT) {
|
18913 | internal(_this3).clients.forEach(function (client) {
|
18914 | client.emit.apply(client, [event].concat(payload));
|
18915 | });
|
18916 | }
|
18917 | });
|
18918 | });
|
18919 |
|
18920 | connection.handleClose = function handleClose(event) {
|
18921 | var isFatal = [ErrorCode.APP_NOT_AVAILABLE, ErrorCode.INVALID_LOGIN, ErrorCode.INVALID_ORIGIN].some(function (errorCode) {
|
18922 | return errorCode === event.code;
|
18923 | });
|
18924 |
|
18925 | if (isFatal) {
|
18926 |
|
18927 | this.throw(createError(event));
|
18928 | } else {
|
18929 |
|
18930 | this.disconnect();
|
18931 | }
|
18932 | };
|
18933 |
|
18934 | internal(_this3).connection = connection;
|
18935 | });
|
18936 | return this._openPromise;
|
18937 | };
|
18938 |
|
18939 | _proto._getRTMServers =
|
18940 |
|
18941 | function () {
|
18942 | var _getRTMServers2 = _asyncToGenerator(
|
18943 |
|
18944 | regenerator.mark(function _callee3(options) {
|
18945 | var info, cachedEndPoints;
|
18946 | return regenerator.wrap(function _callee3$(_context3) {
|
18947 | while (1) {
|
18948 | switch (_context3.prev = _context3.next) {
|
18949 | case 0:
|
18950 | if (!options.RTMServers) {
|
18951 | _context3.next = 2;
|
18952 | break;
|
18953 | }
|
18954 |
|
18955 | return _context3.abrupt("return", shuffle_1(ensureArray(options.RTMServers)));
|
18956 |
|
18957 | case 2:
|
18958 | cachedEndPoints = this._cache.get('endpoints');
|
18959 |
|
18960 | if (!cachedEndPoints) {
|
18961 | _context3.next = 9;
|
18962 | break;
|
18963 | }
|
18964 |
|
18965 | _context3.next = 6;
|
18966 | return cachedEndPoints;
|
18967 |
|
18968 | case 6:
|
18969 | info = _context3.sent;
|
18970 | _context3.next = 13;
|
18971 | break;
|
18972 |
|
18973 | case 9:
|
18974 | _context3.next = 11;
|
18975 | return this.constructor._fetchRTMServers(options);
|
18976 |
|
18977 | case 11:
|
18978 | info = _context3.sent;
|
18979 |
|
18980 | this._cache.set('endpoints', info, info.ttl * 1000);
|
18981 |
|
18982 | case 13:
|
18983 | debug$5('endpoint info: %O', info);
|
18984 | return _context3.abrupt("return", [info.server, info.secondary]);
|
18985 |
|
18986 | case 15:
|
18987 | case "end":
|
18988 | return _context3.stop();
|
18989 | }
|
18990 | }
|
18991 | }, _callee3, this);
|
18992 | }));
|
18993 |
|
18994 | function _getRTMServers(_x2) {
|
18995 | return _getRTMServers2.apply(this, arguments);
|
18996 | }
|
18997 |
|
18998 | return _getRTMServers;
|
18999 | }();
|
19000 |
|
19001 | Realtime._getServerUrls =
|
19002 |
|
19003 | function () {
|
19004 | var _getServerUrls2 = _asyncToGenerator(
|
19005 |
|
19006 | regenerator.mark(function _callee4(_ref5) {
|
19007 | var appId, server, cachedRouter, defaultProtocol;
|
19008 | return regenerator.wrap(function _callee4$(_context4) {
|
19009 | while (1) {
|
19010 | switch (_context4.prev = _context4.next) {
|
19011 | case 0:
|
19012 | appId = _ref5.appId, server = _ref5.server;
|
19013 | debug$5('fetch server urls');
|
19014 |
|
19015 | if (!server) {
|
19016 | _context4.next = 6;
|
19017 | break;
|
19018 | }
|
19019 |
|
19020 | if (!(typeof server !== 'string')) {
|
19021 | _context4.next = 5;
|
19022 | break;
|
19023 | }
|
19024 |
|
19025 | return _context4.abrupt("return", server);
|
19026 |
|
19027 | case 5:
|
19028 | return _context4.abrupt("return", {
|
19029 | RTMRouter: server,
|
19030 | api: server
|
19031 | });
|
19032 |
|
19033 | case 6:
|
19034 | cachedRouter = routerCache.get(appId);
|
19035 |
|
19036 | if (!cachedRouter) {
|
19037 | _context4.next = 9;
|
19038 | break;
|
19039 | }
|
19040 |
|
19041 | return _context4.abrupt("return", cachedRouter);
|
19042 |
|
19043 | case 9:
|
19044 | defaultProtocol = 'https://';
|
19045 | return _context4.abrupt("return", client.get('https://app-router.com/2/route').query({
|
19046 | appId: appId
|
19047 | }).timeout(20000).then(function (res) {
|
19048 | return res.body;
|
19049 | }).then(tap(debug$5)).then(function (_ref6) {
|
19050 | var RTMRouterServer = _ref6.rtm_router_server,
|
19051 | APIServer = _ref6.api_server,
|
19052 | _ref6$ttl = _ref6.ttl,
|
19053 | ttl = _ref6$ttl === void 0 ? 3600 : _ref6$ttl;
|
19054 |
|
19055 | if (!RTMRouterServer) {
|
19056 | throw new Error('rtm router not exists');
|
19057 | }
|
19058 |
|
19059 | var serverUrls = {
|
19060 | RTMRouter: "".concat(defaultProtocol).concat(RTMRouterServer),
|
19061 | api: "".concat(defaultProtocol).concat(APIServer)
|
19062 | };
|
19063 | routerCache.set(appId, serverUrls, ttl * 1000);
|
19064 | return serverUrls;
|
19065 | }).catch(function () {
|
19066 | var id = appId.slice(0, 8).toLowerCase();
|
19067 | var domain = 'lncldglobal.com';
|
19068 | return {
|
19069 | RTMRouter: "".concat(defaultProtocol).concat(id, ".rtm.").concat(domain),
|
19070 | api: "".concat(defaultProtocol).concat(id, ".api.").concat(domain)
|
19071 | };
|
19072 | }));
|
19073 |
|
19074 | case 11:
|
19075 | case "end":
|
19076 | return _context4.stop();
|
19077 | }
|
19078 | }
|
19079 | }, _callee4, this);
|
19080 | }));
|
19081 |
|
19082 | function _getServerUrls(_x3) {
|
19083 | return _getServerUrls2.apply(this, arguments);
|
19084 | }
|
19085 |
|
19086 | return _getServerUrls;
|
19087 | }();
|
19088 |
|
19089 | Realtime._fetchRTMServers = function _fetchRTMServers(_ref7) {
|
19090 | var appId = _ref7.appId,
|
19091 | ssl = _ref7.ssl,
|
19092 | server = _ref7.server,
|
19093 | RTMServerName = _ref7.RTMServerName;
|
19094 | debug$5('fetch endpoint info');
|
19095 | return this._getServerUrls({
|
19096 | appId: appId,
|
19097 | server: server
|
19098 | }).then(tap(debug$5)).then(function (_ref8) {
|
19099 | var RTMRouter = _ref8.RTMRouter;
|
19100 | return client.get("".concat(RTMRouter, "/v1/route")).query({
|
19101 | appId: appId,
|
19102 | secure: ssl,
|
19103 | features: isWeapp ? 'wechat' : undefined,
|
19104 | server: RTMServerName,
|
19105 | _t: Date.now()
|
19106 | }).timeout(20000).then(function (res) {
|
19107 | return res.body;
|
19108 | }).then(tap(debug$5));
|
19109 | });
|
19110 | };
|
19111 |
|
19112 | _proto._close = function _close() {
|
19113 | if (this._openPromise) {
|
19114 | this._openPromise.then(function (connection) {
|
19115 | return connection.close();
|
19116 | });
|
19117 | }
|
19118 |
|
19119 | delete this._openPromise;
|
19120 | }
|
19121 | |
19122 |
|
19123 |
|
19124 |
|
19125 |
|
19126 | ;
|
19127 |
|
19128 | _proto.retry = function retry() {
|
19129 | var _internal = internal(this),
|
19130 | connection = _internal.connection;
|
19131 |
|
19132 | if (!connection) {
|
19133 | throw new Error('no connection established');
|
19134 | }
|
19135 |
|
19136 | if (connection.cannot('retry')) {
|
19137 | throw new Error("retrying not allowed when not disconnected. the connection is now ".concat(connection.current));
|
19138 | }
|
19139 |
|
19140 | return connection.retry();
|
19141 | }
|
19142 | |
19143 |
|
19144 |
|
19145 |
|
19146 |
|
19147 |
|
19148 |
|
19149 |
|
19150 | ;
|
19151 |
|
19152 | _proto.pause = function pause() {
|
19153 |
|
19154 |
|
19155 | var _internal2 = internal(this),
|
19156 | connection = _internal2.connection;
|
19157 |
|
19158 | if (!connection) return;
|
19159 | if (connection.can('pause')) connection.pause();
|
19160 | }
|
19161 | |
19162 |
|
19163 |
|
19164 |
|
19165 |
|
19166 |
|
19167 |
|
19168 | ;
|
19169 |
|
19170 | _proto.resume = function resume() {
|
19171 |
|
19172 | var _internal3 = internal(this),
|
19173 | connection = _internal3.connection;
|
19174 |
|
19175 | if (!connection) return;
|
19176 | if (connection.can('resume')) connection.resume();
|
19177 | };
|
19178 |
|
19179 | _proto._registerPending = function _registerPending(value) {
|
19180 | internal(this).pendingClients.add(value);
|
19181 | };
|
19182 |
|
19183 | _proto._deregisterPending = function _deregisterPending(client) {
|
19184 | internal(this).pendingClients.delete(client);
|
19185 | };
|
19186 |
|
19187 | _proto._register = function _register(client) {
|
19188 | internal(this).clients.add(client);
|
19189 | };
|
19190 |
|
19191 | _proto._deregister = function _deregister(client) {
|
19192 | var _this = internal(this);
|
19193 |
|
19194 | _this.clients.delete(client);
|
19195 |
|
19196 | if (_this.clients.size + _this.pendingClients.size === 0) {
|
19197 | this._close();
|
19198 | }
|
19199 | };
|
19200 |
|
19201 | _proto._dispatchCommand = function _dispatchCommand(command) {
|
19202 | return applyDispatcher(this._plugins.beforeCommandDispatch, [command, this]).then(function (shouldDispatch) {
|
19203 |
|
19204 | if (shouldDispatch) return debug$5('[WARN] Unexpected message received: %O', trim(command));
|
19205 | return false;
|
19206 | });
|
19207 | };
|
19208 |
|
19209 | return Realtime;
|
19210 | }(eventemitter3);
|
19211 |
|
19212 | var polyfilledPromise = Promise;
|
19213 |
|
19214 | var rngBrowser = createCommonjsModule(function (module) {
|
19215 |
|
19216 |
|
19217 |
|
19218 |
|
19219 |
|
19220 |
|
19221 |
|
19222 | var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
|
19223 | (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
|
19224 |
|
19225 | if (getRandomValues) {
|
19226 |
|
19227 | var rnds8 = new Uint8Array(16);
|
19228 |
|
19229 | module.exports = function whatwgRNG() {
|
19230 | getRandomValues(rnds8);
|
19231 | return rnds8;
|
19232 | };
|
19233 | } else {
|
19234 |
|
19235 |
|
19236 |
|
19237 |
|
19238 | var rnds = new Array(16);
|
19239 |
|
19240 | module.exports = function mathRNG() {
|
19241 | for (var i = 0, r; i < 16; i++) {
|
19242 | if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
19243 | rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
19244 | }
|
19245 |
|
19246 | return rnds;
|
19247 | };
|
19248 | }
|
19249 | });
|
19250 |
|
19251 | |
19252 |
|
19253 |
|
19254 |
|
19255 | var byteToHex = [];
|
19256 | for (var i = 0; i < 256; ++i) {
|
19257 | byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
19258 | }
|
19259 |
|
19260 | function bytesToUuid(buf, offset) {
|
19261 | var i = offset || 0;
|
19262 | var bth = byteToHex;
|
19263 |
|
19264 | return ([bth[buf[i++]], bth[buf[i++]],
|
19265 | bth[buf[i++]], bth[buf[i++]], '-',
|
19266 | bth[buf[i++]], bth[buf[i++]], '-',
|
19267 | bth[buf[i++]], bth[buf[i++]], '-',
|
19268 | bth[buf[i++]], bth[buf[i++]], '-',
|
19269 | bth[buf[i++]], bth[buf[i++]],
|
19270 | bth[buf[i++]], bth[buf[i++]],
|
19271 | bth[buf[i++]], bth[buf[i++]]]).join('');
|
19272 | }
|
19273 |
|
19274 | var bytesToUuid_1 = bytesToUuid;
|
19275 |
|
19276 | function v4(options, buf, offset) {
|
19277 | var i = buf && offset || 0;
|
19278 |
|
19279 | if (typeof(options) == 'string') {
|
19280 | buf = options === 'binary' ? new Array(16) : null;
|
19281 | options = null;
|
19282 | }
|
19283 | options = options || {};
|
19284 |
|
19285 | var rnds = options.random || (options.rng || rngBrowser)();
|
19286 |
|
19287 |
|
19288 | rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
19289 | rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
19290 |
|
19291 |
|
19292 | if (buf) {
|
19293 | for (var ii = 0; ii < 16; ++ii) {
|
19294 | buf[i + ii] = rnds[ii];
|
19295 | }
|
19296 | }
|
19297 |
|
19298 | return buf || bytesToUuid_1(rnds);
|
19299 | }
|
19300 |
|
19301 | var v4_1 = v4;
|
19302 |
|
19303 | var base64Arraybuffer = createCommonjsModule(function (module, exports) {
|
19304 | |
19305 |
|
19306 |
|
19307 |
|
19308 |
|
19309 |
|
19310 |
|
19311 | (function(){
|
19312 |
|
19313 | var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
19314 |
|
19315 |
|
19316 | var lookup = new Uint8Array(256);
|
19317 | for (var i = 0; i < chars.length; i++) {
|
19318 | lookup[chars.charCodeAt(i)] = i;
|
19319 | }
|
19320 |
|
19321 | exports.encode = function(arraybuffer) {
|
19322 | var bytes = new Uint8Array(arraybuffer),
|
19323 | i, len = bytes.length, base64 = "";
|
19324 |
|
19325 | for (i = 0; i < len; i+=3) {
|
19326 | base64 += chars[bytes[i] >> 2];
|
19327 | base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
|
19328 | base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
|
19329 | base64 += chars[bytes[i + 2] & 63];
|
19330 | }
|
19331 |
|
19332 | if ((len % 3) === 2) {
|
19333 | base64 = base64.substring(0, base64.length - 1) + "=";
|
19334 | } else if (len % 3 === 1) {
|
19335 | base64 = base64.substring(0, base64.length - 2) + "==";
|
19336 | }
|
19337 |
|
19338 | return base64;
|
19339 | };
|
19340 |
|
19341 | exports.decode = function(base64) {
|
19342 | var bufferLength = base64.length * 0.75,
|
19343 | len = base64.length, i, p = 0,
|
19344 | encoded1, encoded2, encoded3, encoded4;
|
19345 |
|
19346 | if (base64[base64.length - 1] === "=") {
|
19347 | bufferLength--;
|
19348 | if (base64[base64.length - 2] === "=") {
|
19349 | bufferLength--;
|
19350 | }
|
19351 | }
|
19352 |
|
19353 | var arraybuffer = new ArrayBuffer(bufferLength),
|
19354 | bytes = new Uint8Array(arraybuffer);
|
19355 |
|
19356 | for (i = 0; i < len; i+=4) {
|
19357 | encoded1 = lookup[base64.charCodeAt(i)];
|
19358 | encoded2 = lookup[base64.charCodeAt(i+1)];
|
19359 | encoded3 = lookup[base64.charCodeAt(i+2)];
|
19360 | encoded4 = lookup[base64.charCodeAt(i+3)];
|
19361 |
|
19362 | bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
19363 | bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
19364 | bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
19365 | }
|
19366 |
|
19367 | return arraybuffer;
|
19368 | };
|
19369 | })();
|
19370 | });
|
19371 | var base64Arraybuffer_1 = base64Arraybuffer.encode;
|
19372 | var base64Arraybuffer_2 = base64Arraybuffer.decode;
|
19373 |
|
19374 | |
19375 |
|
19376 |
|
19377 |
|
19378 |
|
19379 |
|
19380 |
|
19381 | function listCacheClear() {
|
19382 | this.__data__ = [];
|
19383 | this.size = 0;
|
19384 | }
|
19385 |
|
19386 | var _listCacheClear = listCacheClear;
|
19387 |
|
19388 | |
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 |
|
19395 |
|
19396 |
|
19397 |
|
19398 |
|
19399 |
|
19400 |
|
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 |
|
19407 |
|
19408 |
|
19409 |
|
19410 |
|
19411 |
|
19412 |
|
19413 |
|
19414 |
|
19415 |
|
19416 |
|
19417 |
|
19418 |
|
19419 |
|
19420 | function eq(value, other) {
|
19421 | return value === other || (value !== value && other !== other);
|
19422 | }
|
19423 |
|
19424 | var eq_1 = eq;
|
19425 |
|
19426 | |
19427 |
|
19428 |
|
19429 |
|
19430 |
|
19431 |
|
19432 |
|
19433 |
|
19434 | function assocIndexOf(array, key) {
|
19435 | var length = array.length;
|
19436 | while (length--) {
|
19437 | if (eq_1(array[length][0], key)) {
|
19438 | return length;
|
19439 | }
|
19440 | }
|
19441 | return -1;
|
19442 | }
|
19443 |
|
19444 | var _assocIndexOf = assocIndexOf;
|
19445 |
|
19446 |
|
19447 | var arrayProto = Array.prototype;
|
19448 |
|
19449 |
|
19450 | var splice = arrayProto.splice;
|
19451 |
|
19452 | |
19453 |
|
19454 |
|
19455 |
|
19456 |
|
19457 |
|
19458 |
|
19459 |
|
19460 |
|
19461 | function listCacheDelete(key) {
|
19462 | var data = this.__data__,
|
19463 | index = _assocIndexOf(data, key);
|
19464 |
|
19465 | if (index < 0) {
|
19466 | return false;
|
19467 | }
|
19468 | var lastIndex = data.length - 1;
|
19469 | if (index == lastIndex) {
|
19470 | data.pop();
|
19471 | } else {
|
19472 | splice.call(data, index, 1);
|
19473 | }
|
19474 | --this.size;
|
19475 | return true;
|
19476 | }
|
19477 |
|
19478 | var _listCacheDelete = listCacheDelete;
|
19479 |
|
19480 | |
19481 |
|
19482 |
|
19483 |
|
19484 |
|
19485 |
|
19486 |
|
19487 |
|
19488 |
|
19489 | function listCacheGet(key) {
|
19490 | var data = this.__data__,
|
19491 | index = _assocIndexOf(data, key);
|
19492 |
|
19493 | return index < 0 ? undefined : data[index][1];
|
19494 | }
|
19495 |
|
19496 | var _listCacheGet = listCacheGet;
|
19497 |
|
19498 | |
19499 |
|
19500 |
|
19501 |
|
19502 |
|
19503 |
|
19504 |
|
19505 |
|
19506 |
|
19507 | function listCacheHas(key) {
|
19508 | return _assocIndexOf(this.__data__, key) > -1;
|
19509 | }
|
19510 |
|
19511 | var _listCacheHas = listCacheHas;
|
19512 |
|
19513 | |
19514 |
|
19515 |
|
19516 |
|
19517 |
|
19518 |
|
19519 |
|
19520 |
|
19521 |
|
19522 |
|
19523 | function listCacheSet(key, value) {
|
19524 | var data = this.__data__,
|
19525 | index = _assocIndexOf(data, key);
|
19526 |
|
19527 | if (index < 0) {
|
19528 | ++this.size;
|
19529 | data.push([key, value]);
|
19530 | } else {
|
19531 | data[index][1] = value;
|
19532 | }
|
19533 | return this;
|
19534 | }
|
19535 |
|
19536 | var _listCacheSet = listCacheSet;
|
19537 |
|
19538 | |
19539 |
|
19540 |
|
19541 |
|
19542 |
|
19543 |
|
19544 |
|
19545 | function ListCache(entries) {
|
19546 | var index = -1,
|
19547 | length = entries == null ? 0 : entries.length;
|
19548 |
|
19549 | this.clear();
|
19550 | while (++index < length) {
|
19551 | var entry = entries[index];
|
19552 | this.set(entry[0], entry[1]);
|
19553 | }
|
19554 | }
|
19555 |
|
19556 |
|
19557 | ListCache.prototype.clear = _listCacheClear;
|
19558 | ListCache.prototype['delete'] = _listCacheDelete;
|
19559 | ListCache.prototype.get = _listCacheGet;
|
19560 | ListCache.prototype.has = _listCacheHas;
|
19561 | ListCache.prototype.set = _listCacheSet;
|
19562 |
|
19563 | var _ListCache = ListCache;
|
19564 |
|
19565 | |
19566 |
|
19567 |
|
19568 |
|
19569 |
|
19570 |
|
19571 |
|
19572 | function stackClear() {
|
19573 | this.__data__ = new _ListCache;
|
19574 | this.size = 0;
|
19575 | }
|
19576 |
|
19577 | var _stackClear = stackClear;
|
19578 |
|
19579 | |
19580 |
|
19581 |
|
19582 |
|
19583 |
|
19584 |
|
19585 |
|
19586 |
|
19587 |
|
19588 | function stackDelete(key) {
|
19589 | var data = this.__data__,
|
19590 | result = data['delete'](key);
|
19591 |
|
19592 | this.size = data.size;
|
19593 | return result;
|
19594 | }
|
19595 |
|
19596 | var _stackDelete = stackDelete;
|
19597 |
|
19598 | |
19599 |
|
19600 |
|
19601 |
|
19602 |
|
19603 |
|
19604 |
|
19605 |
|
19606 |
|
19607 | function stackGet(key) {
|
19608 | return this.__data__.get(key);
|
19609 | }
|
19610 |
|
19611 | var _stackGet = stackGet;
|
19612 |
|
19613 | |
19614 |
|
19615 |
|
19616 |
|
19617 |
|
19618 |
|
19619 |
|
19620 |
|
19621 |
|
19622 | function stackHas(key) {
|
19623 | return this.__data__.has(key);
|
19624 | }
|
19625 |
|
19626 | var _stackHas = stackHas;
|
19627 |
|
19628 |
|
19629 | var coreJsData = _root['__core-js_shared__'];
|
19630 |
|
19631 | var _coreJsData = coreJsData;
|
19632 |
|
19633 |
|
19634 | var maskSrcKey = (function() {
|
19635 | var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || '');
|
19636 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
19637 | }());
|
19638 |
|
19639 | |
19640 |
|
19641 |
|
19642 |
|
19643 |
|
19644 |
|
19645 |
|
19646 | function isMasked(func) {
|
19647 | return !!maskSrcKey && (maskSrcKey in func);
|
19648 | }
|
19649 |
|
19650 | var _isMasked = isMasked;
|
19651 |
|
19652 |
|
19653 | var funcProto$1 = Function.prototype;
|
19654 |
|
19655 |
|
19656 | var funcToString$1 = funcProto$1.toString;
|
19657 |
|
19658 | |
19659 |
|
19660 |
|
19661 |
|
19662 |
|
19663 |
|
19664 |
|
19665 | function toSource(func) {
|
19666 | if (func != null) {
|
19667 | try {
|
19668 | return funcToString$1.call(func);
|
19669 | } catch (e) {}
|
19670 | try {
|
19671 | return (func + '');
|
19672 | } catch (e) {}
|
19673 | }
|
19674 | return '';
|
19675 | }
|
19676 |
|
19677 | var _toSource = toSource;
|
19678 |
|
19679 | |
19680 |
|
19681 |
|
19682 |
|
19683 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
19684 |
|
19685 |
|
19686 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
19687 |
|
19688 |
|
19689 | var funcProto$2 = Function.prototype,
|
19690 | objectProto$7 = Object.prototype;
|
19691 |
|
19692 |
|
19693 | var funcToString$2 = funcProto$2.toString;
|
19694 |
|
19695 |
|
19696 | var hasOwnProperty$6 = objectProto$7.hasOwnProperty;
|
19697 |
|
19698 |
|
19699 | var reIsNative = RegExp('^' +
|
19700 | funcToString$2.call(hasOwnProperty$6).replace(reRegExpChar, '\\$&')
|
19701 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
19702 | );
|
19703 |
|
19704 | |
19705 |
|
19706 |
|
19707 |
|
19708 |
|
19709 |
|
19710 |
|
19711 |
|
19712 | function baseIsNative(value) {
|
19713 | if (!isObject_1$1(value) || _isMasked(value)) {
|
19714 | return false;
|
19715 | }
|
19716 | var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
|
19717 | return pattern.test(_toSource(value));
|
19718 | }
|
19719 |
|
19720 | var _baseIsNative = baseIsNative;
|
19721 |
|
19722 | |
19723 |
|
19724 |
|
19725 |
|
19726 |
|
19727 |
|
19728 |
|
19729 |
|
19730 | function getValue(object, key) {
|
19731 | return object == null ? undefined : object[key];
|
19732 | }
|
19733 |
|
19734 | var _getValue = getValue;
|
19735 |
|
19736 | |
19737 |
|
19738 |
|
19739 |
|
19740 |
|
19741 |
|
19742 |
|
19743 |
|
19744 | function getNative(object, key) {
|
19745 | var value = _getValue(object, key);
|
19746 | return _baseIsNative(value) ? value : undefined;
|
19747 | }
|
19748 |
|
19749 | var _getNative = getNative;
|
19750 |
|
19751 |
|
19752 | var Map = _getNative(_root, 'Map');
|
19753 |
|
19754 | var _Map = Map;
|
19755 |
|
19756 |
|
19757 | var nativeCreate = _getNative(Object, 'create');
|
19758 |
|
19759 | var _nativeCreate = nativeCreate;
|
19760 |
|
19761 | |
19762 |
|
19763 |
|
19764 |
|
19765 |
|
19766 |
|
19767 |
|
19768 | function hashClear() {
|
19769 | this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
|
19770 | this.size = 0;
|
19771 | }
|
19772 |
|
19773 | var _hashClear = hashClear;
|
19774 |
|
19775 | |
19776 |
|
19777 |
|
19778 |
|
19779 |
|
19780 |
|
19781 |
|
19782 |
|
19783 |
|
19784 |
|
19785 | function hashDelete(key) {
|
19786 | var result = this.has(key) && delete this.__data__[key];
|
19787 | this.size -= result ? 1 : 0;
|
19788 | return result;
|
19789 | }
|
19790 |
|
19791 | var _hashDelete = hashDelete;
|
19792 |
|
19793 |
|
19794 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
19795 |
|
19796 |
|
19797 | var objectProto$8 = Object.prototype;
|
19798 |
|
19799 |
|
19800 | var hasOwnProperty$7 = objectProto$8.hasOwnProperty;
|
19801 |
|
19802 | |
19803 |
|
19804 |
|
19805 |
|
19806 |
|
19807 |
|
19808 |
|
19809 |
|
19810 |
|
19811 | function hashGet(key) {
|
19812 | var data = this.__data__;
|
19813 | if (_nativeCreate) {
|
19814 | var result = data[key];
|
19815 | return result === HASH_UNDEFINED ? undefined : result;
|
19816 | }
|
19817 | return hasOwnProperty$7.call(data, key) ? data[key] : undefined;
|
19818 | }
|
19819 |
|
19820 | var _hashGet = hashGet;
|
19821 |
|
19822 |
|
19823 | var objectProto$9 = Object.prototype;
|
19824 |
|
19825 |
|
19826 | var hasOwnProperty$8 = objectProto$9.hasOwnProperty;
|
19827 |
|
19828 | |
19829 |
|
19830 |
|
19831 |
|
19832 |
|
19833 |
|
19834 |
|
19835 |
|
19836 |
|
19837 | function hashHas(key) {
|
19838 | var data = this.__data__;
|
19839 | return _nativeCreate ? (data[key] !== undefined) : hasOwnProperty$8.call(data, key);
|
19840 | }
|
19841 |
|
19842 | var _hashHas = hashHas;
|
19843 |
|
19844 |
|
19845 | var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
|
19846 |
|
19847 | |
19848 |
|
19849 |
|
19850 |
|
19851 |
|
19852 |
|
19853 |
|
19854 |
|
19855 |
|
19856 |
|
19857 | function hashSet(key, value) {
|
19858 | var data = this.__data__;
|
19859 | this.size += this.has(key) ? 0 : 1;
|
19860 | data[key] = (_nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value;
|
19861 | return this;
|
19862 | }
|
19863 |
|
19864 | var _hashSet = hashSet;
|
19865 |
|
19866 | |
19867 |
|
19868 |
|
19869 |
|
19870 |
|
19871 |
|
19872 |
|
19873 | function Hash(entries) {
|
19874 | var index = -1,
|
19875 | length = entries == null ? 0 : entries.length;
|
19876 |
|
19877 | this.clear();
|
19878 | while (++index < length) {
|
19879 | var entry = entries[index];
|
19880 | this.set(entry[0], entry[1]);
|
19881 | }
|
19882 | }
|
19883 |
|
19884 |
|
19885 | Hash.prototype.clear = _hashClear;
|
19886 | Hash.prototype['delete'] = _hashDelete;
|
19887 | Hash.prototype.get = _hashGet;
|
19888 | Hash.prototype.has = _hashHas;
|
19889 | Hash.prototype.set = _hashSet;
|
19890 |
|
19891 | var _Hash = Hash;
|
19892 |
|
19893 | |
19894 |
|
19895 |
|
19896 |
|
19897 |
|
19898 |
|
19899 |
|
19900 | function mapCacheClear() {
|
19901 | this.size = 0;
|
19902 | this.__data__ = {
|
19903 | 'hash': new _Hash,
|
19904 | 'map': new (_Map || _ListCache),
|
19905 | 'string': new _Hash
|
19906 | };
|
19907 | }
|
19908 |
|
19909 | var _mapCacheClear = mapCacheClear;
|
19910 |
|
19911 | |
19912 |
|
19913 |
|
19914 |
|
19915 |
|
19916 |
|
19917 |
|
19918 | function isKeyable(value) {
|
19919 | var type = typeof value;
|
19920 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
19921 | ? (value !== '__proto__')
|
19922 | : (value === null);
|
19923 | }
|
19924 |
|
19925 | var _isKeyable = isKeyable;
|
19926 |
|
19927 | |
19928 |
|
19929 |
|
19930 |
|
19931 |
|
19932 |
|
19933 |
|
19934 |
|
19935 | function getMapData(map, key) {
|
19936 | var data = map.__data__;
|
19937 | return _isKeyable(key)
|
19938 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
19939 | : data.map;
|
19940 | }
|
19941 |
|
19942 | var _getMapData = getMapData;
|
19943 |
|
19944 | |
19945 |
|
19946 |
|
19947 |
|
19948 |
|
19949 |
|
19950 |
|
19951 |
|
19952 |
|
19953 | function mapCacheDelete(key) {
|
19954 | var result = _getMapData(this, key)['delete'](key);
|
19955 | this.size -= result ? 1 : 0;
|
19956 | return result;
|
19957 | }
|
19958 |
|
19959 | var _mapCacheDelete = mapCacheDelete;
|
19960 |
|
19961 | |
19962 |
|
19963 |
|
19964 |
|
19965 |
|
19966 |
|
19967 |
|
19968 |
|
19969 |
|
19970 | function mapCacheGet(key) {
|
19971 | return _getMapData(this, key).get(key);
|
19972 | }
|
19973 |
|
19974 | var _mapCacheGet = mapCacheGet;
|
19975 |
|
19976 | |
19977 |
|
19978 |
|
19979 |
|
19980 |
|
19981 |
|
19982 |
|
19983 |
|
19984 |
|
19985 | function mapCacheHas(key) {
|
19986 | return _getMapData(this, key).has(key);
|
19987 | }
|
19988 |
|
19989 | var _mapCacheHas = mapCacheHas;
|
19990 |
|
19991 | |
19992 |
|
19993 |
|
19994 |
|
19995 |
|
19996 |
|
19997 |
|
19998 |
|
19999 |
|
20000 |
|
20001 | function mapCacheSet(key, value) {
|
20002 | var data = _getMapData(this, key),
|
20003 | size = data.size;
|
20004 |
|
20005 | data.set(key, value);
|
20006 | this.size += data.size == size ? 0 : 1;
|
20007 | return this;
|
20008 | }
|
20009 |
|
20010 | var _mapCacheSet = mapCacheSet;
|
20011 |
|
20012 | |
20013 |
|
20014 |
|
20015 |
|
20016 |
|
20017 |
|
20018 |
|
20019 | function MapCache(entries) {
|
20020 | var index = -1,
|
20021 | length = entries == null ? 0 : entries.length;
|
20022 |
|
20023 | this.clear();
|
20024 | while (++index < length) {
|
20025 | var entry = entries[index];
|
20026 | this.set(entry[0], entry[1]);
|
20027 | }
|
20028 | }
|
20029 |
|
20030 |
|
20031 | MapCache.prototype.clear = _mapCacheClear;
|
20032 | MapCache.prototype['delete'] = _mapCacheDelete;
|
20033 | MapCache.prototype.get = _mapCacheGet;
|
20034 | MapCache.prototype.has = _mapCacheHas;
|
20035 | MapCache.prototype.set = _mapCacheSet;
|
20036 |
|
20037 | var _MapCache = MapCache;
|
20038 |
|
20039 |
|
20040 | var LARGE_ARRAY_SIZE = 200;
|
20041 |
|
20042 | |
20043 |
|
20044 |
|
20045 |
|
20046 |
|
20047 |
|
20048 |
|
20049 |
|
20050 |
|
20051 |
|
20052 | function stackSet(key, value) {
|
20053 | var data = this.__data__;
|
20054 | if (data instanceof _ListCache) {
|
20055 | var pairs = data.__data__;
|
20056 | if (!_Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
20057 | pairs.push([key, value]);
|
20058 | this.size = ++data.size;
|
20059 | return this;
|
20060 | }
|
20061 | data = this.__data__ = new _MapCache(pairs);
|
20062 | }
|
20063 | data.set(key, value);
|
20064 | this.size = data.size;
|
20065 | return this;
|
20066 | }
|
20067 |
|
20068 | var _stackSet = stackSet;
|
20069 |
|
20070 | |
20071 |
|
20072 |
|
20073 |
|
20074 |
|
20075 |
|
20076 |
|
20077 | function Stack(entries) {
|
20078 | var data = this.__data__ = new _ListCache(entries);
|
20079 | this.size = data.size;
|
20080 | }
|
20081 |
|
20082 |
|
20083 | Stack.prototype.clear = _stackClear;
|
20084 | Stack.prototype['delete'] = _stackDelete;
|
20085 | Stack.prototype.get = _stackGet;
|
20086 | Stack.prototype.has = _stackHas;
|
20087 | Stack.prototype.set = _stackSet;
|
20088 |
|
20089 | var _Stack = Stack;
|
20090 |
|
20091 |
|
20092 | var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
|
20093 |
|
20094 | |
20095 |
|
20096 |
|
20097 |
|
20098 |
|
20099 |
|
20100 |
|
20101 |
|
20102 |
|
20103 |
|
20104 | function setCacheAdd(value) {
|
20105 | this.__data__.set(value, HASH_UNDEFINED$2);
|
20106 | return this;
|
20107 | }
|
20108 |
|
20109 | var _setCacheAdd = setCacheAdd;
|
20110 |
|
20111 | |
20112 |
|
20113 |
|
20114 |
|
20115 |
|
20116 |
|
20117 |
|
20118 |
|
20119 |
|
20120 | function setCacheHas(value) {
|
20121 | return this.__data__.has(value);
|
20122 | }
|
20123 |
|
20124 | var _setCacheHas = setCacheHas;
|
20125 |
|
20126 | |
20127 |
|
20128 |
|
20129 |
|
20130 |
|
20131 |
|
20132 |
|
20133 |
|
20134 | function SetCache(values) {
|
20135 | var index = -1,
|
20136 | length = values == null ? 0 : values.length;
|
20137 |
|
20138 | this.__data__ = new _MapCache;
|
20139 | while (++index < length) {
|
20140 | this.add(values[index]);
|
20141 | }
|
20142 | }
|
20143 |
|
20144 |
|
20145 | SetCache.prototype.add = SetCache.prototype.push = _setCacheAdd;
|
20146 | SetCache.prototype.has = _setCacheHas;
|
20147 |
|
20148 | var _SetCache = SetCache;
|
20149 |
|
20150 | |
20151 |
|
20152 |
|
20153 |
|
20154 |
|
20155 |
|
20156 |
|
20157 |
|
20158 |
|
20159 |
|
20160 | function arraySome(array, predicate) {
|
20161 | var index = -1,
|
20162 | length = array == null ? 0 : array.length;
|
20163 |
|
20164 | while (++index < length) {
|
20165 | if (predicate(array[index], index, array)) {
|
20166 | return true;
|
20167 | }
|
20168 | }
|
20169 | return false;
|
20170 | }
|
20171 |
|
20172 | var _arraySome = arraySome;
|
20173 |
|
20174 | |
20175 |
|
20176 |
|
20177 |
|
20178 |
|
20179 |
|
20180 |
|
20181 |
|
20182 | function cacheHas(cache, key) {
|
20183 | return cache.has(key);
|
20184 | }
|
20185 |
|
20186 | var _cacheHas = cacheHas;
|
20187 |
|
20188 |
|
20189 | var COMPARE_PARTIAL_FLAG = 1,
|
20190 | COMPARE_UNORDERED_FLAG = 2;
|
20191 |
|
20192 | |
20193 |
|
20194 |
|
20195 |
|
20196 |
|
20197 |
|
20198 |
|
20199 |
|
20200 |
|
20201 |
|
20202 |
|
20203 |
|
20204 |
|
20205 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
20206 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
20207 | arrLength = array.length,
|
20208 | othLength = other.length;
|
20209 |
|
20210 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
20211 | return false;
|
20212 | }
|
20213 |
|
20214 | var stacked = stack.get(array);
|
20215 | if (stacked && stack.get(other)) {
|
20216 | return stacked == other;
|
20217 | }
|
20218 | var index = -1,
|
20219 | result = true,
|
20220 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new _SetCache : undefined;
|
20221 |
|
20222 | stack.set(array, other);
|
20223 | stack.set(other, array);
|
20224 |
|
20225 |
|
20226 | while (++index < arrLength) {
|
20227 | var arrValue = array[index],
|
20228 | othValue = other[index];
|
20229 |
|
20230 | if (customizer) {
|
20231 | var compared = isPartial
|
20232 | ? customizer(othValue, arrValue, index, other, array, stack)
|
20233 | : customizer(arrValue, othValue, index, array, other, stack);
|
20234 | }
|
20235 | if (compared !== undefined) {
|
20236 | if (compared) {
|
20237 | continue;
|
20238 | }
|
20239 | result = false;
|
20240 | break;
|
20241 | }
|
20242 |
|
20243 | if (seen) {
|
20244 | if (!_arraySome(other, function(othValue, othIndex) {
|
20245 | if (!_cacheHas(seen, othIndex) &&
|
20246 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
20247 | return seen.push(othIndex);
|
20248 | }
|
20249 | })) {
|
20250 | result = false;
|
20251 | break;
|
20252 | }
|
20253 | } else if (!(
|
20254 | arrValue === othValue ||
|
20255 | equalFunc(arrValue, othValue, bitmask, customizer, stack)
|
20256 | )) {
|
20257 | result = false;
|
20258 | break;
|
20259 | }
|
20260 | }
|
20261 | stack['delete'](array);
|
20262 | stack['delete'](other);
|
20263 | return result;
|
20264 | }
|
20265 |
|
20266 | var _equalArrays = equalArrays;
|
20267 |
|
20268 |
|
20269 | var Uint8Array$1 = _root.Uint8Array;
|
20270 |
|
20271 | var _Uint8Array = Uint8Array$1;
|
20272 |
|
20273 | |
20274 |
|
20275 |
|
20276 |
|
20277 |
|
20278 |
|
20279 |
|
20280 | function mapToArray(map) {
|
20281 | var index = -1,
|
20282 | result = Array(map.size);
|
20283 |
|
20284 | map.forEach(function(value, key) {
|
20285 | result[++index] = [key, value];
|
20286 | });
|
20287 | return result;
|
20288 | }
|
20289 |
|
20290 | var _mapToArray = mapToArray;
|
20291 |
|
20292 | |
20293 |
|
20294 |
|
20295 |
|
20296 |
|
20297 |
|
20298 |
|
20299 | function setToArray(set) {
|
20300 | var index = -1,
|
20301 | result = Array(set.size);
|
20302 |
|
20303 | set.forEach(function(value) {
|
20304 | result[++index] = value;
|
20305 | });
|
20306 | return result;
|
20307 | }
|
20308 |
|
20309 | var _setToArray = setToArray;
|
20310 |
|
20311 |
|
20312 | var COMPARE_PARTIAL_FLAG$1 = 1,
|
20313 | COMPARE_UNORDERED_FLAG$1 = 2;
|
20314 |
|
20315 |
|
20316 | var boolTag$1 = '[object Boolean]',
|
20317 | dateTag$1 = '[object Date]',
|
20318 | errorTag$1 = '[object Error]',
|
20319 | mapTag$1 = '[object Map]',
|
20320 | numberTag$1 = '[object Number]',
|
20321 | regexpTag$1 = '[object RegExp]',
|
20322 | setTag$1 = '[object Set]',
|
20323 | stringTag$1 = '[object String]',
|
20324 | symbolTag = '[object Symbol]';
|
20325 |
|
20326 | var arrayBufferTag$1 = '[object ArrayBuffer]',
|
20327 | dataViewTag$1 = '[object DataView]';
|
20328 |
|
20329 |
|
20330 | var symbolProto = _Symbol ? _Symbol.prototype : undefined,
|
20331 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
20332 |
|
20333 | |
20334 |
|
20335 |
|
20336 |
|
20337 |
|
20338 |
|
20339 |
|
20340 |
|
20341 |
|
20342 |
|
20343 |
|
20344 |
|
20345 |
|
20346 |
|
20347 |
|
20348 |
|
20349 |
|
20350 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
|
20351 | switch (tag) {
|
20352 | case dataViewTag$1:
|
20353 | if ((object.byteLength != other.byteLength) ||
|
20354 | (object.byteOffset != other.byteOffset)) {
|
20355 | return false;
|
20356 | }
|
20357 | object = object.buffer;
|
20358 | other = other.buffer;
|
20359 |
|
20360 | case arrayBufferTag$1:
|
20361 | if ((object.byteLength != other.byteLength) ||
|
20362 | !equalFunc(new _Uint8Array(object), new _Uint8Array(other))) {
|
20363 | return false;
|
20364 | }
|
20365 | return true;
|
20366 |
|
20367 | case boolTag$1:
|
20368 | case dateTag$1:
|
20369 | case numberTag$1:
|
20370 |
|
20371 |
|
20372 | return eq_1(+object, +other);
|
20373 |
|
20374 | case errorTag$1:
|
20375 | return object.name == other.name && object.message == other.message;
|
20376 |
|
20377 | case regexpTag$1:
|
20378 | case stringTag$1:
|
20379 |
|
20380 |
|
20381 |
|
20382 | return object == (other + '');
|
20383 |
|
20384 | case mapTag$1:
|
20385 | var convert = _mapToArray;
|
20386 |
|
20387 | case setTag$1:
|
20388 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG$1;
|
20389 | convert || (convert = _setToArray);
|
20390 |
|
20391 | if (object.size != other.size && !isPartial) {
|
20392 | return false;
|
20393 | }
|
20394 |
|
20395 | var stacked = stack.get(object);
|
20396 | if (stacked) {
|
20397 | return stacked == other;
|
20398 | }
|
20399 | bitmask |= COMPARE_UNORDERED_FLAG$1;
|
20400 |
|
20401 |
|
20402 | stack.set(object, other);
|
20403 | var result = _equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
20404 | stack['delete'](object);
|
20405 | return result;
|
20406 |
|
20407 | case symbolTag:
|
20408 | if (symbolValueOf) {
|
20409 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
20410 | }
|
20411 | }
|
20412 | return false;
|
20413 | }
|
20414 |
|
20415 | var _equalByTag = equalByTag;
|
20416 |
|
20417 | |
20418 |
|
20419 |
|
20420 |
|
20421 |
|
20422 |
|
20423 |
|
20424 |
|
20425 | function arrayPush(array, values) {
|
20426 | var index = -1,
|
20427 | length = values.length,
|
20428 | offset = array.length;
|
20429 |
|
20430 | while (++index < length) {
|
20431 | array[offset + index] = values[index];
|
20432 | }
|
20433 | return array;
|
20434 | }
|
20435 |
|
20436 | var _arrayPush = arrayPush;
|
20437 |
|
20438 | |
20439 |
|
20440 |
|
20441 |
|
20442 |
|
20443 |
|
20444 |
|
20445 |
|
20446 |
|
20447 |
|
20448 |
|
20449 | function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
20450 | var result = keysFunc(object);
|
20451 | return isArray_1(object) ? result : _arrayPush(result, symbolsFunc(object));
|
20452 | }
|
20453 |
|
20454 | var _baseGetAllKeys = baseGetAllKeys;
|
20455 |
|
20456 | |
20457 |
|
20458 |
|
20459 |
|
20460 |
|
20461 |
|
20462 |
|
20463 |
|
20464 |
|
20465 | function arrayFilter(array, predicate) {
|
20466 | var index = -1,
|
20467 | length = array == null ? 0 : array.length,
|
20468 | resIndex = 0,
|
20469 | result = [];
|
20470 |
|
20471 | while (++index < length) {
|
20472 | var value = array[index];
|
20473 | if (predicate(value, index, array)) {
|
20474 | result[resIndex++] = value;
|
20475 | }
|
20476 | }
|
20477 | return result;
|
20478 | }
|
20479 |
|
20480 | var _arrayFilter = arrayFilter;
|
20481 |
|
20482 | |
20483 |
|
20484 |
|
20485 |
|
20486 |
|
20487 |
|
20488 |
|
20489 |
|
20490 |
|
20491 |
|
20492 |
|
20493 |
|
20494 |
|
20495 |
|
20496 |
|
20497 |
|
20498 |
|
20499 |
|
20500 | function stubArray() {
|
20501 | return [];
|
20502 | }
|
20503 |
|
20504 | var stubArray_1 = stubArray;
|
20505 |
|
20506 |
|
20507 | var objectProto$a = Object.prototype;
|
20508 |
|
20509 |
|
20510 | var propertyIsEnumerable$1 = objectProto$a.propertyIsEnumerable;
|
20511 |
|
20512 |
|
20513 | var nativeGetSymbols = Object.getOwnPropertySymbols;
|
20514 |
|
20515 | |
20516 |
|
20517 |
|
20518 |
|
20519 |
|
20520 |
|
20521 |
|
20522 | var getSymbols = !nativeGetSymbols ? stubArray_1 : function(object) {
|
20523 | if (object == null) {
|
20524 | return [];
|
20525 | }
|
20526 | object = Object(object);
|
20527 | return _arrayFilter(nativeGetSymbols(object), function(symbol) {
|
20528 | return propertyIsEnumerable$1.call(object, symbol);
|
20529 | });
|
20530 | };
|
20531 |
|
20532 | var _getSymbols = getSymbols;
|
20533 |
|
20534 | |
20535 |
|
20536 |
|
20537 |
|
20538 |
|
20539 |
|
20540 |
|
20541 | function getAllKeys(object) {
|
20542 | return _baseGetAllKeys(object, keys_1, _getSymbols);
|
20543 | }
|
20544 |
|
20545 | var _getAllKeys = getAllKeys;
|
20546 |
|
20547 |
|
20548 | var COMPARE_PARTIAL_FLAG$2 = 1;
|
20549 |
|
20550 |
|
20551 | var objectProto$b = Object.prototype;
|
20552 |
|
20553 |
|
20554 | var hasOwnProperty$9 = objectProto$b.hasOwnProperty;
|
20555 |
|
20556 | |
20557 |
|
20558 |
|
20559 |
|
20560 |
|
20561 |
|
20562 |
|
20563 |
|
20564 |
|
20565 |
|
20566 |
|
20567 |
|
20568 |
|
20569 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
|
20570 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG$2,
|
20571 | objProps = _getAllKeys(object),
|
20572 | objLength = objProps.length,
|
20573 | othProps = _getAllKeys(other),
|
20574 | othLength = othProps.length;
|
20575 |
|
20576 | if (objLength != othLength && !isPartial) {
|
20577 | return false;
|
20578 | }
|
20579 | var index = objLength;
|
20580 | while (index--) {
|
20581 | var key = objProps[index];
|
20582 | if (!(isPartial ? key in other : hasOwnProperty$9.call(other, key))) {
|
20583 | return false;
|
20584 | }
|
20585 | }
|
20586 |
|
20587 | var stacked = stack.get(object);
|
20588 | if (stacked && stack.get(other)) {
|
20589 | return stacked == other;
|
20590 | }
|
20591 | var result = true;
|
20592 | stack.set(object, other);
|
20593 | stack.set(other, object);
|
20594 |
|
20595 | var skipCtor = isPartial;
|
20596 | while (++index < objLength) {
|
20597 | key = objProps[index];
|
20598 | var objValue = object[key],
|
20599 | othValue = other[key];
|
20600 |
|
20601 | if (customizer) {
|
20602 | var compared = isPartial
|
20603 | ? customizer(othValue, objValue, key, other, object, stack)
|
20604 | : customizer(objValue, othValue, key, object, other, stack);
|
20605 | }
|
20606 |
|
20607 | if (!(compared === undefined
|
20608 | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
|
20609 | : compared
|
20610 | )) {
|
20611 | result = false;
|
20612 | break;
|
20613 | }
|
20614 | skipCtor || (skipCtor = key == 'constructor');
|
20615 | }
|
20616 | if (result && !skipCtor) {
|
20617 | var objCtor = object.constructor,
|
20618 | othCtor = other.constructor;
|
20619 |
|
20620 |
|
20621 | if (objCtor != othCtor &&
|
20622 | ('constructor' in object && 'constructor' in other) &&
|
20623 | !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
20624 | typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
20625 | result = false;
|
20626 | }
|
20627 | }
|
20628 | stack['delete'](object);
|
20629 | stack['delete'](other);
|
20630 | return result;
|
20631 | }
|
20632 |
|
20633 | var _equalObjects = equalObjects;
|
20634 |
|
20635 |
|
20636 | var DataView = _getNative(_root, 'DataView');
|
20637 |
|
20638 | var _DataView = DataView;
|
20639 |
|
20640 |
|
20641 | var Promise$1 = _getNative(_root, 'Promise');
|
20642 |
|
20643 | var _Promise = Promise$1;
|
20644 |
|
20645 |
|
20646 | var Set$1 = _getNative(_root, 'Set');
|
20647 |
|
20648 | var _Set = Set$1;
|
20649 |
|
20650 |
|
20651 | var WeakMap$1 = _getNative(_root, 'WeakMap');
|
20652 |
|
20653 | var _WeakMap = WeakMap$1;
|
20654 |
|
20655 |
|
20656 | var mapTag$2 = '[object Map]',
|
20657 | objectTag$2 = '[object Object]',
|
20658 | promiseTag = '[object Promise]',
|
20659 | setTag$2 = '[object Set]',
|
20660 | weakMapTag$1 = '[object WeakMap]';
|
20661 |
|
20662 | var dataViewTag$2 = '[object DataView]';
|
20663 |
|
20664 |
|
20665 | var dataViewCtorString = _toSource(_DataView),
|
20666 | mapCtorString = _toSource(_Map),
|
20667 | promiseCtorString = _toSource(_Promise),
|
20668 | setCtorString = _toSource(_Set),
|
20669 | weakMapCtorString = _toSource(_WeakMap);
|
20670 |
|
20671 | |
20672 |
|
20673 |
|
20674 |
|
20675 |
|
20676 |
|
20677 |
|
20678 | var getTag = _baseGetTag;
|
20679 |
|
20680 |
|
20681 | if ((_DataView && getTag(new _DataView(new ArrayBuffer(1))) != dataViewTag$2) ||
|
20682 | (_Map && getTag(new _Map) != mapTag$2) ||
|
20683 | (_Promise && getTag(_Promise.resolve()) != promiseTag) ||
|
20684 | (_Set && getTag(new _Set) != setTag$2) ||
|
20685 | (_WeakMap && getTag(new _WeakMap) != weakMapTag$1)) {
|
20686 | getTag = function(value) {
|
20687 | var result = _baseGetTag(value),
|
20688 | Ctor = result == objectTag$2 ? value.constructor : undefined,
|
20689 | ctorString = Ctor ? _toSource(Ctor) : '';
|
20690 |
|
20691 | if (ctorString) {
|
20692 | switch (ctorString) {
|
20693 | case dataViewCtorString: return dataViewTag$2;
|
20694 | case mapCtorString: return mapTag$2;
|
20695 | case promiseCtorString: return promiseTag;
|
20696 | case setCtorString: return setTag$2;
|
20697 | case weakMapCtorString: return weakMapTag$1;
|
20698 | }
|
20699 | }
|
20700 | return result;
|
20701 | };
|
20702 | }
|
20703 |
|
20704 | var _getTag = getTag;
|
20705 |
|
20706 |
|
20707 | var COMPARE_PARTIAL_FLAG$3 = 1;
|
20708 |
|
20709 |
|
20710 | var argsTag$2 = '[object Arguments]',
|
20711 | arrayTag$1 = '[object Array]',
|
20712 | objectTag$3 = '[object Object]';
|
20713 |
|
20714 |
|
20715 | var objectProto$c = Object.prototype;
|
20716 |
|
20717 |
|
20718 | var hasOwnProperty$a = objectProto$c.hasOwnProperty;
|
20719 |
|
20720 | |
20721 |
|
20722 |
|
20723 |
|
20724 |
|
20725 |
|
20726 |
|
20727 |
|
20728 |
|
20729 |
|
20730 |
|
20731 |
|
20732 |
|
20733 |
|
20734 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
20735 | var objIsArr = isArray_1(object),
|
20736 | othIsArr = isArray_1(other),
|
20737 | objTag = objIsArr ? arrayTag$1 : _getTag(object),
|
20738 | othTag = othIsArr ? arrayTag$1 : _getTag(other);
|
20739 |
|
20740 | objTag = objTag == argsTag$2 ? objectTag$3 : objTag;
|
20741 | othTag = othTag == argsTag$2 ? objectTag$3 : othTag;
|
20742 |
|
20743 | var objIsObj = objTag == objectTag$3,
|
20744 | othIsObj = othTag == objectTag$3,
|
20745 | isSameTag = objTag == othTag;
|
20746 |
|
20747 | if (isSameTag && isBuffer_1(object)) {
|
20748 | if (!isBuffer_1(other)) {
|
20749 | return false;
|
20750 | }
|
20751 | objIsArr = true;
|
20752 | objIsObj = false;
|
20753 | }
|
20754 | if (isSameTag && !objIsObj) {
|
20755 | stack || (stack = new _Stack);
|
20756 | return (objIsArr || isTypedArray_1(object))
|
20757 | ? _equalArrays(object, other, bitmask, customizer, equalFunc, stack)
|
20758 | : _equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
|
20759 | }
|
20760 | if (!(bitmask & COMPARE_PARTIAL_FLAG$3)) {
|
20761 | var objIsWrapped = objIsObj && hasOwnProperty$a.call(object, '__wrapped__'),
|
20762 | othIsWrapped = othIsObj && hasOwnProperty$a.call(other, '__wrapped__');
|
20763 |
|
20764 | if (objIsWrapped || othIsWrapped) {
|
20765 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
20766 | othUnwrapped = othIsWrapped ? other.value() : other;
|
20767 |
|
20768 | stack || (stack = new _Stack);
|
20769 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
20770 | }
|
20771 | }
|
20772 | if (!isSameTag) {
|
20773 | return false;
|
20774 | }
|
20775 | stack || (stack = new _Stack);
|
20776 | return _equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
20777 | }
|
20778 |
|
20779 | var _baseIsEqualDeep = baseIsEqualDeep;
|
20780 |
|
20781 | |
20782 |
|
20783 |
|
20784 |
|
20785 |
|
20786 |
|
20787 |
|
20788 |
|
20789 |
|
20790 |
|
20791 |
|
20792 |
|
20793 |
|
20794 |
|
20795 | function baseIsEqual(value, other, bitmask, customizer, stack) {
|
20796 | if (value === other) {
|
20797 | return true;
|
20798 | }
|
20799 | if (value == null || other == null || (!isObjectLike_1(value) && !isObjectLike_1(other))) {
|
20800 | return value !== value && other !== other;
|
20801 | }
|
20802 | return _baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
20803 | }
|
20804 |
|
20805 | var _baseIsEqual = baseIsEqual;
|
20806 |
|
20807 |
|
20808 | var COMPARE_PARTIAL_FLAG$4 = 1,
|
20809 | COMPARE_UNORDERED_FLAG$2 = 2;
|
20810 |
|
20811 | |
20812 |
|
20813 |
|
20814 |
|
20815 |
|
20816 |
|
20817 |
|
20818 |
|
20819 |
|
20820 |
|
20821 | function baseIsMatch(object, source, matchData, customizer) {
|
20822 | var index = matchData.length,
|
20823 | length = index,
|
20824 | noCustomizer = !customizer;
|
20825 |
|
20826 | if (object == null) {
|
20827 | return !length;
|
20828 | }
|
20829 | object = Object(object);
|
20830 | while (index--) {
|
20831 | var data = matchData[index];
|
20832 | if ((noCustomizer && data[2])
|
20833 | ? data[1] !== object[data[0]]
|
20834 | : !(data[0] in object)
|
20835 | ) {
|
20836 | return false;
|
20837 | }
|
20838 | }
|
20839 | while (++index < length) {
|
20840 | data = matchData[index];
|
20841 | var key = data[0],
|
20842 | objValue = object[key],
|
20843 | srcValue = data[1];
|
20844 |
|
20845 | if (noCustomizer && data[2]) {
|
20846 | if (objValue === undefined && !(key in object)) {
|
20847 | return false;
|
20848 | }
|
20849 | } else {
|
20850 | var stack = new _Stack;
|
20851 | if (customizer) {
|
20852 | var result = customizer(objValue, srcValue, key, object, source, stack);
|
20853 | }
|
20854 | if (!(result === undefined
|
20855 | ? _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$4 | COMPARE_UNORDERED_FLAG$2, customizer, stack)
|
20856 | : result
|
20857 | )) {
|
20858 | return false;
|
20859 | }
|
20860 | }
|
20861 | }
|
20862 | return true;
|
20863 | }
|
20864 |
|
20865 | var _baseIsMatch = baseIsMatch;
|
20866 |
|
20867 | |
20868 |
|
20869 |
|
20870 |
|
20871 |
|
20872 |
|
20873 |
|
20874 |
|
20875 | function isStrictComparable(value) {
|
20876 | return value === value && !isObject_1$1(value);
|
20877 | }
|
20878 |
|
20879 | var _isStrictComparable = isStrictComparable;
|
20880 |
|
20881 | |
20882 |
|
20883 |
|
20884 |
|
20885 |
|
20886 |
|
20887 |
|
20888 | function getMatchData(object) {
|
20889 | var result = keys_1(object),
|
20890 | length = result.length;
|
20891 |
|
20892 | while (length--) {
|
20893 | var key = result[length],
|
20894 | value = object[key];
|
20895 |
|
20896 | result[length] = [key, value, _isStrictComparable(value)];
|
20897 | }
|
20898 | return result;
|
20899 | }
|
20900 |
|
20901 | var _getMatchData = getMatchData;
|
20902 |
|
20903 | |
20904 |
|
20905 |
|
20906 |
|
20907 |
|
20908 |
|
20909 |
|
20910 |
|
20911 |
|
20912 | function matchesStrictComparable(key, srcValue) {
|
20913 | return function(object) {
|
20914 | if (object == null) {
|
20915 | return false;
|
20916 | }
|
20917 | return object[key] === srcValue &&
|
20918 | (srcValue !== undefined || (key in Object(object)));
|
20919 | };
|
20920 | }
|
20921 |
|
20922 | var _matchesStrictComparable = matchesStrictComparable;
|
20923 |
|
20924 | |
20925 |
|
20926 |
|
20927 |
|
20928 |
|
20929 |
|
20930 |
|
20931 | function baseMatches(source) {
|
20932 | var matchData = _getMatchData(source);
|
20933 | if (matchData.length == 1 && matchData[0][2]) {
|
20934 | return _matchesStrictComparable(matchData[0][0], matchData[0][1]);
|
20935 | }
|
20936 | return function(object) {
|
20937 | return object === source || _baseIsMatch(object, source, matchData);
|
20938 | };
|
20939 | }
|
20940 |
|
20941 | var _baseMatches = baseMatches;
|
20942 |
|
20943 |
|
20944 | var symbolTag$1 = '[object Symbol]';
|
20945 |
|
20946 | |
20947 |
|
20948 |
|
20949 |
|
20950 |
|
20951 |
|
20952 |
|
20953 |
|
20954 |
|
20955 |
|
20956 |
|
20957 |
|
20958 |
|
20959 |
|
20960 |
|
20961 |
|
20962 |
|
20963 | function isSymbol(value) {
|
20964 | return typeof value == 'symbol' ||
|
20965 | (isObjectLike_1(value) && _baseGetTag(value) == symbolTag$1);
|
20966 | }
|
20967 |
|
20968 | var isSymbol_1 = isSymbol;
|
20969 |
|
20970 |
|
20971 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
20972 | reIsPlainProp = /^\w*$/;
|
20973 |
|
20974 | |
20975 |
|
20976 |
|
20977 |
|
20978 |
|
20979 |
|
20980 |
|
20981 |
|
20982 | function isKey(value, object) {
|
20983 | if (isArray_1(value)) {
|
20984 | return false;
|
20985 | }
|
20986 | var type = typeof value;
|
20987 | if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
20988 | value == null || isSymbol_1(value)) {
|
20989 | return true;
|
20990 | }
|
20991 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
20992 | (object != null && value in Object(object));
|
20993 | }
|
20994 |
|
20995 | var _isKey = isKey;
|
20996 |
|
20997 |
|
20998 | var FUNC_ERROR_TEXT = 'Expected a function';
|
20999 |
|
21000 | |
21001 |
|
21002 |
|
21003 |
|
21004 |
|
21005 |
|
21006 |
|
21007 |
|
21008 |
|
21009 |
|
21010 |
|
21011 |
|
21012 |
|
21013 |
|
21014 |
|
21015 |
|
21016 |
|
21017 |
|
21018 |
|
21019 |
|
21020 |
|
21021 |
|
21022 |
|
21023 |
|
21024 |
|
21025 |
|
21026 |
|
21027 |
|
21028 |
|
21029 |
|
21030 |
|
21031 |
|
21032 |
|
21033 |
|
21034 |
|
21035 |
|
21036 |
|
21037 |
|
21038 |
|
21039 |
|
21040 |
|
21041 |
|
21042 |
|
21043 |
|
21044 | function memoize(func, resolver) {
|
21045 | if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
21046 | throw new TypeError(FUNC_ERROR_TEXT);
|
21047 | }
|
21048 | var memoized = function() {
|
21049 | var args = arguments,
|
21050 | key = resolver ? resolver.apply(this, args) : args[0],
|
21051 | cache = memoized.cache;
|
21052 |
|
21053 | if (cache.has(key)) {
|
21054 | return cache.get(key);
|
21055 | }
|
21056 | var result = func.apply(this, args);
|
21057 | memoized.cache = cache.set(key, result) || cache;
|
21058 | return result;
|
21059 | };
|
21060 | memoized.cache = new (memoize.Cache || _MapCache);
|
21061 | return memoized;
|
21062 | }
|
21063 |
|
21064 |
|
21065 | memoize.Cache = _MapCache;
|
21066 |
|
21067 | var memoize_1 = memoize;
|
21068 |
|
21069 |
|
21070 | var MAX_MEMOIZE_SIZE = 500;
|
21071 |
|
21072 | |
21073 |
|
21074 |
|
21075 |
|
21076 |
|
21077 |
|
21078 |
|
21079 |
|
21080 | function memoizeCapped(func) {
|
21081 | var result = memoize_1(func, function(key) {
|
21082 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
21083 | cache.clear();
|
21084 | }
|
21085 | return key;
|
21086 | });
|
21087 |
|
21088 | var cache = result.cache;
|
21089 | return result;
|
21090 | }
|
21091 |
|
21092 | var _memoizeCapped = memoizeCapped;
|
21093 |
|
21094 |
|
21095 | var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
21096 |
|
21097 |
|
21098 | var reEscapeChar = /\\(\\)?/g;
|
21099 |
|
21100 | |
21101 |
|
21102 |
|
21103 |
|
21104 |
|
21105 |
|
21106 |
|
21107 | var stringToPath = _memoizeCapped(function(string) {
|
21108 | var result = [];
|
21109 | if (string.charCodeAt(0) === 46 ) {
|
21110 | result.push('');
|
21111 | }
|
21112 | string.replace(rePropName, function(match, number, quote, subString) {
|
21113 | result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
|
21114 | });
|
21115 | return result;
|
21116 | });
|
21117 |
|
21118 | var _stringToPath = stringToPath;
|
21119 |
|
21120 |
|
21121 | var INFINITY = 1 / 0;
|
21122 |
|
21123 |
|
21124 | var symbolProto$1 = _Symbol ? _Symbol.prototype : undefined,
|
21125 | symbolToString = symbolProto$1 ? symbolProto$1.toString : undefined;
|
21126 |
|
21127 | |
21128 |
|
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 |
|
21134 |
|
21135 | function baseToString(value) {
|
21136 |
|
21137 | if (typeof value == 'string') {
|
21138 | return value;
|
21139 | }
|
21140 | if (isArray_1(value)) {
|
21141 |
|
21142 | return _arrayMap(value, baseToString) + '';
|
21143 | }
|
21144 | if (isSymbol_1(value)) {
|
21145 | return symbolToString ? symbolToString.call(value) : '';
|
21146 | }
|
21147 | var result = (value + '');
|
21148 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
21149 | }
|
21150 |
|
21151 | var _baseToString = baseToString;
|
21152 |
|
21153 | |
21154 |
|
21155 |
|
21156 |
|
21157 |
|
21158 |
|
21159 |
|
21160 |
|
21161 |
|
21162 |
|
21163 |
|
21164 |
|
21165 |
|
21166 |
|
21167 |
|
21168 |
|
21169 |
|
21170 |
|
21171 |
|
21172 |
|
21173 |
|
21174 | function toString(value) {
|
21175 | return value == null ? '' : _baseToString(value);
|
21176 | }
|
21177 |
|
21178 | var toString_1 = toString;
|
21179 |
|
21180 | |
21181 |
|
21182 |
|
21183 |
|
21184 |
|
21185 |
|
21186 |
|
21187 |
|
21188 | function castPath(value, object) {
|
21189 | if (isArray_1(value)) {
|
21190 | return value;
|
21191 | }
|
21192 | return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
|
21193 | }
|
21194 |
|
21195 | var _castPath = castPath;
|
21196 |
|
21197 |
|
21198 | var INFINITY$1 = 1 / 0;
|
21199 |
|
21200 | |
21201 |
|
21202 |
|
21203 |
|
21204 |
|
21205 |
|
21206 |
|
21207 | function toKey(value) {
|
21208 | if (typeof value == 'string' || isSymbol_1(value)) {
|
21209 | return value;
|
21210 | }
|
21211 | var result = (value + '');
|
21212 | return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
|
21213 | }
|
21214 |
|
21215 | var _toKey = toKey;
|
21216 |
|
21217 | |
21218 |
|
21219 |
|
21220 |
|
21221 |
|
21222 |
|
21223 |
|
21224 |
|
21225 | function baseGet(object, path) {
|
21226 | path = _castPath(path, object);
|
21227 |
|
21228 | var index = 0,
|
21229 | length = path.length;
|
21230 |
|
21231 | while (object != null && index < length) {
|
21232 | object = object[_toKey(path[index++])];
|
21233 | }
|
21234 | return (index && index == length) ? object : undefined;
|
21235 | }
|
21236 |
|
21237 | var _baseGet = baseGet;
|
21238 |
|
21239 | |
21240 |
|
21241 |
|
21242 |
|
21243 |
|
21244 |
|
21245 |
|
21246 |
|
21247 |
|
21248 |
|
21249 |
|
21250 |
|
21251 |
|
21252 |
|
21253 |
|
21254 |
|
21255 |
|
21256 |
|
21257 |
|
21258 |
|
21259 |
|
21260 |
|
21261 |
|
21262 |
|
21263 |
|
21264 | function get(object, path, defaultValue) {
|
21265 | var result = object == null ? undefined : _baseGet(object, path);
|
21266 | return result === undefined ? defaultValue : result;
|
21267 | }
|
21268 |
|
21269 | var get_1 = get;
|
21270 |
|
21271 | /**
|
21272 | * The base implementation of `_.hasIn` without support for deep paths.
|
21273 | *
|
21274 | * @private
|
21275 | * @param {Object} [object] The object to query.
|
21276 | * @param {Array|string} key The key to check.
|
21277 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
21278 | */
|
21279 | function baseHasIn(object, key) {
|
21280 | return object != null && key in Object(object);
|
21281 | }
|
21282 |
|
21283 | var _baseHasIn = baseHasIn;
|
21284 |
|
21285 | |
21286 |
|
21287 |
|
21288 |
|
21289 |
|
21290 |
|
21291 |
|
21292 |
|
21293 |
|
21294 | function hasPath(object, path, hasFunc) {
|
21295 | path = _castPath(path, object);
|
21296 |
|
21297 | var index = -1,
|
21298 | length = path.length,
|
21299 | result = false;
|
21300 |
|
21301 | while (++index < length) {
|
21302 | var key = _toKey(path[index]);
|
21303 | if (!(result = object != null && hasFunc(object, key))) {
|
21304 | break;
|
21305 | }
|
21306 | object = object[key];
|
21307 | }
|
21308 | if (result || ++index != length) {
|
21309 | return result;
|
21310 | }
|
21311 | length = object == null ? 0 : object.length;
|
21312 | return !!length && isLength_1(length) && _isIndex(key, length) &&
|
21313 | (isArray_1(object) || isArguments_1(object));
|
21314 | }
|
21315 |
|
21316 | var _hasPath = hasPath;
|
21317 |
|
21318 | |
21319 |
|
21320 |
|
21321 |
|
21322 |
|
21323 |
|
21324 |
|
21325 |
|
21326 |
|
21327 |
|
21328 |
|
21329 |
|
21330 |
|
21331 |
|
21332 |
|
21333 |
|
21334 |
|
21335 |
|
21336 |
|
21337 |
|
21338 |
|
21339 |
|
21340 |
|
21341 |
|
21342 |
|
21343 |
|
21344 | function hasIn(object, path) {
|
21345 | return object != null && _hasPath(object, path, _baseHasIn);
|
21346 | }
|
21347 |
|
21348 | var hasIn_1 = hasIn;
|
21349 |
|
21350 |
|
21351 | var COMPARE_PARTIAL_FLAG$5 = 1,
|
21352 | COMPARE_UNORDERED_FLAG$3 = 2;
|
21353 |
|
21354 | |
21355 |
|
21356 |
|
21357 |
|
21358 |
|
21359 |
|
21360 |
|
21361 |
|
21362 | function baseMatchesProperty(path, srcValue) {
|
21363 | if (_isKey(path) && _isStrictComparable(srcValue)) {
|
21364 | return _matchesStrictComparable(_toKey(path), srcValue);
|
21365 | }
|
21366 | return function(object) {
|
21367 | var objValue = get_1(object, path);
|
21368 | return (objValue === undefined && objValue === srcValue)
|
21369 | ? hasIn_1(object, path)
|
21370 | : _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$5 | COMPARE_UNORDERED_FLAG$3);
|
21371 | };
|
21372 | }
|
21373 |
|
21374 | var _baseMatchesProperty = baseMatchesProperty;
|
21375 |
|
21376 | |
21377 |
|
21378 |
|
21379 |
|
21380 |
|
21381 |
|
21382 |
|
21383 |
|
21384 |
|
21385 |
|
21386 |
|
21387 |
|
21388 |
|
21389 |
|
21390 |
|
21391 |
|
21392 | function identity(value) {
|
21393 | return value;
|
21394 | }
|
21395 |
|
21396 | var identity_1 = identity;
|
21397 |
|
21398 | |
21399 |
|
21400 |
|
21401 |
|
21402 |
|
21403 |
|
21404 |
|
21405 | function baseProperty(key) {
|
21406 | return function(object) {
|
21407 | return object == null ? undefined : object[key];
|
21408 | };
|
21409 | }
|
21410 |
|
21411 | var _baseProperty = baseProperty;
|
21412 |
|
21413 | |
21414 |
|
21415 |
|
21416 |
|
21417 |
|
21418 |
|
21419 |
|
21420 | function basePropertyDeep(path) {
|
21421 | return function(object) {
|
21422 | return _baseGet(object, path);
|
21423 | };
|
21424 | }
|
21425 |
|
21426 | var _basePropertyDeep = basePropertyDeep;
|
21427 |
|
21428 | |
21429 |
|
21430 |
|
21431 |
|
21432 |
|
21433 |
|
21434 |
|
21435 |
|
21436 |
|
21437 |
|
21438 |
|
21439 |
|
21440 |
|
21441 |
|
21442 |
|
21443 |
|
21444 |
|
21445 |
|
21446 |
|
21447 |
|
21448 |
|
21449 |
|
21450 | function property(path) {
|
21451 | return _isKey(path) ? _baseProperty(_toKey(path)) : _basePropertyDeep(path);
|
21452 | }
|
21453 |
|
21454 | var property_1 = property;
|
21455 |
|
21456 | |
21457 |
|
21458 |
|
21459 |
|
21460 |
|
21461 |
|
21462 |
|
21463 | function baseIteratee(value) {
|
21464 |
|
21465 |
|
21466 | if (typeof value == 'function') {
|
21467 | return value;
|
21468 | }
|
21469 | if (value == null) {
|
21470 | return identity_1;
|
21471 | }
|
21472 | if (typeof value == 'object') {
|
21473 | return isArray_1(value)
|
21474 | ? _baseMatchesProperty(value[0], value[1])
|
21475 | : _baseMatches(value);
|
21476 | }
|
21477 | return property_1(value);
|
21478 | }
|
21479 |
|
21480 | var _baseIteratee = baseIteratee;
|
21481 |
|
21482 | |
21483 |
|
21484 |
|
21485 |
|
21486 |
|
21487 |
|
21488 |
|
21489 |
|
21490 |
|
21491 |
|
21492 |
|
21493 |
|
21494 |
|
21495 |
|
21496 | function last(array) {
|
21497 | var length = array == null ? 0 : array.length;
|
21498 | return length ? array[length - 1] : undefined;
|
21499 | }
|
21500 |
|
21501 | var last_1 = last;
|
21502 |
|
21503 | |
21504 |
|
21505 |
|
21506 |
|
21507 |
|
21508 |
|
21509 |
|
21510 |
|
21511 |
|
21512 | function baseSlice(array, start, end) {
|
21513 | var index = -1,
|
21514 | length = array.length;
|
21515 |
|
21516 | if (start < 0) {
|
21517 | start = -start > length ? 0 : (length + start);
|
21518 | }
|
21519 | end = end > length ? length : end;
|
21520 | if (end < 0) {
|
21521 | end += length;
|
21522 | }
|
21523 | length = start > end ? 0 : ((end - start) >>> 0);
|
21524 | start >>>= 0;
|
21525 |
|
21526 | var result = Array(length);
|
21527 | while (++index < length) {
|
21528 | result[index] = array[index + start];
|
21529 | }
|
21530 | return result;
|
21531 | }
|
21532 |
|
21533 | var _baseSlice = baseSlice;
|
21534 |
|
21535 | |
21536 |
|
21537 |
|
21538 |
|
21539 |
|
21540 |
|
21541 |
|
21542 |
|
21543 | function parent(object, path) {
|
21544 | return path.length < 2 ? object : _baseGet(object, _baseSlice(path, 0, -1));
|
21545 | }
|
21546 |
|
21547 | var _parent = parent;
|
21548 |
|
21549 | |
21550 |
|
21551 |
|
21552 |
|
21553 |
|
21554 |
|
21555 |
|
21556 |
|
21557 | function baseUnset(object, path) {
|
21558 | path = _castPath(path, object);
|
21559 | object = _parent(object, path);
|
21560 | return object == null || delete object[_toKey(last_1(path))];
|
21561 | }
|
21562 |
|
21563 | var _baseUnset = baseUnset;
|
21564 |
|
21565 |
|
21566 | var arrayProto$1 = Array.prototype;
|
21567 |
|
21568 |
|
21569 | var splice$1 = arrayProto$1.splice;
|
21570 |
|
21571 | |
21572 |
|
21573 |
|
21574 |
|
21575 |
|
21576 |
|
21577 |
|
21578 |
|
21579 |
|
21580 | function basePullAt(array, indexes) {
|
21581 | var length = array ? indexes.length : 0,
|
21582 | lastIndex = length - 1;
|
21583 |
|
21584 | while (length--) {
|
21585 | var index = indexes[length];
|
21586 | if (length == lastIndex || index !== previous) {
|
21587 | var previous = index;
|
21588 | if (_isIndex(index)) {
|
21589 | splice$1.call(array, index, 1);
|
21590 | } else {
|
21591 | _baseUnset(array, index);
|
21592 | }
|
21593 | }
|
21594 | }
|
21595 | return array;
|
21596 | }
|
21597 |
|
21598 | var _basePullAt = basePullAt;
|
21599 |
|
21600 | |
21601 |
|
21602 |
|
21603 |
|
21604 |
|
21605 |
|
21606 |
|
21607 |
|
21608 |
|
21609 |
|
21610 |
|
21611 |
|
21612 |
|
21613 |
|
21614 |
|
21615 |
|
21616 |
|
21617 |
|
21618 |
|
21619 |
|
21620 |
|
21621 |
|
21622 |
|
21623 |
|
21624 |
|
21625 |
|
21626 |
|
21627 |
|
21628 | function remove(array, predicate) {
|
21629 | var result = [];
|
21630 | if (!(array && array.length)) {
|
21631 | return result;
|
21632 | }
|
21633 | var index = -1,
|
21634 | indexes = [],
|
21635 | length = array.length;
|
21636 |
|
21637 | predicate = _baseIteratee(predicate, 3);
|
21638 | while (++index < length) {
|
21639 | var value = array[index];
|
21640 | if (predicate(value, index, array)) {
|
21641 | result.push(value);
|
21642 | indexes.push(index);
|
21643 | }
|
21644 | }
|
21645 | _basePullAt(array, indexes);
|
21646 | return result;
|
21647 | }
|
21648 |
|
21649 | var remove_1 = remove;
|
21650 |
|
21651 |
|
21652 | var mapTag$3 = '[object Map]',
|
21653 | setTag$3 = '[object Set]';
|
21654 |
|
21655 |
|
21656 | var objectProto$d = Object.prototype;
|
21657 |
|
21658 |
|
21659 | var hasOwnProperty$b = objectProto$d.hasOwnProperty;
|
21660 |
|
21661 | |
21662 |
|
21663 |
|
21664 |
|
21665 |
|
21666 |
|
21667 |
|
21668 |
|
21669 |
|
21670 |
|
21671 |
|
21672 |
|
21673 |
|
21674 |
|
21675 |
|
21676 |
|
21677 |
|
21678 |
|
21679 |
|
21680 |
|
21681 |
|
21682 |
|
21683 |
|
21684 |
|
21685 |
|
21686 |
|
21687 |
|
21688 |
|
21689 |
|
21690 |
|
21691 |
|
21692 |
|
21693 |
|
21694 | function isEmpty(value) {
|
21695 | if (value == null) {
|
21696 | return true;
|
21697 | }
|
21698 | if (isArrayLike_1(value) &&
|
21699 | (isArray_1(value) || typeof value == 'string' || typeof value.splice == 'function' ||
|
21700 | isBuffer_1(value) || isTypedArray_1(value) || isArguments_1(value))) {
|
21701 | return !value.length;
|
21702 | }
|
21703 | var tag = _getTag(value);
|
21704 | if (tag == mapTag$3 || tag == setTag$3) {
|
21705 | return !value.size;
|
21706 | }
|
21707 | if (_isPrototype(value)) {
|
21708 | return !_baseKeys(value).length;
|
21709 | }
|
21710 | for (var key in value) {
|
21711 | if (hasOwnProperty$b.call(value, key)) {
|
21712 | return false;
|
21713 | }
|
21714 | }
|
21715 | return true;
|
21716 | }
|
21717 |
|
21718 | var isEmpty_1 = isEmpty;
|
21719 |
|
21720 | |
21721 |
|
21722 |
|
21723 |
|
21724 |
|
21725 |
|
21726 |
|
21727 |
|
21728 |
|
21729 | function arrayEach(array, iteratee) {
|
21730 | var index = -1,
|
21731 | length = array == null ? 0 : array.length;
|
21732 |
|
21733 | while (++index < length) {
|
21734 | if (iteratee(array[index], index, array) === false) {
|
21735 | break;
|
21736 | }
|
21737 | }
|
21738 | return array;
|
21739 | }
|
21740 |
|
21741 | var _arrayEach = arrayEach;
|
21742 |
|
21743 | var defineProperty = (function() {
|
21744 | try {
|
21745 | var func = _getNative(Object, 'defineProperty');
|
21746 | func({}, '', {});
|
21747 | return func;
|
21748 | } catch (e) {}
|
21749 | }());
|
21750 |
|
21751 | var _defineProperty$1 = defineProperty;
|
21752 |
|
21753 | |
21754 |
|
21755 |
|
21756 |
|
21757 |
|
21758 |
|
21759 |
|
21760 |
|
21761 |
|
21762 | function baseAssignValue(object, key, value) {
|
21763 | if (key == '__proto__' && _defineProperty$1) {
|
21764 | _defineProperty$1(object, key, {
|
21765 | 'configurable': true,
|
21766 | 'enumerable': true,
|
21767 | 'value': value,
|
21768 | 'writable': true
|
21769 | });
|
21770 | } else {
|
21771 | object[key] = value;
|
21772 | }
|
21773 | }
|
21774 |
|
21775 | var _baseAssignValue = baseAssignValue;
|
21776 |
|
21777 |
|
21778 | var objectProto$e = Object.prototype;
|
21779 |
|
21780 |
|
21781 | var hasOwnProperty$c = objectProto$e.hasOwnProperty;
|
21782 |
|
21783 | |
21784 |
|
21785 |
|
21786 |
|
21787 |
|
21788 |
|
21789 |
|
21790 |
|
21791 |
|
21792 |
|
21793 | function assignValue(object, key, value) {
|
21794 | var objValue = object[key];
|
21795 | if (!(hasOwnProperty$c.call(object, key) && eq_1(objValue, value)) ||
|
21796 | (value === undefined && !(key in object))) {
|
21797 | _baseAssignValue(object, key, value);
|
21798 | }
|
21799 | }
|
21800 |
|
21801 | var _assignValue = assignValue;
|
21802 |
|
21803 | |
21804 |
|
21805 |
|
21806 |
|
21807 |
|
21808 |
|
21809 |
|
21810 |
|
21811 |
|
21812 |
|
21813 | function copyObject(source, props, object, customizer) {
|
21814 | var isNew = !object;
|
21815 | object || (object = {});
|
21816 |
|
21817 | var index = -1,
|
21818 | length = props.length;
|
21819 |
|
21820 | while (++index < length) {
|
21821 | var key = props[index];
|
21822 |
|
21823 | var newValue = customizer
|
21824 | ? customizer(object[key], source[key], key, object, source)
|
21825 | : undefined;
|
21826 |
|
21827 | if (newValue === undefined) {
|
21828 | newValue = source[key];
|
21829 | }
|
21830 | if (isNew) {
|
21831 | _baseAssignValue(object, key, newValue);
|
21832 | } else {
|
21833 | _assignValue(object, key, newValue);
|
21834 | }
|
21835 | }
|
21836 | return object;
|
21837 | }
|
21838 |
|
21839 | var _copyObject = copyObject;
|
21840 |
|
21841 | |
21842 |
|
21843 |
|
21844 |
|
21845 |
|
21846 |
|
21847 |
|
21848 |
|
21849 |
|
21850 | function baseAssign(object, source) {
|
21851 | return object && _copyObject(source, keys_1(source), object);
|
21852 | }
|
21853 |
|
21854 | var _baseAssign = baseAssign;
|
21855 |
|
21856 | |
21857 |
|
21858 |
|
21859 |
|
21860 |
|
21861 |
|
21862 |
|
21863 |
|
21864 |
|
21865 | function nativeKeysIn(object) {
|
21866 | var result = [];
|
21867 | if (object != null) {
|
21868 | for (var key in Object(object)) {
|
21869 | result.push(key);
|
21870 | }
|
21871 | }
|
21872 | return result;
|
21873 | }
|
21874 |
|
21875 | var _nativeKeysIn = nativeKeysIn;
|
21876 |
|
21877 |
|
21878 | var objectProto$f = Object.prototype;
|
21879 |
|
21880 |
|
21881 | var hasOwnProperty$d = objectProto$f.hasOwnProperty;
|
21882 |
|
21883 | |
21884 |
|
21885 |
|
21886 |
|
21887 |
|
21888 |
|
21889 |
|
21890 | function baseKeysIn(object) {
|
21891 | if (!isObject_1$1(object)) {
|
21892 | return _nativeKeysIn(object);
|
21893 | }
|
21894 | var isProto = _isPrototype(object),
|
21895 | result = [];
|
21896 |
|
21897 | for (var key in object) {
|
21898 | if (!(key == 'constructor' && (isProto || !hasOwnProperty$d.call(object, key)))) {
|
21899 | result.push(key);
|
21900 | }
|
21901 | }
|
21902 | return result;
|
21903 | }
|
21904 |
|
21905 | var _baseKeysIn = baseKeysIn;
|
21906 |
|
21907 | |
21908 |
|
21909 |
|
21910 |
|
21911 |
|
21912 |
|
21913 |
|
21914 |
|
21915 |
|
21916 |
|
21917 |
|
21918 |
|
21919 |
|
21920 |
|
21921 |
|
21922 |
|
21923 |
|
21924 |
|
21925 |
|
21926 |
|
21927 |
|
21928 |
|
21929 |
|
21930 | function keysIn$1(object) {
|
21931 | return isArrayLike_1(object) ? _arrayLikeKeys(object, true) : _baseKeysIn(object);
|
21932 | }
|
21933 |
|
21934 | var keysIn_1 = keysIn$1;
|
21935 |
|
21936 | |
21937 |
|
21938 |
|
21939 |
|
21940 |
|
21941 |
|
21942 |
|
21943 |
|
21944 |
|
21945 | function baseAssignIn(object, source) {
|
21946 | return object && _copyObject(source, keysIn_1(source), object);
|
21947 | }
|
21948 |
|
21949 | var _baseAssignIn = baseAssignIn;
|
21950 |
|
21951 | var _cloneBuffer = createCommonjsModule(function (module, exports) {
|
21952 |
|
21953 | var freeExports = exports && !exports.nodeType && exports;
|
21954 |
|
21955 |
|
21956 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
21957 |
|
21958 |
|
21959 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
21960 |
|
21961 |
|
21962 | var Buffer = moduleExports ? _root.Buffer : undefined,
|
21963 | allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
|
21964 |
|
21965 | |
21966 |
|
21967 |
|
21968 |
|
21969 |
|
21970 |
|
21971 |
|
21972 |
|
21973 | function cloneBuffer(buffer, isDeep) {
|
21974 | if (isDeep) {
|
21975 | return buffer.slice();
|
21976 | }
|
21977 | var length = buffer.length,
|
21978 | result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
21979 |
|
21980 | buffer.copy(result);
|
21981 | return result;
|
21982 | }
|
21983 |
|
21984 | module.exports = cloneBuffer;
|
21985 | });
|
21986 |
|
21987 | |
21988 |
|
21989 |
|
21990 |
|
21991 |
|
21992 |
|
21993 |
|
21994 |
|
21995 | function copySymbols(source, object) {
|
21996 | return _copyObject(source, _getSymbols(source), object);
|
21997 | }
|
21998 |
|
21999 | var _copySymbols = copySymbols;
|
22000 |
|
22001 |
|
22002 | var nativeGetSymbols$1 = Object.getOwnPropertySymbols;
|
22003 |
|
22004 | |
22005 |
|
22006 |
|
22007 |
|
22008 |
|
22009 |
|
22010 |
|
22011 | var getSymbolsIn = !nativeGetSymbols$1 ? stubArray_1 : function(object) {
|
22012 | var result = [];
|
22013 | while (object) {
|
22014 | _arrayPush(result, _getSymbols(object));
|
22015 | object = _getPrototype(object);
|
22016 | }
|
22017 | return result;
|
22018 | };
|
22019 |
|
22020 | var _getSymbolsIn = getSymbolsIn;
|
22021 |
|
22022 | |
22023 |
|
22024 |
|
22025 |
|
22026 |
|
22027 |
|
22028 |
|
22029 |
|
22030 | function copySymbolsIn(source, object) {
|
22031 | return _copyObject(source, _getSymbolsIn(source), object);
|
22032 | }
|
22033 |
|
22034 | var _copySymbolsIn = copySymbolsIn;
|
22035 |
|
22036 | |
22037 |
|
22038 |
|
22039 |
|
22040 |
|
22041 |
|
22042 |
|
22043 |
|
22044 | function getAllKeysIn(object) {
|
22045 | return _baseGetAllKeys(object, keysIn_1, _getSymbolsIn);
|
22046 | }
|
22047 |
|
22048 | var _getAllKeysIn = getAllKeysIn;
|
22049 |
|
22050 |
|
22051 | var objectProto$g = Object.prototype;
|
22052 |
|
22053 |
|
22054 | var hasOwnProperty$e = objectProto$g.hasOwnProperty;
|
22055 |
|
22056 | |
22057 |
|
22058 |
|
22059 |
|
22060 |
|
22061 |
|
22062 |
|
22063 | function initCloneArray(array) {
|
22064 | var length = array.length,
|
22065 | result = new array.constructor(length);
|
22066 |
|
22067 |
|
22068 | if (length && typeof array[0] == 'string' && hasOwnProperty$e.call(array, 'index')) {
|
22069 | result.index = array.index;
|
22070 | result.input = array.input;
|
22071 | }
|
22072 | return result;
|
22073 | }
|
22074 |
|
22075 | var _initCloneArray = initCloneArray;
|
22076 |
|
22077 | |
22078 |
|
22079 |
|
22080 |
|
22081 |
|
22082 |
|
22083 |
|
22084 | function cloneArrayBuffer(arrayBuffer) {
|
22085 | var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
22086 | new _Uint8Array(result).set(new _Uint8Array(arrayBuffer));
|
22087 | return result;
|
22088 | }
|
22089 |
|
22090 | var _cloneArrayBuffer = cloneArrayBuffer;
|
22091 |
|
22092 | |
22093 |
|
22094 |
|
22095 |
|
22096 |
|
22097 |
|
22098 |
|
22099 |
|
22100 | function cloneDataView(dataView, isDeep) {
|
22101 | var buffer = isDeep ? _cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
22102 | return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
22103 | }
|
22104 |
|
22105 | var _cloneDataView = cloneDataView;
|
22106 |
|
22107 |
|
22108 | var reFlags = /\w*$/;
|
22109 |
|
22110 | |
22111 |
|
22112 |
|
22113 |
|
22114 |
|
22115 |
|
22116 |
|
22117 | function cloneRegExp(regexp) {
|
22118 | var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
22119 | result.lastIndex = regexp.lastIndex;
|
22120 | return result;
|
22121 | }
|
22122 |
|
22123 | var _cloneRegExp = cloneRegExp;
|
22124 |
|
22125 |
|
22126 | var symbolProto$2 = _Symbol ? _Symbol.prototype : undefined,
|
22127 | symbolValueOf$1 = symbolProto$2 ? symbolProto$2.valueOf : undefined;
|
22128 |
|
22129 | |
22130 |
|
22131 |
|
22132 |
|
22133 |
|
22134 |
|
22135 |
|
22136 | function cloneSymbol(symbol) {
|
22137 | return symbolValueOf$1 ? Object(symbolValueOf$1.call(symbol)) : {};
|
22138 | }
|
22139 |
|
22140 | var _cloneSymbol = cloneSymbol;
|
22141 |
|
22142 | |
22143 |
|
22144 |
|
22145 |
|
22146 |
|
22147 |
|
22148 |
|
22149 |
|
22150 | function cloneTypedArray(typedArray, isDeep) {
|
22151 | var buffer = isDeep ? _cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
22152 | return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
22153 | }
|
22154 |
|
22155 | var _cloneTypedArray = cloneTypedArray;
|
22156 |
|
22157 |
|
22158 | var boolTag$2 = '[object Boolean]',
|
22159 | dateTag$2 = '[object Date]',
|
22160 | mapTag$4 = '[object Map]',
|
22161 | numberTag$2 = '[object Number]',
|
22162 | regexpTag$2 = '[object RegExp]',
|
22163 | setTag$4 = '[object Set]',
|
22164 | stringTag$2 = '[object String]',
|
22165 | symbolTag$2 = '[object Symbol]';
|
22166 |
|
22167 | var arrayBufferTag$2 = '[object ArrayBuffer]',
|
22168 | dataViewTag$3 = '[object DataView]',
|
22169 | float32Tag$1 = '[object Float32Array]',
|
22170 | float64Tag$1 = '[object Float64Array]',
|
22171 | int8Tag$1 = '[object Int8Array]',
|
22172 | int16Tag$1 = '[object Int16Array]',
|
22173 | int32Tag$1 = '[object Int32Array]',
|
22174 | uint8Tag$1 = '[object Uint8Array]',
|
22175 | uint8ClampedTag$1 = '[object Uint8ClampedArray]',
|
22176 | uint16Tag$1 = '[object Uint16Array]',
|
22177 | uint32Tag$1 = '[object Uint32Array]';
|
22178 |
|
22179 | |
22180 |
|
22181 |
|
22182 |
|
22183 |
|
22184 |
|
22185 |
|
22186 |
|
22187 |
|
22188 |
|
22189 |
|
22190 |
|
22191 | function initCloneByTag(object, tag, isDeep) {
|
22192 | var Ctor = object.constructor;
|
22193 | switch (tag) {
|
22194 | case arrayBufferTag$2:
|
22195 | return _cloneArrayBuffer(object);
|
22196 |
|
22197 | case boolTag$2:
|
22198 | case dateTag$2:
|
22199 | return new Ctor(+object);
|
22200 |
|
22201 | case dataViewTag$3:
|
22202 | return _cloneDataView(object, isDeep);
|
22203 |
|
22204 | case float32Tag$1: case float64Tag$1:
|
22205 | case int8Tag$1: case int16Tag$1: case int32Tag$1:
|
22206 | case uint8Tag$1: case uint8ClampedTag$1: case uint16Tag$1: case uint32Tag$1:
|
22207 | return _cloneTypedArray(object, isDeep);
|
22208 |
|
22209 | case mapTag$4:
|
22210 | return new Ctor;
|
22211 |
|
22212 | case numberTag$2:
|
22213 | case stringTag$2:
|
22214 | return new Ctor(object);
|
22215 |
|
22216 | case regexpTag$2:
|
22217 | return _cloneRegExp(object);
|
22218 |
|
22219 | case setTag$4:
|
22220 | return new Ctor;
|
22221 |
|
22222 | case symbolTag$2:
|
22223 | return _cloneSymbol(object);
|
22224 | }
|
22225 | }
|
22226 |
|
22227 | var _initCloneByTag = initCloneByTag;
|
22228 |
|
22229 |
|
22230 | var objectCreate = Object.create;
|
22231 |
|
22232 | |
22233 |
|
22234 |
|
22235 |
|
22236 |
|
22237 |
|
22238 |
|
22239 |
|
22240 | var baseCreate = (function() {
|
22241 | function object() {}
|
22242 | return function(proto) {
|
22243 | if (!isObject_1$1(proto)) {
|
22244 | return {};
|
22245 | }
|
22246 | if (objectCreate) {
|
22247 | return objectCreate(proto);
|
22248 | }
|
22249 | object.prototype = proto;
|
22250 | var result = new object;
|
22251 | object.prototype = undefined;
|
22252 | return result;
|
22253 | };
|
22254 | }());
|
22255 |
|
22256 | var _baseCreate = baseCreate;
|
22257 |
|
22258 | |
22259 |
|
22260 |
|
22261 |
|
22262 |
|
22263 |
|
22264 |
|
22265 | function initCloneObject(object) {
|
22266 | return (typeof object.constructor == 'function' && !_isPrototype(object))
|
22267 | ? _baseCreate(_getPrototype(object))
|
22268 | : {};
|
22269 | }
|
22270 |
|
22271 | var _initCloneObject = initCloneObject;
|
22272 |
|
22273 |
|
22274 | var mapTag$5 = '[object Map]';
|
22275 |
|
22276 | |
22277 |
|
22278 |
|
22279 |
|
22280 |
|
22281 |
|
22282 |
|
22283 | function baseIsMap(value) {
|
22284 | return isObjectLike_1(value) && _getTag(value) == mapTag$5;
|
22285 | }
|
22286 |
|
22287 | var _baseIsMap = baseIsMap;
|
22288 |
|
22289 |
|
22290 | var nodeIsMap = _nodeUtil && _nodeUtil.isMap;
|
22291 |
|
22292 | |
22293 |
|
22294 |
|
22295 |
|
22296 |
|
22297 |
|
22298 |
|
22299 |
|
22300 |
|
22301 |
|
22302 |
|
22303 |
|
22304 |
|
22305 |
|
22306 |
|
22307 |
|
22308 |
|
22309 | var isMap = nodeIsMap ? _baseUnary(nodeIsMap) : _baseIsMap;
|
22310 |
|
22311 | var isMap_1 = isMap;
|
22312 |
|
22313 |
|
22314 | var setTag$5 = '[object Set]';
|
22315 |
|
22316 | |
22317 |
|
22318 |
|
22319 |
|
22320 |
|
22321 |
|
22322 |
|
22323 | function baseIsSet(value) {
|
22324 | return isObjectLike_1(value) && _getTag(value) == setTag$5;
|
22325 | }
|
22326 |
|
22327 | var _baseIsSet = baseIsSet;
|
22328 |
|
22329 |
|
22330 | var nodeIsSet = _nodeUtil && _nodeUtil.isSet;
|
22331 |
|
22332 | |
22333 |
|
22334 |
|
22335 |
|
22336 |
|
22337 |
|
22338 |
|
22339 |
|
22340 |
|
22341 |
|
22342 |
|
22343 |
|
22344 |
|
22345 |
|
22346 |
|
22347 |
|
22348 |
|
22349 | var isSet = nodeIsSet ? _baseUnary(nodeIsSet) : _baseIsSet;
|
22350 |
|
22351 | var isSet_1 = isSet;
|
22352 |
|
22353 |
|
22354 | var CLONE_DEEP_FLAG = 1,
|
22355 | CLONE_FLAT_FLAG = 2,
|
22356 | CLONE_SYMBOLS_FLAG = 4;
|
22357 |
|
22358 |
|
22359 | var argsTag$3 = '[object Arguments]',
|
22360 | arrayTag$2 = '[object Array]',
|
22361 | boolTag$3 = '[object Boolean]',
|
22362 | dateTag$3 = '[object Date]',
|
22363 | errorTag$2 = '[object Error]',
|
22364 | funcTag$2 = '[object Function]',
|
22365 | genTag$1 = '[object GeneratorFunction]',
|
22366 | mapTag$6 = '[object Map]',
|
22367 | numberTag$3 = '[object Number]',
|
22368 | objectTag$4 = '[object Object]',
|
22369 | regexpTag$3 = '[object RegExp]',
|
22370 | setTag$6 = '[object Set]',
|
22371 | stringTag$3 = '[object String]',
|
22372 | symbolTag$3 = '[object Symbol]',
|
22373 | weakMapTag$2 = '[object WeakMap]';
|
22374 |
|
22375 | var arrayBufferTag$3 = '[object ArrayBuffer]',
|
22376 | dataViewTag$4 = '[object DataView]',
|
22377 | float32Tag$2 = '[object Float32Array]',
|
22378 | float64Tag$2 = '[object Float64Array]',
|
22379 | int8Tag$2 = '[object Int8Array]',
|
22380 | int16Tag$2 = '[object Int16Array]',
|
22381 | int32Tag$2 = '[object Int32Array]',
|
22382 | uint8Tag$2 = '[object Uint8Array]',
|
22383 | uint8ClampedTag$2 = '[object Uint8ClampedArray]',
|
22384 | uint16Tag$2 = '[object Uint16Array]',
|
22385 | uint32Tag$2 = '[object Uint32Array]';
|
22386 |
|
22387 |
|
22388 | var cloneableTags = {};
|
22389 | cloneableTags[argsTag$3] = cloneableTags[arrayTag$2] =
|
22390 | cloneableTags[arrayBufferTag$3] = cloneableTags[dataViewTag$4] =
|
22391 | cloneableTags[boolTag$3] = cloneableTags[dateTag$3] =
|
22392 | cloneableTags[float32Tag$2] = cloneableTags[float64Tag$2] =
|
22393 | cloneableTags[int8Tag$2] = cloneableTags[int16Tag$2] =
|
22394 | cloneableTags[int32Tag$2] = cloneableTags[mapTag$6] =
|
22395 | cloneableTags[numberTag$3] = cloneableTags[objectTag$4] =
|
22396 | cloneableTags[regexpTag$3] = cloneableTags[setTag$6] =
|
22397 | cloneableTags[stringTag$3] = cloneableTags[symbolTag$3] =
|
22398 | cloneableTags[uint8Tag$2] = cloneableTags[uint8ClampedTag$2] =
|
22399 | cloneableTags[uint16Tag$2] = cloneableTags[uint32Tag$2] = true;
|
22400 | cloneableTags[errorTag$2] = cloneableTags[funcTag$2] =
|
22401 | cloneableTags[weakMapTag$2] = false;
|
22402 |
|
22403 | |
22404 |
|
22405 |
|
22406 |
|
22407 |
|
22408 |
|
22409 |
|
22410 |
|
22411 |
|
22412 |
|
22413 |
|
22414 |
|
22415 |
|
22416 |
|
22417 |
|
22418 |
|
22419 | function baseClone(value, bitmask, customizer, key, object, stack) {
|
22420 | var result,
|
22421 | isDeep = bitmask & CLONE_DEEP_FLAG,
|
22422 | isFlat = bitmask & CLONE_FLAT_FLAG,
|
22423 | isFull = bitmask & CLONE_SYMBOLS_FLAG;
|
22424 |
|
22425 | if (customizer) {
|
22426 | result = object ? customizer(value, key, object, stack) : customizer(value);
|
22427 | }
|
22428 | if (result !== undefined) {
|
22429 | return result;
|
22430 | }
|
22431 | if (!isObject_1$1(value)) {
|
22432 | return value;
|
22433 | }
|
22434 | var isArr = isArray_1(value);
|
22435 | if (isArr) {
|
22436 | result = _initCloneArray(value);
|
22437 | if (!isDeep) {
|
22438 | return _copyArray(value, result);
|
22439 | }
|
22440 | } else {
|
22441 | var tag = _getTag(value),
|
22442 | isFunc = tag == funcTag$2 || tag == genTag$1;
|
22443 |
|
22444 | if (isBuffer_1(value)) {
|
22445 | return _cloneBuffer(value, isDeep);
|
22446 | }
|
22447 | if (tag == objectTag$4 || tag == argsTag$3 || (isFunc && !object)) {
|
22448 | result = (isFlat || isFunc) ? {} : _initCloneObject(value);
|
22449 | if (!isDeep) {
|
22450 | return isFlat
|
22451 | ? _copySymbolsIn(value, _baseAssignIn(result, value))
|
22452 | : _copySymbols(value, _baseAssign(result, value));
|
22453 | }
|
22454 | } else {
|
22455 | if (!cloneableTags[tag]) {
|
22456 | return object ? value : {};
|
22457 | }
|
22458 | result = _initCloneByTag(value, tag, isDeep);
|
22459 | }
|
22460 | }
|
22461 |
|
22462 | stack || (stack = new _Stack);
|
22463 | var stacked = stack.get(value);
|
22464 | if (stacked) {
|
22465 | return stacked;
|
22466 | }
|
22467 | stack.set(value, result);
|
22468 |
|
22469 | if (isSet_1(value)) {
|
22470 | value.forEach(function(subValue) {
|
22471 | result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
|
22472 | });
|
22473 |
|
22474 | return result;
|
22475 | }
|
22476 |
|
22477 | if (isMap_1(value)) {
|
22478 | value.forEach(function(subValue, key) {
|
22479 | result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
22480 | });
|
22481 |
|
22482 | return result;
|
22483 | }
|
22484 |
|
22485 | var keysFunc = isFull
|
22486 | ? (isFlat ? _getAllKeysIn : _getAllKeys)
|
22487 | : (isFlat ? keysIn : keys_1);
|
22488 |
|
22489 | var props = isArr ? undefined : keysFunc(value);
|
22490 | _arrayEach(props || value, function(subValue, key) {
|
22491 | if (props) {
|
22492 | key = subValue;
|
22493 | subValue = value[key];
|
22494 | }
|
22495 |
|
22496 | _assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
22497 | });
|
22498 | return result;
|
22499 | }
|
22500 |
|
22501 | var _baseClone = baseClone;
|
22502 |
|
22503 |
|
22504 | var CLONE_DEEP_FLAG$1 = 1,
|
22505 | CLONE_SYMBOLS_FLAG$1 = 4;
|
22506 |
|
22507 | |
22508 |
|
22509 |
|
22510 |
|
22511 |
|
22512 |
|
22513 |
|
22514 |
|
22515 |
|
22516 |
|
22517 |
|
22518 |
|
22519 |
|
22520 |
|
22521 |
|
22522 |
|
22523 |
|
22524 |
|
22525 | function cloneDeep(value) {
|
22526 | return _baseClone(value, CLONE_DEEP_FLAG$1 | CLONE_SYMBOLS_FLAG$1);
|
22527 | }
|
22528 |
|
22529 | var cloneDeep_1 = cloneDeep;
|
22530 |
|
22531 | |
22532 |
|
22533 |
|
22534 |
|
22535 |
|
22536 |
|
22537 |
|
22538 | function createFind(findIndexFunc) {
|
22539 | return function(collection, predicate, fromIndex) {
|
22540 | var iterable = Object(collection);
|
22541 | if (!isArrayLike_1(collection)) {
|
22542 | var iteratee = _baseIteratee(predicate, 3);
|
22543 | collection = keys_1(collection);
|
22544 | predicate = function(key) { return iteratee(iterable[key], key, iterable); };
|
22545 | }
|
22546 | var index = findIndexFunc(collection, predicate, fromIndex);
|
22547 | return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
|
22548 | };
|
22549 | }
|
22550 |
|
22551 | var _createFind = createFind;
|
22552 |
|
22553 | |
22554 |
|
22555 |
|
22556 |
|
22557 |
|
22558 |
|
22559 |
|
22560 |
|
22561 |
|
22562 |
|
22563 |
|
22564 | function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
22565 | var length = array.length,
|
22566 | index = fromIndex + (fromRight ? 1 : -1);
|
22567 |
|
22568 | while ((fromRight ? index-- : ++index < length)) {
|
22569 | if (predicate(array[index], index, array)) {
|
22570 | return index;
|
22571 | }
|
22572 | }
|
22573 | return -1;
|
22574 | }
|
22575 |
|
22576 | var _baseFindIndex = baseFindIndex;
|
22577 |
|
22578 |
|
22579 | var NAN = 0 / 0;
|
22580 |
|
22581 |
|
22582 | var reTrim = /^\s+|\s+$/g;
|
22583 |
|
22584 |
|
22585 | var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
22586 |
|
22587 |
|
22588 | var reIsBinary = /^0b[01]+$/i;
|
22589 |
|
22590 |
|
22591 | var reIsOctal = /^0o[0-7]+$/i;
|
22592 |
|
22593 |
|
22594 | var freeParseInt = parseInt;
|
22595 |
|
22596 | |
22597 |
|
22598 |
|
22599 |
|
22600 |
|
22601 |
|
22602 |
|
22603 |
|
22604 |
|
22605 |
|
22606 |
|
22607 |
|
22608 |
|
22609 |
|
22610 |
|
22611 |
|
22612 |
|
22613 |
|
22614 |
|
22615 |
|
22616 |
|
22617 |
|
22618 |
|
22619 | function toNumber(value) {
|
22620 | if (typeof value == 'number') {
|
22621 | return value;
|
22622 | }
|
22623 | if (isSymbol_1(value)) {
|
22624 | return NAN;
|
22625 | }
|
22626 | if (isObject_1$1(value)) {
|
22627 | var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
22628 | value = isObject_1$1(other) ? (other + '') : other;
|
22629 | }
|
22630 | if (typeof value != 'string') {
|
22631 | return value === 0 ? value : +value;
|
22632 | }
|
22633 | value = value.replace(reTrim, '');
|
22634 | var isBinary = reIsBinary.test(value);
|
22635 | return (isBinary || reIsOctal.test(value))
|
22636 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
22637 | : (reIsBadHex.test(value) ? NAN : +value);
|
22638 | }
|
22639 |
|
22640 | var toNumber_1 = toNumber;
|
22641 |
|
22642 |
|
22643 | var INFINITY$2 = 1 / 0,
|
22644 | MAX_INTEGER = 1.7976931348623157e+308;
|
22645 |
|
22646 | |
22647 |
|
22648 |
|
22649 |
|
22650 |
|
22651 |
|
22652 |
|
22653 |
|
22654 |
|
22655 |
|
22656 |
|
22657 |
|
22658 |
|
22659 |
|
22660 |
|
22661 |
|
22662 |
|
22663 |
|
22664 |
|
22665 |
|
22666 |
|
22667 |
|
22668 |
|
22669 | function toFinite(value) {
|
22670 | if (!value) {
|
22671 | return value === 0 ? value : 0;
|
22672 | }
|
22673 | value = toNumber_1(value);
|
22674 | if (value === INFINITY$2 || value === -INFINITY$2) {
|
22675 | var sign = (value < 0 ? -1 : 1);
|
22676 | return sign * MAX_INTEGER;
|
22677 | }
|
22678 | return value === value ? value : 0;
|
22679 | }
|
22680 |
|
22681 | var toFinite_1 = toFinite;
|
22682 |
|
22683 | |
22684 |
|
22685 |
|
22686 |
|
22687 |
|
22688 |
|
22689 |
|
22690 |
|
22691 |
|
22692 |
|
22693 |
|
22694 |
|
22695 |
|
22696 |
|
22697 |
|
22698 |
|
22699 |
|
22700 |
|
22701 |
|
22702 |
|
22703 |
|
22704 |
|
22705 |
|
22706 |
|
22707 |
|
22708 |
|
22709 | function toInteger(value) {
|
22710 | var result = toFinite_1(value),
|
22711 | remainder = result % 1;
|
22712 |
|
22713 | return result === result ? (remainder ? result - remainder : result) : 0;
|
22714 | }
|
22715 |
|
22716 | var toInteger_1 = toInteger;
|
22717 |
|
22718 |
|
22719 | var nativeMax = Math.max;
|
22720 |
|
22721 | |
22722 |
|
22723 |
|
22724 |
|
22725 |
|
22726 |
|
22727 |
|
22728 |
|
22729 |
|
22730 |
|
22731 |
|
22732 |
|
22733 |
|
22734 |
|
22735 |
|
22736 |
|
22737 |
|
22738 |
|
22739 |
|
22740 |
|
22741 |
|
22742 |
|
22743 |
|
22744 |
|
22745 |
|
22746 |
|
22747 |
|
22748 |
|
22749 |
|
22750 |
|
22751 |
|
22752 |
|
22753 |
|
22754 |
|
22755 |
|
22756 | function findIndex(array, predicate, fromIndex) {
|
22757 | var length = array == null ? 0 : array.length;
|
22758 | if (!length) {
|
22759 | return -1;
|
22760 | }
|
22761 | var index = fromIndex == null ? 0 : toInteger_1(fromIndex);
|
22762 | if (index < 0) {
|
22763 | index = nativeMax(length + index, 0);
|
22764 | }
|
22765 | return _baseFindIndex(array, _baseIteratee(predicate, 3), index);
|
22766 | }
|
22767 |
|
22768 | var findIndex_1 = findIndex;
|
22769 |
|
22770 | |
22771 |
|
22772 |
|
22773 |
|
22774 |
|
22775 |
|
22776 |
|
22777 |
|
22778 |
|
22779 |
|
22780 |
|
22781 |
|
22782 |
|
22783 |
|
22784 |
|
22785 |
|
22786 |
|
22787 |
|
22788 |
|
22789 |
|
22790 |
|
22791 |
|
22792 |
|
22793 |
|
22794 |
|
22795 |
|
22796 |
|
22797 |
|
22798 |
|
22799 |
|
22800 |
|
22801 |
|
22802 |
|
22803 |
|
22804 |
|
22805 |
|
22806 | var find = _createFind(findIndex_1);
|
22807 |
|
22808 | var find_1 = find;
|
22809 |
|
22810 |
|
22811 | var UNREAD_MESSAGES_COUNT_UPDATE = 'unreadmessagescountupdate';
|
22812 | var CLOSE = 'close';
|
22813 | var CONFLICT = 'conflict';
|
22814 | var CONVERSATION_INFO_UPDATED = 'conversationinfoupdated';
|
22815 | var UNHANDLED_MESSAGE = 'unhandledmessage';
|
22816 |
|
22817 | var INVITED = 'invited';
|
22818 | var KICKED = 'kicked';
|
22819 | var MEMBERS_JOINED = 'membersjoined';
|
22820 | var MEMBERS_LEFT = 'membersleft';
|
22821 | var MEMBER_INFO_UPDATED = 'memberinfoupdated';
|
22822 | var BLOCKED = 'blocked';
|
22823 | var UNBLOCKED = 'unblocked';
|
22824 | var MEMBERS_BLOCKED = 'membersblocked';
|
22825 | var MEMBERS_UNBLOCKED = 'membersunblocked';
|
22826 | var MUTED = 'muted';
|
22827 | var UNMUTED = 'unmuted';
|
22828 | var MEMBERS_MUTED = 'membersmuted';
|
22829 | var MEMBERS_UNMUTED = 'membersunmuted';
|
22830 | var MESSAGE$1 = 'message';
|
22831 | var MESSAGE_RECALL = 'messagerecall';
|
22832 | var MESSAGE_UPDATE = 'messageupdate';
|
22833 |
|
22834 | var LAST_DELIVERED_AT_UPDATE = 'lastdeliveredatupdate';
|
22835 | var LAST_READ_AT_UPDATE = 'lastreadatupdate';
|
22836 | var INFO_UPDATED = 'infoupdated';
|
22837 |
|
22838 | var Event = Object.freeze({
|
22839 | UNREAD_MESSAGES_COUNT_UPDATE: UNREAD_MESSAGES_COUNT_UPDATE,
|
22840 | CLOSE: CLOSE,
|
22841 | CONFLICT: CONFLICT,
|
22842 | CONVERSATION_INFO_UPDATED: CONVERSATION_INFO_UPDATED,
|
22843 | UNHANDLED_MESSAGE: UNHANDLED_MESSAGE,
|
22844 | INVITED: INVITED,
|
22845 | KICKED: KICKED,
|
22846 | MEMBERS_JOINED: MEMBERS_JOINED,
|
22847 | MEMBERS_LEFT: MEMBERS_LEFT,
|
22848 | MEMBER_INFO_UPDATED: MEMBER_INFO_UPDATED,
|
22849 | BLOCKED: BLOCKED,
|
22850 | UNBLOCKED: UNBLOCKED,
|
22851 | MEMBERS_BLOCKED: MEMBERS_BLOCKED,
|
22852 | MEMBERS_UNBLOCKED: MEMBERS_UNBLOCKED,
|
22853 | MUTED: MUTED,
|
22854 | UNMUTED: UNMUTED,
|
22855 | MEMBERS_MUTED: MEMBERS_MUTED,
|
22856 | MEMBERS_UNMUTED: MEMBERS_UNMUTED,
|
22857 | MESSAGE: MESSAGE$1,
|
22858 | MESSAGE_RECALL: MESSAGE_RECALL,
|
22859 | MESSAGE_UPDATE: MESSAGE_UPDATE,
|
22860 | LAST_DELIVERED_AT_UPDATE: LAST_DELIVERED_AT_UPDATE,
|
22861 | LAST_READ_AT_UPDATE: LAST_READ_AT_UPDATE,
|
22862 | INFO_UPDATED: INFO_UPDATED
|
22863 | });
|
22864 |
|
22865 | var _rMessageStatus;
|
22866 | |
22867 |
|
22868 |
|
22869 |
|
22870 |
|
22871 |
|
22872 |
|
22873 | var MessageStatus = {
|
22874 |
|
22875 | NONE: Symbol('none'),
|
22876 |
|
22877 |
|
22878 | SENDING: Symbol('sending'),
|
22879 |
|
22880 |
|
22881 | SENT: Symbol('sent'),
|
22882 |
|
22883 |
|
22884 | DELIVERED: Symbol('delivered'),
|
22885 |
|
22886 |
|
22887 | FAILED: Symbol('failed')
|
22888 | };
|
22889 | Object.freeze(MessageStatus);
|
22890 | var rMessageStatus = (_rMessageStatus = {}, _defineProperty(_rMessageStatus, MessageStatus.NONE, true), _defineProperty(_rMessageStatus, MessageStatus.SENDING, true), _defineProperty(_rMessageStatus, MessageStatus.SENT, true), _defineProperty(_rMessageStatus, MessageStatus.DELIVERED, true), _defineProperty(_rMessageStatus, MessageStatus.READ, true), _defineProperty(_rMessageStatus, MessageStatus.FAILED, true), _rMessageStatus);
|
22891 |
|
22892 | var Message =
|
22893 |
|
22894 | function () {
|
22895 | |
22896 |
|
22897 |
|
22898 |
|
22899 | function Message(content) {
|
22900 | Object.assign(this, {
|
22901 | content: content
|
22902 | }, {
|
22903 | |
22904 |
|
22905 |
|
22906 |
|
22907 | id: v4_1(),
|
22908 |
|
22909 | |
22910 |
|
22911 |
|
22912 |
|
22913 |
|
22914 | cid: null,
|
22915 |
|
22916 | |
22917 |
|
22918 |
|
22919 |
|
22920 |
|
22921 | timestamp: new Date(),
|
22922 |
|
22923 | |
22924 |
|
22925 |
|
22926 |
|
22927 |
|
22928 | from: undefined,
|
22929 |
|
22930 | |
22931 |
|
22932 |
|
22933 |
|
22934 |
|
22935 |
|
22936 | mentionList: [],
|
22937 |
|
22938 | |
22939 |
|
22940 |
|
22941 |
|
22942 |
|
22943 |
|
22944 | mentionedAll: false,
|
22945 | _mentioned: false
|
22946 | });
|
22947 |
|
22948 | this._setStatus(MessageStatus.NONE);
|
22949 | }
|
22950 | |
22951 |
|
22952 |
|
22953 |
|
22954 |
|
22955 |
|
22956 |
|
22957 | var _proto = Message.prototype;
|
22958 |
|
22959 | _proto.getPayload = function getPayload() {
|
22960 | return this.content;
|
22961 | };
|
22962 |
|
22963 | _proto._toJSON = function _toJSON() {
|
22964 | var id = this.id,
|
22965 | cid = this.cid,
|
22966 | from = this.from,
|
22967 | timestamp = this.timestamp,
|
22968 | deliveredAt = this.deliveredAt,
|
22969 | updatedAt = this.updatedAt,
|
22970 | mentionList = this.mentionList,
|
22971 | mentionedAll = this.mentionedAll,
|
22972 | mentioned = this.mentioned;
|
22973 | return {
|
22974 | id: id,
|
22975 | cid: cid,
|
22976 | from: from,
|
22977 | timestamp: timestamp,
|
22978 | deliveredAt: deliveredAt,
|
22979 | updatedAt: updatedAt,
|
22980 | mentionList: mentionList,
|
22981 | mentionedAll: mentionedAll,
|
22982 | mentioned: mentioned
|
22983 | };
|
22984 | }
|
22985 | |
22986 |
|
22987 |
|
22988 |
|
22989 | ;
|
22990 |
|
22991 | _proto.toJSON = function toJSON() {
|
22992 | return _objectSpread({}, this._toJSON(), {
|
22993 | data: this.content
|
22994 | });
|
22995 | }
|
22996 | |
22997 |
|
22998 |
|
22999 |
|
23000 |
|
23001 | ;
|
23002 |
|
23003 | _proto.toFullJSON = function toFullJSON() {
|
23004 | var content = this.content,
|
23005 | id = this.id,
|
23006 | cid = this.cid,
|
23007 | from = this.from,
|
23008 | timestamp = this.timestamp,
|
23009 | deliveredAt = this.deliveredAt,
|
23010 | _updatedAt = this._updatedAt,
|
23011 | mentionList = this.mentionList,
|
23012 | mentionedAll = this.mentionedAll;
|
23013 | return {
|
23014 | data: content,
|
23015 | id: id,
|
23016 | cid: cid,
|
23017 | from: from,
|
23018 | timestamp: getTime(timestamp),
|
23019 | deliveredAt: getTime(deliveredAt),
|
23020 | updatedAt: getTime(_updatedAt),
|
23021 | mentionList: mentionList,
|
23022 | mentionedAll: mentionedAll
|
23023 | };
|
23024 | }
|
23025 | |
23026 |
|
23027 |
|
23028 |
|
23029 |
|
23030 |
|
23031 | ;
|
23032 |
|
23033 | _proto._setStatus = function _setStatus(status) {
|
23034 | if (!rMessageStatus[status]) {
|
23035 | throw new Error('Invalid message status');
|
23036 | }
|
23037 |
|
23038 | this._status = status;
|
23039 | };
|
23040 |
|
23041 | _proto._updateMentioned = function _updateMentioned(client) {
|
23042 | this._mentioned = this.from !== client && (this.mentionedAll || this.mentionList.indexOf(client) > -1);
|
23043 | }
|
23044 | |
23045 |
|
23046 |
|
23047 |
|
23048 |
|
23049 | ;
|
23050 |
|
23051 | _proto.getMentionList = function getMentionList() {
|
23052 | return this.mentionList;
|
23053 | }
|
23054 | |
23055 |
|
23056 |
|
23057 |
|
23058 |
|
23059 |
|
23060 | ;
|
23061 |
|
23062 | _proto.setMentionList = function setMentionList(clients) {
|
23063 | this.mentionList = ensureArray(clients);
|
23064 | return this;
|
23065 | }
|
23066 | |
23067 |
|
23068 |
|
23069 |
|
23070 |
|
23071 |
|
23072 | ;
|
23073 |
|
23074 | _proto.mentionAll = function mentionAll() {
|
23075 | var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
23076 | this.mentionedAll = Boolean(value);
|
23077 | return this;
|
23078 | }
|
23079 | |
23080 |
|
23081 |
|
23082 |
|
23083 |
|
23084 |
|
23085 |
|
23086 | ;
|
23087 |
|
23088 | Message.validate = function validate() {
|
23089 | return true;
|
23090 | }
|
23091 | |
23092 |
|
23093 |
|
23094 |
|
23095 |
|
23096 |
|
23097 |
|
23098 |
|
23099 |
|
23100 |
|
23101 |
|
23102 | ;
|
23103 |
|
23104 | Message.parse = function parse(json, message) {
|
23105 | return message || new this(json);
|
23106 | };
|
23107 |
|
23108 | _createClass(Message, [{
|
23109 | key: "status",
|
23110 | get: function get() {
|
23111 | return this._status;
|
23112 | }
|
23113 | }, {
|
23114 | key: "timestamp",
|
23115 | get: function get() {
|
23116 | return this._timestamp;
|
23117 | },
|
23118 | set: function set(value) {
|
23119 | this._timestamp = decodeDate(value);
|
23120 | }
|
23121 | |
23122 |
|
23123 |
|
23124 |
|
23125 |
|
23126 | }, {
|
23127 | key: "deliveredAt",
|
23128 | get: function get() {
|
23129 | return this._deliveredAt;
|
23130 | },
|
23131 | set: function set(value) {
|
23132 | this._deliveredAt = decodeDate(value);
|
23133 | }
|
23134 | |
23135 |
|
23136 |
|
23137 |
|
23138 |
|
23139 |
|
23140 | }, {
|
23141 | key: "updatedAt",
|
23142 | get: function get() {
|
23143 | return this._updatedAt || this.timestamp;
|
23144 | },
|
23145 | set: function set(value) {
|
23146 | this._updatedAt = decodeDate(value);
|
23147 | }
|
23148 | |
23149 |
|
23150 |
|
23151 |
|
23152 |
|
23153 |
|
23154 |
|
23155 | }, {
|
23156 | key: "mentioned",
|
23157 | get: function get() {
|
23158 | return this._mentioned;
|
23159 | }
|
23160 | }]);
|
23161 |
|
23162 | return Message;
|
23163 | }();
|
23164 |
|
23165 |
|
23166 |
|
23167 | var messageType = function messageType(type) {
|
23168 | if (typeof type !== 'number') {
|
23169 | throw new TypeError("".concat(type, " is not a Number"));
|
23170 | }
|
23171 |
|
23172 | return function (target) {
|
23173 | target.TYPE = type;
|
23174 |
|
23175 | target.validate = function (json) {
|
23176 | return json._lctype === type;
|
23177 | };
|
23178 |
|
23179 | target.prototype._getType = function () {
|
23180 | return {
|
23181 | _lctype: type
|
23182 | };
|
23183 | };
|
23184 | };
|
23185 | };
|
23186 |
|
23187 | var messageField = function messageField(fields) {
|
23188 | if (typeof fields !== 'string') {
|
23189 | if (!Array.isArray(fields)) {
|
23190 | throw new TypeError("".concat(fields, " is not an Array"));
|
23191 | } else if (fields.some(function (value) {
|
23192 | return typeof value !== 'string';
|
23193 | })) {
|
23194 | throw new TypeError('fields contains non-string typed member');
|
23195 | }
|
23196 | }
|
23197 |
|
23198 | return function (target) {
|
23199 |
|
23200 |
|
23201 |
|
23202 | var originalCustomFields = isIE10 ? getStaticProperty(target, '_customFields') : target._customFields;
|
23203 | originalCustomFields = Array.isArray(originalCustomFields) ? originalCustomFields : [];
|
23204 | target._customFields = originalCustomFields.concat(fields);
|
23205 | };
|
23206 | };
|
23207 |
|
23208 |
|
23209 |
|
23210 | var IE10Compatible = function IE10Compatible(target) {
|
23211 | if (isIE10) {
|
23212 | target.parse = getStaticProperty(target, 'parse');
|
23213 | }
|
23214 | };
|
23215 |
|
23216 | var _dec, _class$1;
|
23217 |
|
23218 | var
|
23219 |
|
23220 | |
23221 |
|
23222 |
|
23223 |
|
23224 | TypedMessage = (_dec = messageField(['_lctext', '_lcattrs']), _dec(_class$1 =
|
23225 |
|
23226 | function (_Message) {
|
23227 | _inheritsLoose(TypedMessage, _Message);
|
23228 |
|
23229 | function TypedMessage() {
|
23230 | return _Message.apply(this, arguments) || this;
|
23231 | }
|
23232 |
|
23233 | var _proto = TypedMessage.prototype;
|
23234 |
|
23235 | |
23236 |
|
23237 |
|
23238 |
|
23239 | _proto.setText = function setText(text) {
|
23240 | this._lctext = text;
|
23241 | return this;
|
23242 | }
|
23243 | |
23244 |
|
23245 |
|
23246 | ;
|
23247 |
|
23248 | _proto.getText = function getText() {
|
23249 | return this._lctext;
|
23250 | }
|
23251 | |
23252 |
|
23253 |
|
23254 |
|
23255 | ;
|
23256 |
|
23257 | _proto.setAttributes = function setAttributes(attributes) {
|
23258 | this._lcattrs = attributes;
|
23259 | return this;
|
23260 | }
|
23261 | |
23262 |
|
23263 |
|
23264 | ;
|
23265 |
|
23266 | _proto.getAttributes = function getAttributes() {
|
23267 | return this._lcattrs;
|
23268 | };
|
23269 |
|
23270 | _proto._getCustomFields = function _getCustomFields() {
|
23271 | var _this = this;
|
23272 |
|
23273 | var fields = Array.isArray(this.constructor._customFields) ? this.constructor._customFields : [];
|
23274 | return fields.reduce(function (result, field) {
|
23275 | if (typeof field !== 'string') return result;
|
23276 | result[field] = _this[field];
|
23277 |
|
23278 | return result;
|
23279 | }, {});
|
23280 | }
|
23281 |
|
23282 | ;
|
23283 |
|
23284 | _proto._getType = function _getType() {
|
23285 | throw new Error('not implemented');
|
23286 | }
|
23287 |
|
23288 | ;
|
23289 |
|
23290 | _proto.getPayload = function getPayload() {
|
23291 | return compact(Object.assign({
|
23292 | _lctext: this.getText(),
|
23293 | _lcattrs: this.getAttributes()
|
23294 | }, this._getCustomFields(), this._getType()));
|
23295 | };
|
23296 |
|
23297 | _proto.toJSON = function toJSON() {
|
23298 | var type = this.type,
|
23299 | text = this.text,
|
23300 | attributes = this.attributes,
|
23301 | summary = this.summary;
|
23302 | return _objectSpread({}, _Message.prototype._toJSON.call(this), {
|
23303 | type: type,
|
23304 | text: text,
|
23305 | attributes: attributes,
|
23306 | summary: summary
|
23307 | });
|
23308 | };
|
23309 |
|
23310 | _proto.toFullJSON = function toFullJSON() {
|
23311 | return _objectSpread({}, _Message.prototype.toFullJSON.call(this), {
|
23312 | data: this.getPayload()
|
23313 | });
|
23314 | }
|
23315 | |
23316 |
|
23317 |
|
23318 |
|
23319 |
|
23320 |
|
23321 |
|
23322 |
|
23323 |
|
23324 |
|
23325 |
|
23326 | ;
|
23327 |
|
23328 | TypedMessage.parse = function parse(json) {
|
23329 | var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new this();
|
23330 | message.content = json;
|
23331 |
|
23332 | var customFields = isIE10 ? getStaticProperty(message.constructor, '_customFields') : message.constructor._customFields;
|
23333 | var fields = Array.isArray(customFields) ? customFields : [];
|
23334 | fields = fields.reduce(function (result, field) {
|
23335 | if (typeof field !== 'string') return result;
|
23336 | result[field] = json[field];
|
23337 |
|
23338 | return result;
|
23339 | }, {});
|
23340 | Object.assign(message, fields);
|
23341 | return _Message.parse.call(this, json, message);
|
23342 | };
|
23343 |
|
23344 | _createClass(TypedMessage, [{
|
23345 | key: "type",
|
23346 |
|
23347 | |
23348 |
|
23349 |
|
23350 |
|
23351 | get: function get() {
|
23352 | return this.constructor.TYPE;
|
23353 | }
|
23354 |
|
23355 |
|
23356 | }, {
|
23357 | key: "text",
|
23358 | set: function set(text) {
|
23359 | return this.setText(text);
|
23360 | },
|
23361 | get: function get() {
|
23362 | return this.getText();
|
23363 | }
|
23364 |
|
23365 |
|
23366 | }, {
|
23367 | key: "attributes",
|
23368 | set: function set(attributes) {
|
23369 | return this.setAttributes(attributes);
|
23370 | },
|
23371 | get: function get() {
|
23372 | return this.getAttributes();
|
23373 | }
|
23374 | |
23375 |
|
23376 |
|
23377 |
|
23378 |
|
23379 |
|
23380 |
|
23381 |
|
23382 | }, {
|
23383 | key: "summary",
|
23384 | get: function get() {
|
23385 | return this.text;
|
23386 | }
|
23387 | }]);
|
23388 |
|
23389 | return TypedMessage;
|
23390 | }(Message)) || _class$1);
|
23391 |
|
23392 | var _dec$1, _class$2;
|
23393 |
|
23394 | var
|
23395 |
|
23396 | |
23397 |
|
23398 |
|
23399 |
|
23400 | RecalledMessage = (_dec$1 = messageType(-127), _dec$1(_class$2 = IE10Compatible(_class$2 =
|
23401 |
|
23402 | function (_TypedMessage) {
|
23403 | _inheritsLoose(RecalledMessage, _TypedMessage);
|
23404 |
|
23405 | function RecalledMessage() {
|
23406 | return _TypedMessage.apply(this, arguments) || this;
|
23407 | }
|
23408 |
|
23409 | _createClass(RecalledMessage, [{
|
23410 | key: "summary",
|
23411 |
|
23412 | |
23413 |
|
23414 |
|
23415 |
|
23416 |
|
23417 |
|
23418 | get: function get() {
|
23419 | return '[该消息已撤回]';
|
23420 | }
|
23421 | }]);
|
23422 |
|
23423 | return RecalledMessage;
|
23424 | }(TypedMessage)) || _class$2) || _class$2);
|
23425 |
|
23426 | var debug$6 = browser('LC:Conversation');
|
23427 |
|
23428 | var serializeMessage = function serializeMessage(message) {
|
23429 | var content = message.getPayload();
|
23430 | var msg;
|
23431 | var binaryMsg;
|
23432 |
|
23433 | if (content instanceof ArrayBuffer) {
|
23434 | binaryMsg = content;
|
23435 | } else if (typeof content !== 'string') {
|
23436 | msg = JSON.stringify(content);
|
23437 | } else {
|
23438 | msg = content;
|
23439 | }
|
23440 |
|
23441 | return {
|
23442 | msg: msg,
|
23443 | binaryMsg: binaryMsg
|
23444 | };
|
23445 | };
|
23446 |
|
23447 | var _LogsCommand$QueryDir = LogsCommand.QueryDirection,
|
23448 | NEW = _LogsCommand$QueryDir.NEW,
|
23449 | OLD = _LogsCommand$QueryDir.OLD;
|
23450 | |
23451 |
|
23452 |
|
23453 |
|
23454 |
|
23455 |
|
23456 |
|
23457 | var MessageQueryDirection = {
|
23458 |
|
23459 | NEW_TO_OLD: OLD,
|
23460 |
|
23461 |
|
23462 | OLD_TO_NEW: NEW
|
23463 | };
|
23464 | Object.freeze(MessageQueryDirection);
|
23465 |
|
23466 | var ConversationBase =
|
23467 |
|
23468 | function (_EventEmitter) {
|
23469 | _inheritsLoose(ConversationBase, _EventEmitter);
|
23470 |
|
23471 | |
23472 |
|
23473 |
|
23474 |
|
23475 |
|
23476 | function ConversationBase(_ref, client) {
|
23477 | var _this;
|
23478 |
|
23479 | var id = _ref.id,
|
23480 | lastMessageAt = _ref.lastMessageAt,
|
23481 | lastMessage = _ref.lastMessage,
|
23482 | lastDeliveredAt = _ref.lastDeliveredAt,
|
23483 | lastReadAt = _ref.lastReadAt,
|
23484 | _ref$unreadMessagesCo = _ref.unreadMessagesCount,
|
23485 | unreadMessagesCount = _ref$unreadMessagesCo === void 0 ? 0 : _ref$unreadMessagesCo,
|
23486 | _ref$members = _ref.members,
|
23487 | members = _ref$members === void 0 ? [] : _ref$members,
|
23488 | _ref$mentioned = _ref.mentioned,
|
23489 | mentioned = _ref$mentioned === void 0 ? false : _ref$mentioned,
|
23490 | properties = _objectWithoutProperties(_ref, ["id", "lastMessageAt", "lastMessage", "lastDeliveredAt", "lastReadAt", "unreadMessagesCount", "members", "mentioned"]);
|
23491 |
|
23492 | _this = _EventEmitter.call(this) || this;
|
23493 | Object.assign(_assertThisInitialized(_this), _objectSpread({
|
23494 | |
23495 |
|
23496 |
|
23497 |
|
23498 |
|
23499 | id: id,
|
23500 |
|
23501 | |
23502 |
|
23503 |
|
23504 |
|
23505 |
|
23506 | lastMessageAt: lastMessageAt,
|
23507 |
|
23508 | |
23509 |
|
23510 |
|
23511 |
|
23512 |
|
23513 | lastMessage: lastMessage,
|
23514 |
|
23515 | |
23516 |
|
23517 |
|
23518 |
|
23519 |
|
23520 | members: members
|
23521 | }, properties));
|
23522 | _this.members = Array.from(new Set(_this.members));
|
23523 | Object.assign(internal(_assertThisInitialized(_this)), {
|
23524 | messagesWaitingForReceipt: {},
|
23525 | lastDeliveredAt: lastDeliveredAt,
|
23526 | lastReadAt: lastReadAt,
|
23527 | unreadMessagesCount: unreadMessagesCount,
|
23528 | mentioned: mentioned
|
23529 | });
|
23530 | _this._client = client;
|
23531 |
|
23532 | if (debug$6.enabled) {
|
23533 | values_1(Event).forEach(function (event) {
|
23534 | return _this.on(event, function () {
|
23535 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
23536 | payload[_key] = arguments[_key];
|
23537 | }
|
23538 |
|
23539 | return _this._debug("".concat(event, " event emitted. %o"), payload);
|
23540 | });
|
23541 | });
|
23542 | }
|
23543 |
|
23544 |
|
23545 | applyDecorators(_this._client._plugins.onConversationCreate, _assertThisInitialized(_this));
|
23546 | return _this;
|
23547 | }
|
23548 | |
23549 |
|
23550 |
|
23551 |
|
23552 |
|
23553 |
|
23554 |
|
23555 | var _proto = ConversationBase.prototype;
|
23556 |
|
23557 | _proto._setUnreadMessagesMentioned = function _setUnreadMessagesMentioned(value) {
|
23558 | internal(this).unreadMessagesMentioned = Boolean(value);
|
23559 | };
|
23560 |
|
23561 | _proto._setLastDeliveredAt = function _setLastDeliveredAt(value) {
|
23562 | var date = decodeDate(value);
|
23563 |
|
23564 | if (!(date < internal(this).lastDeliveredAt)) {
|
23565 | internal(this).lastDeliveredAt = date;
|
23566 | |
23567 |
|
23568 |
|
23569 |
|
23570 |
|
23571 |
|
23572 | this.emit(LAST_DELIVERED_AT_UPDATE);
|
23573 | }
|
23574 | }
|
23575 | |
23576 |
|
23577 |
|
23578 |
|
23579 |
|
23580 | ;
|
23581 |
|
23582 | _proto._setLastReadAt = function _setLastReadAt(value) {
|
23583 | var date = decodeDate(value);
|
23584 |
|
23585 | if (!(date < internal(this).lastReadAt)) {
|
23586 | internal(this).lastReadAt = date;
|
23587 | |
23588 |
|
23589 |
|
23590 |
|
23591 |
|
23592 |
|
23593 | this.emit(LAST_READ_AT_UPDATE);
|
23594 | }
|
23595 | }
|
23596 | |
23597 |
|
23598 |
|
23599 |
|
23600 |
|
23601 | ;
|
23602 |
|
23603 | _proto.toFullJSON = function toFullJSON() {
|
23604 | var id = this.id,
|
23605 | members = this.members,
|
23606 | lastMessageAt = this.lastMessageAt,
|
23607 | lastDeliveredAt = this.lastDeliveredAt,
|
23608 | lastReadAt = this.lastReadAt,
|
23609 | lastMessage = this.lastMessage,
|
23610 | unreadMessagesCount = this.unreadMessagesCount;
|
23611 | return {
|
23612 | id: id,
|
23613 | members: members,
|
23614 | lastMessageAt: getTime(lastMessageAt),
|
23615 | lastDeliveredAt: getTime(lastDeliveredAt),
|
23616 | lastReadAt: getTime(lastReadAt),
|
23617 | lastMessage: lastMessage ? lastMessage.toFullJSON() : undefined,
|
23618 | unreadMessagesCount: unreadMessagesCount
|
23619 | };
|
23620 | }
|
23621 | |
23622 |
|
23623 |
|
23624 |
|
23625 |
|
23626 | ;
|
23627 |
|
23628 | _proto.toJSON = function toJSON() {
|
23629 | var id = this.id,
|
23630 | members = this.members,
|
23631 | lastMessageAt = this.lastMessageAt,
|
23632 | lastDeliveredAt = this.lastDeliveredAt,
|
23633 | lastReadAt = this.lastReadAt,
|
23634 | lastMessage = this.lastMessage,
|
23635 | unreadMessagesCount = this.unreadMessagesCount,
|
23636 | unreadMessagesMentioned = this.unreadMessagesMentioned;
|
23637 | return {
|
23638 | id: id,
|
23639 | members: members,
|
23640 | lastMessageAt: lastMessageAt,
|
23641 | lastDeliveredAt: lastDeliveredAt,
|
23642 | lastReadAt: lastReadAt,
|
23643 | lastMessage: lastMessage ? lastMessage.toJSON() : undefined,
|
23644 | unreadMessagesCount: unreadMessagesCount,
|
23645 | unreadMessagesMentioned: unreadMessagesMentioned
|
23646 | };
|
23647 | };
|
23648 |
|
23649 | _proto._debug = function _debug() {
|
23650 | for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
23651 | params[_key2] = arguments[_key2];
|
23652 | }
|
23653 |
|
23654 | debug$6.apply(void 0, params.concat(["[".concat(this.id, "]")]));
|
23655 | };
|
23656 |
|
23657 | _proto._send = function _send(command) {
|
23658 | var _this$_client;
|
23659 |
|
23660 |
|
23661 | if (command.cmd === null) {
|
23662 | command.cmd = 'conv';
|
23663 | }
|
23664 |
|
23665 | if (command.cmd === 'conv' && command.convMessage === null) {
|
23666 | command.convMessage = new ConvCommand();
|
23667 | }
|
23668 |
|
23669 | if (command.convMessage && command.convMessage.cid === null) {
|
23670 | command.convMessage.cid = this.id;
|
23671 | }
|
23672 |
|
23673 |
|
23674 |
|
23675 | for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
23676 | args[_key3 - 1] = arguments[_key3];
|
23677 | }
|
23678 |
|
23679 | return (_this$_client = this._client)._send.apply(_this$_client, [command].concat(args));
|
23680 | }
|
23681 | |
23682 |
|
23683 |
|
23684 |
|
23685 |
|
23686 |
|
23687 |
|
23688 |
|
23689 |
|
23690 |
|
23691 |
|
23692 |
|
23693 |
|
23694 | ;
|
23695 |
|
23696 | _proto.send =
|
23697 |
|
23698 | function () {
|
23699 | var _send2 = _asyncToGenerator(
|
23700 |
|
23701 | regenerator.mark(function _callee(message, options) {
|
23702 | var _Object$assign, transient, receipt, priority, pushData, will, _serializeMessage, msg, binaryMsg, command, resCommand, _resCommand$ackMessag, uid, t, code, reason, appCode;
|
23703 |
|
23704 | return regenerator.wrap(function _callee$(_context) {
|
23705 | while (1) {
|
23706 | switch (_context.prev = _context.next) {
|
23707 | case 0:
|
23708 | this._debug(message, 'send');
|
23709 |
|
23710 | if (message instanceof Message) {
|
23711 | _context.next = 3;
|
23712 | break;
|
23713 | }
|
23714 |
|
23715 | throw new TypeError("".concat(message, " is not a Message"));
|
23716 |
|
23717 | case 3:
|
23718 | _Object$assign = Object.assign({},
|
23719 | message.constructor.sendOptions,
|
23720 | typeof message.constructor.getSendOptions === 'function' ? message.constructor.getSendOptions(message) : {}, options), transient = _Object$assign.transient, receipt = _Object$assign.receipt, priority = _Object$assign.priority, pushData = _Object$assign.pushData, will = _Object$assign.will;
|
23721 |
|
23722 | if (receipt) {
|
23723 | if (this.transient) {
|
23724 | console.warn('receipt option is ignored as the conversation is transient.');
|
23725 | } else if (transient) {
|
23726 | console.warn('receipt option is ignored as the message is sent transiently.');
|
23727 | } else if (this.members.length > 2) {
|
23728 | console.warn('receipt option is recommended to be used in one-on-one conversation.');
|
23729 | }
|
23730 | }
|
23731 |
|
23732 | if (priority && !this.transient) {
|
23733 | console.warn('priority option is ignored as the conversation is not transient.');
|
23734 | }
|
23735 |
|
23736 | Object.assign(message, {
|
23737 | cid: this.id,
|
23738 | from: this._client.id
|
23739 | });
|
23740 |
|
23741 | message._setStatus(MessageStatus.SENDING);
|
23742 |
|
23743 | _serializeMessage = serializeMessage(message), msg = _serializeMessage.msg, binaryMsg = _serializeMessage.binaryMsg;
|
23744 | command = new GenericCommand({
|
23745 | cmd: 'direct',
|
23746 | directMessage: new DirectCommand({
|
23747 | msg: msg,
|
23748 | binaryMsg: binaryMsg,
|
23749 | cid: this.id,
|
23750 | r: receipt,
|
23751 | transient: transient,
|
23752 | dt: message.id,
|
23753 | pushData: JSON.stringify(pushData),
|
23754 | will: will,
|
23755 | mentionPids: message.mentionList,
|
23756 | mentionAll: message.mentionedAll
|
23757 | }),
|
23758 | priority: priority
|
23759 | });
|
23760 | _context.prev = 10;
|
23761 | _context.next = 13;
|
23762 | return this._send(command);
|
23763 |
|
23764 | case 13:
|
23765 | resCommand = _context.sent;
|
23766 | _resCommand$ackMessag = resCommand.ackMessage, uid = _resCommand$ackMessag.uid, t = _resCommand$ackMessag.t, code = _resCommand$ackMessag.code, reason = _resCommand$ackMessag.reason, appCode = _resCommand$ackMessag.appCode;
|
23767 |
|
23768 | if (!(code !== null)) {
|
23769 | _context.next = 17;
|
23770 | break;
|
23771 | }
|
23772 |
|
23773 | throw createError({
|
23774 | code: code,
|
23775 | reason: reason,
|
23776 | appCode: appCode
|
23777 | });
|
23778 |
|
23779 | case 17:
|
23780 | Object.assign(message, {
|
23781 | id: uid,
|
23782 | timestamp: t
|
23783 | });
|
23784 |
|
23785 | if (!transient) {
|
23786 | this.lastMessage = message;
|
23787 | this.lastMessageAt = message.timestamp;
|
23788 | }
|
23789 |
|
23790 | message._setStatus(MessageStatus.SENT);
|
23791 |
|
23792 | if (receipt) {
|
23793 | internal(this).messagesWaitingForReceipt[message.id] = message;
|
23794 | }
|
23795 |
|
23796 | return _context.abrupt("return", message);
|
23797 |
|
23798 | case 24:
|
23799 | _context.prev = 24;
|
23800 | _context.t0 = _context["catch"](10);
|
23801 |
|
23802 | message._setStatus(MessageStatus.FAILED);
|
23803 |
|
23804 | throw _context.t0;
|
23805 |
|
23806 | case 28:
|
23807 | case "end":
|
23808 | return _context.stop();
|
23809 | }
|
23810 | }
|
23811 | }, _callee, this, [[10, 24]]);
|
23812 | }));
|
23813 |
|
23814 | function send(_x, _x2) {
|
23815 | return _send2.apply(this, arguments);
|
23816 | }
|
23817 |
|
23818 | return send;
|
23819 | }();
|
23820 |
|
23821 | _proto._update =
|
23822 |
|
23823 | function () {
|
23824 | var _update2 = _asyncToGenerator(
|
23825 |
|
23826 | regenerator.mark(function _callee2(message, newMessage, recall) {
|
23827 | var msg, binaryMsg, content, id, cid, timestamp, from, _status;
|
23828 |
|
23829 | return regenerator.wrap(function _callee2$(_context2) {
|
23830 | while (1) {
|
23831 | switch (_context2.prev = _context2.next) {
|
23832 | case 0:
|
23833 | this._debug('patch %O %O %O', message, newMessage, recall);
|
23834 |
|
23835 | if (!(message instanceof Message)) {
|
23836 | _context2.next = 8;
|
23837 | break;
|
23838 | }
|
23839 |
|
23840 | if (!(message.from !== this._client.id)) {
|
23841 | _context2.next = 4;
|
23842 | break;
|
23843 | }
|
23844 |
|
23845 | throw new Error('Updating message from others is not allowed');
|
23846 |
|
23847 | case 4:
|
23848 | if (!(message.status !== MessageStatus.SENT && message.status !== MessageStatus.DELIVERED)) {
|
23849 | _context2.next = 6;
|
23850 | break;
|
23851 | }
|
23852 |
|
23853 | throw new Error('Message is not sent');
|
23854 |
|
23855 | case 6:
|
23856 | _context2.next = 10;
|
23857 | break;
|
23858 |
|
23859 | case 8:
|
23860 | if (message.id && message.timestamp) {
|
23861 | _context2.next = 10;
|
23862 | break;
|
23863 | }
|
23864 |
|
23865 | throw new TypeError("".concat(message, " is not a Message"));
|
23866 |
|
23867 | case 10:
|
23868 | if (!recall) {
|
23869 | content = serializeMessage(newMessage);
|
23870 | msg = content.msg;
|
23871 | binaryMsg = content.binaryMsg;
|
23872 | }
|
23873 |
|
23874 | _context2.next = 13;
|
23875 | return this._send(new GenericCommand({
|
23876 | cmd: CommandType.patch,
|
23877 | op: OpType.modify,
|
23878 | patchMessage: new PatchCommand({
|
23879 | patches: [new PatchItem({
|
23880 | cid: this.id,
|
23881 | mid: message.id,
|
23882 | timestamp: Number(message.timestamp),
|
23883 | recall: recall,
|
23884 | data: msg,
|
23885 | binaryMsg: binaryMsg,
|
23886 | mentionPids: newMessage.mentionList,
|
23887 | mentionAll: newMessage.mentionedAll
|
23888 | })],
|
23889 | lastPatchTime: this._client._lastPatchTime
|
23890 | })
|
23891 | }));
|
23892 |
|
23893 | case 13:
|
23894 | id = message.id, cid = message.cid, timestamp = message.timestamp, from = message.from, _status = message._status;
|
23895 | Object.assign(newMessage, {
|
23896 | id: id,
|
23897 | cid: cid,
|
23898 | timestamp: timestamp,
|
23899 | from: from,
|
23900 | _status: _status
|
23901 | });
|
23902 |
|
23903 | if (this.lastMessage.id === newMessage.id) {
|
23904 | this.lastMessage = newMessage;
|
23905 | }
|
23906 |
|
23907 | return _context2.abrupt("return", newMessage);
|
23908 |
|
23909 | case 17:
|
23910 | case "end":
|
23911 | return _context2.stop();
|
23912 | }
|
23913 | }
|
23914 | }, _callee2, this);
|
23915 | }));
|
23916 |
|
23917 | function _update(_x3, _x4, _x5) {
|
23918 | return _update2.apply(this, arguments);
|
23919 | }
|
23920 |
|
23921 | return _update;
|
23922 | }()
|
23923 | |
23924 |
|
23925 |
|
23926 |
|
23927 | ;
|
23928 |
|
23929 | _proto.count =
|
23930 |
|
23931 | function () {
|
23932 | var _count = _asyncToGenerator(
|
23933 |
|
23934 | regenerator.mark(function _callee3() {
|
23935 | var resCommand;
|
23936 | return regenerator.wrap(function _callee3$(_context3) {
|
23937 | while (1) {
|
23938 | switch (_context3.prev = _context3.next) {
|
23939 | case 0:
|
23940 | this._debug('count');
|
23941 |
|
23942 | _context3.next = 3;
|
23943 | return this._send(new GenericCommand({
|
23944 | op: 'count'
|
23945 | }));
|
23946 |
|
23947 | case 3:
|
23948 | resCommand = _context3.sent;
|
23949 | return _context3.abrupt("return", resCommand.convMessage.count);
|
23950 |
|
23951 | case 5:
|
23952 | case "end":
|
23953 | return _context3.stop();
|
23954 | }
|
23955 | }
|
23956 | }, _callee3, this);
|
23957 | }));
|
23958 |
|
23959 | function count() {
|
23960 | return _count.apply(this, arguments);
|
23961 | }
|
23962 |
|
23963 | return count;
|
23964 | }()
|
23965 | |
23966 |
|
23967 |
|
23968 |
|
23969 |
|
23970 |
|
23971 | ;
|
23972 |
|
23973 | _proto._addMembers = function _addMembers() {}
|
23974 | |
23975 |
|
23976 |
|
23977 |
|
23978 |
|
23979 |
|
23980 | ;
|
23981 |
|
23982 | _proto._removeMembers = function _removeMembers() {}
|
23983 | |
23984 |
|
23985 |
|
23986 |
|
23987 |
|
23988 |
|
23989 | ;
|
23990 |
|
23991 | _proto.update =
|
23992 |
|
23993 | function () {
|
23994 | var _update3 = _asyncToGenerator(
|
23995 |
|
23996 | regenerator.mark(function _callee4(message, newMessage) {
|
23997 | return regenerator.wrap(function _callee4$(_context4) {
|
23998 | while (1) {
|
23999 | switch (_context4.prev = _context4.next) {
|
24000 | case 0:
|
24001 | if (newMessage instanceof Message) {
|
24002 | _context4.next = 2;
|
24003 | break;
|
24004 | }
|
24005 |
|
24006 | throw new TypeError("".concat(newMessage, " is not a Message"));
|
24007 |
|
24008 | case 2:
|
24009 | return _context4.abrupt("return", this._update(message, newMessage, false));
|
24010 |
|
24011 | case 3:
|
24012 | case "end":
|
24013 | return _context4.stop();
|
24014 | }
|
24015 | }
|
24016 | }, _callee4, this);
|
24017 | }));
|
24018 |
|
24019 | function update(_x6, _x7) {
|
24020 | return _update3.apply(this, arguments);
|
24021 | }
|
24022 |
|
24023 | return update;
|
24024 | }()
|
24025 | |
24026 |
|
24027 |
|
24028 |
|
24029 |
|
24030 | ;
|
24031 |
|
24032 | _proto.recall =
|
24033 |
|
24034 | function () {
|
24035 | var _recall = _asyncToGenerator(
|
24036 |
|
24037 | regenerator.mark(function _callee5(message) {
|
24038 | return regenerator.wrap(function _callee5$(_context5) {
|
24039 | while (1) {
|
24040 | switch (_context5.prev = _context5.next) {
|
24041 | case 0:
|
24042 | return _context5.abrupt("return", this._update(message, new RecalledMessage(), true));
|
24043 |
|
24044 | case 1:
|
24045 | case "end":
|
24046 | return _context5.stop();
|
24047 | }
|
24048 | }
|
24049 | }, _callee5, this);
|
24050 | }));
|
24051 |
|
24052 | function recall(_x8) {
|
24053 | return _recall.apply(this, arguments);
|
24054 | }
|
24055 |
|
24056 | return recall;
|
24057 | }()
|
24058 | |
24059 |
|
24060 |
|
24061 |
|
24062 |
|
24063 |
|
24064 |
|
24065 |
|
24066 |
|
24067 |
|
24068 |
|
24069 |
|
24070 |
|
24071 |
|
24072 |
|
24073 |
|
24074 |
|
24075 |
|
24076 |
|
24077 |
|
24078 |
|
24079 |
|
24080 |
|
24081 |
|
24082 |
|
24083 |
|
24084 |
|
24085 | ;
|
24086 |
|
24087 | _proto.queryMessages =
|
24088 |
|
24089 | function () {
|
24090 | var _queryMessages = _asyncToGenerator(
|
24091 |
|
24092 | regenerator.mark(function _callee7() {
|
24093 | var _this2 = this;
|
24094 |
|
24095 | var options,
|
24096 | beforeTime,
|
24097 | beforeMessageId,
|
24098 | afterTime,
|
24099 | afterMessageId,
|
24100 | limit,
|
24101 | direction,
|
24102 | type,
|
24103 | startTime,
|
24104 | startMessageId,
|
24105 | startClosed,
|
24106 | endTime,
|
24107 | endMessageId,
|
24108 | endClosed,
|
24109 | conditions,
|
24110 | resCommand,
|
24111 | _args7 = arguments;
|
24112 | return regenerator.wrap(function _callee7$(_context7) {
|
24113 | while (1) {
|
24114 | switch (_context7.prev = _context7.next) {
|
24115 | case 0:
|
24116 | options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
|
24117 |
|
24118 | this._debug('query messages %O', options);
|
24119 |
|
24120 | beforeTime = options.beforeTime, beforeMessageId = options.beforeMessageId, afterTime = options.afterTime, afterMessageId = options.afterMessageId, limit = options.limit, direction = options.direction, type = options.type, startTime = options.startTime, startMessageId = options.startMessageId, startClosed = options.startClosed, endTime = options.endTime, endMessageId = options.endMessageId, endClosed = options.endClosed;
|
24121 |
|
24122 | if (!(beforeMessageId || beforeTime || afterMessageId || afterTime)) {
|
24123 | _context7.next = 6;
|
24124 | break;
|
24125 | }
|
24126 |
|
24127 | console.warn('DEPRECATION: queryMessages options beforeTime, beforeMessageId, afterTime and afterMessageId are deprecated in favor of startTime, startMessageId, endTime and endMessageId.');
|
24128 | return _context7.abrupt("return", this.queryMessages({
|
24129 | startTime: beforeTime,
|
24130 | startMessageId: beforeMessageId,
|
24131 | endTime: afterTime,
|
24132 | endMessageId: afterMessageId,
|
24133 | limit: limit
|
24134 | }));
|
24135 |
|
24136 | case 6:
|
24137 | if (!(startMessageId && !startTime)) {
|
24138 | _context7.next = 8;
|
24139 | break;
|
24140 | }
|
24141 |
|
24142 | throw new Error('query option startMessageId must be used with option startTime');
|
24143 |
|
24144 | case 8:
|
24145 | if (!(endMessageId && !endTime)) {
|
24146 | _context7.next = 10;
|
24147 | break;
|
24148 | }
|
24149 |
|
24150 | throw new Error('query option endMessageId must be used with option endTime');
|
24151 |
|
24152 | case 10:
|
24153 | conditions = {
|
24154 | t: startTime,
|
24155 | mid: startMessageId,
|
24156 | tIncluded: startClosed,
|
24157 | tt: endTime,
|
24158 | tmid: endMessageId,
|
24159 | ttIncluded: endClosed,
|
24160 | l: limit,
|
24161 | lctype: type
|
24162 | };
|
24163 |
|
24164 | if (conditions.t instanceof Date) {
|
24165 | conditions.t = conditions.t.getTime();
|
24166 | }
|
24167 |
|
24168 | if (conditions.tt instanceof Date) {
|
24169 | conditions.tt = conditions.tt.getTime();
|
24170 | }
|
24171 |
|
24172 | if (direction !== undefined) {
|
24173 | conditions.direction = direction;
|
24174 | } else if (conditions.tt > conditions.t) {
|
24175 | conditions.direction = MessageQueryDirection.OLD_TO_NEW;
|
24176 | }
|
24177 |
|
24178 | _context7.next = 16;
|
24179 | return this._send(new GenericCommand({
|
24180 | cmd: 'logs',
|
24181 | logsMessage: new LogsCommand(Object.assign(conditions, {
|
24182 | cid: this.id
|
24183 | }))
|
24184 | }));
|
24185 |
|
24186 | case 16:
|
24187 | resCommand = _context7.sent;
|
24188 | return _context7.abrupt("return", Promise.all(resCommand.logsMessage.logs.map(
|
24189 |
|
24190 | function () {
|
24191 | var _ref3 = _asyncToGenerator(
|
24192 |
|
24193 | regenerator.mark(function _callee6(_ref2) {
|
24194 | var msgId, timestamp, patchTimestamp, from, ackAt, readAt, data, mentionAll, mentionPids, bin, messageData, message, status;
|
24195 | return regenerator.wrap(function _callee6$(_context6) {
|
24196 | while (1) {
|
24197 | switch (_context6.prev = _context6.next) {
|
24198 | case 0:
|
24199 | msgId = _ref2.msgId, timestamp = _ref2.timestamp, patchTimestamp = _ref2.patchTimestamp, from = _ref2.from, ackAt = _ref2.ackAt, readAt = _ref2.readAt, data = _ref2.data, mentionAll = _ref2.mentionAll, mentionPids = _ref2.mentionPids, bin = _ref2.bin;
|
24200 | messageData = {
|
24201 | data: data,
|
24202 | bin: bin,
|
24203 | id: msgId,
|
24204 | cid: _this2.id,
|
24205 | timestamp: timestamp,
|
24206 | from: from,
|
24207 | deliveredAt: ackAt,
|
24208 | updatedAt: patchTimestamp,
|
24209 | mentionList: mentionPids,
|
24210 | mentionedAll: mentionAll
|
24211 | };
|
24212 | _context6.next = 4;
|
24213 | return _this2._client.parseMessage(messageData);
|
24214 |
|
24215 | case 4:
|
24216 | message = _context6.sent;
|
24217 | status = MessageStatus.SENT;
|
24218 |
|
24219 | if (_this2.members.length === 2) {
|
24220 | if (ackAt) status = MessageStatus.DELIVERED;
|
24221 | if (ackAt) _this2._setLastDeliveredAt(ackAt);
|
24222 | if (readAt) _this2._setLastReadAt(readAt);
|
24223 | }
|
24224 |
|
24225 | message._setStatus(status);
|
24226 |
|
24227 | return _context6.abrupt("return", message);
|
24228 |
|
24229 | case 9:
|
24230 | case "end":
|
24231 | return _context6.stop();
|
24232 | }
|
24233 | }
|
24234 | }, _callee6, this);
|
24235 | }));
|
24236 |
|
24237 | return function (_x9) {
|
24238 | return _ref3.apply(this, arguments);
|
24239 | };
|
24240 | }())));
|
24241 |
|
24242 | case 18:
|
24243 | case "end":
|
24244 | return _context7.stop();
|
24245 | }
|
24246 | }
|
24247 | }, _callee7, this);
|
24248 | }));
|
24249 |
|
24250 | function queryMessages() {
|
24251 | return _queryMessages.apply(this, arguments);
|
24252 | }
|
24253 |
|
24254 | return queryMessages;
|
24255 | }()
|
24256 | |
24257 |
|
24258 |
|
24259 |
|
24260 |
|
24261 |
|
24262 |
|
24263 |
|
24264 |
|
24265 |
|
24266 |
|
24267 |
|
24268 |
|
24269 |
|
24270 |
|
24271 |
|
24272 |
|
24273 |
|
24274 |
|
24275 |
|
24276 |
|
24277 |
|
24278 |
|
24279 |
|
24280 |
|
24281 |
|
24282 | ;
|
24283 |
|
24284 | _proto.createMessagesIterator = function createMessagesIterator() {
|
24285 | var _this3 = this;
|
24286 |
|
24287 | var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
24288 | beforeTime = _ref4.beforeTime,
|
24289 | beforeMessageId = _ref4.beforeMessageId,
|
24290 | limit = _ref4.limit;
|
24291 |
|
24292 | var promise;
|
24293 | return {
|
24294 | next: function next() {
|
24295 | if (promise === undefined) {
|
24296 |
|
24297 | promise = _this3.queryMessages({
|
24298 | limit: limit,
|
24299 | startTime: beforeTime,
|
24300 | startMessageId: beforeMessageId
|
24301 | });
|
24302 | } else {
|
24303 | promise = promise.then(function (prevMessages) {
|
24304 | if (prevMessages.length === 0 || prevMessages.length < limit) {
|
24305 |
|
24306 | return [];
|
24307 | }
|
24308 |
|
24309 | return _this3.queryMessages({
|
24310 | startTime: prevMessages[0].timestamp,
|
24311 | startMessageId: prevMessages[0].id,
|
24312 | limit: limit
|
24313 | });
|
24314 | });
|
24315 | }
|
24316 |
|
24317 | return promise.then(function (value) {
|
24318 | return {
|
24319 | value: Array.from(value),
|
24320 | done: value.length === 0 || value.length < limit
|
24321 | };
|
24322 | });
|
24323 | }
|
24324 | };
|
24325 | }
|
24326 | |
24327 |
|
24328 |
|
24329 |
|
24330 | ;
|
24331 |
|
24332 | _proto.read =
|
24333 |
|
24334 | function () {
|
24335 | var _read = _asyncToGenerator(
|
24336 |
|
24337 | regenerator.mark(function _callee8() {
|
24338 | var client;
|
24339 | return regenerator.wrap(function _callee8$(_context8) {
|
24340 | while (1) {
|
24341 | switch (_context8.prev = _context8.next) {
|
24342 | case 0:
|
24343 | this.unreadMessagesCount = 0;
|
24344 |
|
24345 | this._setUnreadMessagesMentioned(false);
|
24346 |
|
24347 |
|
24348 | if (!this.transient) {
|
24349 | _context8.next = 4;
|
24350 | break;
|
24351 | }
|
24352 |
|
24353 | return _context8.abrupt("return", this);
|
24354 |
|
24355 | case 4:
|
24356 | client = this._client;
|
24357 |
|
24358 | if (!internal(client).readConversationsBuffer) {
|
24359 | internal(client).readConversationsBuffer = new Set();
|
24360 | }
|
24361 |
|
24362 | internal(client).readConversationsBuffer.add(this);
|
24363 |
|
24364 | client._doSendRead();
|
24365 |
|
24366 | return _context8.abrupt("return", this);
|
24367 |
|
24368 | case 9:
|
24369 | case "end":
|
24370 | return _context8.stop();
|
24371 | }
|
24372 | }
|
24373 | }, _callee8, this);
|
24374 | }));
|
24375 |
|
24376 | function read() {
|
24377 | return _read.apply(this, arguments);
|
24378 | }
|
24379 |
|
24380 | return read;
|
24381 | }();
|
24382 |
|
24383 | _proto._handleReceipt = function _handleReceipt(_ref5) {
|
24384 | var messageId = _ref5.messageId,
|
24385 | timestamp = _ref5.timestamp,
|
24386 | read = _ref5.read;
|
24387 |
|
24388 | if (read) {
|
24389 | this._setLastReadAt(timestamp);
|
24390 | } else {
|
24391 | this._setLastDeliveredAt(timestamp);
|
24392 | }
|
24393 |
|
24394 | var _internal = internal(this),
|
24395 | messagesWaitingForReceipt = _internal.messagesWaitingForReceipt;
|
24396 |
|
24397 | var message = messagesWaitingForReceipt[messageId];
|
24398 | if (!message) return;
|
24399 |
|
24400 | message._setStatus(MessageStatus.DELIVERED);
|
24401 |
|
24402 | message.deliveredAt = timestamp;
|
24403 | delete messagesWaitingForReceipt[messageId];
|
24404 | }
|
24405 | |
24406 |
|
24407 |
|
24408 |
|
24409 |
|
24410 | ;
|
24411 |
|
24412 | _proto.fetchReceiptTimestamps =
|
24413 |
|
24414 | function () {
|
24415 | var _fetchReceiptTimestamps = _asyncToGenerator(
|
24416 |
|
24417 | regenerator.mark(function _callee9() {
|
24418 | var _ref6, _ref6$convMessage, maxReadTimestamp, maxAckTimestamp;
|
24419 |
|
24420 | return regenerator.wrap(function _callee9$(_context9) {
|
24421 | while (1) {
|
24422 | switch (_context9.prev = _context9.next) {
|
24423 | case 0:
|
24424 | _context9.next = 2;
|
24425 | return this._send(new GenericCommand({
|
24426 | op: 'max_read'
|
24427 | }));
|
24428 |
|
24429 | case 2:
|
24430 | _ref6 = _context9.sent;
|
24431 | _ref6$convMessage = _ref6.convMessage;
|
24432 | maxReadTimestamp = _ref6$convMessage.maxReadTimestamp;
|
24433 | maxAckTimestamp = _ref6$convMessage.maxAckTimestamp;
|
24434 |
|
24435 | this._setLastDeliveredAt(maxAckTimestamp);
|
24436 |
|
24437 | this._setLastReadAt(maxReadTimestamp);
|
24438 |
|
24439 | return _context9.abrupt("return", this);
|
24440 |
|
24441 | case 9:
|
24442 | case "end":
|
24443 | return _context9.stop();
|
24444 | }
|
24445 | }
|
24446 | }, _callee9, this);
|
24447 | }));
|
24448 |
|
24449 | function fetchReceiptTimestamps() {
|
24450 | return _fetchReceiptTimestamps.apply(this, arguments);
|
24451 | }
|
24452 |
|
24453 | return fetchReceiptTimestamps;
|
24454 | }();
|
24455 |
|
24456 | _proto._fetchAllReceiptTimestamps = function _fetchAllReceiptTimestamps() {
|
24457 | var convMessage = new ConvCommand({
|
24458 | queryAllMembers: true
|
24459 | });
|
24460 | return this._send(new GenericCommand({
|
24461 | op: 'max_read',
|
24462 | convMessage: convMessage
|
24463 | })).then(function (_ref7) {
|
24464 | var maxReadTuples = _ref7.convMessage.maxReadTuples;
|
24465 | return maxReadTuples.filter(function (maxReadTuple) {
|
24466 | return maxReadTuple.maxAckTimestamp || maxReadTuple.maxReadTimestamp;
|
24467 | }).map(function (_ref8) {
|
24468 | var pid = _ref8.pid,
|
24469 | maxAckTimestamp = _ref8.maxAckTimestamp,
|
24470 | maxReadTimestamp = _ref8.maxReadTimestamp;
|
24471 | return {
|
24472 | pid: pid,
|
24473 | lastDeliveredAt: decodeDate(maxAckTimestamp),
|
24474 | lastReadAt: decodeDate(maxReadTimestamp)
|
24475 | };
|
24476 | });
|
24477 | });
|
24478 | };
|
24479 |
|
24480 | _createClass(ConversationBase, [{
|
24481 | key: "unreadMessagesMentioned",
|
24482 | get: function get() {
|
24483 | return internal(this).unreadMessagesMentioned;
|
24484 | }
|
24485 | }, {
|
24486 | key: "unreadMessagesCount",
|
24487 | set: function set(value) {
|
24488 | if (value !== this.unreadMessagesCount) {
|
24489 | internal(this).unreadMessagesCount = value;
|
24490 |
|
24491 | this._client.emit(UNREAD_MESSAGES_COUNT_UPDATE, [this]);
|
24492 | }
|
24493 | }
|
24494 | |
24495 |
|
24496 |
|
24497 |
|
24498 | ,
|
24499 | get: function get() {
|
24500 | return internal(this).unreadMessagesCount;
|
24501 | }
|
24502 | }, {
|
24503 | key: "lastMessageAt",
|
24504 | set: function set(value) {
|
24505 | var time = decodeDate(value);
|
24506 | if (time <= this._lastMessageAt) return;
|
24507 | this._lastMessageAt = time;
|
24508 | },
|
24509 | get: function get() {
|
24510 | return this._lastMessageAt;
|
24511 | }
|
24512 | |
24513 |
|
24514 |
|
24515 |
|
24516 |
|
24517 |
|
24518 | }, {
|
24519 | key: "lastDeliveredAt",
|
24520 | get: function get() {
|
24521 | if (this.members.length !== 2) return null;
|
24522 | return internal(this).lastDeliveredAt;
|
24523 | }
|
24524 | }, {
|
24525 | key: "lastReadAt",
|
24526 | get: function get() {
|
24527 | if (this.members.length !== 2) return null;
|
24528 | return internal(this).lastReadAt;
|
24529 | }
|
24530 | }]);
|
24531 |
|
24532 | return ConversationBase;
|
24533 | }(eventemitter3);
|
24534 |
|
24535 | var debug$7 = browser('LC:SignatureFactoryRunner');
|
24536 |
|
24537 | function _validateSignature() {
|
24538 | var signatureResult = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
24539 | var signature = signatureResult.signature,
|
24540 | timestamp = signatureResult.timestamp,
|
24541 | nonce = signatureResult.nonce;
|
24542 |
|
24543 | if (typeof signature !== 'string' || typeof timestamp !== 'number' || typeof nonce !== 'string') {
|
24544 | throw new Error('malformed signature');
|
24545 | }
|
24546 |
|
24547 | return {
|
24548 | signature: signature,
|
24549 | timestamp: timestamp,
|
24550 | nonce: nonce
|
24551 | };
|
24552 | }
|
24553 |
|
24554 | var runSignatureFactory = (function (signatureFactory, params) {
|
24555 | return Promise.resolve().then(function () {
|
24556 | debug$7('call signatureFactory with %O', params);
|
24557 | return signatureFactory.apply(void 0, _toConsumableArray(params));
|
24558 | }).then(tap(function (signatureResult) {
|
24559 | return debug$7('sign result %O', signatureResult);
|
24560 | }), function (error) {
|
24561 |
|
24562 | error.message = "sign error: ".concat(error.message);
|
24563 | debug$7(error);
|
24564 | throw error;
|
24565 | }).then(_validateSignature);
|
24566 | });
|
24567 |
|
24568 | |
24569 |
|
24570 |
|
24571 |
|
24572 |
|
24573 |
|
24574 |
|
24575 |
|
24576 |
|
24577 |
|
24578 | |
24579 |
|
24580 |
|
24581 |
|
24582 |
|
24583 |
|
24584 |
|
24585 |
|
24586 | |
24587 |
|
24588 |
|
24589 |
|
24590 |
|
24591 |
|
24592 |
|
24593 |
|
24594 | var createPartiallySuccess = function createPartiallySuccess(_ref) {
|
24595 | var allowedPids = _ref.allowedPids,
|
24596 | failedPids = _ref.failedPids;
|
24597 | return {
|
24598 | successfulClientIds: allowedPids,
|
24599 | failures: failedPids.map(function (_ref2) {
|
24600 | var pids = _ref2.pids,
|
24601 | error = _objectWithoutProperties(_ref2, ["pids"]);
|
24602 |
|
24603 | return Object.assign(createError(error), {
|
24604 | clientIds: pids
|
24605 | });
|
24606 | })
|
24607 | };
|
24608 | };
|
24609 | |
24610 |
|
24611 |
|
24612 |
|
24613 |
|
24614 |
|
24615 |
|
24616 | var PersistentConversation =
|
24617 |
|
24618 | function (_ConversationBase) {
|
24619 | _inheritsLoose(PersistentConversation, _ConversationBase);
|
24620 |
|
24621 | function PersistentConversation(data, _ref3, client) {
|
24622 | var _this;
|
24623 |
|
24624 | var creator = _ref3.creator,
|
24625 | createdAt = _ref3.createdAt,
|
24626 | updatedAt = _ref3.updatedAt,
|
24627 | _ref3$transient = _ref3.transient,
|
24628 | transient = _ref3$transient === void 0 ? false : _ref3$transient,
|
24629 | _ref3$system = _ref3.system,
|
24630 | system = _ref3$system === void 0 ? false : _ref3$system,
|
24631 | _ref3$muted = _ref3.muted,
|
24632 | muted = _ref3$muted === void 0 ? false : _ref3$muted,
|
24633 | _ref3$mutedMembers = _ref3.mutedMembers,
|
24634 | mutedMembers = _ref3$mutedMembers === void 0 ? [] : _ref3$mutedMembers,
|
24635 | attributes = _objectWithoutProperties(_ref3, ["creator", "createdAt", "updatedAt", "transient", "system", "muted", "mutedMembers"]);
|
24636 |
|
24637 | _this = _ConversationBase.call(this, _objectSpread({}, data, {
|
24638 | |
24639 |
|
24640 |
|
24641 |
|
24642 |
|
24643 | creator: creator,
|
24644 |
|
24645 | |
24646 |
|
24647 |
|
24648 |
|
24649 |
|
24650 | createdAt: createdAt,
|
24651 |
|
24652 | |
24653 |
|
24654 |
|
24655 |
|
24656 |
|
24657 | updatedAt: updatedAt,
|
24658 |
|
24659 | |
24660 |
|
24661 |
|
24662 |
|
24663 |
|
24664 | mutedMembers: mutedMembers,
|
24665 |
|
24666 | |
24667 |
|
24668 |
|
24669 |
|
24670 |
|
24671 | transient: transient,
|
24672 |
|
24673 | |
24674 |
|
24675 |
|
24676 |
|
24677 |
|
24678 |
|
24679 | system: system,
|
24680 |
|
24681 | |
24682 |
|
24683 |
|
24684 |
|
24685 |
|
24686 | muted: muted,
|
24687 | _attributes: attributes
|
24688 | }), client) || this;
|
24689 |
|
24690 | _this._reset();
|
24691 |
|
24692 | return _this;
|
24693 | }
|
24694 |
|
24695 | var _proto = PersistentConversation.prototype;
|
24696 |
|
24697 | |
24698 |
|
24699 |
|
24700 |
|
24701 |
|
24702 |
|
24703 | _proto.get = function get(key) {
|
24704 | return internal(this).currentAttributes[key];
|
24705 | }
|
24706 | |
24707 |
|
24708 |
|
24709 |
|
24710 |
|
24711 |
|
24712 |
|
24713 |
|
24714 |
|
24715 |
|
24716 |
|
24717 |
|
24718 |
|
24719 |
|
24720 |
|
24721 |
|
24722 | ;
|
24723 |
|
24724 | _proto.set = function set(key, value) {
|
24725 | this._debug("set [".concat(key, "]: ").concat(value));
|
24726 |
|
24727 | var _internal = internal(this),
|
24728 | pendingAttributes = _internal.pendingAttributes;
|
24729 |
|
24730 | var pendingKeys = Object.keys(pendingAttributes);
|
24731 |
|
24732 |
|
24733 | var re = new RegExp("^".concat(key));
|
24734 | var childKeys = pendingKeys.filter(re.test.bind(re));
|
24735 | childKeys.forEach(function (k) {
|
24736 | delete pendingAttributes[k];
|
24737 | });
|
24738 |
|
24739 | if (childKeys.length) {
|
24740 | pendingAttributes[key] = value;
|
24741 | } else {
|
24742 |
|
24743 |
|
24744 | var parentKey = find_1(pendingKeys, function (k) {
|
24745 | return key.indexOf(k) === 0;
|
24746 | });
|
24747 |
|
24748 | if (parentKey) {
|
24749 | setValue(pendingAttributes[parentKey], key.slice(parentKey.length + 1), value);
|
24750 | } else {
|
24751 | pendingAttributes[key] = value;
|
24752 | }
|
24753 | }
|
24754 |
|
24755 | this._buildCurrentAttributes();
|
24756 |
|
24757 | return this;
|
24758 | };
|
24759 |
|
24760 | _proto._buildCurrentAttributes = function _buildCurrentAttributes() {
|
24761 | var _internal2 = internal(this),
|
24762 | pendingAttributes = _internal2.pendingAttributes;
|
24763 |
|
24764 | internal(this).currentAttributes = Object.keys(pendingAttributes).reduce(function (target, k) {
|
24765 | return setValue(target, k, pendingAttributes[k]);
|
24766 | }, cloneDeep_1(this._attributes));
|
24767 | };
|
24768 |
|
24769 | _proto._updateServerAttributes = function _updateServerAttributes(attributes) {
|
24770 | var _this2 = this;
|
24771 |
|
24772 | Object.keys(attributes).forEach(function (key) {
|
24773 | return setValue(_this2._attributes, key, attributes[key]);
|
24774 | });
|
24775 |
|
24776 | this._buildCurrentAttributes();
|
24777 | };
|
24778 |
|
24779 | _proto._reset = function _reset() {
|
24780 | Object.assign(internal(this), {
|
24781 | pendingAttributes: {},
|
24782 | currentAttributes: this._attributes
|
24783 | });
|
24784 | }
|
24785 | |
24786 |
|
24787 |
|
24788 |
|
24789 | ;
|
24790 |
|
24791 | _proto.save =
|
24792 |
|
24793 | function () {
|
24794 | var _save = _asyncToGenerator(
|
24795 |
|
24796 | regenerator.mark(function _callee() {
|
24797 | var attr, convMessage, resCommand;
|
24798 | return regenerator.wrap(function _callee$(_context) {
|
24799 | while (1) {
|
24800 | switch (_context.prev = _context.next) {
|
24801 | case 0:
|
24802 | this._debug('save');
|
24803 |
|
24804 | attr = internal(this).pendingAttributes;
|
24805 |
|
24806 | if (!isEmpty_1(attr)) {
|
24807 | _context.next = 5;
|
24808 | break;
|
24809 | }
|
24810 |
|
24811 | this._debug('nothing touched, resolve with self');
|
24812 |
|
24813 | return _context.abrupt("return", this);
|
24814 |
|
24815 | case 5:
|
24816 | this._debug('attr: %O', attr);
|
24817 |
|
24818 | convMessage = new ConvCommand({
|
24819 | attr: new JsonObjectMessage({
|
24820 | data: JSON.stringify(encode(attr))
|
24821 | })
|
24822 | });
|
24823 | _context.next = 9;
|
24824 | return this._send(new GenericCommand({
|
24825 | op: 'update',
|
24826 | convMessage: convMessage
|
24827 | }));
|
24828 |
|
24829 | case 9:
|
24830 | resCommand = _context.sent;
|
24831 | this.updatedAt = resCommand.convMessage.udate;
|
24832 | this._attributes = internal(this).currentAttributes;
|
24833 | internal(this).pendingAttributes = {};
|
24834 | return _context.abrupt("return", this);
|
24835 |
|
24836 | case 14:
|
24837 | case "end":
|
24838 | return _context.stop();
|
24839 | }
|
24840 | }
|
24841 | }, _callee, this);
|
24842 | }));
|
24843 |
|
24844 | function save() {
|
24845 | return _save.apply(this, arguments);
|
24846 | }
|
24847 |
|
24848 | return save;
|
24849 | }()
|
24850 | |
24851 |
|
24852 |
|
24853 |
|
24854 | ;
|
24855 |
|
24856 | _proto.fetch =
|
24857 |
|
24858 | function () {
|
24859 | var _fetch = _asyncToGenerator(
|
24860 |
|
24861 | regenerator.mark(function _callee2() {
|
24862 | var query;
|
24863 | return regenerator.wrap(function _callee2$(_context2) {
|
24864 | while (1) {
|
24865 | switch (_context2.prev = _context2.next) {
|
24866 | case 0:
|
24867 | query = this._client.getQuery().equalTo('objectId', this.id);
|
24868 | _context2.next = 3;
|
24869 | return query.find();
|
24870 |
|
24871 | case 3:
|
24872 | return _context2.abrupt("return", this);
|
24873 |
|
24874 | case 4:
|
24875 | case "end":
|
24876 | return _context2.stop();
|
24877 | }
|
24878 | }
|
24879 | }, _callee2, this);
|
24880 | }));
|
24881 |
|
24882 | function fetch() {
|
24883 | return _fetch.apply(this, arguments);
|
24884 | }
|
24885 |
|
24886 | return fetch;
|
24887 | }()
|
24888 | |
24889 |
|
24890 |
|
24891 |
|
24892 | ;
|
24893 |
|
24894 | _proto.mute =
|
24895 |
|
24896 | function () {
|
24897 | var _mute = _asyncToGenerator(
|
24898 |
|
24899 | regenerator.mark(function _callee3() {
|
24900 | return regenerator.wrap(function _callee3$(_context3) {
|
24901 | while (1) {
|
24902 | switch (_context3.prev = _context3.next) {
|
24903 | case 0:
|
24904 | this._debug('mute');
|
24905 |
|
24906 | _context3.next = 3;
|
24907 | return this._send(new GenericCommand({
|
24908 | op: 'mute'
|
24909 | }));
|
24910 |
|
24911 | case 3:
|
24912 | if (!this.transient) {
|
24913 | this.muted = true;
|
24914 | this.mutedMembers = union(this.mutedMembers, [this._client.id]);
|
24915 | }
|
24916 |
|
24917 | return _context3.abrupt("return", this);
|
24918 |
|
24919 | case 5:
|
24920 | case "end":
|
24921 | return _context3.stop();
|
24922 | }
|
24923 | }
|
24924 | }, _callee3, this);
|
24925 | }));
|
24926 |
|
24927 | function mute() {
|
24928 | return _mute.apply(this, arguments);
|
24929 | }
|
24930 |
|
24931 | return mute;
|
24932 | }()
|
24933 | |
24934 |
|
24935 |
|
24936 |
|
24937 | ;
|
24938 |
|
24939 | _proto.unmute =
|
24940 |
|
24941 | function () {
|
24942 | var _unmute = _asyncToGenerator(
|
24943 |
|
24944 | regenerator.mark(function _callee4() {
|
24945 | return regenerator.wrap(function _callee4$(_context4) {
|
24946 | while (1) {
|
24947 | switch (_context4.prev = _context4.next) {
|
24948 | case 0:
|
24949 | this._debug('unmute');
|
24950 |
|
24951 | _context4.next = 3;
|
24952 | return this._send(new GenericCommand({
|
24953 | op: 'unmute'
|
24954 | }));
|
24955 |
|
24956 | case 3:
|
24957 | if (!this.transient) {
|
24958 | this.muted = false;
|
24959 | this.mutedMembers = difference(this.mutedMembers, [this._client.id]);
|
24960 | }
|
24961 |
|
24962 | return _context4.abrupt("return", this);
|
24963 |
|
24964 | case 5:
|
24965 | case "end":
|
24966 | return _context4.stop();
|
24967 | }
|
24968 | }
|
24969 | }, _callee4, this);
|
24970 | }));
|
24971 |
|
24972 | function unmute() {
|
24973 | return _unmute.apply(this, arguments);
|
24974 | }
|
24975 |
|
24976 | return unmute;
|
24977 | }();
|
24978 |
|
24979 | _proto._appendConversationSignature =
|
24980 |
|
24981 | function () {
|
24982 | var _appendConversationSignature2 = _asyncToGenerator(
|
24983 |
|
24984 | regenerator.mark(function _callee5(command, action, clientIds) {
|
24985 | var params, signatureResult;
|
24986 | return regenerator.wrap(function _callee5$(_context5) {
|
24987 | while (1) {
|
24988 | switch (_context5.prev = _context5.next) {
|
24989 | case 0:
|
24990 | if (!this._client.options.conversationSignatureFactory) {
|
24991 | _context5.next = 6;
|
24992 | break;
|
24993 | }
|
24994 |
|
24995 | params = [this.id, this._client.id, clientIds.sort(), action];
|
24996 | _context5.next = 4;
|
24997 | return runSignatureFactory(this._client.options.conversationSignatureFactory, params);
|
24998 |
|
24999 | case 4:
|
25000 | signatureResult = _context5.sent;
|
25001 | Object.assign(command.convMessage, keyRemap({
|
25002 | signature: 's',
|
25003 | timestamp: 't',
|
25004 | nonce: 'n'
|
25005 | }, signatureResult));
|
25006 |
|
25007 | case 6:
|
25008 | case "end":
|
25009 | return _context5.stop();
|
25010 | }
|
25011 | }
|
25012 | }, _callee5, this);
|
25013 | }));
|
25014 |
|
25015 | function _appendConversationSignature(_x, _x2, _x3) {
|
25016 | return _appendConversationSignature2.apply(this, arguments);
|
25017 | }
|
25018 |
|
25019 | return _appendConversationSignature;
|
25020 | }();
|
25021 |
|
25022 | _proto._appendBlacklistSignature =
|
25023 |
|
25024 | function () {
|
25025 | var _appendBlacklistSignature2 = _asyncToGenerator(
|
25026 |
|
25027 | regenerator.mark(function _callee6(command, action, clientIds) {
|
25028 | var params, signatureResult;
|
25029 | return regenerator.wrap(function _callee6$(_context6) {
|
25030 | while (1) {
|
25031 | switch (_context6.prev = _context6.next) {
|
25032 | case 0:
|
25033 | if (!this._client.options.blacklistSignatureFactory) {
|
25034 | _context6.next = 6;
|
25035 | break;
|
25036 | }
|
25037 |
|
25038 | params = [this._client.id, this.id, clientIds.sort(), action];
|
25039 | _context6.next = 4;
|
25040 | return runSignatureFactory(this._client.options.blacklistSignatureFactory, params);
|
25041 |
|
25042 | case 4:
|
25043 | signatureResult = _context6.sent;
|
25044 | Object.assign(command.blacklistMessage, keyRemap({
|
25045 | signature: 's',
|
25046 | timestamp: 't',
|
25047 | nonce: 'n'
|
25048 | }, signatureResult));
|
25049 |
|
25050 | case 6:
|
25051 | case "end":
|
25052 | return _context6.stop();
|
25053 | }
|
25054 | }
|
25055 | }, _callee6, this);
|
25056 | }));
|
25057 |
|
25058 | function _appendBlacklistSignature(_x4, _x5, _x6) {
|
25059 | return _appendBlacklistSignature2.apply(this, arguments);
|
25060 | }
|
25061 |
|
25062 | return _appendBlacklistSignature;
|
25063 | }()
|
25064 | |
25065 |
|
25066 |
|
25067 |
|
25068 |
|
25069 | ;
|
25070 |
|
25071 | _proto.add =
|
25072 |
|
25073 | function () {
|
25074 | var _add = _asyncToGenerator(
|
25075 |
|
25076 | regenerator.mark(function _callee7(clientIds) {
|
25077 | var command, _ref4, convMessage, allowedPids;
|
25078 |
|
25079 | return regenerator.wrap(function _callee7$(_context7) {
|
25080 | while (1) {
|
25081 | switch (_context7.prev = _context7.next) {
|
25082 | case 0:
|
25083 | this._debug('add', clientIds);
|
25084 |
|
25085 | if (typeof clientIds === 'string') {
|
25086 | clientIds = [clientIds];
|
25087 | }
|
25088 |
|
25089 | command = new GenericCommand({
|
25090 | op: 'add',
|
25091 | convMessage: new ConvCommand({
|
25092 | m: clientIds
|
25093 | })
|
25094 | });
|
25095 | _context7.next = 5;
|
25096 | return this._appendConversationSignature(command, 'add', clientIds);
|
25097 |
|
25098 | case 5:
|
25099 | _context7.next = 7;
|
25100 | return this._send(command);
|
25101 |
|
25102 | case 7:
|
25103 | _ref4 = _context7.sent;
|
25104 | convMessage = _ref4.convMessage;
|
25105 | allowedPids = _ref4.convMessage.allowedPids;
|
25106 |
|
25107 | this._addMembers(allowedPids);
|
25108 |
|
25109 | return _context7.abrupt("return", createPartiallySuccess(convMessage));
|
25110 |
|
25111 | case 12:
|
25112 | case "end":
|
25113 | return _context7.stop();
|
25114 | }
|
25115 | }
|
25116 | }, _callee7, this);
|
25117 | }));
|
25118 |
|
25119 | function add(_x7) {
|
25120 | return _add.apply(this, arguments);
|
25121 | }
|
25122 |
|
25123 | return add;
|
25124 | }()
|
25125 | |
25126 |
|
25127 |
|
25128 |
|
25129 |
|
25130 | ;
|
25131 |
|
25132 | _proto.remove =
|
25133 |
|
25134 | function () {
|
25135 | var _remove = _asyncToGenerator(
|
25136 |
|
25137 | regenerator.mark(function _callee8(clientIds) {
|
25138 | var command, _ref5, convMessage, allowedPids;
|
25139 |
|
25140 | return regenerator.wrap(function _callee8$(_context8) {
|
25141 | while (1) {
|
25142 | switch (_context8.prev = _context8.next) {
|
25143 | case 0:
|
25144 | this._debug('remove', clientIds);
|
25145 |
|
25146 | if (typeof clientIds === 'string') {
|
25147 | clientIds = [clientIds];
|
25148 | }
|
25149 |
|
25150 | command = new GenericCommand({
|
25151 | op: 'remove',
|
25152 | convMessage: new ConvCommand({
|
25153 | m: clientIds
|
25154 | })
|
25155 | });
|
25156 | _context8.next = 5;
|
25157 | return this._appendConversationSignature(command, 'remove', clientIds);
|
25158 |
|
25159 | case 5:
|
25160 | _context8.next = 7;
|
25161 | return this._send(command);
|
25162 |
|
25163 | case 7:
|
25164 | _ref5 = _context8.sent;
|
25165 | convMessage = _ref5.convMessage;
|
25166 | allowedPids = _ref5.convMessage.allowedPids;
|
25167 |
|
25168 | this._removeMembers(allowedPids);
|
25169 |
|
25170 | return _context8.abrupt("return", createPartiallySuccess(convMessage));
|
25171 |
|
25172 | case 12:
|
25173 | case "end":
|
25174 | return _context8.stop();
|
25175 | }
|
25176 | }
|
25177 | }, _callee8, this);
|
25178 | }));
|
25179 |
|
25180 | function remove(_x8) {
|
25181 | return _remove.apply(this, arguments);
|
25182 | }
|
25183 |
|
25184 | return remove;
|
25185 | }()
|
25186 | |
25187 |
|
25188 |
|
25189 |
|
25190 | ;
|
25191 |
|
25192 | _proto.join =
|
25193 |
|
25194 | function () {
|
25195 | var _join = _asyncToGenerator(
|
25196 |
|
25197 | regenerator.mark(function _callee9() {
|
25198 | var _this3 = this;
|
25199 |
|
25200 | return regenerator.wrap(function _callee9$(_context9) {
|
25201 | while (1) {
|
25202 | switch (_context9.prev = _context9.next) {
|
25203 | case 0:
|
25204 | this._debug('join');
|
25205 |
|
25206 | return _context9.abrupt("return", this.add(this._client.id).then(function (_ref6) {
|
25207 | var failures = _ref6.failures;
|
25208 | if (failures[0]) throw failures[0];
|
25209 | return _this3;
|
25210 | }));
|
25211 |
|
25212 | case 2:
|
25213 | case "end":
|
25214 | return _context9.stop();
|
25215 | }
|
25216 | }
|
25217 | }, _callee9, this);
|
25218 | }));
|
25219 |
|
25220 | function join() {
|
25221 | return _join.apply(this, arguments);
|
25222 | }
|
25223 |
|
25224 | return join;
|
25225 | }()
|
25226 | |
25227 |
|
25228 |
|
25229 |
|
25230 | ;
|
25231 |
|
25232 | _proto.quit =
|
25233 |
|
25234 | function () {
|
25235 | var _quit = _asyncToGenerator(
|
25236 |
|
25237 | regenerator.mark(function _callee10() {
|
25238 | var _this4 = this;
|
25239 |
|
25240 | return regenerator.wrap(function _callee10$(_context10) {
|
25241 | while (1) {
|
25242 | switch (_context10.prev = _context10.next) {
|
25243 | case 0:
|
25244 | this._debug('quit');
|
25245 |
|
25246 | return _context10.abrupt("return", this.remove(this._client.id).then(function (_ref7) {
|
25247 | var failures = _ref7.failures;
|
25248 | if (failures[0]) throw failures[0];
|
25249 | return _this4;
|
25250 | }));
|
25251 |
|
25252 | case 2:
|
25253 | case "end":
|
25254 | return _context10.stop();
|
25255 | }
|
25256 | }
|
25257 | }, _callee10, this);
|
25258 | }));
|
25259 |
|
25260 | function quit() {
|
25261 | return _quit.apply(this, arguments);
|
25262 | }
|
25263 |
|
25264 | return quit;
|
25265 | }()
|
25266 | |
25267 |
|
25268 |
|
25269 |
|
25270 |
|
25271 | ;
|
25272 |
|
25273 | _proto.muteMembers =
|
25274 |
|
25275 | function () {
|
25276 | var _muteMembers = _asyncToGenerator(
|
25277 |
|
25278 | regenerator.mark(function _callee11(clientIds) {
|
25279 | var command, _ref8, convMessage;
|
25280 |
|
25281 | return regenerator.wrap(function _callee11$(_context11) {
|
25282 | while (1) {
|
25283 | switch (_context11.prev = _context11.next) {
|
25284 | case 0:
|
25285 | this._debug('mute', clientIds);
|
25286 |
|
25287 | clientIds = ensureArray(clientIds);
|
25288 |
|
25289 | command = new GenericCommand({
|
25290 | op: OpType.add_shutup,
|
25291 | convMessage: new ConvCommand({
|
25292 | m: clientIds
|
25293 | })
|
25294 | });
|
25295 | _context11.next = 5;
|
25296 | return this._send(command);
|
25297 |
|
25298 | case 5:
|
25299 | _ref8 = _context11.sent;
|
25300 | convMessage = _ref8.convMessage;
|
25301 | return _context11.abrupt("return", createPartiallySuccess(convMessage));
|
25302 |
|
25303 | case 8:
|
25304 | case "end":
|
25305 | return _context11.stop();
|
25306 | }
|
25307 | }
|
25308 | }, _callee11, this);
|
25309 | }));
|
25310 |
|
25311 | function muteMembers(_x9) {
|
25312 | return _muteMembers.apply(this, arguments);
|
25313 | }
|
25314 |
|
25315 | return muteMembers;
|
25316 | }()
|
25317 | |
25318 |
|
25319 |
|
25320 |
|
25321 |
|
25322 | ;
|
25323 |
|
25324 | _proto.unmuteMembers =
|
25325 |
|
25326 | function () {
|
25327 | var _unmuteMembers = _asyncToGenerator(
|
25328 |
|
25329 | regenerator.mark(function _callee12(clientIds) {
|
25330 | var command, _ref9, convMessage;
|
25331 |
|
25332 | return regenerator.wrap(function _callee12$(_context12) {
|
25333 | while (1) {
|
25334 | switch (_context12.prev = _context12.next) {
|
25335 | case 0:
|
25336 | this._debug('unmute', clientIds);
|
25337 |
|
25338 | clientIds = ensureArray(clientIds);
|
25339 |
|
25340 | command = new GenericCommand({
|
25341 | op: OpType.remove_shutup,
|
25342 | convMessage: new ConvCommand({
|
25343 | m: clientIds
|
25344 | })
|
25345 | });
|
25346 | _context12.next = 5;
|
25347 | return this._send(command);
|
25348 |
|
25349 | case 5:
|
25350 | _ref9 = _context12.sent;
|
25351 | convMessage = _ref9.convMessage;
|
25352 | return _context12.abrupt("return", createPartiallySuccess(convMessage));
|
25353 |
|
25354 | case 8:
|
25355 | case "end":
|
25356 | return _context12.stop();
|
25357 | }
|
25358 | }
|
25359 | }, _callee12, this);
|
25360 | }));
|
25361 |
|
25362 | function unmuteMembers(_x10) {
|
25363 | return _unmuteMembers.apply(this, arguments);
|
25364 | }
|
25365 |
|
25366 | return unmuteMembers;
|
25367 | }()
|
25368 | |
25369 |
|
25370 |
|
25371 |
|
25372 |
|
25373 |
|
25374 |
|
25375 | ;
|
25376 |
|
25377 | _proto.queryMutedMembers =
|
25378 |
|
25379 | function () {
|
25380 | var _queryMutedMembers = _asyncToGenerator(
|
25381 |
|
25382 | regenerator.mark(function _callee13() {
|
25383 | var _ref10,
|
25384 | limit,
|
25385 | next,
|
25386 | command,
|
25387 | _ref11,
|
25388 | _ref11$convMessage,
|
25389 | m,
|
25390 | newNext,
|
25391 | _args13 = arguments;
|
25392 |
|
25393 | return regenerator.wrap(function _callee13$(_context13) {
|
25394 | while (1) {
|
25395 | switch (_context13.prev = _context13.next) {
|
25396 | case 0:
|
25397 | _ref10 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, limit = _ref10.limit, next = _ref10.next;
|
25398 |
|
25399 | this._debug('query muted: limit %O, next: %O', limit, next);
|
25400 |
|
25401 | command = new GenericCommand({
|
25402 | op: OpType.query_shutup,
|
25403 | convMessage: new ConvCommand({
|
25404 | limit: limit,
|
25405 | next: next
|
25406 | })
|
25407 | });
|
25408 | _context13.next = 5;
|
25409 | return this._send(command);
|
25410 |
|
25411 | case 5:
|
25412 | _ref11 = _context13.sent;
|
25413 | _ref11$convMessage = _ref11.convMessage;
|
25414 | m = _ref11$convMessage.m;
|
25415 | newNext = _ref11$convMessage.next;
|
25416 | return _context13.abrupt("return", {
|
25417 | results: m,
|
25418 | next: newNext
|
25419 | });
|
25420 |
|
25421 | case 10:
|
25422 | case "end":
|
25423 | return _context13.stop();
|
25424 | }
|
25425 | }
|
25426 | }, _callee13, this);
|
25427 | }));
|
25428 |
|
25429 | function queryMutedMembers() {
|
25430 | return _queryMutedMembers.apply(this, arguments);
|
25431 | }
|
25432 |
|
25433 | return queryMutedMembers;
|
25434 | }()
|
25435 | |
25436 |
|
25437 |
|
25438 |
|
25439 |
|
25440 | ;
|
25441 |
|
25442 | _proto.blockMembers =
|
25443 |
|
25444 | function () {
|
25445 | var _blockMembers = _asyncToGenerator(
|
25446 |
|
25447 | regenerator.mark(function _callee14(clientIds) {
|
25448 | var command, _ref12, blacklistMessage;
|
25449 |
|
25450 | return regenerator.wrap(function _callee14$(_context14) {
|
25451 | while (1) {
|
25452 | switch (_context14.prev = _context14.next) {
|
25453 | case 0:
|
25454 | this._debug('block', clientIds);
|
25455 |
|
25456 | clientIds = ensureArray(clientIds);
|
25457 |
|
25458 | command = new GenericCommand({
|
25459 | cmd: 'blacklist',
|
25460 | op: OpType.block,
|
25461 | blacklistMessage: new BlacklistCommand({
|
25462 | srcCid: this.id,
|
25463 | toPids: clientIds
|
25464 | })
|
25465 | });
|
25466 | _context14.next = 5;
|
25467 | return this._appendBlacklistSignature(command, 'conversation-block-clients', clientIds);
|
25468 |
|
25469 | case 5:
|
25470 | _context14.next = 7;
|
25471 | return this._send(command);
|
25472 |
|
25473 | case 7:
|
25474 | _ref12 = _context14.sent;
|
25475 | blacklistMessage = _ref12.blacklistMessage;
|
25476 | return _context14.abrupt("return", createPartiallySuccess(blacklistMessage));
|
25477 |
|
25478 | case 10:
|
25479 | case "end":
|
25480 | return _context14.stop();
|
25481 | }
|
25482 | }
|
25483 | }, _callee14, this);
|
25484 | }));
|
25485 |
|
25486 | function blockMembers(_x11) {
|
25487 | return _blockMembers.apply(this, arguments);
|
25488 | }
|
25489 |
|
25490 | return blockMembers;
|
25491 | }()
|
25492 | |
25493 |
|
25494 |
|
25495 |
|
25496 |
|
25497 | ;
|
25498 |
|
25499 | _proto.unblockMembers =
|
25500 |
|
25501 | function () {
|
25502 | var _unblockMembers = _asyncToGenerator(
|
25503 |
|
25504 | regenerator.mark(function _callee15(clientIds) {
|
25505 | var command, _ref13, blacklistMessage;
|
25506 |
|
25507 | return regenerator.wrap(function _callee15$(_context15) {
|
25508 | while (1) {
|
25509 | switch (_context15.prev = _context15.next) {
|
25510 | case 0:
|
25511 | this._debug('unblock', clientIds);
|
25512 |
|
25513 | clientIds = ensureArray(clientIds);
|
25514 |
|
25515 | command = new GenericCommand({
|
25516 | cmd: 'blacklist',
|
25517 | op: OpType.unblock,
|
25518 | blacklistMessage: new BlacklistCommand({
|
25519 | srcCid: this.id,
|
25520 | toPids: clientIds
|
25521 | })
|
25522 | });
|
25523 | _context15.next = 5;
|
25524 | return this._appendBlacklistSignature(command, 'conversation-unblock-clients', clientIds);
|
25525 |
|
25526 | case 5:
|
25527 | _context15.next = 7;
|
25528 | return this._send(command);
|
25529 |
|
25530 | case 7:
|
25531 | _ref13 = _context15.sent;
|
25532 | blacklistMessage = _ref13.blacklistMessage;
|
25533 | return _context15.abrupt("return", createPartiallySuccess(blacklistMessage));
|
25534 |
|
25535 | case 10:
|
25536 | case "end":
|
25537 | return _context15.stop();
|
25538 | }
|
25539 | }
|
25540 | }, _callee15, this);
|
25541 | }));
|
25542 |
|
25543 | function unblockMembers(_x12) {
|
25544 | return _unblockMembers.apply(this, arguments);
|
25545 | }
|
25546 |
|
25547 | return unblockMembers;
|
25548 | }()
|
25549 | |
25550 |
|
25551 |
|
25552 |
|
25553 |
|
25554 |
|
25555 |
|
25556 | ;
|
25557 |
|
25558 | _proto.queryBlockedMembers =
|
25559 |
|
25560 | function () {
|
25561 | var _queryBlockedMembers = _asyncToGenerator(
|
25562 |
|
25563 | regenerator.mark(function _callee16() {
|
25564 | var _ref14,
|
25565 | limit,
|
25566 | next,
|
25567 | command,
|
25568 | _ref15,
|
25569 | _ref15$blacklistMessa,
|
25570 | blockedPids,
|
25571 | newNext,
|
25572 | _args16 = arguments;
|
25573 |
|
25574 | return regenerator.wrap(function _callee16$(_context16) {
|
25575 | while (1) {
|
25576 | switch (_context16.prev = _context16.next) {
|
25577 | case 0:
|
25578 | _ref14 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, limit = _ref14.limit, next = _ref14.next;
|
25579 |
|
25580 | this._debug('query blocked: limit %O, next: %O', limit, next);
|
25581 |
|
25582 | command = new GenericCommand({
|
25583 | cmd: 'blacklist',
|
25584 | op: OpType.query,
|
25585 | blacklistMessage: new BlacklistCommand({
|
25586 | srcCid: this.id,
|
25587 | limit: limit,
|
25588 | next: next
|
25589 | })
|
25590 | });
|
25591 | _context16.next = 5;
|
25592 | return this._send(command);
|
25593 |
|
25594 | case 5:
|
25595 | _ref15 = _context16.sent;
|
25596 | _ref15$blacklistMessa = _ref15.blacklistMessage;
|
25597 | blockedPids = _ref15$blacklistMessa.blockedPids;
|
25598 | newNext = _ref15$blacklistMessa.next;
|
25599 | return _context16.abrupt("return", {
|
25600 | results: blockedPids,
|
25601 | next: newNext
|
25602 | });
|
25603 |
|
25604 | case 10:
|
25605 | case "end":
|
25606 | return _context16.stop();
|
25607 | }
|
25608 | }
|
25609 | }, _callee16, this);
|
25610 | }));
|
25611 |
|
25612 | function queryBlockedMembers() {
|
25613 | return _queryBlockedMembers.apply(this, arguments);
|
25614 | }
|
25615 |
|
25616 | return queryBlockedMembers;
|
25617 | }();
|
25618 |
|
25619 | _proto.toFullJSON = function toFullJSON() {
|
25620 | var creator = this.creator,
|
25621 | system = this.system,
|
25622 | transient = this.transient,
|
25623 | createdAt = this.createdAt,
|
25624 | updatedAt = this.updatedAt,
|
25625 | _attributes = this._attributes;
|
25626 | return _objectSpread({}, _ConversationBase.prototype.toFullJSON.call(this), {
|
25627 | creator: creator,
|
25628 | system: system,
|
25629 | transient: transient,
|
25630 | createdAt: getTime(createdAt),
|
25631 | updatedAt: getTime(updatedAt)
|
25632 | }, _attributes);
|
25633 | };
|
25634 |
|
25635 | _proto.toJSON = function toJSON() {
|
25636 | var creator = this.creator,
|
25637 | system = this.system,
|
25638 | transient = this.transient,
|
25639 | muted = this.muted,
|
25640 | mutedMembers = this.mutedMembers,
|
25641 | createdAt = this.createdAt,
|
25642 | updatedAt = this.updatedAt,
|
25643 | _attributes = this._attributes;
|
25644 | return _objectSpread({}, _ConversationBase.prototype.toJSON.call(this), {
|
25645 | creator: creator,
|
25646 | system: system,
|
25647 | transient: transient,
|
25648 | muted: muted,
|
25649 | mutedMembers: mutedMembers,
|
25650 | createdAt: createdAt,
|
25651 | updatedAt: updatedAt
|
25652 | }, _attributes);
|
25653 | };
|
25654 |
|
25655 | _createClass(PersistentConversation, [{
|
25656 | key: "createdAt",
|
25657 | set: function set(value) {
|
25658 | this._createdAt = decodeDate(value);
|
25659 | },
|
25660 | get: function get() {
|
25661 | return this._createdAt;
|
25662 | }
|
25663 | }, {
|
25664 | key: "updatedAt",
|
25665 | set: function set(value) {
|
25666 | this._updatedAt = decodeDate(value);
|
25667 | },
|
25668 | get: function get() {
|
25669 | return this._updatedAt;
|
25670 | }
|
25671 | |
25672 |
|
25673 |
|
25674 |
|
25675 |
|
25676 | }, {
|
25677 | key: "name",
|
25678 | get: function get() {
|
25679 | return this.get('name');
|
25680 | },
|
25681 | set: function set(value) {
|
25682 | this.set('name', value);
|
25683 | }
|
25684 | }]);
|
25685 |
|
25686 | return PersistentConversation;
|
25687 | }(ConversationBase);
|
25688 |
|
25689 | |
25690 |
|
25691 |
|
25692 |
|
25693 |
|
25694 |
|
25695 |
|
25696 | var ConversationMemberRole = {
|
25697 |
|
25698 | OWNER: 'Owner',
|
25699 |
|
25700 |
|
25701 | MANAGER: 'Manager',
|
25702 |
|
25703 |
|
25704 | MEMBER: 'Member'
|
25705 | };
|
25706 | Object.freeze(ConversationMemberRole);
|
25707 |
|
25708 | var ConversationMemberInfo =
|
25709 |
|
25710 | function () {
|
25711 | |
25712 |
|
25713 |
|
25714 |
|
25715 | function ConversationMemberInfo(_ref) {
|
25716 | var conversation = _ref.conversation,
|
25717 | memberId = _ref.memberId,
|
25718 | role = _ref.role;
|
25719 | if (!conversation) throw new Error('conversation requried');
|
25720 | if (!memberId) throw new Error('memberId requried');
|
25721 | Object.assign(internal(this), {
|
25722 | conversation: conversation,
|
25723 | memberId: memberId,
|
25724 | role: role
|
25725 | });
|
25726 | }
|
25727 | |
25728 |
|
25729 |
|
25730 |
|
25731 |
|
25732 |
|
25733 |
|
25734 | var _proto = ConversationMemberInfo.prototype;
|
25735 |
|
25736 | _proto.toJSON = function toJSON() {
|
25737 | var conversationId = this.conversationId,
|
25738 | memberId = this.memberId,
|
25739 | role = this.role,
|
25740 | isOwner = this.isOwner;
|
25741 | return {
|
25742 | conversationId: conversationId,
|
25743 | memberId: memberId,
|
25744 | role: role,
|
25745 | isOwner: isOwner
|
25746 | };
|
25747 | };
|
25748 |
|
25749 | _createClass(ConversationMemberInfo, [{
|
25750 | key: "conversationId",
|
25751 | get: function get() {
|
25752 | return internal(this).conversation.id;
|
25753 | }
|
25754 | |
25755 |
|
25756 |
|
25757 |
|
25758 |
|
25759 |
|
25760 | }, {
|
25761 | key: "memberId",
|
25762 | get: function get() {
|
25763 | return internal(this).memberId;
|
25764 | }
|
25765 | |
25766 |
|
25767 |
|
25768 |
|
25769 |
|
25770 |
|
25771 | }, {
|
25772 | key: "role",
|
25773 | get: function get() {
|
25774 | if (this.isOwner) return ConversationMemberRole.OWNER;
|
25775 | return internal(this).role;
|
25776 | }
|
25777 | |
25778 |
|
25779 |
|
25780 |
|
25781 |
|
25782 |
|
25783 | }, {
|
25784 | key: "isOwner",
|
25785 | get: function get() {
|
25786 | return this.memberId === internal(this).conversation.creator;
|
25787 | }
|
25788 | }]);
|
25789 |
|
25790 | return ConversationMemberInfo;
|
25791 | }();
|
25792 |
|
25793 | |
25794 |
|
25795 |
|
25796 |
|
25797 |
|
25798 |
|
25799 |
|
25800 |
|
25801 | var Conversation =
|
25802 |
|
25803 | function (_PersistentConversati) {
|
25804 | _inheritsLoose(Conversation, _PersistentConversati);
|
25805 |
|
25806 | function Conversation() {
|
25807 | return _PersistentConversati.apply(this, arguments) || this;
|
25808 | }
|
25809 |
|
25810 | var _proto = Conversation.prototype;
|
25811 |
|
25812 | _proto._addMembers = function _addMembers(members) {
|
25813 | var _this = this;
|
25814 |
|
25815 | _PersistentConversati.prototype._addMembers.call(this, members);
|
25816 |
|
25817 | this.members = union(this.members, members);
|
25818 |
|
25819 | var _internal = internal(this),
|
25820 | memberInfoMap = _internal.memberInfoMap;
|
25821 |
|
25822 | if (!memberInfoMap) return;
|
25823 | members.forEach(function (memberId) {
|
25824 | memberInfoMap[memberId] = memberInfoMap[memberId] || new ConversationMemberInfo({
|
25825 | conversation: _this,
|
25826 | memberId: memberId,
|
25827 | role: ConversationMemberRole.MEMBER
|
25828 | });
|
25829 | });
|
25830 | };
|
25831 |
|
25832 | _proto._removeMembers = function _removeMembers(members) {
|
25833 | _PersistentConversati.prototype._removeMembers.call(this, members);
|
25834 |
|
25835 | this.members = difference(this.members, members);
|
25836 |
|
25837 | var _internal2 = internal(this),
|
25838 | memberInfoMap = _internal2.memberInfoMap;
|
25839 |
|
25840 | if (!memberInfoMap) return;
|
25841 | members.forEach(function (memberId) {
|
25842 | delete memberInfoMap[memberId];
|
25843 | });
|
25844 | };
|
25845 |
|
25846 | _proto._fetchAllMemberInfo =
|
25847 |
|
25848 | function () {
|
25849 | var _fetchAllMemberInfo2 = _asyncToGenerator(
|
25850 |
|
25851 | regenerator.mark(function _callee() {
|
25852 | var _this2 = this;
|
25853 |
|
25854 | var response, memberInfos, memberInfoMap;
|
25855 | return regenerator.wrap(function _callee$(_context) {
|
25856 | while (1) {
|
25857 | switch (_context.prev = _context.next) {
|
25858 | case 0:
|
25859 | _context.next = 2;
|
25860 | return this._client._requestWithSessionToken({
|
25861 | method: 'GET',
|
25862 | path: '/classes/_ConversationMemberInfo',
|
25863 | query: {
|
25864 | where: {
|
25865 | cid: this.id
|
25866 | }
|
25867 | }
|
25868 | });
|
25869 |
|
25870 | case 2:
|
25871 | response = _context.sent;
|
25872 | memberInfos = response.results.map(function (info) {
|
25873 | return new ConversationMemberInfo({
|
25874 | conversation: _this2,
|
25875 | memberId: info.clientId,
|
25876 | role: info.role
|
25877 | });
|
25878 | });
|
25879 | memberInfoMap = {};
|
25880 | memberInfos.forEach(function (memberInfo) {
|
25881 | memberInfoMap[memberInfo.memberId] = memberInfo;
|
25882 | });
|
25883 | this.members.forEach(function (memberId) {
|
25884 | memberInfoMap[memberId] = memberInfoMap[memberId] || new ConversationMemberInfo({
|
25885 | conversation: _this2,
|
25886 | memberId: memberId,
|
25887 | role: ConversationMemberRole.MEMBER
|
25888 | });
|
25889 | });
|
25890 | internal(this).memberInfoMap = memberInfoMap;
|
25891 | return _context.abrupt("return", memberInfoMap);
|
25892 |
|
25893 | case 9:
|
25894 | case "end":
|
25895 | return _context.stop();
|
25896 | }
|
25897 | }
|
25898 | }, _callee, this);
|
25899 | }));
|
25900 |
|
25901 | function _fetchAllMemberInfo() {
|
25902 | return _fetchAllMemberInfo2.apply(this, arguments);
|
25903 | }
|
25904 |
|
25905 | return _fetchAllMemberInfo;
|
25906 | }()
|
25907 | |
25908 |
|
25909 |
|
25910 |
|
25911 |
|
25912 | ;
|
25913 |
|
25914 | _proto.getAllMemberInfo =
|
25915 |
|
25916 | function () {
|
25917 | var _getAllMemberInfo = _asyncToGenerator(
|
25918 |
|
25919 | regenerator.mark(function _callee2() {
|
25920 | var _ref,
|
25921 | _ref$noCache,
|
25922 | noCache,
|
25923 | _internal3,
|
25924 | memberInfoMap,
|
25925 | _args2 = arguments;
|
25926 |
|
25927 | return regenerator.wrap(function _callee2$(_context2) {
|
25928 | while (1) {
|
25929 | switch (_context2.prev = _context2.next) {
|
25930 | case 0:
|
25931 | _ref = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref$noCache = _ref.noCache, noCache = _ref$noCache === void 0 ? false : _ref$noCache;
|
25932 | _internal3 = internal(this), memberInfoMap = _internal3.memberInfoMap;
|
25933 |
|
25934 | if (!(!memberInfoMap || noCache)) {
|
25935 | _context2.next = 6;
|
25936 | break;
|
25937 | }
|
25938 |
|
25939 | _context2.next = 5;
|
25940 | return this._fetchAllMemberInfo();
|
25941 |
|
25942 | case 5:
|
25943 | memberInfoMap = _context2.sent;
|
25944 |
|
25945 | case 6:
|
25946 | return _context2.abrupt("return", this.members.map(function (memberId) {
|
25947 | return memberInfoMap[memberId];
|
25948 | }));
|
25949 |
|
25950 | case 7:
|
25951 | case "end":
|
25952 | return _context2.stop();
|
25953 | }
|
25954 | }
|
25955 | }, _callee2, this);
|
25956 | }));
|
25957 |
|
25958 | function getAllMemberInfo() {
|
25959 | return _getAllMemberInfo.apply(this, arguments);
|
25960 | }
|
25961 |
|
25962 | return getAllMemberInfo;
|
25963 | }()
|
25964 | |
25965 |
|
25966 |
|
25967 |
|
25968 |
|
25969 |
|
25970 | ;
|
25971 |
|
25972 | _proto.getMemberInfo =
|
25973 |
|
25974 | function () {
|
25975 | var _getMemberInfo = _asyncToGenerator(
|
25976 |
|
25977 | regenerator.mark(function _callee3(memberId) {
|
25978 | var _internal4, memberInfoMap;
|
25979 |
|
25980 | return regenerator.wrap(function _callee3$(_context3) {
|
25981 | while (1) {
|
25982 | switch (_context3.prev = _context3.next) {
|
25983 | case 0:
|
25984 | if (!(this.members.indexOf(memberId) === -1)) {
|
25985 | _context3.next = 2;
|
25986 | break;
|
25987 | }
|
25988 |
|
25989 | throw new Error("".concat(memberId, " is not the mumber of conversation[").concat(this.id, "]"));
|
25990 |
|
25991 | case 2:
|
25992 | _internal4 = internal(this), memberInfoMap = _internal4.memberInfoMap;
|
25993 |
|
25994 | if (memberInfoMap && memberInfoMap[memberId]) {
|
25995 | _context3.next = 6;
|
25996 | break;
|
25997 | }
|
25998 |
|
25999 | _context3.next = 6;
|
26000 | return this.getAllMemberInfo();
|
26001 |
|
26002 | case 6:
|
26003 | return _context3.abrupt("return", internal(this).memberInfoMap[memberId]);
|
26004 |
|
26005 | case 7:
|
26006 | case "end":
|
26007 | return _context3.stop();
|
26008 | }
|
26009 | }
|
26010 | }, _callee3, this);
|
26011 | }));
|
26012 |
|
26013 | function getMemberInfo(_x) {
|
26014 | return _getMemberInfo.apply(this, arguments);
|
26015 | }
|
26016 |
|
26017 | return getMemberInfo;
|
26018 | }()
|
26019 | |
26020 |
|
26021 |
|
26022 |
|
26023 |
|
26024 |
|
26025 |
|
26026 | ;
|
26027 |
|
26028 | _proto.updateMemberRole =
|
26029 |
|
26030 | function () {
|
26031 | var _updateMemberRole = _asyncToGenerator(
|
26032 |
|
26033 | regenerator.mark(function _callee4(memberId, role) {
|
26034 | var _internal5, memberInfos;
|
26035 |
|
26036 | return regenerator.wrap(function _callee4$(_context4) {
|
26037 | while (1) {
|
26038 | switch (_context4.prev = _context4.next) {
|
26039 | case 0:
|
26040 | this._debug('update member role');
|
26041 |
|
26042 | if (!(role === ConversationMemberRole.OWNER)) {
|
26043 | _context4.next = 3;
|
26044 | break;
|
26045 | }
|
26046 |
|
26047 | throw createError({
|
26048 | code: ErrorCode.OWNER_PROMOTION_NOT_ALLOWED
|
26049 | });
|
26050 |
|
26051 | case 3:
|
26052 | _context4.next = 5;
|
26053 | return this._send(new GenericCommand({
|
26054 | op: OpType.member_info_update,
|
26055 | convMessage: new ConvCommand({
|
26056 | targetClientId: memberId,
|
26057 | info: new ConvMemberInfo({
|
26058 | pid: memberId,
|
26059 | role: role
|
26060 | })
|
26061 | })
|
26062 | }));
|
26063 |
|
26064 | case 5:
|
26065 | _internal5 = internal(this), memberInfos = _internal5.memberInfos;
|
26066 |
|
26067 | if (memberInfos && memberInfos[memberId]) {
|
26068 | internal(memberInfos[memberId]).role = role;
|
26069 | }
|
26070 |
|
26071 | return _context4.abrupt("return", this);
|
26072 |
|
26073 | case 8:
|
26074 | case "end":
|
26075 | return _context4.stop();
|
26076 | }
|
26077 | }
|
26078 | }, _callee4, this);
|
26079 | }));
|
26080 |
|
26081 | function updateMemberRole(_x2, _x3) {
|
26082 | return _updateMemberRole.apply(this, arguments);
|
26083 | }
|
26084 |
|
26085 | return updateMemberRole;
|
26086 | }();
|
26087 |
|
26088 | return Conversation;
|
26089 | }(PersistentConversation);
|
26090 |
|
26091 | |
26092 |
|
26093 |
|
26094 |
|
26095 |
|
26096 |
|
26097 |
|
26098 |
|
26099 |
|
26100 | var ChatRoom =
|
26101 |
|
26102 | function (_PersistentConversati) {
|
26103 | _inheritsLoose(ChatRoom, _PersistentConversati);
|
26104 |
|
26105 | function ChatRoom() {
|
26106 | return _PersistentConversati.apply(this, arguments) || this;
|
26107 | }
|
26108 |
|
26109 | return ChatRoom;
|
26110 | }(PersistentConversation);
|
26111 |
|
26112 | |
26113 |
|
26114 |
|
26115 |
|
26116 |
|
26117 |
|
26118 |
|
26119 |
|
26120 |
|
26121 | var ServiceConversation =
|
26122 |
|
26123 | function (_PersistentConversati) {
|
26124 | _inheritsLoose(ServiceConversation, _PersistentConversati);
|
26125 |
|
26126 | function ServiceConversation() {
|
26127 | return _PersistentConversati.apply(this, arguments) || this;
|
26128 | }
|
26129 |
|
26130 | var _proto = ServiceConversation.prototype;
|
26131 |
|
26132 | |
26133 |
|
26134 |
|
26135 |
|
26136 | _proto.subscribe =
|
26137 |
|
26138 | function () {
|
26139 | var _subscribe = _asyncToGenerator(
|
26140 |
|
26141 | regenerator.mark(function _callee() {
|
26142 | return regenerator.wrap(function _callee$(_context) {
|
26143 | while (1) {
|
26144 | switch (_context.prev = _context.next) {
|
26145 | case 0:
|
26146 | return _context.abrupt("return", this.join());
|
26147 |
|
26148 | case 1:
|
26149 | case "end":
|
26150 | return _context.stop();
|
26151 | }
|
26152 | }
|
26153 | }, _callee, this);
|
26154 | }));
|
26155 |
|
26156 | function subscribe() {
|
26157 | return _subscribe.apply(this, arguments);
|
26158 | }
|
26159 |
|
26160 | return subscribe;
|
26161 | }()
|
26162 | |
26163 |
|
26164 |
|
26165 |
|
26166 | ;
|
26167 |
|
26168 | _proto.unsubscribe =
|
26169 |
|
26170 | function () {
|
26171 | var _unsubscribe = _asyncToGenerator(
|
26172 |
|
26173 | regenerator.mark(function _callee2() {
|
26174 | return regenerator.wrap(function _callee2$(_context2) {
|
26175 | while (1) {
|
26176 | switch (_context2.prev = _context2.next) {
|
26177 | case 0:
|
26178 | return _context2.abrupt("return", this.quit());
|
26179 |
|
26180 | case 1:
|
26181 | case "end":
|
26182 | return _context2.stop();
|
26183 | }
|
26184 | }
|
26185 | }, _callee2, this);
|
26186 | }));
|
26187 |
|
26188 | function unsubscribe() {
|
26189 | return _unsubscribe.apply(this, arguments);
|
26190 | }
|
26191 |
|
26192 | return unsubscribe;
|
26193 | }();
|
26194 |
|
26195 | return ServiceConversation;
|
26196 | }(PersistentConversation);
|
26197 |
|
26198 | var transformNotFoundError = function transformNotFoundError(error) {
|
26199 | return error.code === ErrorCode.CONVERSATION_NOT_FOUND ? createError({
|
26200 | code: ErrorCode.TEMPORARY_CONVERSATION_EXPIRED
|
26201 | }) : error;
|
26202 | };
|
26203 | |
26204 |
|
26205 |
|
26206 |
|
26207 |
|
26208 |
|
26209 |
|
26210 |
|
26211 | var TemporaryConversation =
|
26212 |
|
26213 | function (_ConversationBase) {
|
26214 | _inheritsLoose(TemporaryConversation, _ConversationBase);
|
26215 |
|
26216 | |
26217 |
|
26218 |
|
26219 | function TemporaryConversation(data, _ref, client) {
|
26220 | var expiredAt = _ref.expiredAt;
|
26221 | return _ConversationBase.call(this, _objectSpread({}, data, {
|
26222 | expiredAt: expiredAt
|
26223 | }), client) || this;
|
26224 | }
|
26225 | |
26226 |
|
26227 |
|
26228 |
|
26229 |
|
26230 |
|
26231 | var _proto = TemporaryConversation.prototype;
|
26232 |
|
26233 | _proto._send =
|
26234 |
|
26235 | function () {
|
26236 | var _send2 = _asyncToGenerator(
|
26237 |
|
26238 | regenerator.mark(function _callee() {
|
26239 | var _ConversationBase$pro,
|
26240 | _len,
|
26241 | args,
|
26242 | _key,
|
26243 | _args = arguments;
|
26244 |
|
26245 | return regenerator.wrap(function _callee$(_context) {
|
26246 | while (1) {
|
26247 | switch (_context.prev = _context.next) {
|
26248 | case 0:
|
26249 | if (!this.expired) {
|
26250 | _context.next = 2;
|
26251 | break;
|
26252 | }
|
26253 |
|
26254 | throw createError({
|
26255 | code: ErrorCode.TEMPORARY_CONVERSATION_EXPIRED
|
26256 | });
|
26257 |
|
26258 | case 2:
|
26259 | _context.prev = 2;
|
26260 |
|
26261 | for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
26262 | args[_key] = _args[_key];
|
26263 | }
|
26264 |
|
26265 | _context.next = 6;
|
26266 | return (_ConversationBase$pro = _ConversationBase.prototype._send).call.apply(_ConversationBase$pro, [this].concat(args));
|
26267 |
|
26268 | case 6:
|
26269 | return _context.abrupt("return", _context.sent);
|
26270 |
|
26271 | case 9:
|
26272 | _context.prev = 9;
|
26273 | _context.t0 = _context["catch"](2);
|
26274 | throw transformNotFoundError(_context.t0);
|
26275 |
|
26276 | case 12:
|
26277 | case "end":
|
26278 | return _context.stop();
|
26279 | }
|
26280 | }
|
26281 | }, _callee, this, [[2, 9]]);
|
26282 | }));
|
26283 |
|
26284 | function _send() {
|
26285 | return _send2.apply(this, arguments);
|
26286 | }
|
26287 |
|
26288 | return _send;
|
26289 | }();
|
26290 |
|
26291 | _proto.send =
|
26292 |
|
26293 | function () {
|
26294 | var _send3 = _asyncToGenerator(
|
26295 |
|
26296 | regenerator.mark(function _callee2() {
|
26297 | var _ConversationBase$pro2,
|
26298 | _len2,
|
26299 | args,
|
26300 | _key2,
|
26301 | _args2 = arguments;
|
26302 |
|
26303 | return regenerator.wrap(function _callee2$(_context2) {
|
26304 | while (1) {
|
26305 | switch (_context2.prev = _context2.next) {
|
26306 | case 0:
|
26307 | _context2.prev = 0;
|
26308 |
|
26309 | for (_len2 = _args2.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
26310 | args[_key2] = _args2[_key2];
|
26311 | }
|
26312 |
|
26313 | _context2.next = 4;
|
26314 | return (_ConversationBase$pro2 = _ConversationBase.prototype.send).call.apply(_ConversationBase$pro2, [this].concat(args));
|
26315 |
|
26316 | case 4:
|
26317 | return _context2.abrupt("return", _context2.sent);
|
26318 |
|
26319 | case 7:
|
26320 | _context2.prev = 7;
|
26321 | _context2.t0 = _context2["catch"](0);
|
26322 | throw transformNotFoundError(_context2.t0);
|
26323 |
|
26324 | case 10:
|
26325 | case "end":
|
26326 | return _context2.stop();
|
26327 | }
|
26328 | }
|
26329 | }, _callee2, this, [[0, 7]]);
|
26330 | }));
|
26331 |
|
26332 | function send() {
|
26333 | return _send3.apply(this, arguments);
|
26334 | }
|
26335 |
|
26336 | return send;
|
26337 | }();
|
26338 |
|
26339 | _proto.toFullJSON = function toFullJSON() {
|
26340 | var expiredAt = this.expiredAt;
|
26341 | return _objectSpread({}, _ConversationBase.prototype.toFullJSON.call(this), {
|
26342 | expiredAt: getTime(expiredAt)
|
26343 | });
|
26344 | };
|
26345 |
|
26346 | _proto.toJSON = function toJSON() {
|
26347 | var expiredAt = this.expiredAt,
|
26348 | expired = this.expired;
|
26349 | return _objectSpread({}, _ConversationBase.prototype.toJSON.call(this), {
|
26350 | expiredAt: expiredAt,
|
26351 | expired: expired
|
26352 | });
|
26353 | };
|
26354 |
|
26355 | _createClass(TemporaryConversation, [{
|
26356 | key: "expiredAt",
|
26357 | set: function set(value) {
|
26358 | this._expiredAt = decodeDate(value);
|
26359 | },
|
26360 | get: function get() {
|
26361 | return this._expiredAt;
|
26362 | }
|
26363 | |
26364 |
|
26365 |
|
26366 |
|
26367 |
|
26368 | }, {
|
26369 | key: "expired",
|
26370 | get: function get() {
|
26371 | return this.expiredAt < new Date();
|
26372 | }
|
26373 | }]);
|
26374 |
|
26375 | return TemporaryConversation;
|
26376 | }(ConversationBase);
|
26377 |
|
26378 | var debug$8 = browser('LC:ConversationQuery');
|
26379 |
|
26380 | var ConversationQuery =
|
26381 |
|
26382 | function () {
|
26383 | ConversationQuery._encode = function _encode(value) {
|
26384 | if (value instanceof Date) {
|
26385 | return {
|
26386 | __type: 'Date',
|
26387 | iso: value.toJSON()
|
26388 | };
|
26389 | }
|
26390 |
|
26391 | if (value instanceof RegExp) {
|
26392 | return value.source;
|
26393 | }
|
26394 |
|
26395 | return value;
|
26396 | };
|
26397 |
|
26398 | ConversationQuery._quote = function _quote(s) {
|
26399 | return "\\Q".concat(s.replace('\\E', '\\E\\\\E\\Q'), "\\E");
|
26400 | };
|
26401 |
|
26402 | ConversationQuery._calculateFlag = function _calculateFlag(options) {
|
26403 | return ['withLastMessagesRefreshed', 'compact'].reduce(
|
26404 | function (prev, key) {
|
26405 | return (prev << 1) + Boolean(options[key]);
|
26406 | }, 0);
|
26407 | }
|
26408 | |
26409 |
|
26410 |
|
26411 |
|
26412 | ;
|
26413 |
|
26414 | function ConversationQuery(client) {
|
26415 | this._client = client;
|
26416 | this._where = {};
|
26417 | this._extraOptions = {};
|
26418 | }
|
26419 |
|
26420 | var _proto = ConversationQuery.prototype;
|
26421 |
|
26422 | _proto._addCondition = function _addCondition(key, condition, value) {
|
26423 |
|
26424 | if (!this._where[key]) {
|
26425 | this._where[key] = {};
|
26426 | }
|
26427 |
|
26428 | this._where[key][condition] = this.constructor._encode(value);
|
26429 | return this;
|
26430 | };
|
26431 |
|
26432 | _proto.toJSON = function toJSON() {
|
26433 | var json = {
|
26434 | where: this._where,
|
26435 | flag: this.constructor._calculateFlag(this._extraOptions)
|
26436 | };
|
26437 | if (typeof this._skip !== 'undefined') json.skip = this._skip;
|
26438 | if (typeof this._limit !== 'undefined') json.limit = this._limit;
|
26439 | if (typeof this._order !== 'undefined') json.sort = this._order;
|
26440 | debug$8(json);
|
26441 | return json;
|
26442 | }
|
26443 | |
26444 |
|
26445 |
|
26446 |
|
26447 |
|
26448 | ;
|
26449 |
|
26450 | _proto.containsMembers = function containsMembers(peerIds) {
|
26451 | return this.containsAll('m', peerIds);
|
26452 | }
|
26453 | |
26454 |
|
26455 |
|
26456 |
|
26457 |
|
26458 |
|
26459 |
|
26460 | ;
|
26461 |
|
26462 | _proto.withMembers = function withMembers(peerIds, includeSelf) {
|
26463 | var peerIdsSet = new Set(peerIds);
|
26464 |
|
26465 | if (includeSelf) {
|
26466 | peerIdsSet.add(this._client.id);
|
26467 | }
|
26468 |
|
26469 | this.sizeEqualTo('m', peerIdsSet.size);
|
26470 | return this.containsMembers(Array.from(peerIdsSet));
|
26471 | }
|
26472 | |
26473 |
|
26474 |
|
26475 |
|
26476 |
|
26477 |
|
26478 |
|
26479 | ;
|
26480 |
|
26481 | _proto.equalTo = function equalTo(key, value) {
|
26482 | this._where[key] = this.constructor._encode(value);
|
26483 | return this;
|
26484 | }
|
26485 | |
26486 |
|
26487 |
|
26488 |
|
26489 |
|
26490 |
|
26491 | ;
|
26492 |
|
26493 | _proto.lessThan = function lessThan(key, value) {
|
26494 | return this._addCondition(key, '$lt', value);
|
26495 | }
|
26496 | |
26497 |
|
26498 |
|
26499 |
|
26500 |
|
26501 |
|
26502 | ;
|
26503 |
|
26504 | _proto.lessThanOrEqualTo = function lessThanOrEqualTo(key, value) {
|
26505 | return this._addCondition(key, '$lte', value);
|
26506 | }
|
26507 | |
26508 |
|
26509 |
|
26510 |
|
26511 |
|
26512 |
|
26513 |
|
26514 | ;
|
26515 |
|
26516 | _proto.greaterThan = function greaterThan(key, value) {
|
26517 | return this._addCondition(key, '$gt', value);
|
26518 | }
|
26519 | |
26520 |
|
26521 |
|
26522 |
|
26523 |
|
26524 |
|
26525 |
|
26526 | ;
|
26527 |
|
26528 | _proto.greaterThanOrEqualTo = function greaterThanOrEqualTo(key, value) {
|
26529 | return this._addCondition(key, '$gte', value);
|
26530 | }
|
26531 | |
26532 |
|
26533 |
|
26534 |
|
26535 |
|
26536 |
|
26537 |
|
26538 | ;
|
26539 |
|
26540 | _proto.notEqualTo = function notEqualTo(key, value) {
|
26541 | return this._addCondition(key, '$ne', value);
|
26542 | }
|
26543 | |
26544 |
|
26545 |
|
26546 |
|
26547 |
|
26548 |
|
26549 |
|
26550 | ;
|
26551 |
|
26552 | _proto.exists = function exists(key) {
|
26553 | return this._addCondition(key, '$exists', true);
|
26554 | }
|
26555 | |
26556 |
|
26557 |
|
26558 |
|
26559 |
|
26560 |
|
26561 |
|
26562 | ;
|
26563 |
|
26564 | _proto.doesNotExist = function doesNotExist(key) {
|
26565 | return this._addCondition(key, '$exists', false);
|
26566 | }
|
26567 | |
26568 |
|
26569 |
|
26570 |
|
26571 |
|
26572 |
|
26573 |
|
26574 | ;
|
26575 |
|
26576 | _proto.containedIn = function containedIn(key, values) {
|
26577 | return this._addCondition(key, '$in', values);
|
26578 | }
|
26579 | |
26580 |
|
26581 |
|
26582 |
|
26583 |
|
26584 |
|
26585 |
|
26586 | ;
|
26587 |
|
26588 | _proto.notContainsIn = function notContainsIn(key, values) {
|
26589 | return this._addCondition(key, '$nin', values);
|
26590 | }
|
26591 | |
26592 |
|
26593 |
|
26594 |
|
26595 |
|
26596 |
|
26597 |
|
26598 | ;
|
26599 |
|
26600 | _proto.containsAll = function containsAll(key, values) {
|
26601 | return this._addCondition(key, '$all', values);
|
26602 | }
|
26603 | |
26604 |
|
26605 |
|
26606 |
|
26607 |
|
26608 |
|
26609 |
|
26610 | ;
|
26611 |
|
26612 | _proto.contains = function contains(key, subString) {
|
26613 | return this._addCondition(key, '$regex', ConversationQuery._quote(subString));
|
26614 | }
|
26615 | |
26616 |
|
26617 |
|
26618 |
|
26619 |
|
26620 |
|
26621 |
|
26622 | ;
|
26623 |
|
26624 | _proto.startsWith = function startsWith(key, prefix) {
|
26625 | return this._addCondition(key, '$regex', "^".concat(ConversationQuery._quote(prefix)));
|
26626 | }
|
26627 | |
26628 |
|
26629 |
|
26630 |
|
26631 |
|
26632 |
|
26633 |
|
26634 | ;
|
26635 |
|
26636 | _proto.endsWith = function endsWith(key, suffix) {
|
26637 | return this._addCondition(key, '$regex', "".concat(ConversationQuery._quote(suffix), "$"));
|
26638 | }
|
26639 | |
26640 |
|
26641 |
|
26642 |
|
26643 |
|
26644 |
|
26645 |
|
26646 | ;
|
26647 |
|
26648 | _proto.matches = function matches(key, regex) {
|
26649 | this._addCondition(key, '$regex', regex);
|
26650 |
|
26651 |
|
26652 |
|
26653 |
|
26654 | var _modifiers = '';
|
26655 |
|
26656 | if (regex.ignoreCase) {
|
26657 | _modifiers += 'i';
|
26658 | }
|
26659 |
|
26660 | if (regex.multiline) {
|
26661 | _modifiers += 'm';
|
26662 | }
|
26663 |
|
26664 | if (_modifiers && _modifiers.length) {
|
26665 | this._addCondition(key, '$options', _modifiers);
|
26666 | }
|
26667 |
|
26668 | return this;
|
26669 | }
|
26670 | |
26671 |
|
26672 |
|
26673 |
|
26674 |
|
26675 |
|
26676 |
|
26677 | ;
|
26678 |
|
26679 | _proto.sizeEqualTo = function sizeEqualTo(key, length) {
|
26680 | return this._addCondition(key, '$size', length);
|
26681 | }
|
26682 | |
26683 |
|
26684 |
|
26685 |
|
26686 |
|
26687 |
|
26688 | ;
|
26689 |
|
26690 | _proto.limit = function limit(_limit) {
|
26691 | this._limit = _limit;
|
26692 | return this;
|
26693 | }
|
26694 | |
26695 |
|
26696 |
|
26697 |
|
26698 |
|
26699 |
|
26700 | ;
|
26701 |
|
26702 | _proto.skip = function skip(_skip) {
|
26703 | this._skip = _skip;
|
26704 | return this;
|
26705 | }
|
26706 | |
26707 |
|
26708 |
|
26709 |
|
26710 |
|
26711 |
|
26712 | ;
|
26713 |
|
26714 | _proto.ascending = function ascending(key) {
|
26715 | this._order = key;
|
26716 | return this;
|
26717 | }
|
26718 | |
26719 |
|
26720 |
|
26721 |
|
26722 |
|
26723 |
|
26724 | ;
|
26725 |
|
26726 | _proto.addAscending = function addAscending(key) {
|
26727 | if (this._order) {
|
26728 | this._order += ",".concat(key);
|
26729 | } else {
|
26730 | this._order = key;
|
26731 | }
|
26732 |
|
26733 | return this;
|
26734 | }
|
26735 | |
26736 |
|
26737 |
|
26738 |
|
26739 |
|
26740 |
|
26741 | ;
|
26742 |
|
26743 | _proto.descending = function descending(key) {
|
26744 | this._order = "-".concat(key);
|
26745 | return this;
|
26746 | }
|
26747 | |
26748 |
|
26749 |
|
26750 |
|
26751 |
|
26752 |
|
26753 | ;
|
26754 |
|
26755 | _proto.addDescending = function addDescending(key) {
|
26756 | if (this._order) {
|
26757 | this._order += ",-".concat(key);
|
26758 | } else {
|
26759 | this._order = "-".concat(key);
|
26760 | }
|
26761 |
|
26762 | return this;
|
26763 | }
|
26764 | |
26765 |
|
26766 |
|
26767 |
|
26768 |
|
26769 | ;
|
26770 |
|
26771 | _proto.withLastMessagesRefreshed = function withLastMessagesRefreshed() {
|
26772 | var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
26773 | this._extraOptions.withLastMessagesRefreshed = enabled;
|
26774 | return this;
|
26775 | }
|
26776 | |
26777 |
|
26778 |
|
26779 |
|
26780 |
|
26781 | ;
|
26782 |
|
26783 | _proto.compact = function compact() {
|
26784 | var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
26785 | this._extraOptions.compact = enabled;
|
26786 | return this;
|
26787 | }
|
26788 | |
26789 |
|
26790 |
|
26791 |
|
26792 | ;
|
26793 |
|
26794 | _proto.find =
|
26795 |
|
26796 | function () {
|
26797 | var _find = _asyncToGenerator(
|
26798 |
|
26799 | regenerator.mark(function _callee() {
|
26800 | return regenerator.wrap(function _callee$(_context) {
|
26801 | while (1) {
|
26802 | switch (_context.prev = _context.next) {
|
26803 | case 0:
|
26804 | return _context.abrupt("return", this._client._executeQuery(this));
|
26805 |
|
26806 | case 1:
|
26807 | case "end":
|
26808 | return _context.stop();
|
26809 | }
|
26810 | }
|
26811 | }, _callee, this);
|
26812 | }));
|
26813 |
|
26814 | function find() {
|
26815 | return _find.apply(this, arguments);
|
26816 | }
|
26817 |
|
26818 | return find;
|
26819 | }();
|
26820 |
|
26821 | return ConversationQuery;
|
26822 | }();
|
26823 |
|
26824 | var debug$9 = browser('LC:SessionManager');
|
26825 |
|
26826 | var SessionManager =
|
26827 |
|
26828 | function () {
|
26829 | function SessionManager() {
|
26830 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
26831 | refresh = _ref.refresh,
|
26832 | onBeforeGetSessionToken = _ref.onBeforeGetSessionToken;
|
26833 |
|
26834 | this.refresh = refresh;
|
26835 | this._onBeforeGetSessionToken = onBeforeGetSessionToken;
|
26836 | this.setSessionToken(null, 0);
|
26837 | }
|
26838 |
|
26839 | var _proto = SessionManager.prototype;
|
26840 |
|
26841 | _proto.setSessionToken = function setSessionToken(token, ttl) {
|
26842 | debug$9('set session token', token, ttl);
|
26843 | var sessionToken = new Expirable(token, ttl * 1000);
|
26844 | this._sessionToken = sessionToken;
|
26845 | delete this._pendingSessionTokenPromise;
|
26846 | return sessionToken;
|
26847 | };
|
26848 |
|
26849 | _proto.setSessionTokenAsync =
|
26850 |
|
26851 | function () {
|
26852 | var _setSessionTokenAsync = _asyncToGenerator(
|
26853 |
|
26854 | regenerator.mark(function _callee(promise) {
|
26855 | var _this = this;
|
26856 |
|
26857 | var currentSessionToken;
|
26858 | return regenerator.wrap(function _callee$(_context) {
|
26859 | while (1) {
|
26860 | switch (_context.prev = _context.next) {
|
26861 | case 0:
|
26862 | currentSessionToken = this._sessionToken;
|
26863 | this._pendingSessionTokenPromise = promise.catch(function (error) {
|
26864 |
|
26865 |
|
26866 | _this._sessionToken = currentSessionToken;
|
26867 | throw error;
|
26868 | });
|
26869 | _context.t0 = this.setSessionToken;
|
26870 | _context.t1 = this;
|
26871 | _context.t2 = _toConsumableArray;
|
26872 | _context.next = 7;
|
26873 | return this._pendingSessionTokenPromise;
|
26874 |
|
26875 | case 7:
|
26876 | _context.t3 = _context.sent;
|
26877 | _context.t4 = (0, _context.t2)(_context.t3);
|
26878 | return _context.abrupt("return", _context.t0.apply.call(_context.t0, _context.t1, _context.t4));
|
26879 |
|
26880 | case 10:
|
26881 | case "end":
|
26882 | return _context.stop();
|
26883 | }
|
26884 | }
|
26885 | }, _callee, this);
|
26886 | }));
|
26887 |
|
26888 | function setSessionTokenAsync(_x) {
|
26889 | return _setSessionTokenAsync.apply(this, arguments);
|
26890 | }
|
26891 |
|
26892 | return setSessionTokenAsync;
|
26893 | }();
|
26894 |
|
26895 | _proto.getSessionToken =
|
26896 |
|
26897 | function () {
|
26898 | var _getSessionToken = _asyncToGenerator(
|
26899 |
|
26900 | regenerator.mark(function _callee2() {
|
26901 | var _ref2,
|
26902 | _ref2$autoRefresh,
|
26903 | autoRefresh,
|
26904 | _ref3,
|
26905 | value,
|
26906 | originalValue,
|
26907 | _ref4,
|
26908 | newValue,
|
26909 | _args2 = arguments;
|
26910 |
|
26911 | return regenerator.wrap(function _callee2$(_context2) {
|
26912 | while (1) {
|
26913 | switch (_context2.prev = _context2.next) {
|
26914 | case 0:
|
26915 | _ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref2$autoRefresh = _ref2.autoRefresh, autoRefresh = _ref2$autoRefresh === void 0 ? true : _ref2$autoRefresh;
|
26916 | debug$9('get session token');
|
26917 |
|
26918 | if (this._onBeforeGetSessionToken) {
|
26919 | this._onBeforeGetSessionToken(this);
|
26920 | }
|
26921 |
|
26922 | _context2.t0 = this._sessionToken;
|
26923 |
|
26924 | if (_context2.t0) {
|
26925 | _context2.next = 8;
|
26926 | break;
|
26927 | }
|
26928 |
|
26929 | _context2.next = 7;
|
26930 | return this._pendingSessionTokenPromise;
|
26931 |
|
26932 | case 7:
|
26933 | _context2.t0 = _context2.sent;
|
26934 |
|
26935 | case 8:
|
26936 | _ref3 = _context2.t0;
|
26937 | value = _ref3.value;
|
26938 | originalValue = _ref3.originalValue;
|
26939 |
|
26940 | if (!(value === Expirable.EXPIRED && autoRefresh && this.refresh)) {
|
26941 | _context2.next = 19;
|
26942 | break;
|
26943 | }
|
26944 |
|
26945 | debug$9('refresh expired session token');
|
26946 | _context2.next = 15;
|
26947 | return this.setSessionTokenAsync(this.refresh(this, originalValue));
|
26948 |
|
26949 | case 15:
|
26950 | _ref4 = _context2.sent;
|
26951 | newValue = _ref4.value;
|
26952 | debug$9('session token', newValue);
|
26953 | return _context2.abrupt("return", newValue);
|
26954 |
|
26955 | case 19:
|
26956 | debug$9('session token', value);
|
26957 | return _context2.abrupt("return", value);
|
26958 |
|
26959 | case 21:
|
26960 | case "end":
|
26961 | return _context2.stop();
|
26962 | }
|
26963 | }
|
26964 | }, _callee2, this);
|
26965 | }));
|
26966 |
|
26967 | function getSessionToken() {
|
26968 | return _getSessionToken.apply(this, arguments);
|
26969 | }
|
26970 |
|
26971 | return getSessionToken;
|
26972 | }();
|
26973 |
|
26974 | _proto.revoke = function revoke() {
|
26975 | if (this._sessionToken) this._sessionToken.expiredAt = -1;
|
26976 | };
|
26977 |
|
26978 | return SessionManager;
|
26979 | }();
|
26980 |
|
26981 | var _dec$2, _dec2, _class$3;
|
26982 | var debug$a = browser('LC:IMClient');
|
26983 | var INVITED$1 = INVITED,
|
26984 | KICKED$1 = KICKED,
|
26985 | MEMBERS_JOINED$1 = MEMBERS_JOINED,
|
26986 | MEMBERS_LEFT$1 = MEMBERS_LEFT,
|
26987 | MEMBER_INFO_UPDATED$1 = MEMBER_INFO_UPDATED,
|
26988 | BLOCKED$1 = BLOCKED,
|
26989 | UNBLOCKED$1 = UNBLOCKED,
|
26990 | MEMBERS_BLOCKED$1 = MEMBERS_BLOCKED,
|
26991 | MEMBERS_UNBLOCKED$1 = MEMBERS_UNBLOCKED,
|
26992 | MUTED$1 = MUTED,
|
26993 | UNMUTED$1 = UNMUTED,
|
26994 | MEMBERS_MUTED$1 = MEMBERS_MUTED,
|
26995 | MEMBERS_UNMUTED$1 = MEMBERS_UNMUTED,
|
26996 | MESSAGE$2 = MESSAGE$1,
|
26997 | UNREAD_MESSAGES_COUNT_UPDATE$1 = UNREAD_MESSAGES_COUNT_UPDATE,
|
26998 | CLOSE$1 = CLOSE,
|
26999 | CONFLICT$1 = CONFLICT,
|
27000 | UNHANDLED_MESSAGE$1 = UNHANDLED_MESSAGE,
|
27001 | CONVERSATION_INFO_UPDATED$1 = CONVERSATION_INFO_UPDATED,
|
27002 | MESSAGE_RECALL$1 = MESSAGE_RECALL,
|
27003 | MESSAGE_UPDATE$1 = MESSAGE_UPDATE,
|
27004 | INFO_UPDATED$1 = INFO_UPDATED;
|
27005 |
|
27006 | var isTemporaryConversatrionId = function isTemporaryConversatrionId(id) {
|
27007 | return /^_tmp:/.test(id);
|
27008 | };
|
27009 | |
27010 |
|
27011 |
|
27012 |
|
27013 |
|
27014 |
|
27015 |
|
27016 |
|
27017 |
|
27018 |
|
27019 |
|
27020 | var configBitmap = 59;
|
27021 | var IMClient = (_dec$2 = throttle(1000), _dec2 = throttle(1000), (_class$3 =
|
27022 |
|
27023 | function (_EventEmitter) {
|
27024 | _inheritsLoose(IMClient, _EventEmitter);
|
27025 |
|
27026 | |
27027 |
|
27028 |
|
27029 |
|
27030 |
|
27031 | function IMClient(id) {
|
27032 | var _this;
|
27033 |
|
27034 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
27035 | var props = arguments.length > 2 ? arguments[2] : undefined;
|
27036 |
|
27037 | if (!(id === undefined || typeof id === 'string')) {
|
27038 | throw new TypeError("Client id [".concat(id, "] is not a String"));
|
27039 | }
|
27040 |
|
27041 | _this = _EventEmitter.call(this) || this;
|
27042 | Object.assign(_assertThisInitialized(_this), {
|
27043 | |
27044 |
|
27045 |
|
27046 |
|
27047 | id: id,
|
27048 | options: options
|
27049 | }, props);
|
27050 |
|
27051 | if (!_this._messageParser) {
|
27052 | throw new Error('IMClient must be initialized with a MessageParser');
|
27053 | }
|
27054 |
|
27055 | _this._conversationCache = new Cache("client:".concat(_this.id));
|
27056 | _this._ackMessageBuffer = {};
|
27057 | internal(_assertThisInitialized(_this)).lastPatchTime = Date.now();
|
27058 | internal(_assertThisInitialized(_this)).lastNotificationTime = undefined;
|
27059 | internal(_assertThisInitialized(_this))._eventemitter = new eventemitter3();
|
27060 |
|
27061 | if (debug$a.enabled) {
|
27062 | values_1(Event).forEach(function (event) {
|
27063 | return _this.on(event, function () {
|
27064 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
27065 | payload[_key] = arguments[_key];
|
27066 | }
|
27067 |
|
27068 | return _this._debug("".concat(event, " event emitted. %o"), payload);
|
27069 | });
|
27070 | });
|
27071 | }
|
27072 |
|
27073 |
|
27074 | applyDecorators(_this._plugins.onIMClientCreate, _assertThisInitialized(_this));
|
27075 | return _this;
|
27076 | }
|
27077 |
|
27078 | var _proto = IMClient.prototype;
|
27079 |
|
27080 | _proto._debug = function _debug() {
|
27081 | for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
27082 | params[_key2] = arguments[_key2];
|
27083 | }
|
27084 |
|
27085 | debug$a.apply(void 0, params.concat(["[".concat(this.id, "]")]));
|
27086 | }
|
27087 | |
27088 |
|
27089 |
|
27090 |
|
27091 | ;
|
27092 |
|
27093 | _proto._dispatchCommand =
|
27094 |
|
27095 | function () {
|
27096 | var _dispatchCommand2 = _asyncToGenerator(
|
27097 |
|
27098 | regenerator.mark(function _callee(command) {
|
27099 | return regenerator.wrap(function _callee$(_context) {
|
27100 | while (1) {
|
27101 | switch (_context.prev = _context.next) {
|
27102 | case 0:
|
27103 | this._debug(trim(command), 'received');
|
27104 |
|
27105 | if (command.serverTs && command.notificationType === 1) {
|
27106 | internal(this).lastNotificationTime = getTime(decodeDate(command.serverTs));
|
27107 | }
|
27108 |
|
27109 | _context.t0 = command.cmd;
|
27110 | _context.next = _context.t0 === CommandType.conv ? 5 : _context.t0 === CommandType.direct ? 6 : _context.t0 === CommandType.session ? 7 : _context.t0 === CommandType.unread ? 8 : _context.t0 === CommandType.rcp ? 9 : _context.t0 === CommandType.patch ? 10 : 11;
|
27111 | break;
|
27112 |
|
27113 | case 5:
|
27114 | return _context.abrupt("return", this._dispatchConvMessage(command));
|
27115 |
|
27116 | case 6:
|
27117 | return _context.abrupt("return", this._dispatchDirectMessage(command));
|
27118 |
|
27119 | case 7:
|
27120 | return _context.abrupt("return", this._dispatchSessionMessage(command));
|
27121 |
|
27122 | case 8:
|
27123 | return _context.abrupt("return", this._dispatchUnreadMessage(command));
|
27124 |
|
27125 | case 9:
|
27126 | return _context.abrupt("return", this._dispatchRcpMessage(command));
|
27127 |
|
27128 | case 10:
|
27129 | return _context.abrupt("return", this._dispatchPatchMessage(command));
|
27130 |
|
27131 | case 11:
|
27132 | return _context.abrupt("return", this.emit(UNHANDLED_MESSAGE$1, command));
|
27133 |
|
27134 | case 12:
|
27135 | case "end":
|
27136 | return _context.stop();
|
27137 | }
|
27138 | }
|
27139 | }, _callee, this);
|
27140 | }));
|
27141 |
|
27142 | function _dispatchCommand(_x) {
|
27143 | return _dispatchCommand2.apply(this, arguments);
|
27144 | }
|
27145 |
|
27146 | return _dispatchCommand;
|
27147 | }();
|
27148 |
|
27149 | _proto._dispatchSessionMessage =
|
27150 |
|
27151 | function () {
|
27152 | var _dispatchSessionMessage2 = _asyncToGenerator(
|
27153 |
|
27154 | regenerator.mark(function _callee2(message) {
|
27155 | var _message$sessionMessa, code, reason;
|
27156 |
|
27157 | return regenerator.wrap(function _callee2$(_context2) {
|
27158 | while (1) {
|
27159 | switch (_context2.prev = _context2.next) {
|
27160 | case 0:
|
27161 | _message$sessionMessa = message.sessionMessage, code = _message$sessionMessa.code, reason = _message$sessionMessa.reason;
|
27162 | _context2.t0 = message.op;
|
27163 | _context2.next = _context2.t0 === OpType.closed ? 4 : 8;
|
27164 | break;
|
27165 |
|
27166 | case 4:
|
27167 | internal(this)._eventemitter.emit('close');
|
27168 |
|
27169 | if (!(code === ErrorCode.SESSION_CONFLICT)) {
|
27170 | _context2.next = 7;
|
27171 | break;
|
27172 | }
|
27173 |
|
27174 | return _context2.abrupt("return", this.emit(CONFLICT$1, {
|
27175 | reason: reason
|
27176 | }));
|
27177 |
|
27178 | case 7:
|
27179 | return _context2.abrupt("return", this.emit(CLOSE$1, {
|
27180 | code: code,
|
27181 | reason: reason
|
27182 | }));
|
27183 |
|
27184 | case 8:
|
27185 | this.emit(UNHANDLED_MESSAGE$1, message);
|
27186 | throw new Error('Unrecognized session command');
|
27187 |
|
27188 | case 10:
|
27189 | case "end":
|
27190 | return _context2.stop();
|
27191 | }
|
27192 | }
|
27193 | }, _callee2, this);
|
27194 | }));
|
27195 |
|
27196 | function _dispatchSessionMessage(_x2) {
|
27197 | return _dispatchSessionMessage2.apply(this, arguments);
|
27198 | }
|
27199 |
|
27200 | return _dispatchSessionMessage;
|
27201 | }();
|
27202 |
|
27203 | _proto._dispatchUnreadMessage = function _dispatchUnreadMessage(_ref) {
|
27204 | var _this2 = this;
|
27205 |
|
27206 | var _ref$unreadMessage = _ref.unreadMessage,
|
27207 | convs = _ref$unreadMessage.convs,
|
27208 | notifTime = _ref$unreadMessage.notifTime;
|
27209 | internal(this).lastUnreadNotifTime = notifTime;
|
27210 |
|
27211 | return this.getConversations(convs.map(function (conv) {
|
27212 | return conv.cid;
|
27213 | })).then(function () {
|
27214 | return (
|
27215 | Promise.all(convs.map(function (_ref2) {
|
27216 | var cid = _ref2.cid,
|
27217 | unread = _ref2.unread,
|
27218 | mid = _ref2.mid,
|
27219 | ts = _ref2.timestamp,
|
27220 | from = _ref2.from,
|
27221 | data = _ref2.data,
|
27222 | binaryMsg = _ref2.binaryMsg,
|
27223 | patchTimestamp = _ref2.patchTimestamp,
|
27224 | mentioned = _ref2.mentioned;
|
27225 |
|
27226 | var conversation = _this2._conversationCache.get(cid);
|
27227 |
|
27228 |
|
27229 | if (!conversation) return null;
|
27230 | var timestamp;
|
27231 |
|
27232 | if (ts) {
|
27233 | timestamp = decodeDate(ts);
|
27234 | conversation.lastMessageAt = timestamp;
|
27235 | }
|
27236 |
|
27237 | return (mid ? _this2._messageParser.parse(binaryMsg || data).then(function (message) {
|
27238 | var messageProps = {
|
27239 | id: mid,
|
27240 | cid: cid,
|
27241 | timestamp: timestamp,
|
27242 | updatedAt: patchTimestamp,
|
27243 | from: from
|
27244 | };
|
27245 | Object.assign(message, messageProps);
|
27246 | conversation.lastMessage = message;
|
27247 | }) : Promise.resolve()).then(function () {
|
27248 | conversation._setUnreadMessagesMentioned(mentioned);
|
27249 |
|
27250 | var countNotUpdated = unread === internal(conversation).unreadMessagesCount;
|
27251 | if (countNotUpdated) return null;
|
27252 |
|
27253 |
|
27254 | internal(conversation).unreadMessagesCount = unread;
|
27255 | return conversation;
|
27256 | });
|
27257 | })).then(function (conversations) {
|
27258 | return conversations.filter(function (conversation) {
|
27259 | return conversation;
|
27260 | });
|
27261 | })
|
27262 | );
|
27263 | }).then(function (conversations) {
|
27264 | if (conversations.length) {
|
27265 | |
27266 |
|
27267 |
|
27268 |
|
27269 |
|
27270 |
|
27271 | _this2.emit(UNREAD_MESSAGES_COUNT_UPDATE$1, conversations);
|
27272 | }
|
27273 | });
|
27274 | };
|
27275 |
|
27276 | _proto._dispatchRcpMessage =
|
27277 |
|
27278 | function () {
|
27279 | var _dispatchRcpMessage2 = _asyncToGenerator(
|
27280 |
|
27281 | regenerator.mark(function _callee3(message) {
|
27282 | var rcpMessage, read, conversationId, messageId, timestamp, conversation;
|
27283 | return regenerator.wrap(function _callee3$(_context3) {
|
27284 | while (1) {
|
27285 | switch (_context3.prev = _context3.next) {
|
27286 | case 0:
|
27287 | rcpMessage = message.rcpMessage, read = message.rcpMessage.read;
|
27288 | conversationId = rcpMessage.cid;
|
27289 | messageId = rcpMessage.id;
|
27290 | timestamp = decodeDate(rcpMessage.t);
|
27291 | conversation = this._conversationCache.get(conversationId);
|
27292 |
|
27293 |
|
27294 | if (conversation) {
|
27295 | _context3.next = 7;
|
27296 | break;
|
27297 | }
|
27298 |
|
27299 | return _context3.abrupt("return");
|
27300 |
|
27301 | case 7:
|
27302 | conversation._handleReceipt({
|
27303 | messageId: messageId,
|
27304 | timestamp: timestamp,
|
27305 | read: read
|
27306 | });
|
27307 |
|
27308 | case 8:
|
27309 | case "end":
|
27310 | return _context3.stop();
|
27311 | }
|
27312 | }
|
27313 | }, _callee3, this);
|
27314 | }));
|
27315 |
|
27316 | function _dispatchRcpMessage(_x3) {
|
27317 | return _dispatchRcpMessage2.apply(this, arguments);
|
27318 | }
|
27319 |
|
27320 | return _dispatchRcpMessage;
|
27321 | }();
|
27322 |
|
27323 | _proto._dispatchPatchMessage = function _dispatchPatchMessage(_ref3) {
|
27324 | var _this3 = this;
|
27325 |
|
27326 | var patches = _ref3.patchMessage.patches;
|
27327 |
|
27328 | return this.getConversations(patches.map(function (patch) {
|
27329 | return patch.cid;
|
27330 | })).then(function () {
|
27331 | return Promise.all(patches.map(function (_ref4) {
|
27332 | var cid = _ref4.cid,
|
27333 | mid = _ref4.mid,
|
27334 | timestamp = _ref4.timestamp,
|
27335 | recall = _ref4.recall,
|
27336 | data = _ref4.data,
|
27337 | patchTimestamp = _ref4.patchTimestamp,
|
27338 | from = _ref4.from,
|
27339 | binaryMsg = _ref4.binaryMsg,
|
27340 | mentionAll = _ref4.mentionAll,
|
27341 | mentionPids = _ref4.mentionPids,
|
27342 | patchCode = _ref4.patchCode,
|
27343 | patchReason = _ref4.patchReason;
|
27344 |
|
27345 | var conversation = _this3._conversationCache.get(cid);
|
27346 |
|
27347 |
|
27348 | if (!conversation) return null;
|
27349 | return _this3._messageParser.parse(binaryMsg || data).then(function (message) {
|
27350 | var patchTime = getTime(decodeDate(patchTimestamp));
|
27351 | var messageProps = {
|
27352 | id: mid,
|
27353 | cid: cid,
|
27354 | timestamp: timestamp,
|
27355 | updatedAt: patchTime,
|
27356 | from: from,
|
27357 | mentionList: mentionPids,
|
27358 | mentionedAll: mentionAll
|
27359 | };
|
27360 | Object.assign(message, messageProps);
|
27361 |
|
27362 | message._setStatus(MessageStatus.SENT);
|
27363 |
|
27364 | message._updateMentioned(_this3.id);
|
27365 |
|
27366 | if (internal(_this3).lastPatchTime < patchTime) {
|
27367 | internal(_this3).lastPatchTime = patchTime;
|
27368 | }
|
27369 |
|
27370 |
|
27371 | if (conversation.lastMessage && conversation.lastMessage.id === mid) {
|
27372 | conversation.lastMessage = message;
|
27373 | }
|
27374 |
|
27375 | var reason;
|
27376 |
|
27377 | if (patchCode) {
|
27378 | reason = {
|
27379 | code: patchCode.toNumber(),
|
27380 | detail: patchReason
|
27381 | };
|
27382 | }
|
27383 |
|
27384 | if (recall) {
|
27385 | |
27386 |
|
27387 |
|
27388 |
|
27389 |
|
27390 |
|
27391 |
|
27392 | _this3.emit(MESSAGE_RECALL$1, message, conversation, reason);
|
27393 | |
27394 |
|
27395 |
|
27396 |
|
27397 |
|
27398 |
|
27399 |
|
27400 |
|
27401 | conversation.emit(MESSAGE_RECALL$1, message, reason);
|
27402 | } else {
|
27403 | |
27404 |
|
27405 |
|
27406 |
|
27407 |
|
27408 |
|
27409 |
|
27410 | _this3.emit(MESSAGE_UPDATE$1, message, conversation, reason);
|
27411 | |
27412 |
|
27413 |
|
27414 |
|
27415 |
|
27416 |
|
27417 |
|
27418 |
|
27419 | conversation.emit(MESSAGE_UPDATE$1, message, reason);
|
27420 | }
|
27421 | });
|
27422 | }));
|
27423 | });
|
27424 | };
|
27425 |
|
27426 | _proto._dispatchConvMessage =
|
27427 |
|
27428 | function () {
|
27429 | var _dispatchConvMessage2 = _asyncToGenerator(
|
27430 |
|
27431 | regenerator.mark(function _callee4(message) {
|
27432 | var convMessage, _message$convMessage, initBy, m, info, attr, conversation, payload, _payload, _payload2, _payload3, _payload4, _payload5, _payload6, _payload7, _payload8, _payload9, _payload10, _payload11, pid, role, _internal, memberInfoMap, memberInfo, _payload12, attributes, _payload13;
|
27433 |
|
27434 | return regenerator.wrap(function _callee4$(_context4) {
|
27435 | while (1) {
|
27436 | switch (_context4.prev = _context4.next) {
|
27437 | case 0:
|
27438 | convMessage = message.convMessage, _message$convMessage = message.convMessage, initBy = _message$convMessage.initBy, m = _message$convMessage.m, info = _message$convMessage.info, attr = _message$convMessage.attr;
|
27439 | _context4.next = 3;
|
27440 | return this.getConversation(convMessage.cid);
|
27441 |
|
27442 | case 3:
|
27443 | conversation = _context4.sent;
|
27444 | _context4.t0 = message.op;
|
27445 | _context4.next = _context4.t0 === OpType.joined ? 7 : _context4.t0 === OpType.left ? 12 : _context4.t0 === OpType.members_joined ? 17 : _context4.t0 === OpType.members_left ? 22 : _context4.t0 === OpType.members_blocked ? 27 : _context4.t0 === OpType.members_unblocked ? 31 : _context4.t0 === OpType.blocked ? 35 : _context4.t0 === OpType.unblocked ? 39 : _context4.t0 === OpType.members_shutuped ? 43 : _context4.t0 === OpType.members_unshutuped ? 47 : _context4.t0 === OpType.shutuped ? 51 : _context4.t0 === OpType.unshutuped ? 55 : _context4.t0 === OpType.member_info_changed ? 59 : _context4.t0 === OpType.updated ? 71 : 77;
|
27446 | break;
|
27447 |
|
27448 | case 7:
|
27449 | conversation._addMembers([this.id]);
|
27450 |
|
27451 | payload = {
|
27452 | invitedBy: initBy
|
27453 | };
|
27454 | |
27455 |
|
27456 |
|
27457 |
|
27458 |
|
27459 |
|
27460 |
|
27461 |
|
27462 | this.emit(INVITED$1, payload, conversation);
|
27463 | |
27464 |
|
27465 |
|
27466 |
|
27467 |
|
27468 |
|
27469 |
|
27470 | conversation.emit(INVITED$1, payload);
|
27471 | return _context4.abrupt("return");
|
27472 |
|
27473 | case 12:
|
27474 | conversation._removeMembers([this.id]);
|
27475 |
|
27476 | _payload = {
|
27477 | kickedBy: initBy
|
27478 | };
|
27479 | |
27480 |
|
27481 |
|
27482 |
|
27483 |
|
27484 |
|
27485 |
|
27486 |
|
27487 | this.emit(KICKED$1, _payload, conversation);
|
27488 | |
27489 |
|
27490 |
|
27491 |
|
27492 |
|
27493 |
|
27494 |
|
27495 | conversation.emit(KICKED$1, _payload);
|
27496 | return _context4.abrupt("return");
|
27497 |
|
27498 | case 17:
|
27499 | conversation._addMembers(m);
|
27500 |
|
27501 | _payload2 = {
|
27502 | invitedBy: initBy,
|
27503 | members: m
|
27504 | };
|
27505 | |
27506 |
|
27507 |
|
27508 |
|
27509 |
|
27510 |
|
27511 |
|
27512 |
|
27513 |
|
27514 | this.emit(MEMBERS_JOINED$1, _payload2, conversation);
|
27515 | |
27516 |
|
27517 |
|
27518 |
|
27519 |
|
27520 |
|
27521 |
|
27522 |
|
27523 | conversation.emit(MEMBERS_JOINED$1, _payload2);
|
27524 | return _context4.abrupt("return");
|
27525 |
|
27526 | case 22:
|
27527 | conversation._removeMembers(m);
|
27528 |
|
27529 | _payload3 = {
|
27530 | kickedBy: initBy,
|
27531 | members: m
|
27532 | };
|
27533 | |
27534 |
|
27535 |
|
27536 |
|
27537 |
|
27538 |
|
27539 |
|
27540 |
|
27541 |
|
27542 | this.emit(MEMBERS_LEFT$1, _payload3, conversation);
|
27543 | |
27544 |
|
27545 |
|
27546 |
|
27547 |
|
27548 |
|
27549 |
|
27550 |
|
27551 | conversation.emit(MEMBERS_LEFT$1, _payload3);
|
27552 | return _context4.abrupt("return");
|
27553 |
|
27554 | case 27:
|
27555 | _payload4 = {
|
27556 | blockedBy: initBy,
|
27557 | members: m
|
27558 | };
|
27559 | |
27560 |
|
27561 |
|
27562 |
|
27563 |
|
27564 |
|
27565 |
|
27566 |
|
27567 |
|
27568 | this.emit(MEMBERS_BLOCKED$1, _payload4, conversation);
|
27569 | |
27570 |
|
27571 |
|
27572 |
|
27573 |
|
27574 |
|
27575 |
|
27576 |
|
27577 | conversation.emit(MEMBERS_BLOCKED$1, _payload4);
|
27578 | return _context4.abrupt("return");
|
27579 |
|
27580 | case 31:
|
27581 | _payload5 = {
|
27582 | unblockedBy: initBy,
|
27583 | members: m
|
27584 | };
|
27585 | |
27586 |
|
27587 |
|
27588 |
|
27589 |
|
27590 |
|
27591 |
|
27592 |
|
27593 |
|
27594 | this.emit(MEMBERS_UNBLOCKED$1, _payload5, conversation);
|
27595 | |
27596 |
|
27597 |
|
27598 |
|
27599 |
|
27600 |
|
27601 |
|
27602 |
|
27603 | conversation.emit(MEMBERS_UNBLOCKED$1, _payload5);
|
27604 | return _context4.abrupt("return");
|
27605 |
|
27606 | case 35:
|
27607 | _payload6 = {
|
27608 | blockedBy: initBy
|
27609 | };
|
27610 | |
27611 |
|
27612 |
|
27613 |
|
27614 |
|
27615 |
|
27616 |
|
27617 |
|
27618 | this.emit(BLOCKED$1, _payload6, conversation);
|
27619 | |
27620 |
|
27621 |
|
27622 |
|
27623 |
|
27624 |
|
27625 |
|
27626 | conversation.emit(BLOCKED$1, _payload6);
|
27627 | return _context4.abrupt("return");
|
27628 |
|
27629 | case 39:
|
27630 | _payload7 = {
|
27631 | unblockedBy: initBy
|
27632 | };
|
27633 | |
27634 |
|
27635 |
|
27636 |
|
27637 |
|
27638 |
|
27639 |
|
27640 |
|
27641 | this.emit(UNBLOCKED$1, _payload7, conversation);
|
27642 | |
27643 |
|
27644 |
|
27645 |
|
27646 |
|
27647 |
|
27648 |
|
27649 | conversation.emit(UNBLOCKED$1, _payload7);
|
27650 | return _context4.abrupt("return");
|
27651 |
|
27652 | case 43:
|
27653 | _payload8 = {
|
27654 | mutedBy: initBy,
|
27655 | members: m
|
27656 | };
|
27657 | |
27658 |
|
27659 |
|
27660 |
|
27661 |
|
27662 |
|
27663 |
|
27664 |
|
27665 |
|
27666 | this.emit(MEMBERS_MUTED$1, _payload8, conversation);
|
27667 | |
27668 |
|
27669 |
|
27670 |
|
27671 |
|
27672 |
|
27673 |
|
27674 |
|
27675 | conversation.emit(MEMBERS_MUTED$1, _payload8);
|
27676 | return _context4.abrupt("return");
|
27677 |
|
27678 | case 47:
|
27679 | _payload9 = {
|
27680 | unmutedBy: initBy,
|
27681 | members: m
|
27682 | };
|
27683 | |
27684 |
|
27685 |
|
27686 |
|
27687 |
|
27688 |
|
27689 |
|
27690 |
|
27691 |
|
27692 | this.emit(MEMBERS_UNMUTED$1, _payload9, conversation);
|
27693 | |
27694 |
|
27695 |
|
27696 |
|
27697 |
|
27698 |
|
27699 |
|
27700 |
|
27701 | conversation.emit(MEMBERS_UNMUTED$1, _payload9);
|
27702 | return _context4.abrupt("return");
|
27703 |
|
27704 | case 51:
|
27705 | _payload10 = {
|
27706 | mutedBy: initBy
|
27707 | };
|
27708 | |
27709 |
|
27710 |
|
27711 |
|
27712 |
|
27713 |
|
27714 |
|
27715 |
|
27716 | this.emit(MUTED$1, _payload10, conversation);
|
27717 | |
27718 |
|
27719 |
|
27720 |
|
27721 |
|
27722 |
|
27723 |
|
27724 | conversation.emit(MUTED$1, _payload10);
|
27725 | return _context4.abrupt("return");
|
27726 |
|
27727 | case 55:
|
27728 | _payload11 = {
|
27729 | unmutedBy: initBy
|
27730 | };
|
27731 | |
27732 |
|
27733 |
|
27734 |
|
27735 |
|
27736 |
|
27737 |
|
27738 |
|
27739 | this.emit(UNMUTED$1, _payload11, conversation);
|
27740 | |
27741 |
|
27742 |
|
27743 |
|
27744 |
|
27745 |
|
27746 |
|
27747 | conversation.emit(UNMUTED$1, _payload11);
|
27748 | return _context4.abrupt("return");
|
27749 |
|
27750 | case 59:
|
27751 | pid = info.pid, role = info.role;
|
27752 | _internal = internal(conversation), memberInfoMap = _internal.memberInfoMap;
|
27753 |
|
27754 | if (!(!memberInfoMap && !role)) {
|
27755 | _context4.next = 63;
|
27756 | break;
|
27757 | }
|
27758 |
|
27759 | return _context4.abrupt("return");
|
27760 |
|
27761 | case 63:
|
27762 | _context4.next = 65;
|
27763 | return conversation.getMemberInfo(pid);
|
27764 |
|
27765 | case 65:
|
27766 | memberInfo = _context4.sent;
|
27767 | internal(memberInfo).role = role;
|
27768 | _payload12 = {
|
27769 | member: pid,
|
27770 | memberInfo: memberInfo,
|
27771 | updatedBy: initBy
|
27772 | };
|
27773 | |
27774 |
|
27775 |
|
27776 |
|
27777 |
|
27778 |
|
27779 |
|
27780 |
|
27781 |
|
27782 |
|
27783 | this.emit(MEMBER_INFO_UPDATED$1, _payload12, conversation);
|
27784 | |
27785 |
|
27786 |
|
27787 |
|
27788 |
|
27789 |
|
27790 |
|
27791 |
|
27792 |
|
27793 | conversation.emit(MEMBER_INFO_UPDATED$1, _payload12);
|
27794 | return _context4.abrupt("return");
|
27795 |
|
27796 | case 71:
|
27797 | attributes = decode(JSON.parse(attr.data));
|
27798 |
|
27799 | conversation._updateServerAttributes(attributes);
|
27800 |
|
27801 | _payload13 = {
|
27802 | attributes: attributes,
|
27803 | updatedBy: initBy
|
27804 | };
|
27805 | |
27806 |
|
27807 |
|
27808 |
|
27809 |
|
27810 |
|
27811 |
|
27812 |
|
27813 |
|
27814 | this.emit(CONVERSATION_INFO_UPDATED$1, _payload13, conversation);
|
27815 | |
27816 |
|
27817 |
|
27818 |
|
27819 |
|
27820 |
|
27821 |
|
27822 |
|
27823 | conversation.emit(INFO_UPDATED$1, _payload13);
|
27824 | return _context4.abrupt("return");
|
27825 |
|
27826 | case 77:
|
27827 | this.emit(UNHANDLED_MESSAGE$1, message);
|
27828 | throw new Error('Unrecognized conversation command');
|
27829 |
|
27830 | case 79:
|
27831 | case "end":
|
27832 | return _context4.stop();
|
27833 | }
|
27834 | }
|
27835 | }, _callee4, this);
|
27836 | }));
|
27837 |
|
27838 | function _dispatchConvMessage(_x4) {
|
27839 | return _dispatchConvMessage2.apply(this, arguments);
|
27840 | }
|
27841 |
|
27842 | return _dispatchConvMessage;
|
27843 | }();
|
27844 |
|
27845 | _proto._dispatchDirectMessage = function _dispatchDirectMessage(originalMessage) {
|
27846 | var _this4 = this;
|
27847 |
|
27848 | var directMessage = originalMessage.directMessage,
|
27849 | _originalMessage$dire = originalMessage.directMessage,
|
27850 | id = _originalMessage$dire.id,
|
27851 | cid = _originalMessage$dire.cid,
|
27852 | fromPeerId = _originalMessage$dire.fromPeerId,
|
27853 | timestamp = _originalMessage$dire.timestamp,
|
27854 | transient = _originalMessage$dire.transient,
|
27855 | patchTimestamp = _originalMessage$dire.patchTimestamp,
|
27856 | mentionPids = _originalMessage$dire.mentionPids,
|
27857 | mentionAll = _originalMessage$dire.mentionAll,
|
27858 | binaryMsg = _originalMessage$dire.binaryMsg,
|
27859 | msg = _originalMessage$dire.msg;
|
27860 | var content = binaryMsg ? binaryMsg.toArrayBuffer() : msg;
|
27861 | return Promise.all([this.getConversation(directMessage.cid), this._messageParser.parse(content)]).then(function (_ref5) {
|
27862 | var _ref6 = _slicedToArray(_ref5, 2),
|
27863 | conversation = _ref6[0],
|
27864 | message = _ref6[1];
|
27865 |
|
27866 |
|
27867 | if (!conversation) return undefined;
|
27868 | var messageProps = {
|
27869 | id: id,
|
27870 | cid: cid,
|
27871 | timestamp: timestamp,
|
27872 | updatedAt: patchTimestamp,
|
27873 | from: fromPeerId,
|
27874 | mentionList: mentionPids,
|
27875 | mentionedAll: mentionAll
|
27876 | };
|
27877 | Object.assign(message, messageProps);
|
27878 |
|
27879 | message._updateMentioned(_this4.id);
|
27880 |
|
27881 | message._setStatus(MessageStatus.SENT);
|
27882 |
|
27883 |
|
27884 | if (message.from !== _this4.id) {
|
27885 | if (!(transient || conversation.transient)) {
|
27886 | _this4._sendAck(message);
|
27887 | }
|
27888 | }
|
27889 |
|
27890 | return _this4._dispatchParsedMessage(message, conversation);
|
27891 | });
|
27892 | };
|
27893 |
|
27894 | _proto._dispatchParsedMessage = function _dispatchParsedMessage(message, conversation) {
|
27895 | var _this5 = this;
|
27896 |
|
27897 |
|
27898 | return applyDispatcher(this._plugins.beforeMessageDispatch, [message, conversation]).then(function (shouldDispatch) {
|
27899 | if (shouldDispatch === false) return;
|
27900 | conversation.lastMessage = message;
|
27901 |
|
27902 | conversation.lastMessageAt = message.timestamp;
|
27903 |
|
27904 |
|
27905 | if (message.from !== _this5.id) {
|
27906 | conversation.unreadMessagesCount += 1;
|
27907 |
|
27908 | if (message.mentioned) conversation._setUnreadMessagesMentioned(true);
|
27909 | }
|
27910 | |
27911 |
|
27912 |
|
27913 |
|
27914 |
|
27915 |
|
27916 |
|
27917 |
|
27918 | _this5.emit(MESSAGE$2, message, conversation);
|
27919 | |
27920 |
|
27921 |
|
27922 |
|
27923 |
|
27924 |
|
27925 |
|
27926 | conversation.emit(MESSAGE$2, message);
|
27927 | });
|
27928 | };
|
27929 |
|
27930 | _proto._sendAck = function _sendAck(message) {
|
27931 | this._debug('send ack for %O', message);
|
27932 |
|
27933 | var cid = message.cid;
|
27934 |
|
27935 | if (!cid) {
|
27936 | throw new Error('missing cid');
|
27937 | }
|
27938 |
|
27939 | if (!this._ackMessageBuffer[cid]) {
|
27940 | this._ackMessageBuffer[cid] = [];
|
27941 | }
|
27942 |
|
27943 | this._ackMessageBuffer[cid].push(message);
|
27944 |
|
27945 | return this._doSendAck();
|
27946 | }
|
27947 | ;
|
27948 |
|
27949 | _proto.
|
27950 | _doSendAck = function _doSendAck() {
|
27951 | var _this6 = this;
|
27952 |
|
27953 |
|
27954 | if (!this._connection.is('connected')) return;
|
27955 |
|
27956 | this._debug('do send ack %O', this._ackMessageBuffer);
|
27957 |
|
27958 | Promise.all(Object.keys(this._ackMessageBuffer).map(function (cid) {
|
27959 | var convAckMessages = _this6._ackMessageBuffer[cid];
|
27960 | var timestamps = convAckMessages.map(function (message) {
|
27961 | return message.timestamp;
|
27962 | });
|
27963 | var command = new GenericCommand({
|
27964 | cmd: 'ack',
|
27965 | peerId: _this6.id,
|
27966 | ackMessage: new AckCommand({
|
27967 | cid: cid,
|
27968 | fromts: Math.min.apply(null, timestamps),
|
27969 | tots: Math.max.apply(null, timestamps)
|
27970 | })
|
27971 | });
|
27972 | delete _this6._ackMessageBuffer[cid];
|
27973 | return _this6._send(command, false).catch(function (error) {
|
27974 | _this6._debug('send ack failed: %O', error);
|
27975 |
|
27976 | _this6._ackMessageBuffer[cid] = convAckMessages;
|
27977 | });
|
27978 | }));
|
27979 | };
|
27980 |
|
27981 | _proto._omitPeerId = function _omitPeerId(value) {
|
27982 | internal(this).peerIdOmittable = value;
|
27983 | };
|
27984 |
|
27985 | _proto._send = function _send(cmd) {
|
27986 | var _this$_connection;
|
27987 |
|
27988 | var command = cmd;
|
27989 |
|
27990 | if (!internal(this).peerIdOmittable && this.id) {
|
27991 | command.peerId = this.id;
|
27992 | }
|
27993 |
|
27994 | for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
27995 | args[_key3 - 1] = arguments[_key3];
|
27996 | }
|
27997 |
|
27998 | return (_this$_connection = this._connection).send.apply(_this$_connection, [command].concat(args));
|
27999 | };
|
28000 |
|
28001 | _proto._open =
|
28002 |
|
28003 | function () {
|
28004 | var _open2 = _asyncToGenerator(
|
28005 |
|
28006 | regenerator.mark(function _callee5(appId, tag, deviceId) {
|
28007 | var isReconnect,
|
28008 | _internal2,
|
28009 | lastUnreadNotifTime,
|
28010 | lastPatchTime,
|
28011 | lastNotificationTime,
|
28012 | command,
|
28013 | signatureResult,
|
28014 | sessionToken,
|
28015 | resCommand,
|
28016 | _resCommand,
|
28017 | peerId,
|
28018 | sessionMessage,
|
28019 | _resCommand$sessionMe,
|
28020 | token,
|
28021 | tokenTTL,
|
28022 | code,
|
28023 | serverTs,
|
28024 | serverTime,
|
28025 | _args5 = arguments;
|
28026 |
|
28027 | return regenerator.wrap(function _callee5$(_context5) {
|
28028 | while (1) {
|
28029 | switch (_context5.prev = _context5.next) {
|
28030 | case 0:
|
28031 | isReconnect = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : false;
|
28032 |
|
28033 | this._debug('open session');
|
28034 |
|
28035 | _internal2 = internal(this), lastUnreadNotifTime = _internal2.lastUnreadNotifTime, lastPatchTime = _internal2.lastPatchTime, lastNotificationTime = _internal2.lastNotificationTime;
|
28036 | command = new GenericCommand({
|
28037 | cmd: 'session',
|
28038 | op: 'open',
|
28039 | appId: appId,
|
28040 | peerId: this.id,
|
28041 | sessionMessage: new SessionCommand({
|
28042 | ua: "js/".concat(version),
|
28043 | r: isReconnect,
|
28044 | lastUnreadNotifTime: lastUnreadNotifTime,
|
28045 | lastPatchTime: lastPatchTime,
|
28046 | configBitmap: configBitmap
|
28047 | })
|
28048 | });
|
28049 |
|
28050 | if (isReconnect) {
|
28051 | _context5.next = 13;
|
28052 | break;
|
28053 | }
|
28054 |
|
28055 | Object.assign(command.sessionMessage, trim({
|
28056 | tag: tag,
|
28057 | deviceId: deviceId
|
28058 | }));
|
28059 |
|
28060 | if (!this.options.signatureFactory) {
|
28061 | _context5.next = 11;
|
28062 | break;
|
28063 | }
|
28064 |
|
28065 | _context5.next = 9;
|
28066 | return runSignatureFactory(this.options.signatureFactory, [this._identity]);
|
28067 |
|
28068 | case 9:
|
28069 | signatureResult = _context5.sent;
|
28070 | Object.assign(command.sessionMessage, keyRemap({
|
28071 | signature: 's',
|
28072 | timestamp: 't',
|
28073 | nonce: 'n'
|
28074 | }, signatureResult));
|
28075 |
|
28076 | case 11:
|
28077 | _context5.next = 17;
|
28078 | break;
|
28079 |
|
28080 | case 13:
|
28081 | _context5.next = 15;
|
28082 | return this._sessionManager.getSessionToken({
|
28083 | autoRefresh: false
|
28084 | });
|
28085 |
|
28086 | case 15:
|
28087 | sessionToken = _context5.sent;
|
28088 |
|
28089 | if (sessionToken && sessionToken !== Expirable.EXPIRED) {
|
28090 | Object.assign(command.sessionMessage, {
|
28091 | st: sessionToken
|
28092 | });
|
28093 | }
|
28094 |
|
28095 | case 17:
|
28096 | _context5.prev = 17;
|
28097 | _context5.next = 20;
|
28098 | return this._send(command);
|
28099 |
|
28100 | case 20:
|
28101 | resCommand = _context5.sent;
|
28102 | _context5.next = 32;
|
28103 | break;
|
28104 |
|
28105 | case 23:
|
28106 | _context5.prev = 23;
|
28107 | _context5.t0 = _context5["catch"](17);
|
28108 |
|
28109 | if (!(_context5.t0.code === ErrorCode.SESSION_TOKEN_EXPIRED)) {
|
28110 | _context5.next = 31;
|
28111 | break;
|
28112 | }
|
28113 |
|
28114 | if (this._sessionManager) {
|
28115 | _context5.next = 28;
|
28116 | break;
|
28117 | }
|
28118 |
|
28119 | throw new Error('Unexpected session expiration');
|
28120 |
|
28121 | case 28:
|
28122 | debug$a('Session token expired, reopening');
|
28123 |
|
28124 | this._sessionManager.revoke();
|
28125 |
|
28126 | return _context5.abrupt("return", this._open(appId, tag, deviceId, isReconnect));
|
28127 |
|
28128 | case 31:
|
28129 | throw _context5.t0;
|
28130 |
|
28131 | case 32:
|
28132 | _resCommand = resCommand, peerId = _resCommand.peerId, sessionMessage = _resCommand.sessionMessage, _resCommand$sessionMe = _resCommand.sessionMessage, token = _resCommand$sessionMe.st, tokenTTL = _resCommand$sessionMe.stTtl, code = _resCommand$sessionMe.code, serverTs = _resCommand.serverTs;
|
28133 |
|
28134 | if (!code) {
|
28135 | _context5.next = 35;
|
28136 | break;
|
28137 | }
|
28138 |
|
28139 | throw createError(sessionMessage);
|
28140 |
|
28141 | case 35:
|
28142 | if (peerId) {
|
28143 | this.id = peerId;
|
28144 | if (!this._identity) this._identity = peerId;
|
28145 |
|
28146 | if (token) {
|
28147 | this._sessionManager = this._sessionManager || this._createSessionManager();
|
28148 |
|
28149 | this._sessionManager.setSessionToken(token, tokenTTL);
|
28150 | }
|
28151 |
|
28152 | serverTime = getTime(decodeDate(serverTs));
|
28153 |
|
28154 | if (serverTs) {
|
28155 | internal(this).lastPatchTime = serverTime;
|
28156 | }
|
28157 |
|
28158 | if (lastNotificationTime) {
|
28159 |
|
28160 | this._syncNotifications(lastNotificationTime).catch(function (error) {
|
28161 | return console.warn('Syncing notifications failed:', error);
|
28162 | });
|
28163 | } else {
|
28164 |
|
28165 | internal(this).lastNotificationTime = serverTime;
|
28166 | }
|
28167 | } else {
|
28168 | console.warn('Unexpected session opened without peerId.');
|
28169 | }
|
28170 |
|
28171 | return _context5.abrupt("return", undefined);
|
28172 |
|
28173 | case 37:
|
28174 | case "end":
|
28175 | return _context5.stop();
|
28176 | }
|
28177 | }
|
28178 | }, _callee5, this, [[17, 23]]);
|
28179 | }));
|
28180 |
|
28181 | function _open(_x5, _x6, _x7) {
|
28182 | return _open2.apply(this, arguments);
|
28183 | }
|
28184 |
|
28185 | return _open;
|
28186 | }();
|
28187 |
|
28188 | _proto._syncNotifications =
|
28189 |
|
28190 | function () {
|
28191 | var _syncNotifications2 = _asyncToGenerator(
|
28192 |
|
28193 | regenerator.mark(function _callee6(timestamp) {
|
28194 | var _this7 = this;
|
28195 |
|
28196 | var _ref7, hasMore, notifications;
|
28197 |
|
28198 | return regenerator.wrap(function _callee6$(_context6) {
|
28199 | while (1) {
|
28200 | switch (_context6.prev = _context6.next) {
|
28201 | case 0:
|
28202 | _context6.next = 2;
|
28203 | return this._fetchNotifications(timestamp);
|
28204 |
|
28205 | case 2:
|
28206 | _ref7 = _context6.sent;
|
28207 | hasMore = _ref7.hasMore;
|
28208 | notifications = _ref7.notifications;
|
28209 | notifications.forEach(function (notification) {
|
28210 | var cmd = notification.cmd,
|
28211 | op = notification.op,
|
28212 | serverTs = notification.serverTs,
|
28213 | notificationType = notification.notificationType,
|
28214 | payload = _objectWithoutProperties(notification, ["cmd", "op", "serverTs", "notificationType"]);
|
28215 |
|
28216 | _this7._dispatchCommand(_defineProperty({
|
28217 | cmd: CommandType[cmd],
|
28218 | op: OpType[op],
|
28219 | serverTs: serverTs,
|
28220 | notificationType: notificationType
|
28221 | }, "".concat(cmd, "Message"), payload));
|
28222 | });
|
28223 |
|
28224 | if (!hasMore) {
|
28225 | _context6.next = 8;
|
28226 | break;
|
28227 | }
|
28228 |
|
28229 | return _context6.abrupt("return", this._syncNotifications(internal(this).lastNotificationTime));
|
28230 |
|
28231 | case 8:
|
28232 | return _context6.abrupt("return", undefined);
|
28233 |
|
28234 | case 9:
|
28235 | case "end":
|
28236 | return _context6.stop();
|
28237 | }
|
28238 | }
|
28239 | }, _callee6, this);
|
28240 | }));
|
28241 |
|
28242 | function _syncNotifications(_x8) {
|
28243 | return _syncNotifications2.apply(this, arguments);
|
28244 | }
|
28245 |
|
28246 | return _syncNotifications;
|
28247 | }();
|
28248 |
|
28249 | _proto._fetchNotifications =
|
28250 |
|
28251 | function () {
|
28252 | var _fetchNotifications2 = _asyncToGenerator(
|
28253 |
|
28254 | regenerator.mark(function _callee7(timestamp) {
|
28255 | return regenerator.wrap(function _callee7$(_context7) {
|
28256 | while (1) {
|
28257 | switch (_context7.prev = _context7.next) {
|
28258 | case 0:
|
28259 | return _context7.abrupt("return", this._requestWithSessionToken({
|
28260 | method: 'GET',
|
28261 | path: '/rtm/notifications',
|
28262 | query: {
|
28263 | start_ts: timestamp,
|
28264 | notification_type: 'permanent'
|
28265 | }
|
28266 | }));
|
28267 |
|
28268 | case 1:
|
28269 | case "end":
|
28270 | return _context7.stop();
|
28271 | }
|
28272 | }
|
28273 | }, _callee7, this);
|
28274 | }));
|
28275 |
|
28276 | function _fetchNotifications(_x9) {
|
28277 | return _fetchNotifications2.apply(this, arguments);
|
28278 | }
|
28279 |
|
28280 | return _fetchNotifications;
|
28281 | }();
|
28282 |
|
28283 | _proto._createSessionManager = function _createSessionManager() {
|
28284 | var _this8 = this;
|
28285 |
|
28286 | debug$a('create SessionManager');
|
28287 | return new SessionManager({
|
28288 | onBeforeGetSessionToken: this._connection.checkConnectionAvailability.bind(this._connection),
|
28289 | refresh: function refresh(manager, expiredSessionToken) {
|
28290 | return manager.setSessionTokenAsync(Promise.resolve(new GenericCommand({
|
28291 | cmd: 'session',
|
28292 | op: 'refresh',
|
28293 | sessionMessage: new SessionCommand({
|
28294 | ua: "js/".concat(version),
|
28295 | st: expiredSessionToken
|
28296 | })
|
28297 | })).then(
|
28298 |
|
28299 | function () {
|
28300 | var _ref8 = _asyncToGenerator(
|
28301 |
|
28302 | regenerator.mark(function _callee8(command) {
|
28303 | var signatureResult;
|
28304 | return regenerator.wrap(function _callee8$(_context8) {
|
28305 | while (1) {
|
28306 | switch (_context8.prev = _context8.next) {
|
28307 | case 0:
|
28308 | if (!_this8.options.signatureFactory) {
|
28309 | _context8.next = 5;
|
28310 | break;
|
28311 | }
|
28312 |
|
28313 | _context8.next = 3;
|
28314 | return runSignatureFactory(_this8.options.signatureFactory, [_this8._identity]);
|
28315 |
|
28316 | case 3:
|
28317 | signatureResult = _context8.sent;
|
28318 | Object.assign(command.sessionMessage, keyRemap({
|
28319 | signature: 's',
|
28320 | timestamp: 't',
|
28321 | nonce: 'n'
|
28322 | }, signatureResult));
|
28323 |
|
28324 | case 5:
|
28325 | return _context8.abrupt("return", command);
|
28326 |
|
28327 | case 6:
|
28328 | case "end":
|
28329 | return _context8.stop();
|
28330 | }
|
28331 | }
|
28332 | }, _callee8, this);
|
28333 | }));
|
28334 |
|
28335 | return function (_x10) {
|
28336 | return _ref8.apply(this, arguments);
|
28337 | };
|
28338 | }()).then(_this8._send.bind(_this8)).then(function (_ref9) {
|
28339 | var _ref9$sessionMessage = _ref9.sessionMessage,
|
28340 | token = _ref9$sessionMessage.st,
|
28341 | ttl = _ref9$sessionMessage.stTtl;
|
28342 | return [token, ttl];
|
28343 | }));
|
28344 | }
|
28345 | });
|
28346 | };
|
28347 |
|
28348 | _proto._requestWithSessionToken =
|
28349 |
|
28350 | function () {
|
28351 | var _requestWithSessionToken2 = _asyncToGenerator(
|
28352 |
|
28353 | regenerator.mark(function _callee9(_ref10) {
|
28354 | var headers, query, params, sessionToken;
|
28355 | return regenerator.wrap(function _callee9$(_context9) {
|
28356 | while (1) {
|
28357 | switch (_context9.prev = _context9.next) {
|
28358 | case 0:
|
28359 | headers = _ref10.headers, query = _ref10.query, params = _objectWithoutProperties(_ref10, ["headers", "query"]);
|
28360 | _context9.next = 3;
|
28361 | return this._sessionManager.getSessionToken();
|
28362 |
|
28363 | case 3:
|
28364 | sessionToken = _context9.sent;
|
28365 | return _context9.abrupt("return", this._request(_objectSpread({
|
28366 | headers: _objectSpread({
|
28367 | 'X-LC-IM-Session-Token': sessionToken
|
28368 | }, headers),
|
28369 | query: _objectSpread({
|
28370 | client_id: this.id
|
28371 | }, query)
|
28372 | }, params)));
|
28373 |
|
28374 | case 5:
|
28375 | case "end":
|
28376 | return _context9.stop();
|
28377 | }
|
28378 | }
|
28379 | }, _callee9, this);
|
28380 | }));
|
28381 |
|
28382 | function _requestWithSessionToken(_x11) {
|
28383 | return _requestWithSessionToken2.apply(this, arguments);
|
28384 | }
|
28385 |
|
28386 | return _requestWithSessionToken;
|
28387 | }()
|
28388 | |
28389 |
|
28390 |
|
28391 |
|
28392 | ;
|
28393 |
|
28394 | _proto.close =
|
28395 |
|
28396 | function () {
|
28397 | var _close = _asyncToGenerator(
|
28398 |
|
28399 | regenerator.mark(function _callee10() {
|
28400 | var _ee, command;
|
28401 |
|
28402 | return regenerator.wrap(function _callee10$(_context10) {
|
28403 | while (1) {
|
28404 | switch (_context10.prev = _context10.next) {
|
28405 | case 0:
|
28406 | this._debug('close session');
|
28407 |
|
28408 | _ee = internal(this)._eventemitter;
|
28409 |
|
28410 | _ee.emit('beforeclose');
|
28411 |
|
28412 | if (!this._connection.is('connected')) {
|
28413 | _context10.next = 7;
|
28414 | break;
|
28415 | }
|
28416 |
|
28417 | command = new GenericCommand({
|
28418 | cmd: 'session',
|
28419 | op: 'close'
|
28420 | });
|
28421 | _context10.next = 7;
|
28422 | return this._send(command);
|
28423 |
|
28424 | case 7:
|
28425 | _ee.emit('close');
|
28426 |
|
28427 | this.emit(CLOSE$1, {
|
28428 | code: 0
|
28429 | });
|
28430 |
|
28431 | case 9:
|
28432 | case "end":
|
28433 | return _context10.stop();
|
28434 | }
|
28435 | }
|
28436 | }, _callee10, this);
|
28437 | }));
|
28438 |
|
28439 | function close() {
|
28440 | return _close.apply(this, arguments);
|
28441 | }
|
28442 |
|
28443 | return close;
|
28444 | }()
|
28445 | |
28446 |
|
28447 |
|
28448 |
|
28449 |
|
28450 | ;
|
28451 |
|
28452 | _proto.ping =
|
28453 |
|
28454 | function () {
|
28455 | var _ping = _asyncToGenerator(
|
28456 |
|
28457 | regenerator.mark(function _callee11(clientIds) {
|
28458 | var command, resCommand;
|
28459 | return regenerator.wrap(function _callee11$(_context11) {
|
28460 | while (1) {
|
28461 | switch (_context11.prev = _context11.next) {
|
28462 | case 0:
|
28463 | this._debug('ping');
|
28464 |
|
28465 | if (clientIds instanceof Array) {
|
28466 | _context11.next = 3;
|
28467 | break;
|
28468 | }
|
28469 |
|
28470 | throw new TypeError("clientIds ".concat(clientIds, " is not an Array"));
|
28471 |
|
28472 | case 3:
|
28473 | if (clientIds.length) {
|
28474 | _context11.next = 5;
|
28475 | break;
|
28476 | }
|
28477 |
|
28478 | return _context11.abrupt("return", Promise.resolve([]));
|
28479 |
|
28480 | case 5:
|
28481 | command = new GenericCommand({
|
28482 | cmd: 'session',
|
28483 | op: 'query',
|
28484 | sessionMessage: new SessionCommand({
|
28485 | sessionPeerIds: clientIds
|
28486 | })
|
28487 | });
|
28488 | _context11.next = 8;
|
28489 | return this._send(command);
|
28490 |
|
28491 | case 8:
|
28492 | resCommand = _context11.sent;
|
28493 | return _context11.abrupt("return", resCommand.sessionMessage.onlineSessionPeerIds);
|
28494 |
|
28495 | case 10:
|
28496 | case "end":
|
28497 | return _context11.stop();
|
28498 | }
|
28499 | }
|
28500 | }, _callee11, this);
|
28501 | }));
|
28502 |
|
28503 | function ping(_x12) {
|
28504 | return _ping.apply(this, arguments);
|
28505 | }
|
28506 |
|
28507 | return ping;
|
28508 | }()
|
28509 | |
28510 |
|
28511 |
|
28512 |
|
28513 |
|
28514 |
|
28515 | ;
|
28516 |
|
28517 | _proto.getConversation =
|
28518 |
|
28519 | function () {
|
28520 | var _getConversation = _asyncToGenerator(
|
28521 |
|
28522 | regenerator.mark(function _callee12(id) {
|
28523 | var noCache,
|
28524 | cachedConversation,
|
28525 | _args12 = arguments;
|
28526 | return regenerator.wrap(function _callee12$(_context12) {
|
28527 | while (1) {
|
28528 | switch (_context12.prev = _context12.next) {
|
28529 | case 0:
|
28530 | noCache = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
|
28531 |
|
28532 | if (!(typeof id !== 'string')) {
|
28533 | _context12.next = 3;
|
28534 | break;
|
28535 | }
|
28536 |
|
28537 | throw new TypeError("".concat(id, " is not a String"));
|
28538 |
|
28539 | case 3:
|
28540 | if (noCache) {
|
28541 | _context12.next = 7;
|
28542 | break;
|
28543 | }
|
28544 |
|
28545 | cachedConversation = this._conversationCache.get(id);
|
28546 |
|
28547 | if (!cachedConversation) {
|
28548 | _context12.next = 7;
|
28549 | break;
|
28550 | }
|
28551 |
|
28552 | return _context12.abrupt("return", cachedConversation);
|
28553 |
|
28554 | case 7:
|
28555 | if (!isTemporaryConversatrionId(id)) {
|
28556 | _context12.next = 14;
|
28557 | break;
|
28558 | }
|
28559 |
|
28560 | _context12.next = 10;
|
28561 | return this._getTemporaryConversations([id]);
|
28562 |
|
28563 | case 10:
|
28564 | _context12.t0 = _context12.sent[0];
|
28565 |
|
28566 | if (_context12.t0) {
|
28567 | _context12.next = 13;
|
28568 | break;
|
28569 | }
|
28570 |
|
28571 | _context12.t0 = null;
|
28572 |
|
28573 | case 13:
|
28574 | return _context12.abrupt("return", _context12.t0);
|
28575 |
|
28576 | case 14:
|
28577 | return _context12.abrupt("return", this.getQuery().equalTo('objectId', id).find().then(function (conversations) {
|
28578 | return conversations[0] || null;
|
28579 | }));
|
28580 |
|
28581 | case 15:
|
28582 | case "end":
|
28583 | return _context12.stop();
|
28584 | }
|
28585 | }
|
28586 | }, _callee12, this);
|
28587 | }));
|
28588 |
|
28589 | function getConversation(_x13) {
|
28590 | return _getConversation.apply(this, arguments);
|
28591 | }
|
28592 |
|
28593 | return getConversation;
|
28594 | }()
|
28595 | |
28596 |
|
28597 |
|
28598 |
|
28599 |
|
28600 |
|
28601 |
|
28602 | ;
|
28603 |
|
28604 | _proto.getConversations =
|
28605 |
|
28606 | function () {
|
28607 | var _getConversations = _asyncToGenerator(
|
28608 |
|
28609 | regenerator.mark(function _callee13(ids) {
|
28610 | var _this9 = this;
|
28611 |
|
28612 | var noCache,
|
28613 | remoteConversationIds,
|
28614 | remoteTemporaryConversationIds,
|
28615 | query,
|
28616 | remoteTemporaryConversationsPromise,
|
28617 | _args13 = arguments;
|
28618 | return regenerator.wrap(function _callee13$(_context13) {
|
28619 | while (1) {
|
28620 | switch (_context13.prev = _context13.next) {
|
28621 | case 0:
|
28622 | noCache = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
|
28623 | remoteConversationIds = noCache ? ids : ids.filter(function (id) {
|
28624 | return _this9._conversationCache.get(id) === null;
|
28625 | });
|
28626 |
|
28627 | if (!remoteConversationIds.length) {
|
28628 | _context13.next = 9;
|
28629 | break;
|
28630 | }
|
28631 |
|
28632 | remoteTemporaryConversationIds = remove_1(remoteConversationIds, isTemporaryConversatrionId);
|
28633 | query = [];
|
28634 |
|
28635 | if (remoteConversationIds.length) {
|
28636 | query.push(this.getQuery().containedIn('objectId', remoteConversationIds).limit(999).find());
|
28637 | }
|
28638 |
|
28639 | if (remoteTemporaryConversationIds.length) {
|
28640 | remoteTemporaryConversationsPromise = remoteTemporaryConversationIds.map(this._getTemporaryConversations.bind(this));
|
28641 | query.push.apply(query, _toConsumableArray(remoteTemporaryConversationsPromise));
|
28642 | }
|
28643 |
|
28644 | _context13.next = 9;
|
28645 | return Promise.all(query);
|
28646 |
|
28647 | case 9:
|
28648 | return _context13.abrupt("return", ids.map(function (id) {
|
28649 | return _this9._conversationCache.get(id);
|
28650 | }));
|
28651 |
|
28652 | case 10:
|
28653 | case "end":
|
28654 | return _context13.stop();
|
28655 | }
|
28656 | }
|
28657 | }, _callee13, this);
|
28658 | }));
|
28659 |
|
28660 | function getConversations(_x14) {
|
28661 | return _getConversations.apply(this, arguments);
|
28662 | }
|
28663 |
|
28664 | return getConversations;
|
28665 | }();
|
28666 |
|
28667 | _proto._getTemporaryConversations =
|
28668 |
|
28669 | function () {
|
28670 | var _getTemporaryConversations2 = _asyncToGenerator(
|
28671 |
|
28672 | regenerator.mark(function _callee14(ids) {
|
28673 | var command, resCommand;
|
28674 | return regenerator.wrap(function _callee14$(_context14) {
|
28675 | while (1) {
|
28676 | switch (_context14.prev = _context14.next) {
|
28677 | case 0:
|
28678 | command = new GenericCommand({
|
28679 | cmd: 'conv',
|
28680 | op: 'query',
|
28681 | convMessage: new ConvCommand({
|
28682 | tempConvIds: ids
|
28683 | })
|
28684 | });
|
28685 | _context14.next = 3;
|
28686 | return this._send(command);
|
28687 |
|
28688 | case 3:
|
28689 | resCommand = _context14.sent;
|
28690 | return _context14.abrupt("return", this._handleQueryResults(resCommand));
|
28691 |
|
28692 | case 5:
|
28693 | case "end":
|
28694 | return _context14.stop();
|
28695 | }
|
28696 | }
|
28697 | }, _callee14, this);
|
28698 | }));
|
28699 |
|
28700 | function _getTemporaryConversations(_x15) {
|
28701 | return _getTemporaryConversations2.apply(this, arguments);
|
28702 | }
|
28703 |
|
28704 | return _getTemporaryConversations;
|
28705 | }()
|
28706 | |
28707 |
|
28708 |
|
28709 |
|
28710 | ;
|
28711 |
|
28712 | _proto.getQuery = function getQuery() {
|
28713 | return new ConversationQuery(this);
|
28714 | }
|
28715 | |
28716 |
|
28717 |
|
28718 |
|
28719 | ;
|
28720 |
|
28721 | _proto.getChatRoomQuery = function getChatRoomQuery() {
|
28722 | return this.getQuery().equalTo('tr', true);
|
28723 | }
|
28724 | |
28725 |
|
28726 |
|
28727 |
|
28728 | ;
|
28729 |
|
28730 | _proto.getServiceConversationQuery = function getServiceConversationQuery() {
|
28731 | return this.getQuery().equalTo('sys', true);
|
28732 | };
|
28733 |
|
28734 | _proto._executeQuery =
|
28735 |
|
28736 | function () {
|
28737 | var _executeQuery2 = _asyncToGenerator(
|
28738 |
|
28739 | regenerator.mark(function _callee15(query) {
|
28740 | var queryJSON, command, resCommand;
|
28741 | return regenerator.wrap(function _callee15$(_context15) {
|
28742 | while (1) {
|
28743 | switch (_context15.prev = _context15.next) {
|
28744 | case 0:
|
28745 | queryJSON = query.toJSON();
|
28746 | queryJSON.where = new JsonObjectMessage({
|
28747 | data: JSON.stringify(encode(queryJSON.where))
|
28748 | });
|
28749 | command = new GenericCommand({
|
28750 | cmd: 'conv',
|
28751 | op: 'query',
|
28752 | convMessage: new ConvCommand(queryJSON)
|
28753 | });
|
28754 | _context15.next = 5;
|
28755 | return this._send(command);
|
28756 |
|
28757 | case 5:
|
28758 | resCommand = _context15.sent;
|
28759 | return _context15.abrupt("return", this._handleQueryResults(resCommand));
|
28760 |
|
28761 | case 7:
|
28762 | case "end":
|
28763 | return _context15.stop();
|
28764 | }
|
28765 | }
|
28766 | }, _callee15, this);
|
28767 | }));
|
28768 |
|
28769 | function _executeQuery(_x16) {
|
28770 | return _executeQuery2.apply(this, arguments);
|
28771 | }
|
28772 |
|
28773 | return _executeQuery;
|
28774 | }();
|
28775 |
|
28776 | _proto._handleQueryResults =
|
28777 |
|
28778 | function () {
|
28779 | var _handleQueryResults2 = _asyncToGenerator(
|
28780 |
|
28781 | regenerator.mark(function _callee16(resCommand) {
|
28782 | var conversations, commandString;
|
28783 | return regenerator.wrap(function _callee16$(_context16) {
|
28784 | while (1) {
|
28785 | switch (_context16.prev = _context16.next) {
|
28786 | case 0:
|
28787 | _context16.prev = 0;
|
28788 | conversations = decode(JSON.parse(resCommand.convMessage.results.data));
|
28789 | _context16.next = 8;
|
28790 | break;
|
28791 |
|
28792 | case 4:
|
28793 | _context16.prev = 4;
|
28794 | _context16.t0 = _context16["catch"](0);
|
28795 | commandString = JSON.stringify(trim(resCommand));
|
28796 | throw new Error("Parse query result failed: ".concat(_context16.t0.message, ". Command: ").concat(commandString));
|
28797 |
|
28798 | case 8:
|
28799 | _context16.next = 10;
|
28800 | return Promise.all(conversations.map(this._parseConversationFromRawData.bind(this)));
|
28801 |
|
28802 | case 10:
|
28803 | conversations = _context16.sent;
|
28804 | return _context16.abrupt("return", conversations.map(this._upsertConversationToCache.bind(this)));
|
28805 |
|
28806 | case 12:
|
28807 | case "end":
|
28808 | return _context16.stop();
|
28809 | }
|
28810 | }
|
28811 | }, _callee16, this, [[0, 4]]);
|
28812 | }));
|
28813 |
|
28814 | function _handleQueryResults(_x17) {
|
28815 | return _handleQueryResults2.apply(this, arguments);
|
28816 | }
|
28817 |
|
28818 | return _handleQueryResults;
|
28819 | }();
|
28820 |
|
28821 | _proto._upsertConversationToCache = function _upsertConversationToCache(fetchedConversation) {
|
28822 | var conversation = this._conversationCache.get(fetchedConversation.id);
|
28823 |
|
28824 | if (!conversation) {
|
28825 | conversation = fetchedConversation;
|
28826 |
|
28827 | this._debug('no match, set cache');
|
28828 |
|
28829 | this._conversationCache.set(fetchedConversation.id, fetchedConversation);
|
28830 | } else {
|
28831 | this._debug('update cached conversation');
|
28832 |
|
28833 | ['creator', 'createdAt', 'updatedAt', 'lastMessageAt', 'lastMessage', 'mutedMembers', 'members', '_attributes', 'transient', 'muted'].forEach(function (key) {
|
28834 | var value = fetchedConversation[key];
|
28835 | if (value !== undefined) conversation[key] = value;
|
28836 | });
|
28837 | if (conversation._reset) conversation._reset();
|
28838 | }
|
28839 |
|
28840 | return conversation;
|
28841 | }
|
28842 | |
28843 |
|
28844 |
|
28845 |
|
28846 |
|
28847 |
|
28848 | ;
|
28849 |
|
28850 | _proto.parseMessage =
|
28851 |
|
28852 | function () {
|
28853 | var _parseMessage = _asyncToGenerator(
|
28854 |
|
28855 | regenerator.mark(function _callee17(_ref11) {
|
28856 | var data, _ref11$bin, bin, properties, content, message;
|
28857 |
|
28858 | return regenerator.wrap(function _callee17$(_context17) {
|
28859 | while (1) {
|
28860 | switch (_context17.prev = _context17.next) {
|
28861 | case 0:
|
28862 | data = _ref11.data, _ref11$bin = _ref11.bin, bin = _ref11$bin === void 0 ? false : _ref11$bin, properties = _objectWithoutProperties(_ref11, ["data", "bin"]);
|
28863 | content = bin ? base64Arraybuffer_2(data) : data;
|
28864 | _context17.next = 4;
|
28865 | return this._messageParser.parse(content);
|
28866 |
|
28867 | case 4:
|
28868 | message = _context17.sent;
|
28869 | Object.assign(message, properties);
|
28870 |
|
28871 | message._updateMentioned(this.id);
|
28872 |
|
28873 | return _context17.abrupt("return", message);
|
28874 |
|
28875 | case 8:
|
28876 | case "end":
|
28877 | return _context17.stop();
|
28878 | }
|
28879 | }
|
28880 | }, _callee17, this);
|
28881 | }));
|
28882 |
|
28883 | function parseMessage(_x18) {
|
28884 | return _parseMessage.apply(this, arguments);
|
28885 | }
|
28886 |
|
28887 | return parseMessage;
|
28888 | }()
|
28889 | |
28890 |
|
28891 |
|
28892 |
|
28893 |
|
28894 |
|
28895 | ;
|
28896 |
|
28897 | _proto.parseConversation =
|
28898 |
|
28899 | function () {
|
28900 | var _parseConversation = _asyncToGenerator(
|
28901 |
|
28902 | regenerator.mark(function _callee18(_ref12) {
|
28903 | var id, lastMessageAt, lastMessage, lastDeliveredAt, lastReadAt, unreadMessagesCount, members, mentioned, properties, conversationData, transient, system, expiredAt;
|
28904 | return regenerator.wrap(function _callee18$(_context18) {
|
28905 | while (1) {
|
28906 | switch (_context18.prev = _context18.next) {
|
28907 | case 0:
|
28908 | id = _ref12.id, lastMessageAt = _ref12.lastMessageAt, lastMessage = _ref12.lastMessage, lastDeliveredAt = _ref12.lastDeliveredAt, lastReadAt = _ref12.lastReadAt, unreadMessagesCount = _ref12.unreadMessagesCount, members = _ref12.members, mentioned = _ref12.mentioned, properties = _objectWithoutProperties(_ref12, ["id", "lastMessageAt", "lastMessage", "lastDeliveredAt", "lastReadAt", "unreadMessagesCount", "members", "mentioned"]);
|
28909 | conversationData = {
|
28910 | id: id,
|
28911 | lastMessageAt: lastMessageAt,
|
28912 | lastMessage: lastMessage,
|
28913 | lastDeliveredAt: lastDeliveredAt,
|
28914 | lastReadAt: lastReadAt,
|
28915 | unreadMessagesCount: unreadMessagesCount,
|
28916 | members: members,
|
28917 | mentioned: mentioned
|
28918 | };
|
28919 |
|
28920 | if (!lastMessage) {
|
28921 | _context18.next = 7;
|
28922 | break;
|
28923 | }
|
28924 |
|
28925 | _context18.next = 5;
|
28926 | return this.parseMessage(lastMessage);
|
28927 |
|
28928 | case 5:
|
28929 | conversationData.lastMessage = _context18.sent;
|
28930 |
|
28931 | conversationData.lastMessage._setStatus(MessageStatus.SENT);
|
28932 |
|
28933 | case 7:
|
28934 | transient = properties.transient, system = properties.system, expiredAt = properties.expiredAt;
|
28935 |
|
28936 | if (!transient) {
|
28937 | _context18.next = 10;
|
28938 | break;
|
28939 | }
|
28940 |
|
28941 | return _context18.abrupt("return", new ChatRoom(conversationData, properties, this));
|
28942 |
|
28943 | case 10:
|
28944 | if (!system) {
|
28945 | _context18.next = 12;
|
28946 | break;
|
28947 | }
|
28948 |
|
28949 | return _context18.abrupt("return", new ServiceConversation(conversationData, properties, this));
|
28950 |
|
28951 | case 12:
|
28952 | if (!(expiredAt || isTemporaryConversatrionId(id))) {
|
28953 | _context18.next = 14;
|
28954 | break;
|
28955 | }
|
28956 |
|
28957 | return _context18.abrupt("return", new TemporaryConversation(conversationData, {
|
28958 | expiredAt: expiredAt
|
28959 | }, this));
|
28960 |
|
28961 | case 14:
|
28962 | return _context18.abrupt("return", new Conversation(conversationData, properties, this));
|
28963 |
|
28964 | case 15:
|
28965 | case "end":
|
28966 | return _context18.stop();
|
28967 | }
|
28968 | }
|
28969 | }, _callee18, this);
|
28970 | }));
|
28971 |
|
28972 | function parseConversation(_x19) {
|
28973 | return _parseConversation.apply(this, arguments);
|
28974 | }
|
28975 |
|
28976 | return parseConversation;
|
28977 | }();
|
28978 |
|
28979 | _proto._parseConversationFromRawData =
|
28980 |
|
28981 | function () {
|
28982 | var _parseConversationFromRawData2 = _asyncToGenerator(
|
28983 |
|
28984 | regenerator.mark(function _callee19(rawData) {
|
28985 | var data, ttl;
|
28986 | return regenerator.wrap(function _callee19$(_context19) {
|
28987 | while (1) {
|
28988 | switch (_context19.prev = _context19.next) {
|
28989 | case 0:
|
28990 | data = keyRemap({
|
28991 | objectId: 'id',
|
28992 | lm: 'lastMessageAt',
|
28993 | m: 'members',
|
28994 | tr: 'transient',
|
28995 | sys: 'system',
|
28996 | c: 'creator',
|
28997 | mu: 'mutedMembers'
|
28998 | }, rawData);
|
28999 |
|
29000 | if (data.msg) {
|
29001 | data.lastMessage = {
|
29002 | data: data.msg,
|
29003 | bin: data.bin,
|
29004 | from: data.msg_from,
|
29005 | id: data.msg_mid,
|
29006 | timestamp: data.msg_timestamp,
|
29007 | updatedAt: data.patch_timestamp
|
29008 | };
|
29009 | delete data.lastMessageFrom;
|
29010 | delete data.lastMessageId;
|
29011 | delete data.lastMessageTimestamp;
|
29012 | delete data.lastMessagePatchTimestamp;
|
29013 | }
|
29014 |
|
29015 | ttl = data.ttl;
|
29016 | if (ttl) data.expiredAt = Date.now() + ttl * 1000;
|
29017 | return _context19.abrupt("return", this.parseConversation(data));
|
29018 |
|
29019 | case 5:
|
29020 | case "end":
|
29021 | return _context19.stop();
|
29022 | }
|
29023 | }
|
29024 | }, _callee19, this);
|
29025 | }));
|
29026 |
|
29027 | function _parseConversationFromRawData(_x20) {
|
29028 | return _parseConversationFromRawData2.apply(this, arguments);
|
29029 | }
|
29030 |
|
29031 | return _parseConversationFromRawData;
|
29032 | }()
|
29033 | |
29034 |
|
29035 |
|
29036 |
|
29037 |
|
29038 |
|
29039 |
|
29040 |
|
29041 | ;
|
29042 |
|
29043 | _proto.createConversation =
|
29044 |
|
29045 | function () {
|
29046 | var _createConversation = _asyncToGenerator(
|
29047 |
|
29048 | regenerator.mark(function _callee20() {
|
29049 | var _ref13,
|
29050 | m,
|
29051 | name,
|
29052 | transient,
|
29053 | _ref13$unique,
|
29054 | unique,
|
29055 | tempConv,
|
29056 | tempConvTTL,
|
29057 | properties,
|
29058 | members,
|
29059 | attr,
|
29060 | startCommandJson,
|
29061 | command,
|
29062 | params,
|
29063 | signatureResult,
|
29064 | _ref14,
|
29065 | _ref14$convMessage,
|
29066 | cid,
|
29067 | cdate,
|
29068 | ttl,
|
29069 | data,
|
29070 | conversation,
|
29071 | _args20 = arguments;
|
29072 |
|
29073 | return regenerator.wrap(function _callee20$(_context20) {
|
29074 | while (1) {
|
29075 | switch (_context20.prev = _context20.next) {
|
29076 | case 0:
|
29077 | _ref13 = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {}, m = _ref13.members, name = _ref13.name, transient = _ref13.transient, _ref13$unique = _ref13.unique, unique = _ref13$unique === void 0 ? true : _ref13$unique, tempConv = _ref13._tempConv, tempConvTTL = _ref13._tempConvTTL, properties = _objectWithoutProperties(_ref13, ["members", "name", "transient", "unique", "_tempConv", "_tempConvTTL"]);
|
29078 |
|
29079 | if (transient || Array.isArray(m)) {
|
29080 | _context20.next = 3;
|
29081 | break;
|
29082 | }
|
29083 |
|
29084 | throw new TypeError("conversation members ".concat(m, " is not an array"));
|
29085 |
|
29086 | case 3:
|
29087 | members = new Set(m);
|
29088 | members.add(this.id);
|
29089 | members = Array.from(members).sort();
|
29090 | attr = properties || {};
|
29091 |
|
29092 | if (!name) {
|
29093 | _context20.next = 11;
|
29094 | break;
|
29095 | }
|
29096 |
|
29097 | if (!(typeof name !== 'string')) {
|
29098 | _context20.next = 10;
|
29099 | break;
|
29100 | }
|
29101 |
|
29102 | throw new TypeError("conversation name ".concat(name, " is not a string"));
|
29103 |
|
29104 | case 10:
|
29105 | attr.name = name;
|
29106 |
|
29107 | case 11:
|
29108 | attr = new JsonObjectMessage({
|
29109 | data: JSON.stringify(encode(attr))
|
29110 | });
|
29111 | startCommandJson = {
|
29112 | m: members,
|
29113 | attr: attr,
|
29114 | transient: transient,
|
29115 | unique: unique,
|
29116 | tempConv: tempConv,
|
29117 | tempConvTTL: tempConvTTL
|
29118 | };
|
29119 | command = new GenericCommand({
|
29120 | cmd: 'conv',
|
29121 | op: 'start',
|
29122 | convMessage: new ConvCommand(startCommandJson)
|
29123 | });
|
29124 |
|
29125 | if (!this.options.conversationSignatureFactory) {
|
29126 | _context20.next = 20;
|
29127 | break;
|
29128 | }
|
29129 |
|
29130 | params = [null, this._identity, members, 'create'];
|
29131 | _context20.next = 18;
|
29132 | return runSignatureFactory(this.options.conversationSignatureFactory, params);
|
29133 |
|
29134 | case 18:
|
29135 | signatureResult = _context20.sent;
|
29136 | Object.assign(command.convMessage, keyRemap({
|
29137 | signature: 's',
|
29138 | timestamp: 't',
|
29139 | nonce: 'n'
|
29140 | }, signatureResult));
|
29141 |
|
29142 | case 20:
|
29143 | _context20.next = 22;
|
29144 | return this._send(command);
|
29145 |
|
29146 | case 22:
|
29147 | _ref14 = _context20.sent;
|
29148 | _ref14$convMessage = _ref14.convMessage;
|
29149 | cid = _ref14$convMessage.cid;
|
29150 | cdate = _ref14$convMessage.cdate;
|
29151 | ttl = _ref14$convMessage.tempConvTTL;
|
29152 | data = _objectSpread({
|
29153 | name: name,
|
29154 | transient: transient,
|
29155 | unique: unique,
|
29156 | id: cid,
|
29157 | createdAt: cdate,
|
29158 | updatedAt: cdate,
|
29159 | lastMessageAt: null,
|
29160 | creator: this.id,
|
29161 | members: transient ? [] : members
|
29162 | }, properties);
|
29163 | if (ttl) data.expiredAt = Date.now() + ttl * 1000;
|
29164 | _context20.next = 31;
|
29165 | return this.parseConversation(data);
|
29166 |
|
29167 | case 31:
|
29168 | conversation = _context20.sent;
|
29169 | return _context20.abrupt("return", this._upsertConversationToCache(conversation));
|
29170 |
|
29171 | case 33:
|
29172 | case "end":
|
29173 | return _context20.stop();
|
29174 | }
|
29175 | }
|
29176 | }, _callee20, this);
|
29177 | }));
|
29178 |
|
29179 | function createConversation() {
|
29180 | return _createConversation.apply(this, arguments);
|
29181 | }
|
29182 |
|
29183 | return createConversation;
|
29184 | }()
|
29185 | |
29186 |
|
29187 |
|
29188 |
|
29189 |
|
29190 |
|
29191 |
|
29192 | ;
|
29193 |
|
29194 | _proto.createChatRoom =
|
29195 |
|
29196 | function () {
|
29197 | var _createChatRoom = _asyncToGenerator(
|
29198 |
|
29199 | regenerator.mark(function _callee21(param) {
|
29200 | return regenerator.wrap(function _callee21$(_context21) {
|
29201 | while (1) {
|
29202 | switch (_context21.prev = _context21.next) {
|
29203 | case 0:
|
29204 | return _context21.abrupt("return", this.createConversation(_objectSpread({}, param, {
|
29205 | transient: true,
|
29206 | members: null,
|
29207 | unique: false,
|
29208 | _tempConv: false
|
29209 | })));
|
29210 |
|
29211 | case 1:
|
29212 | case "end":
|
29213 | return _context21.stop();
|
29214 | }
|
29215 | }
|
29216 | }, _callee21, this);
|
29217 | }));
|
29218 |
|
29219 | function createChatRoom(_x21) {
|
29220 | return _createChatRoom.apply(this, arguments);
|
29221 | }
|
29222 |
|
29223 | return createChatRoom;
|
29224 | }()
|
29225 | |
29226 |
|
29227 |
|
29228 |
|
29229 |
|
29230 |
|
29231 |
|
29232 |
|
29233 | ;
|
29234 |
|
29235 | _proto.createTemporaryConversation =
|
29236 |
|
29237 | function () {
|
29238 | var _createTemporaryConversation = _asyncToGenerator(
|
29239 |
|
29240 | regenerator.mark(function _callee22(_ref15) {
|
29241 | var _tempConvTTL, param;
|
29242 |
|
29243 | return regenerator.wrap(function _callee22$(_context22) {
|
29244 | while (1) {
|
29245 | switch (_context22.prev = _context22.next) {
|
29246 | case 0:
|
29247 | _tempConvTTL = _ref15.ttl, param = _objectWithoutProperties(_ref15, ["ttl"]);
|
29248 | return _context22.abrupt("return", this.createConversation(_objectSpread({}, param, {
|
29249 | transient: false,
|
29250 | unique: false,
|
29251 | _tempConv: true,
|
29252 | _tempConvTTL: _tempConvTTL
|
29253 | })));
|
29254 |
|
29255 | case 2:
|
29256 | case "end":
|
29257 | return _context22.stop();
|
29258 | }
|
29259 | }
|
29260 | }, _callee22, this);
|
29261 | }));
|
29262 |
|
29263 | function createTemporaryConversation(_x22) {
|
29264 | return _createTemporaryConversation.apply(this, arguments);
|
29265 | }
|
29266 |
|
29267 | return createTemporaryConversation;
|
29268 | }()
|
29269 | ;
|
29270 |
|
29271 | _proto.
|
29272 | _doSendRead = function _doSendRead() {
|
29273 | var _this10 = this;
|
29274 |
|
29275 |
|
29276 | if (!this._connection.is('connected')) return;
|
29277 | var buffer = internal(this).readConversationsBuffer;
|
29278 | var conversations = Array.from(buffer);
|
29279 | if (!conversations.length) return;
|
29280 | var ids = conversations.map(function (conversation) {
|
29281 | if (!(conversation instanceof ConversationBase)) {
|
29282 | throw new TypeError("".concat(conversation, " is not a Conversation"));
|
29283 | }
|
29284 |
|
29285 | return conversation.id;
|
29286 | });
|
29287 |
|
29288 | this._debug("mark [".concat(ids, "] as read"));
|
29289 |
|
29290 | buffer.clear();
|
29291 |
|
29292 | this._sendReadCommand(conversations).catch(function (error) {
|
29293 | _this10._debug('send read failed: %O', error);
|
29294 |
|
29295 | conversations.forEach(buffer.add.bind(buffer));
|
29296 | });
|
29297 | };
|
29298 |
|
29299 | _proto._sendReadCommand = function _sendReadCommand(conversations) {
|
29300 | var _this11 = this;
|
29301 |
|
29302 | return this._send(new GenericCommand({
|
29303 | cmd: 'read',
|
29304 | readMessage: new ReadCommand({
|
29305 | convs: conversations.map(function (conversation) {
|
29306 | return new ReadTuple({
|
29307 | cid: conversation.id,
|
29308 | mid: conversation.lastMessage && conversation.lastMessage.from !== _this11.id ? conversation.lastMessage.id : undefined,
|
29309 | timestamp: (conversation.lastMessageAt || new Date()).getTime()
|
29310 | });
|
29311 | })
|
29312 | })
|
29313 | }), false);
|
29314 | };
|
29315 |
|
29316 | return IMClient;
|
29317 | }(eventemitter3), (_applyDecoratedDescriptor(_class$3.prototype, "_doSendAck", [_dec$2], Object.getOwnPropertyDescriptor(_class$3.prototype, "_doSendAck"), _class$3.prototype), _applyDecoratedDescriptor(_class$3.prototype, "_doSendRead", [_dec2], Object.getOwnPropertyDescriptor(_class$3.prototype, "_doSendRead"), _class$3.prototype)), _class$3));
|
29318 | |
29319 |
|
29320 |
|
29321 |
|
29322 |
|
29323 |
|
29324 |
|
29325 |
|
29326 | var RECONNECT_ERROR = 'reconnecterror';
|
29327 |
|
29328 | var CoreEvent = Object.freeze({
|
29329 | RECONNECT_ERROR: RECONNECT_ERROR,
|
29330 | DISCONNECT: DISCONNECT,
|
29331 | RECONNECT: RECONNECT,
|
29332 | RETRY: RETRY,
|
29333 | SCHEDULE: SCHEDULE,
|
29334 | OFFLINE: OFFLINE,
|
29335 | ONLINE: ONLINE
|
29336 | });
|
29337 |
|
29338 | var _class$4;
|
29339 |
|
29340 | var
|
29341 | BinaryMessage = IE10Compatible(_class$4 =
|
29342 |
|
29343 | function (_Message) {
|
29344 | _inheritsLoose(BinaryMessage, _Message);
|
29345 |
|
29346 | |
29347 |
|
29348 |
|
29349 |
|
29350 |
|
29351 |
|
29352 | function BinaryMessage(buffer) {
|
29353 | if (!(buffer instanceof ArrayBuffer)) {
|
29354 | throw new TypeError("".concat(buffer, " is not an ArrayBuffer"));
|
29355 | }
|
29356 |
|
29357 | return _Message.call(this, buffer) || this;
|
29358 | }
|
29359 | |
29360 |
|
29361 |
|
29362 |
|
29363 |
|
29364 | BinaryMessage.validate = function validate(target) {
|
29365 | return target instanceof ArrayBuffer;
|
29366 | };
|
29367 |
|
29368 | var _proto = BinaryMessage.prototype;
|
29369 |
|
29370 | _proto.toJSON = function toJSON() {
|
29371 | return _objectSpread({}, _Message.prototype._toJSON.call(this), {
|
29372 | data: base64Arraybuffer_1(this.content)
|
29373 | });
|
29374 | };
|
29375 |
|
29376 | _proto.toFullJSON = function toFullJSON() {
|
29377 | return _objectSpread({}, _Message.prototype.toFullJSON.call(this), {
|
29378 | bin: true,
|
29379 | data: base64Arraybuffer_1(this.content)
|
29380 | });
|
29381 | };
|
29382 |
|
29383 | _createClass(BinaryMessage, [{
|
29384 | key: "buffer",
|
29385 | get: function get() {
|
29386 | return this.content;
|
29387 | },
|
29388 | set: function set(buffer) {
|
29389 | this.content = buffer;
|
29390 | }
|
29391 | }]);
|
29392 |
|
29393 | return BinaryMessage;
|
29394 | }(Message)) || _class$4;
|
29395 |
|
29396 | var _dec$3, _class$5;
|
29397 |
|
29398 | var
|
29399 | TextMessage = (_dec$3 = messageType(-1), _dec$3(_class$5 = IE10Compatible(_class$5 =
|
29400 |
|
29401 | function (_TypedMessage) {
|
29402 | _inheritsLoose(TextMessage, _TypedMessage);
|
29403 |
|
29404 | |
29405 |
|
29406 |
|
29407 |
|
29408 |
|
29409 |
|
29410 | function TextMessage() {
|
29411 | var _this;
|
29412 |
|
29413 | var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
29414 |
|
29415 | if (typeof text !== 'string') {
|
29416 | throw new TypeError("".concat(text, " is not a string"));
|
29417 | }
|
29418 |
|
29419 | _this = _TypedMessage.call(this) || this;
|
29420 |
|
29421 | _this.setText(text);
|
29422 |
|
29423 | return _this;
|
29424 | }
|
29425 |
|
29426 | return TextMessage;
|
29427 | }(TypedMessage)) || _class$5) || _class$5);
|
29428 | |
29429 |
|
29430 |
|
29431 |
|
29432 |
|
29433 |
|
29434 |
|
29435 |
|
29436 | var _class$6;
|
29437 | var debug$b = browser('LC:MessageParser');
|
29438 |
|
29439 | var tryParseJson = function tryParseJson(target, key, descriptor) {
|
29440 | var fn = descriptor.value;
|
29441 |
|
29442 | descriptor.value = function wrapper(param) {
|
29443 | var content;
|
29444 |
|
29445 | if (typeof param !== 'string') {
|
29446 | content = param;
|
29447 | } else {
|
29448 | try {
|
29449 | content = JSON.parse(param);
|
29450 | } catch (error) {
|
29451 | content = param;
|
29452 | }
|
29453 | }
|
29454 |
|
29455 | return fn.call(this, content);
|
29456 | };
|
29457 | };
|
29458 |
|
29459 | var applyPlugins = function applyPlugins(target, key, descriptor) {
|
29460 | var fn = descriptor.value;
|
29461 |
|
29462 | descriptor.value = function wrapper(json) {
|
29463 | var _this = this;
|
29464 |
|
29465 | return Promise.resolve(json).then(applyMiddlewares(this._plugins.beforeMessageParse)).then(function (decoratedJson) {
|
29466 | return fn.call(_this, decoratedJson);
|
29467 | }).then(applyMiddlewares(this._plugins.afterMessageParse));
|
29468 | };
|
29469 | };
|
29470 |
|
29471 | var MessageParser = (_class$6 =
|
29472 |
|
29473 | function () {
|
29474 | function MessageParser() {
|
29475 | var plugins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
29476 | this._plugins = plugins;
|
29477 | this._messageClasses = [];
|
29478 | }
|
29479 |
|
29480 | var _proto = MessageParser.prototype;
|
29481 |
|
29482 | _proto.register = function register(messageClass) {
|
29483 | if (messageClass && messageClass.parse && messageClass.prototype && messageClass.prototype.getPayload) {
|
29484 | this._messageClasses.unshift(messageClass);
|
29485 | } else {
|
29486 | throw new TypeError('Invalid messageClass');
|
29487 | }
|
29488 | }
|
29489 | ;
|
29490 |
|
29491 | _proto.
|
29492 | parse = function parse(content) {
|
29493 | debug$b('parsing message: %O', content);
|
29494 |
|
29495 | var _iteratorNormalCompletion = true;
|
29496 | var _didIteratorError = false;
|
29497 | var _iteratorError = undefined;
|
29498 |
|
29499 | try {
|
29500 | for (var _iterator = this._messageClasses[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
29501 | var Klass = _step.value;
|
29502 | var contentCopy = isPlainObject_1(content) ? Object.assign({}, content) : content;
|
29503 | var valid = void 0;
|
29504 | var result = void 0;
|
29505 |
|
29506 | try {
|
29507 | valid = Klass.validate(contentCopy);
|
29508 | } catch (error) {
|
29509 | }
|
29510 |
|
29511 | if (valid) {
|
29512 | try {
|
29513 | result = Klass.parse(contentCopy);
|
29514 | } catch (error) {
|
29515 | console.warn('parsing a valid message content error', {
|
29516 | error: error,
|
29517 | Klass: Klass,
|
29518 | content: contentCopy
|
29519 | });
|
29520 | }
|
29521 |
|
29522 | if (result !== undefined) {
|
29523 | debug$b('parse result: %O', result);
|
29524 | return result;
|
29525 | }
|
29526 | }
|
29527 | }
|
29528 | } catch (err) {
|
29529 | _didIteratorError = true;
|
29530 | _iteratorError = err;
|
29531 | } finally {
|
29532 | try {
|
29533 | if (!_iteratorNormalCompletion && _iterator.return != null) {
|
29534 | _iterator.return();
|
29535 | }
|
29536 | } finally {
|
29537 | if (_didIteratorError) {
|
29538 | throw _iteratorError;
|
29539 | }
|
29540 | }
|
29541 | }
|
29542 |
|
29543 | throw new Error('No Message Class matched');
|
29544 | };
|
29545 |
|
29546 | return MessageParser;
|
29547 | }(), (_applyDecoratedDescriptor(_class$6.prototype, "parse", [tryParseJson, applyPlugins], Object.getOwnPropertyDescriptor(_class$6.prototype, "parse"), _class$6.prototype)), _class$6);
|
29548 |
|
29549 | var debug$c = browser('LC:IMPlugin');
|
29550 | |
29551 |
|
29552 |
|
29553 |
|
29554 |
|
29555 |
|
29556 | var MessagePriority = {
|
29557 |
|
29558 | HIGH: 1,
|
29559 |
|
29560 |
|
29561 | NORMAL: 2,
|
29562 |
|
29563 |
|
29564 | LOW: 3
|
29565 | };
|
29566 | Object.freeze(MessagePriority);
|
29567 | |
29568 |
|
29569 |
|
29570 |
|
29571 |
|
29572 |
|
29573 |
|
29574 |
|
29575 |
|
29576 |
|
29577 |
|
29578 |
|
29579 |
|
29580 |
|
29581 |
|
29582 |
|
29583 | var defineConversationProperty = function defineConversationProperty(prop) {
|
29584 | var descriptor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
29585 | get: function get() {
|
29586 | return this.get(prop);
|
29587 | },
|
29588 | set: function set(value) {
|
29589 | this.set(prop, value);
|
29590 | }
|
29591 | };
|
29592 | Object.defineProperty(Conversation.prototype, prop, descriptor);
|
29593 | };
|
29594 |
|
29595 | var onRealtimeCreate = function onRealtimeCreate(realtime) {
|
29596 |
|
29597 | var deviceId = v4_1();
|
29598 | realtime._IMClients = {};
|
29599 | realtime._IMClientsCreationCount = 0;
|
29600 | var messageParser = new MessageParser(realtime._plugins);
|
29601 | realtime._messageParser = messageParser;
|
29602 |
|
29603 | var signAVUser =
|
29604 |
|
29605 | function () {
|
29606 | var _ref = _asyncToGenerator(
|
29607 |
|
29608 | regenerator.mark(function _callee(user) {
|
29609 | return regenerator.wrap(function _callee$(_context) {
|
29610 | while (1) {
|
29611 | switch (_context.prev = _context.next) {
|
29612 | case 0:
|
29613 | return _context.abrupt("return", realtime._request({
|
29614 | method: 'POST',
|
29615 | path: '/rtm/sign',
|
29616 | data: {
|
29617 | session_token: user.getSessionToken()
|
29618 | }
|
29619 | }));
|
29620 |
|
29621 | case 1:
|
29622 | case "end":
|
29623 | return _context.stop();
|
29624 | }
|
29625 | }
|
29626 | }, _callee, this);
|
29627 | }));
|
29628 |
|
29629 | return function signAVUser(_x) {
|
29630 | return _ref.apply(this, arguments);
|
29631 | };
|
29632 | }();
|
29633 | |
29634 |
|
29635 |
|
29636 |
|
29637 |
|
29638 |
|
29639 |
|
29640 |
|
29641 |
|
29642 |
|
29643 |
|
29644 |
|
29645 |
|
29646 | var register = function register(messageClass) {
|
29647 | return ensureArray(messageClass).map(messageParser.register.bind(messageParser));
|
29648 | };
|
29649 |
|
29650 | register(ensureArray(realtime._plugins.messageClasses));
|
29651 | |
29652 |
|
29653 |
|
29654 |
|
29655 |
|
29656 |
|
29657 |
|
29658 |
|
29659 |
|
29660 |
|
29661 |
|
29662 |
|
29663 |
|
29664 |
|
29665 |
|
29666 | var createIMClient =
|
29667 |
|
29668 | function () {
|
29669 | var _ref2 = _asyncToGenerator(
|
29670 |
|
29671 | regenerator.mark(function _callee2(identity) {
|
29672 | var _realtime$_open$then;
|
29673 |
|
29674 | var _ref3,
|
29675 | tag,
|
29676 | isReconnect,
|
29677 | clientOptions,
|
29678 | lagecyTag,
|
29679 | id,
|
29680 | buildinOptions,
|
29681 | sessionToken,
|
29682 | _tag,
|
29683 | promise,
|
29684 | _args2 = arguments;
|
29685 |
|
29686 | return regenerator.wrap(function _callee2$(_context2) {
|
29687 | while (1) {
|
29688 | switch (_context2.prev = _context2.next) {
|
29689 | case 0:
|
29690 | _ref3 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, tag = _ref3.tag, isReconnect = _ref3.isReconnect, clientOptions = _objectWithoutProperties(_ref3, ["tag", "isReconnect"]);
|
29691 | lagecyTag = _args2.length > 2 ? _args2[2] : undefined;
|
29692 | buildinOptions = {};
|
29693 |
|
29694 | if (!identity) {
|
29695 | _context2.next = 19;
|
29696 | break;
|
29697 | }
|
29698 |
|
29699 | if (!(typeof identity === 'string')) {
|
29700 | _context2.next = 8;
|
29701 | break;
|
29702 | }
|
29703 |
|
29704 | id = identity;
|
29705 | _context2.next = 17;
|
29706 | break;
|
29707 |
|
29708 | case 8:
|
29709 | if (!(identity.id && identity.getSessionToken)) {
|
29710 | _context2.next = 16;
|
29711 | break;
|
29712 | }
|
29713 |
|
29714 | id = identity.id;
|
29715 | sessionToken = identity.getSessionToken();
|
29716 |
|
29717 | if (sessionToken) {
|
29718 | _context2.next = 13;
|
29719 | break;
|
29720 | }
|
29721 |
|
29722 | throw new Error('User must be authenticated');
|
29723 |
|
29724 | case 13:
|
29725 | buildinOptions.signatureFactory = signAVUser;
|
29726 | _context2.next = 17;
|
29727 | break;
|
29728 |
|
29729 | case 16:
|
29730 | throw new TypeError('Identity must be a String or an AV.User');
|
29731 |
|
29732 | case 17:
|
29733 | if (!(realtime._IMClients[id] !== undefined)) {
|
29734 | _context2.next = 19;
|
29735 | break;
|
29736 | }
|
29737 |
|
29738 | return _context2.abrupt("return", realtime._IMClients[id]);
|
29739 |
|
29740 | case 19:
|
29741 | if (lagecyTag) {
|
29742 | console.warn('DEPRECATION createIMClient tag param: Use options.tag instead.');
|
29743 | }
|
29744 |
|
29745 | _tag = tag || lagecyTag;
|
29746 | promise = (_realtime$_open$then = realtime._open().then(function (connection) {
|
29747 | var client = new IMClient(id, _objectSpread({}, buildinOptions, clientOptions), {
|
29748 | _connection: connection,
|
29749 | _request: realtime._request.bind(realtime),
|
29750 | _messageParser: messageParser,
|
29751 | _plugins: realtime._plugins,
|
29752 | _identity: identity
|
29753 | });
|
29754 | connection.on(RECONNECT, function () {
|
29755 | return client._open(realtime._options.appId, _tag, deviceId, true)
|
29756 | |
29757 |
|
29758 |
|
29759 |
|
29760 |
|
29761 |
|
29762 |
|
29763 | |
29764 |
|
29765 |
|
29766 |
|
29767 |
|
29768 | .then(function () {
|
29769 | return client.emit(RECONNECT);
|
29770 | }, function (error) {
|
29771 | return client.emit(RECONNECT_ERROR, error);
|
29772 | });
|
29773 | });
|
29774 |
|
29775 | internal(client)._eventemitter.on('beforeclose', function () {
|
29776 | delete realtime._IMClients[client.id];
|
29777 |
|
29778 | if (realtime._firstIMClient === client) {
|
29779 | delete realtime._firstIMClient;
|
29780 | }
|
29781 | }, realtime);
|
29782 |
|
29783 | internal(client)._eventemitter.on('close', function () {
|
29784 | realtime._deregister(client);
|
29785 | }, realtime);
|
29786 |
|
29787 | return client._open(realtime._options.appId, _tag, deviceId, isReconnect).then(function () {
|
29788 | realtime._IMClients[client.id] = client;
|
29789 | realtime._IMClientsCreationCount += 1;
|
29790 |
|
29791 | if (realtime._IMClientsCreationCount === 1) {
|
29792 | client._omitPeerId(true);
|
29793 |
|
29794 | realtime._firstIMClient = client;
|
29795 | } else if (realtime._IMClientsCreationCount > 1 && realtime._firstIMClient) {
|
29796 | realtime._firstIMClient._omitPeerId(false);
|
29797 | }
|
29798 |
|
29799 | realtime._register(client);
|
29800 |
|
29801 | return client;
|
29802 | }).catch(function (error) {
|
29803 | delete realtime._IMClients[client.id];
|
29804 | throw error;
|
29805 | });
|
29806 | })).then.apply(_realtime$_open$then, _toConsumableArray(finalize(function () {
|
29807 | realtime._deregisterPending(promise);
|
29808 | })));
|
29809 |
|
29810 | if (identity) {
|
29811 | realtime._IMClients[id] = promise;
|
29812 | }
|
29813 |
|
29814 | realtime._registerPending(promise);
|
29815 |
|
29816 | return _context2.abrupt("return", promise);
|
29817 |
|
29818 | case 25:
|
29819 | case "end":
|
29820 | return _context2.stop();
|
29821 | }
|
29822 | }
|
29823 | }, _callee2, this);
|
29824 | }));
|
29825 |
|
29826 | return function createIMClient(_x2) {
|
29827 | return _ref2.apply(this, arguments);
|
29828 | };
|
29829 | }();
|
29830 |
|
29831 | Object.assign(realtime, {
|
29832 | register: register,
|
29833 | createIMClient: createIMClient
|
29834 | });
|
29835 |
|
29836 | };
|
29837 |
|
29838 | var beforeCommandDispatch = function beforeCommandDispatch(command, realtime) {
|
29839 | var isIMCommand = command.service === null || command.service === 2;
|
29840 | if (!isIMCommand) return true;
|
29841 | var targetClient = command.peerId ? realtime._IMClients[command.peerId] : realtime._firstIMClient;
|
29842 |
|
29843 | if (targetClient) {
|
29844 | Promise.resolve(targetClient).then(function (client) {
|
29845 | return client._dispatchCommand(command);
|
29846 | }).catch(debug$c);
|
29847 | } else {
|
29848 | debug$c('[WARN] Unexpected message received without any live client match: %O', trim(command));
|
29849 | }
|
29850 |
|
29851 | return false;
|
29852 | };
|
29853 |
|
29854 | var IMPlugin = {
|
29855 | name: 'leancloud-realtime-plugin-im',
|
29856 | onRealtimeCreate: onRealtimeCreate,
|
29857 | beforeCommandDispatch: beforeCommandDispatch,
|
29858 | messageClasses: [Message, BinaryMessage, RecalledMessage, TextMessage]
|
29859 | };
|
29860 |
|
29861 | Realtime.defineConversationProperty = defineConversationProperty;
|
29862 | Realtime.__preRegisteredPlugins = [IMPlugin];
|
29863 |
|
29864 | var Event$1 = _objectSpread({}, CoreEvent, Event);
|
29865 |
|
29866 | exports.Event = Event$1;
|
29867 | exports.ErrorCode = ErrorCode;
|
29868 | exports.Protocals = message;
|
29869 | exports.Promise = polyfilledPromise;
|
29870 | exports.EventEmitter = eventemitter3;
|
29871 | exports.Realtime = Realtime;
|
29872 | exports.debug = debug$2;
|
29873 | exports.Message = Message;
|
29874 | exports.BinaryMessage = BinaryMessage;
|
29875 | exports.TypedMessage = TypedMessage;
|
29876 | exports.TextMessage = TextMessage;
|
29877 | exports.RecalledMessage = RecalledMessage;
|
29878 | exports.MessagePriority = MessagePriority;
|
29879 | exports.MessageStatus = MessageStatus;
|
29880 | exports.MessageQueryDirection = MessageQueryDirection;
|
29881 | exports.defineConversationProperty = defineConversationProperty;
|
29882 | exports.IMPlugin = IMPlugin;
|
29883 | exports.messageType = messageType;
|
29884 | exports.messageField = messageField;
|
29885 | exports.IE10Compatible = IE10Compatible;
|
29886 | exports.ConversationMemberRole = ConversationMemberRole;
|
29887 | exports.Conversation = Conversation;
|
29888 | exports.ChatRoom = ChatRoom;
|
29889 | exports.ServiceConversation = ServiceConversation;
|
29890 | exports.TemporaryConversation = TemporaryConversation;
|
29891 |
|
29892 | Object.defineProperty(exports, '__esModule', { value: true });
|
29893 |
|
29894 | }));
|
29895 |
|