@byteplus/react-native-live-push 1.0.3-rc.1 → 1.1.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -272,173 +272,27 @@ const gBase64 = {
272
272
  extendBuiltins: extendBuiltins
273
273
  };
274
274
 
275
- var _a;
276
- (_a = Symbol.metadata) !== null && _a !== void 0 ? _a : (Symbol.metadata = Symbol('Symbol.metadata'));
275
+ Symbol.metadata ?? (Symbol.metadata = Symbol('Symbol.metadata'));
277
276
 
278
- /******************************************************************************
279
- Copyright (c) Microsoft Corporation.
280
-
281
- Permission to use, copy, modify, and/or distribute this software for any
282
- purpose with or without fee is hereby granted.
283
-
284
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
285
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
286
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
287
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
288
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
289
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
290
- PERFORMANCE OF THIS SOFTWARE.
291
- ***************************************************************************** */
292
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
293
-
294
- var extendStatics$1 = function(d, b) {
295
- extendStatics$1 = Object.setPrototypeOf ||
296
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
297
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
298
- return extendStatics$1(d, b);
299
- };
300
-
301
- function __extends$1(d, b) {
302
- if (typeof b !== "function" && b !== null)
303
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
304
- extendStatics$1(d, b);
305
- function __() { this.constructor = d; }
306
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
307
- }
308
-
309
- var __assign$1 = function() {
310
- __assign$1 = Object.assign || function __assign(t) {
311
- for (var s, i = 1, n = arguments.length; i < n; i++) {
312
- s = arguments[i];
313
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
314
- }
315
- return t;
316
- };
317
- return __assign$1.apply(this, arguments);
318
- };
319
-
320
- function __esDecorate$1(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
321
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
322
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
323
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
324
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
325
- var _, done = false;
326
- for (var i = decorators.length - 1; i >= 0; i--) {
327
- var context = {};
328
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
329
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
330
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
331
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
332
- if (kind === "accessor") {
333
- if (result === void 0) continue;
334
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
335
- if (_ = accept(result.get)) descriptor.get = _;
336
- if (_ = accept(result.set)) descriptor.set = _;
337
- if (_ = accept(result.init)) initializers.unshift(_);
338
- }
339
- else if (_ = accept(result)) {
340
- if (kind === "field") initializers.unshift(_);
341
- else descriptor[key] = _;
342
- }
343
- }
344
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
345
- done = true;
346
- }
347
- function __runInitializers$1(thisArg, initializers, value) {
348
- var useValue = arguments.length > 2;
349
- for (var i = 0; i < initializers.length; i++) {
350
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
351
- }
352
- return useValue ? value : void 0;
353
- }
354
- function __setFunctionName$1(f, name, prefix) {
355
- if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
356
- return Object.defineProperty(f, "name", { configurable: true, value: name });
357
- }
358
- function __awaiter$1(thisArg, _arguments, P, generator) {
359
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
360
- return new (P || (P = Promise))(function (resolve, reject) {
361
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
362
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
363
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
364
- step((generator = generator.apply(thisArg, _arguments || [])).next());
365
- });
366
- }
367
-
368
- function __generator$1(thisArg, body) {
369
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
370
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
371
- function verb(n) { return function (v) { return step([n, v]); }; }
372
- function step(op) {
373
- if (f) throw new TypeError("Generator is already executing.");
374
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
375
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
376
- if (y = 0, t) op = [op[0] & 2, t.value];
377
- switch (op[0]) {
378
- case 0: case 1: t = op; break;
379
- case 4: _.label++; return { value: op[1], done: false };
380
- case 5: _.label++; y = op[1]; op = [0]; continue;
381
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
382
- default:
383
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
384
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
385
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
386
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
387
- if (t[2]) _.ops.pop();
388
- _.trys.pop(); continue;
389
- }
390
- op = body.call(thisArg, _);
391
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
392
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
393
- }
394
- }
395
-
396
- function __spreadArray$1(to, from, pack) {
397
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
398
- if (ar || !(i in from)) {
399
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
400
- ar[i] = from[i];
401
- }
402
- }
403
- return to.concat(ar || Array.prototype.slice.call(from));
404
- }
405
-
406
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
407
- var e = new Error(message);
408
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
409
- };
410
-
411
- var DISABLE_INIT = Symbol();
277
+ const DISABLE_INIT = Symbol();
412
278
  function PackClass() {
413
- return function (target, ctx) {
414
- return /** @class */ (function (_super) {
415
- __extends$1(class_1, _super);
416
- function class_1() {
417
- var args = [];
418
- for (var _i = 0; _i < arguments.length; _i++) {
419
- args[_i] = arguments[_i];
420
- }
421
- var _this = _super.apply(this, args) || this;
422
- var _init = function () {
423
- var _a, _b;
424
- (_b = (_a = _this).__init) === null || _b === void 0 ? void 0 : _b.call.apply(_b, __spreadArray$1([_a], args, false));
279
+ return (target, ctx) => {
280
+ return class extends target {
281
+ constructor(...args) {
282
+ super(...args);
283
+ const _init = () => {
284
+ this.__init?.(...args);
425
285
  };
426
- var isDisableInit = args.includes(DISABLE_INIT);
286
+ const isDisableInit = args.includes(DISABLE_INIT);
427
287
  if (!isDisableInit) {
428
288
  _init();
429
289
  }
430
- Object.defineProperty(_this, '$$pack', {
290
+ Object.defineProperty(this, '$$pack', {
431
291
  value: true,
432
292
  enumerable: false,
433
293
  });
434
- return _this;
435
294
  }
436
- class_1.prototype.__destroy = function () {
437
- var _a, _b;
438
- (_b = (_a = this._instance).__destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
439
- };
440
- return class_1;
441
- }(target));
295
+ };
442
296
  };
443
297
  }
444
298
 
@@ -453,7 +307,7 @@ function packObject(receiver, ctor) {
453
307
  if (isPrimateValue(receiver)) {
454
308
  return receiver;
455
309
  }
456
- var ins = new ctor(DISABLE_INIT);
310
+ const ins = new ctor(DISABLE_INIT);
457
311
  Object.defineProperty(ins, '_instance', {
458
312
  value: receiver,
459
313
  enumerable: false,
@@ -468,23 +322,19 @@ function unpackObject(proxyInstance, _nativeClass) {
468
322
  }
469
323
 
470
324
  function fn2AndroidClass(tsFn, nativeClass, methodName) {
471
- var ins = new nativeClass();
325
+ const ins = new nativeClass();
472
326
  ins[methodName] = tsFn;
473
327
  return ins;
474
328
  }
475
329
  function extendsClassMethod(ctor, methodName, overrideFn) {
476
- var proto = ctor.prototype;
477
- var originalFn = ctor.prototype[methodName];
478
- proto[methodName] = function () {
479
- var args = [];
480
- for (var _i = 0; _i < arguments.length; _i++) {
481
- args[_i] = arguments[_i];
482
- }
483
- return overrideFn(originalFn === null || originalFn === void 0 ? void 0 : originalFn.bind(this)).apply(this, args);
330
+ const proto = ctor.prototype;
331
+ const originalFn = ctor.prototype[methodName];
332
+ proto[methodName] = function (...args) {
333
+ return overrideFn(originalFn?.bind(this)).apply(this, args);
484
334
  };
485
335
  }
486
336
 
487
- var impl;
337
+ let impl;
488
338
  function setupEnv(e) {
489
339
  impl = e;
490
340
  }
@@ -502,11 +352,10 @@ var env = /*#__PURE__*/Object.freeze({
502
352
  setupEnv: setupEnv
503
353
  });
504
354
 
505
- var SIZE = 32;
506
- var getUuid = function (namespace) {
507
- if (namespace === void 0) { namespace = ''; }
508
- var random = String(Math.random()).slice(2);
509
- var prefix = namespace.slice(0, 24);
355
+ const SIZE = 32;
356
+ const getUuid = (namespace = '') => {
357
+ const random = String(Math.random()).slice(2);
358
+ const prefix = namespace.slice(0, 24);
510
359
  return '@js#' + prefix + '#' + random.slice(0, SIZE - prefix.length - 1);
511
360
  };
512
361
 
@@ -557,10 +406,6 @@ var CALL_TYPE$1;
557
406
  * 事件执行后的返回值
558
407
  */
559
408
  CALL_TYPE["INSTANCE_EVENT_RESULT"] = "instance_event_result";
560
- /**
561
- * 销毁实例
562
- */
563
- CALL_TYPE["DESTROY_INSTANCE"] = "destroy_instance";
564
409
  /**
565
410
  * 触发事件
566
411
  */
@@ -572,82 +417,133 @@ var RETURN_STATUS$1;
572
417
  RETURN_STATUS["FAILED"] = "failed";
573
418
  RETURN_STATUS["NOT_IMPLEMENTED"] = "not_implemented";
574
419
  })(RETURN_STATUS$1 || (RETURN_STATUS$1 = {}));
575
- var INSTANCE_TYPE$1;
576
- (function (INSTANCE_TYPE) {
577
- /**
578
- * 自动 GC 类型
579
- */
580
- INSTANCE_TYPE[INSTANCE_TYPE["AUTOMATIC"] = 0] = "AUTOMATIC";
581
- /**
582
- * 手动 GC 类型
583
- */
584
- INSTANCE_TYPE[INSTANCE_TYPE["MANUAL"] = 1] = "MANUAL";
585
- })(INSTANCE_TYPE$1 || (INSTANCE_TYPE$1 = {}));
586
420
 
587
- var DefaultBridgeImpl = /** @class */ (function () {
588
- function DefaultBridgeImpl() {
589
- }
590
- DefaultBridgeImpl.prototype.call = function () {
591
- return new Promise(function (resolve, reject) {
421
+ class DefaultBridgeImpl {
422
+ call() {
423
+ return new Promise((resolve, reject) => {
592
424
  resolve({
593
425
  status: 'success',
594
426
  msg: null,
595
427
  });
596
428
  });
597
- };
598
- DefaultBridgeImpl.prototype.callSync = function () {
429
+ }
430
+ callSync() {
599
431
  return {
600
432
  status: 'success',
601
433
  msg: null,
602
434
  };
603
- };
604
- DefaultBridgeImpl.prototype.registerHandler = function (handlerName, handler) {
435
+ }
436
+ registerHandler(handlerName, handler) {
605
437
  // dsBridge.register(handlerName, handler);
606
- };
607
- DefaultBridgeImpl.prototype.registerAsyncHandler = function (handlerName, handler) {
438
+ }
439
+ registerAsyncHandler(handlerName, handler) {
608
440
  //
609
- };
610
- return DefaultBridgeImpl;
611
- }());
441
+ }
442
+ }
612
443
 
613
- var createJSBridge = function () {
444
+ const createJSBridge = () => {
614
445
  return new DefaultBridgeImpl();
615
446
  };
616
447
 
448
+ /******************************************************************************
449
+ Copyright (c) Microsoft Corporation.
450
+
451
+ Permission to use, copy, modify, and/or distribute this software for any
452
+ purpose with or without fee is hereby granted.
453
+
454
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
455
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
456
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
457
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
458
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
459
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
460
+ PERFORMANCE OF THIS SOFTWARE.
461
+ ***************************************************************************** */
462
+ /* global Reflect, Promise, SuppressedError, Symbol */
463
+
464
+
465
+ function __esDecorate$1(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
466
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
467
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
468
+ var target = ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
469
+ var descriptor = (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
470
+ var _, done = false;
471
+ for (var i = decorators.length - 1; i >= 0; i--) {
472
+ var context = {};
473
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
474
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
475
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
476
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
477
+ if (kind === "accessor") {
478
+ if (result === void 0) continue;
479
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
480
+ if (_ = accept(result.get)) descriptor.get = _;
481
+ if (_ = accept(result.set)) descriptor.set = _;
482
+ if (_ = accept(result.init)) initializers.unshift(_);
483
+ }
484
+ else if (_ = accept(result)) {
485
+ if (kind === "field") initializers.unshift(_);
486
+ else descriptor[key] = _;
487
+ }
488
+ }
489
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
490
+ done = true;
491
+ }
492
+ function __runInitializers$1(thisArg, initializers, value) {
493
+ var useValue = arguments.length > 2;
494
+ for (var i = 0; i < initializers.length; i++) {
495
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
496
+ }
497
+ return useValue ? value : void 0;
498
+ }
499
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
500
+ var e = new Error(message);
501
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
502
+ };
503
+
617
504
  function assert(expression, msg) {
618
505
  if (!expression) {
619
506
  throw new Error(msg);
620
507
  }
621
508
  }
622
509
 
623
- var isArray = function (value) {
624
- return Array.isArray(value);
625
- };
626
- var isInstance = function (value) {
510
+ const isArray = (value) => Array.isArray(value);
511
+ const isInstance = (value) => {
627
512
  if (typeof value !== 'object' || value === null) {
628
513
  return false;
629
514
  }
630
515
  if ('instanceId' in value || '_instanceId' in value) {
631
516
  return true;
632
517
  }
633
- var proto = Object.getPrototypeOf(value);
518
+ const proto = Object.getPrototypeOf(value);
634
519
  return (!!proto &&
635
520
  proto.constructor.name !== 'Array' &&
636
521
  proto.constructor.name !== 'Object');
637
522
  };
638
- var isCallback = function (value) {
523
+ const isCallback = (value) => {
639
524
  return typeof value === 'function';
640
525
  };
641
- var isPlainObject = function (value) {
526
+ const isPlainObject = (value) => {
642
527
  return typeof value === 'object' && value !== null;
643
528
  };
644
- var isInstanceArg = function (value) {
529
+ const isInstanceArg = (value) => {
645
530
  return (isPlainObject(value) && value._type === "instance" /* ARG_TYPE.INSTANCE */);
646
531
  };
647
532
 
533
+ function safeStringify(val) {
534
+ try {
535
+ if (val instanceof Error) {
536
+ return `Error: ${val.message}`;
537
+ }
538
+ return JSON.stringify(val);
539
+ }
540
+ catch (er) {
541
+ return String(val);
542
+ }
543
+ }
544
+
648
545
  function fromPairs(entries) {
649
- return entries.reduce(function (acc, _a) {
650
- var k = _a[0], v = _a[1];
546
+ return entries.reduce((acc, [k, v]) => {
651
547
  acc[k] = v;
652
548
  return acc;
653
549
  }, {});
@@ -656,32 +552,17 @@ function toPairs(obj) {
656
552
  return Object.entries(obj);
657
553
  }
658
554
  function mapValues(data, fn) {
659
- var paris = toPairs(data);
660
- var mappedPairs = paris.map(function (_a) {
661
- var k = _a[0], v = _a[1];
662
- return [k, fn(v, k)];
663
- });
555
+ const paris = toPairs(data);
556
+ const mappedPairs = paris.map(([k, v]) => [k, fn(v, k)]);
664
557
  return fromPairs(mappedPairs);
665
558
  }
666
559
 
667
- function resolveInstance(instanceOrId) {
668
- var id = typeof instanceOrId === 'string'
669
- ? instanceOrId
670
- : isInstanceArg(instanceOrId)
671
- ? instanceOrId._instanceId
672
- : undefined;
673
- if (!id) {
674
- throw new Error('instanceOrId is not an instance');
675
- }
676
- return id;
677
- }
678
-
679
- var keyPathVisitor = function (obj, path, defaultValue) {
680
- var getResult = obj
681
- ? path.reduce(function (pre, next) {
560
+ const keyPathVisitor = (obj, path, defaultValue) => {
561
+ const getResult = obj
562
+ ? path.reduce((pre, next) => {
682
563
  if (pre && pre !== defaultValue) {
683
- var preValue = pre;
684
- var nextvalue = preValue[next];
564
+ const preValue = pre;
565
+ const nextvalue = preValue[next];
685
566
  return !nextvalue ? defaultValue : nextvalue;
686
567
  }
687
568
  return defaultValue;
@@ -690,9 +571,9 @@ var keyPathVisitor = function (obj, path, defaultValue) {
690
571
  return getResult;
691
572
  };
692
573
 
693
- var Bind = function (target, context) {
574
+ const Bind = (target, context) => {
694
575
  context.addInitializer(function () {
695
- var fnName = context.name;
576
+ const fnName = context.name;
696
577
  this[fnName] = this[fnName].bind(this);
697
578
  });
698
579
  return target;
@@ -700,1094 +581,343 @@ var Bind = function (target, context) {
700
581
 
701
582
  var LogLevel;
702
583
  (function (LogLevel) {
703
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
704
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
705
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
706
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
707
- LogLevel[LogLevel["NONE"] = 999] = "NONE";
584
+ LogLevel[LogLevel["verbose"] = 0] = "verbose";
585
+ LogLevel[LogLevel["debug"] = 1] = "debug";
586
+ LogLevel[LogLevel["info"] = 2] = "info";
587
+ LogLevel[LogLevel["warn"] = 3] = "warn";
588
+ LogLevel[LogLevel["error"] = 4] = "error";
708
589
  })(LogLevel || (LogLevel = {}));
709
590
 
710
- var LoggerImpl = /** @class */ (function () {
711
- function LoggerImpl() {
712
- this._logLevel = LogLevel.WARN;
591
+ class LoggerImpl {
592
+ constructor() {
593
+ this._enablePrintVerbose = false;
713
594
  this._consumers = [];
714
595
  }
715
- LoggerImpl.getInstance = function () {
716
- if (!LoggerImpl.instance) {
717
- LoggerImpl.instance = new LoggerImpl();
718
- }
719
- return LoggerImpl.instance;
720
- };
721
- LoggerImpl.prototype.init = function (opt) {
596
+ init(opt) {
722
597
  this.options = opt;
723
- if (opt.logLevel) {
724
- this._logLevel = opt.logLevel;
725
- }
726
- };
727
- LoggerImpl.prototype.setLogLevel = function (level) {
728
- this._logLevel = level;
729
- };
730
- LoggerImpl.prototype.registerConsumer = function (consumer) {
598
+ }
599
+ enableVerbose(enable) {
600
+ this._enablePrintVerbose = enable;
601
+ }
602
+ registerConsumer(consumer) {
731
603
  this._consumers.push(consumer);
732
- };
733
- LoggerImpl.prototype._shouldLog = function (level) {
734
- return level >= this._logLevel;
735
- };
736
- LoggerImpl.prototype._formatMessage = function (args) {
737
- try {
738
- var message = args
739
- .map(function (arg) {
740
- if (typeof arg === 'object') {
741
- return JSON.stringify(arg, null, 2);
742
- }
743
- return String(arg);
744
- })
745
- .join(' ');
746
- if (message.length > LoggerImpl.MAX_LOG_LENGTH) {
747
- return message.substring(0, LoggerImpl.MAX_LOG_LENGTH);
748
- }
749
- return message;
750
- }
751
- catch (e) {
752
- if (e instanceof Error) {
753
- return "[Format Error] ".concat(args.join(' '), " - ").concat(e.message);
754
- }
755
- return "[Format Error] ".concat(args.join(' '));
756
- }
757
- };
758
- LoggerImpl.prototype._formatDate = function (date) {
759
- var pad = function (n) { return (n < 10 ? '0' + n : n); };
760
- return "".concat(pad(date.getHours()), ":").concat(pad(date.getMinutes()), ":").concat(pad(date.getSeconds()));
761
- };
762
- LoggerImpl.prototype._getCurrentTimestamp = function () {
763
- return this._formatDate(new Date());
764
- };
765
- LoggerImpl.prototype._log = function (level, args) {
766
- var _this = this;
767
- if (!this._shouldLog(level)) {
768
- return;
769
- }
770
- var timestamp = this._getCurrentTimestamp();
771
- var message = this._formatMessage(args);
772
- var logMsg = {
773
- level: level,
774
- content: ["".concat(timestamp, " ").concat(message)],
775
- };
776
- // 发送给消费者
777
- this._consumers.forEach(function (c) { return __awaiter$1(_this, void 0, void 0, function () {
778
- return __generator$1(this, function (_a) {
779
- switch (_a.label) {
780
- case 0:
781
- _a.trys.push([0, 2, , 3]);
782
- return [4 /*yield*/, c(logMsg)];
783
- case 1:
784
- _a.sent();
785
- return [3 /*break*/, 3];
786
- case 2:
787
- _a.sent();
788
- return [3 /*break*/, 3];
789
- case 3: return [2 /*return*/];
790
- }
791
- });
792
- }); });
793
- // 控制台输出
794
- switch (level) {
795
- case LogLevel.ERROR:
796
- console.error("".concat(timestamp, " ").concat(message));
797
- break;
798
- case LogLevel.WARN:
799
- console.warn("".concat(timestamp, " ").concat(message));
800
- break;
801
- case LogLevel.INFO:
802
- console.log("".concat(timestamp, " ").concat(message));
803
- break;
804
- case LogLevel.DEBUG:
805
- console.debug("".concat(timestamp, " ").concat(message));
806
- break;
807
- }
808
- };
809
- LoggerImpl.prototype.debug = function () {
810
- var args = [];
811
- for (var _i = 0; _i < arguments.length; _i++) {
812
- args[_i] = arguments[_i];
813
- }
814
- this._log(LogLevel.DEBUG, args);
815
- };
816
- LoggerImpl.prototype.info = function () {
817
- var args = [];
818
- for (var _i = 0; _i < arguments.length; _i++) {
819
- args[_i] = arguments[_i];
820
- }
821
- this._log(LogLevel.INFO, args);
822
- };
823
- LoggerImpl.prototype.warn = function () {
824
- var args = [];
825
- for (var _i = 0; _i < arguments.length; _i++) {
826
- args[_i] = arguments[_i];
604
+ }
605
+ verbose(...args) {
606
+ if (this._enablePrintVerbose) {
607
+ console.debug('[verbose]', ...args);
827
608
  }
828
- this._log(LogLevel.WARN, args);
829
- };
830
- LoggerImpl.prototype.error = function () {
831
- var args = [];
832
- for (var _i = 0; _i < arguments.length; _i++) {
833
- args[_i] = arguments[_i];
609
+ }
610
+ debug(...args) {
611
+ const msg = {
612
+ level: LogLevel.debug,
613
+ content: args,
614
+ };
615
+ this._log(msg);
616
+ if (this._enablePrintVerbose) {
617
+ console.debug('[debug]', ...args);
834
618
  }
835
- this._log(LogLevel.ERROR, args);
836
- };
837
- LoggerImpl.MAX_LOG_LENGTH = 4096;
838
- return LoggerImpl;
839
- }());
840
-
841
- function assertReturn(ret) {
842
- if (!ret || typeof ret !== 'object') {
843
- return;
844
619
  }
845
- if (ret.status === RETURN_STATUS$1.FAILED) {
846
- throw new Error(String(ret.msg));
620
+ info(...args) {
621
+ const msg = {
622
+ level: LogLevel.info,
623
+ content: args,
624
+ };
625
+ this._log(msg);
626
+ console.log(...args);
847
627
  }
848
- return ret.decoded || ret.msg;
849
- }
850
- function isPromiseLike(val) {
851
- if (typeof val === 'object' && val !== null) {
852
- if (typeof val.then === 'function') {
853
- return true;
854
- }
628
+ warn(...args) {
629
+ const msg = {
630
+ level: LogLevel.warn,
631
+ content: args,
632
+ };
633
+ this._log(msg);
634
+ console.warn(...args);
635
+ }
636
+ error(...args) {
637
+ const msg = {
638
+ level: LogLevel.error,
639
+ content: args,
640
+ };
641
+ this._log(msg);
642
+ console.error(...args);
643
+ }
644
+ _log(msg) {
645
+ this._consumers.forEach(async (c) => {
646
+ try {
647
+ await c(msg);
648
+ }
649
+ catch (ignore) {
650
+ //
651
+ }
652
+ });
855
653
  }
856
- return false;
857
654
  }
858
655
 
859
- var KEY_NAMESPACE = Symbol.for('#namespace');
860
- var KEY_NATIVE_CLASS_NAME = Symbol.for('#nativeClassName');
861
- function findNamespace(ctor) {
862
- var obj = ctor;
863
- var desc;
864
- while (!desc && obj) {
865
- desc = Object.getOwnPropertyDescriptor(obj, KEY_NAMESPACE);
866
- obj = Object.getPrototypeOf(obj);
867
- }
868
- return desc === null || desc === void 0 ? void 0 : desc.value;
869
- }
870
- function findMethods(ins, opt) {
871
- if (opt === void 0) { opt = {}; }
872
- var methodNames = [];
873
- var proto = Object.getPrototypeOf(ins);
874
- while (proto && proto !== Object.prototype) {
875
- var ownMethods = Object.getOwnPropertyNames(proto)
876
- .filter(function (name) { return name !== 'constructor'; })
877
- .map(function (name) { return opt[name] || name; });
878
- methodNames.push.apply(methodNames, ownMethods);
879
- proto = Object.getPrototypeOf(proto);
880
- }
881
- return methodNames;
882
- }
883
- /**
884
- * 垃圾回收检查器,JS 对象被回收后,清除 Native 中的实例
885
- */
886
- var getRegistry = function () {
887
- if (typeof FinalizationRegistry !== 'undefined') {
888
- try {
889
- return new FinalizationRegistry(function (heldValue) {
890
- var _a = heldValue.split('::'), instanceId = _a[0], namespace = _a[1];
891
- if (instanceId) {
892
- getMessageClient(instanceId).sendDestroyInstance(instanceId, namespace || '');
893
- logger.debug('instance has been destroyed', instanceId);
894
- }
895
- });
896
- }
897
- catch (e) {
898
- logger.warn('Failed to create FinalizationRegistry', e);
899
- return null;
900
- }
901
- }
902
- return null;
903
- };
904
- var NativeObserverClass = function (className, opt) {
905
- if (opt === void 0) { opt = {
906
- instanceType: INSTANCE_TYPE$1.AUTOMATIC,
907
- }; }
908
- return function (target, ctx) {
909
- ctx.addInitializer(function () {
910
- Object.defineProperty(this, KEY_NAMESPACE, {
911
- value: className,
912
- writable: true,
913
- });
914
- Object.defineProperty(this, KEY_NATIVE_CLASS_NAME, { value: className });
915
- });
916
- // @ts-ignore
917
- return /** @class */ (function (_super) {
918
- __extends$1(class_1, _super);
919
- function class_1() {
920
- var args = [];
921
- for (var _i = 0; _i < arguments.length; _i++) {
922
- args[_i] = arguments[_i];
923
- }
924
- var _a;
925
- var _this = _super.apply(this, args) || this;
926
- var t = _this;
927
- var instanceId = getUuid(className);
928
- t.namespace = className;
929
- t.instanceId = instanceId;
930
- t.messageClient = getMessageClient(t);
931
- t.options = opt;
932
- t.instanceType = opt.instanceType || INSTANCE_TYPE$1.AUTOMATIC;
933
- (_a = getRegistry()) === null || _a === void 0 ? void 0 : _a.register(_this, "".concat(instanceId, "::").concat(className));
934
- // custom consume native event
935
- /**
936
- * @param this
937
- * @param name native method name
938
- * @param params
939
- */
940
- t.emit = function (name) {
941
- var _a;
942
- var params = [];
943
- for (var _i = 1; _i < arguments.length; _i++) {
944
- params[_i - 1] = arguments[_i];
945
- }
946
- var curName = ((_a = Object.entries(opt).find(function (_a) {
947
- var v = _a[1];
948
- return v === name;
949
- })) === null || _a === void 0 ? void 0 : _a[0]) || name;
950
- var fn = this[curName];
951
- if (typeof fn === 'function') {
952
- return fn.apply(this, params);
953
- }
954
- };
955
- var _init = function () {
956
- var events = findMethods(_this, opt);
957
- t.messageClient.sendNewInstanceCall(className, [events], instanceId, t);
958
- };
959
- // proxy native created class
960
- if (!args.includes(DISABLE_INIT)) {
961
- _init();
962
- }
963
- return _this;
964
- }
965
- class_1.prototype.__destroy = function () {
966
- var _a;
967
- var t = this;
968
- (_a = t.messageClient) === null || _a === void 0 ? void 0 : _a.sendDestroyInstance(t, t.namespace || '');
969
- };
970
- return class_1;
971
- }(target));
972
- };
973
- };
974
- var NativeClass = function (className, opt) {
975
- if (opt === void 0) { opt = {
976
- instanceType: INSTANCE_TYPE$1.AUTOMATIC,
977
- }; }
978
- return function (target, ctx) {
979
- ctx.addInitializer(function () {
980
- Object.defineProperty(this, KEY_NAMESPACE, {
981
- value: className,
982
- writable: true,
983
- });
984
- Object.defineProperty(this, KEY_NATIVE_CLASS_NAME, { value: className });
985
- });
986
- // @ts-ignore
987
- return /** @class */ (function (_super) {
988
- __extends$1(class_2, _super);
989
- function class_2() {
990
- var args = [];
991
- for (var _i = 0; _i < arguments.length; _i++) {
992
- args[_i] = arguments[_i];
993
- }
994
- var _a;
995
- var _this = _super.apply(this, args) || this;
996
- var t = _this;
997
- var instanceId = getUuid(className);
998
- t.namespace = className;
999
- t.instanceId = instanceId;
1000
- t.messageClient = getMessageClient(t);
1001
- t.instanceType = opt.instanceType || INSTANCE_TYPE$1.AUTOMATIC;
1002
- (_a = getRegistry()) === null || _a === void 0 ? void 0 : _a.register(_this, "".concat(instanceId, "::").concat(className));
1003
- var _init = function () {
1004
- t.messageClient.sendNewInstanceCall(className, args.filter(function (v) { return v !== undefined; }), instanceId, t);
1005
- if (getOS() === "ios" /* OS.ios */ &&
1006
- typeof _this.init === 'function') {
1007
- _this.init();
1008
- }
1009
- };
1010
- // proxy native created class
1011
- if (!args.includes(DISABLE_INIT)) {
1012
- _init();
1013
- }
1014
- return _this;
1015
- }
1016
- class_2.prototype.__destroy = function () {
1017
- var _a;
1018
- var t = this;
1019
- (_a = t.messageClient) === null || _a === void 0 ? void 0 : _a.sendDestroyInstance(t, t.namespace || '');
1020
- };
1021
- return class_2;
1022
- }(target));
1023
- };
1024
- };
1025
- var NativeStaticMethod = function (methodSelector) {
1026
- return function (target, ctx) {
1027
- var name = ctx.name;
1028
- return function impl() {
1029
- var args = [];
1030
- for (var _i = 0; _i < arguments.length; _i++) {
1031
- args[_i] = arguments[_i];
1032
- }
1033
- return __awaiter$1(this, void 0, void 0, function () {
1034
- var namespace, client, returnValue, data;
1035
- return __generator$1(this, function (_a) {
1036
- switch (_a.label) {
1037
- case 0:
1038
- namespace = findNamespace(this);
1039
- client = getMessageClient(this);
1040
- return [4 /*yield*/, client.sendStaticCall(namespace || '', methodSelector || name, args)];
1041
- case 1:
1042
- returnValue = _a.sent();
1043
- data = assertReturn(returnValue);
1044
- return [2 /*return*/, data];
1045
- }
1046
- });
1047
- });
1048
- };
1049
- };
1050
- };
1051
- var NativeStaticMethodSync = function (methodSelector) {
1052
- return function (target, ctx) {
1053
- var name = ctx.name;
1054
- return function impl() {
1055
- var args = [];
1056
- for (var _i = 0; _i < arguments.length; _i++) {
1057
- args[_i] = arguments[_i];
1058
- }
1059
- var namespace = findNamespace(this);
1060
- var client = getMessageClient(this);
1061
- var returnValue = client.sendStaticCallSync(namespace || '', methodSelector || name, args);
1062
- var data = assertReturn(returnValue);
1063
- return data;
1064
- };
1065
- };
1066
- };
1067
- var ReturnClass = function (getCtor) {
1068
- return function (target, ctx) {
1069
- // TODO: impl
1070
- return function impl() {
1071
- var args = [];
1072
- for (var _i = 0; _i < arguments.length; _i++) {
1073
- args[_i] = arguments[_i];
1074
- }
1075
- var returnValue = target.apply(this, args);
1076
- if (isPromiseLike(returnValue)) {
1077
- return returnValue.then(function (v) {
1078
- return proxyNativeInstance(v, getCtor());
1079
- });
1080
- }
1081
- return proxyNativeInstance(returnValue, getCtor());
1082
- };
1083
- };
1084
- };
1085
- var NativeMember = function (_a) {
1086
- var _b = {} , cache = _b.cache, readonly = _b.readonly;
1087
- return function (_, ctx) {
1088
- ctx.addInitializer(function () {
1089
- var _this = this;
1090
- var field = ctx.name;
1091
- var key = Symbol.for(ctx.name);
1092
- Object.defineProperty(this, field, {
1093
- get: function () {
1094
- if (cache && _this[key] !== undefined) {
1095
- return _this[key];
1096
- }
1097
- var _a = _this, instanceId = _a.instanceId, namespace = _a.namespace;
1098
- var ret = getMessageClient(_this).sendInstanceGet(instanceId, namespace || '', field);
1099
- var value = assertReturn(ret);
1100
- _this[key] = value;
1101
- return value;
1102
- },
1103
- set: function (v) {
1104
- if (readonly) {
1105
- throw new Error("field ".concat(field, " is readonly."));
1106
- }
1107
- _this[key] = v;
1108
- var _a = _this, instanceId = _a.instanceId, namespace = _a.namespace;
1109
- getMessageClient(_this).sendInstanceSet(instanceId, namespace || '', field, v);
1110
- },
1111
- });
1112
- });
1113
- return _;
1114
- };
1115
- };
1116
-
1117
- var key = Symbol.for('args');
1118
- function NativeArgType(argIndex, type) {
1119
- return function (method, ctx) {
1120
- var _a;
1121
- var args = ((_a = method[key]) !== null && _a !== void 0 ? _a : (method[key] = []));
1122
- args[argIndex] = type;
1123
- };
1124
- }
1125
- function processArg(method) {
1126
- var _a;
1127
- var args = (_a = method[key]) !== null && _a !== void 0 ? _a : [];
1128
- return function (arg, idx) {
1129
- var _a, _b;
1130
- return (_b = (_a = args[idx]) === null || _a === void 0 ? void 0 : _a.transform(arg)) !== null && _b !== void 0 ? _b : arg;
1131
- };
1132
- }
1133
- var NativeMethod = function (methodSelector, opt) {
1134
- return function (_, ctx) {
1135
- var name = ctx.name;
1136
- function impl() {
1137
- var args = [];
1138
- for (var _i = 0; _i < arguments.length; _i++) {
1139
- args[_i] = arguments[_i];
1140
- }
1141
- return __awaiter$1(this, void 0, void 0, function () {
1142
- var _a, instanceId, namespace, returnValue, data;
1143
- return __generator$1(this, function (_b) {
1144
- switch (_b.label) {
1145
- case 0:
1146
- _a = this, instanceId = _a.instanceId, namespace = _a.namespace;
1147
- return [4 /*yield*/, getMessageClient(this).sendInstanceCall(instanceId, namespace || '', methodSelector || name, args.map(processArg(_)).filter(function (v) { return v !== undefined; }), opt)];
1148
- case 1:
1149
- returnValue = _b.sent();
1150
- data = assertReturn(returnValue);
1151
- return [2 /*return*/, data];
1152
- }
1153
- });
1154
- });
1155
- }
1156
- return impl;
1157
- };
1158
- };
1159
- var NativeMethodSync = function (methodSelector, opt) {
1160
- return function (_, ctx) {
1161
- var name = ctx.name;
1162
- function impl() {
1163
- var args = [];
1164
- for (var _i = 0; _i < arguments.length; _i++) {
1165
- args[_i] = arguments[_i];
1166
- }
1167
- var _a = this, instanceId = _a.instanceId, namespace = _a.namespace;
1168
- var returnValue = getMessageClient(this).sendInstanceCallSync(instanceId, namespace || '', methodSelector || name, args.map(processArg(_)).filter(function (v) { return v !== undefined; }), opt);
1169
- var data = assertReturn(returnValue);
1170
- return data;
1171
- }
1172
- return impl;
1173
- };
1174
- };
1175
-
1176
- var NativeVar = function (varName, ctor) {
1177
- return function (_, ctx) {
1178
- return function impl() {
1179
- var args = [];
1180
- for (var _i = 0; _i < arguments.length; _i++) {
1181
- args[_i] = arguments[_i];
1182
- }
1183
- return __awaiter$1(this, void 0, void 0, function () {
1184
- var client, ret, ins;
1185
- return __generator$1(this, function (_a) {
1186
- switch (_a.label) {
1187
- case 0:
1188
- client = getMessageClient(this);
1189
- return [4 /*yield*/, client.sendVarGet(varName, args)];
1190
- case 1:
1191
- ret = _a.sent();
1192
- ins = new ctor(DISABLE_INIT);
1193
- ins.instanceId = ret.msg._instanceId;
1194
- ins.messageClient = client;
1195
- ins.namespace = '$var';
1196
- return [2 /*return*/, ins];
1197
- }
1198
- });
1199
- });
1200
- };
1201
- };
1202
- };
1203
-
1204
- (function () {
1205
- var _a;
1206
- var _instanceExtraInitializers = [];
1207
- var _on_decorators;
1208
- var _emit_decorators;
1209
- return _a = /** @class */ (function () {
1210
- function NativeObserver(className) {
1211
- this._events = __runInitializers$1(this, _instanceExtraInitializers);
1212
- this.namespace = className;
1213
- this.instanceId = getUuid(className);
1214
- this.messageClient = getGlobalMessageClient();
1215
- this._events = {};
1216
- }
1217
- NativeObserver.prototype.on = function (ev, handler) {
1218
- var handlers = this._events[ev];
1219
- if (!handlers) {
1220
- handlers = [];
1221
- this._events[ev] = handlers;
1222
- }
1223
- if (handlers.length === 0) {
1224
- // 第一次,通知 native 注册
1225
- this.messageClient.sendInstanceEventAdd(this.instanceId, this.namespace || '', ev);
1226
- }
1227
- handlers.push(handler);
1228
- };
1229
- NativeObserver.prototype.emit = function (ev) {
1230
- var args = [];
1231
- for (var _i = 1; _i < arguments.length; _i++) {
1232
- args[_i - 1] = arguments[_i];
1233
- }
1234
- var handlers = this._events[ev];
1235
- // console.log('emit:', ev, args.length);
1236
- handlers === null || handlers === void 0 ? void 0 : handlers.forEach(function (cb) {
1237
- cb.apply(void 0, args);
1238
- });
1239
- };
1240
- return NativeObserver;
1241
- }()),
1242
- (function () {
1243
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1244
- _on_decorators = [Bind];
1245
- _emit_decorators = [Bind];
1246
- __esDecorate$1(_a, null, _on_decorators, { kind: "method", name: "on", static: false, private: false, access: { has: function (obj) { return "on" in obj; }, get: function (obj) { return obj.on; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1247
- __esDecorate$1(_a, null, _emit_decorators, { kind: "method", name: "emit", static: false, private: false, access: { has: function (obj) { return "emit" in obj; }, get: function (obj) { return obj.emit; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1248
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1249
- })(),
1250
- _a;
1251
- })();
1252
- (function () {
1253
- var _a;
1254
- var _instanceExtraInitializers = [];
1255
- var _on_decorators;
1256
- var _emit_decorators;
1257
- return _a = /** @class */ (function () {
1258
- function NativeObserverProxy() {
1259
- this.__observer = __runInitializers$1(this, _instanceExtraInitializers);
1260
- }
1261
- NativeObserverProxy.prototype.on = function (ev, handler) {
1262
- this.__observer.on(ev, handler);
1263
- };
1264
- NativeObserverProxy.prototype.emit = function (ev) {
1265
- var _b;
1266
- var args = [];
1267
- for (var _i = 1; _i < arguments.length; _i++) {
1268
- args[_i - 1] = arguments[_i];
1269
- }
1270
- (_b = this.__observer).emit.apply(_b, __spreadArray$1([ev], args, false));
1271
- };
1272
- return NativeObserverProxy;
1273
- }()),
1274
- (function () {
1275
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1276
- _on_decorators = [Bind];
1277
- _emit_decorators = [Bind];
1278
- __esDecorate$1(_a, null, _on_decorators, { kind: "method", name: "on", static: false, private: false, access: { has: function (obj) { return "on" in obj; }, get: function (obj) { return obj.on; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1279
- __esDecorate$1(_a, null, _emit_decorators, { kind: "method", name: "emit", static: false, private: false, access: { has: function (obj) { return "emit" in obj; }, get: function (obj) { return obj.emit; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1280
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1281
- })(),
1282
- _a;
1283
- })();
1284
-
1285
- var NativeView = /** @class */ (function () {
1286
- function NativeView(viewId) {
1287
- this.viewId = viewId;
1288
- initViewProxyObject(this, viewId);
1289
- }
1290
- NativeView.getView = function (viewId, ctor) {
1291
- var _ins = new ctor(viewId);
1292
- var ins = initViewProxyObject(_ins, viewId);
1293
- return ins;
1294
- };
1295
- return NativeView;
1296
- }());
1297
- function initViewProxyObject(obj, viewId) {
1298
- obj.instanceId = obj._instanceId = viewId;
1299
- obj.namespace = obj._serviceName = '$View';
1300
- obj._type = "instance" /* ARG_TYPE.INSTANCE */;
1301
- return obj;
1302
- }
1303
-
1304
- var NativeImageResource = {
1305
- transform: function (origin) {
1306
- var r = __assign$1({}, resolveImageResource(origin));
1307
- return r;
1308
- },
1309
- };
1310
- // ios
1311
- var UIImage = NativeImageResource;
1312
- // android
1313
- var Bitmap = NativeImageResource;
1314
-
1315
- var nativeType = /*#__PURE__*/Object.freeze({
1316
- __proto__: null,
1317
- Bitmap: Bitmap,
1318
- NativeImageResource: NativeImageResource,
1319
- UIImage: UIImage
1320
- });
1321
-
1322
- var NativeInstanceManager$1 = function () {
1323
- var _classDecorators = [NativeClass('com.volcengine.VolcApiEngine.runtime.ProtoImpl')];
1324
- var _classDescriptor;
1325
- var _classExtraInitializers = [];
1326
- var _classThis;
1327
- var _staticExtraInitializers = [];
1328
- var _static_isInstanceDestroyed_decorators;
1329
- _classThis = /** @class */ (function () {
1330
- function NativeInstanceManager_1() {
1331
- }
1332
- NativeInstanceManager_1.isInstanceDestroyed = function (instanceId) {
1333
- throw new Error('not implemented');
1334
- };
1335
- return NativeInstanceManager_1;
1336
- }());
1337
- __setFunctionName$1(_classThis, "NativeInstanceManager");
1338
- (function () {
1339
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1340
- _static_isInstanceDestroyed_decorators = [NativeStaticMethodSync()];
1341
- __esDecorate$1(_classThis, null, _static_isInstanceDestroyed_decorators, { kind: "method", name: "isInstanceDestroyed", static: true, private: false, access: { has: function (obj) { return "isInstanceDestroyed" in obj; }, get: function (obj) { return obj.isInstanceDestroyed; } }, metadata: _metadata }, null, _staticExtraInitializers);
1342
- __esDecorate$1(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
1343
- _classThis = _classDescriptor.value;
1344
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1345
- __runInitializers$1(_classThis, _staticExtraInitializers);
1346
- __runInitializers$1(_classThis, _classExtraInitializers);
1347
- })();
1348
- return _classThis;
1349
- }();
1350
-
1351
- var NativeLoggerManager$1 = function () {
1352
- var _classDecorators = [NativeClass('com.volcengine.VolcApiEngine.logger.VolcLogger')];
1353
- var _classDescriptor;
1354
- var _classExtraInitializers = [];
1355
- var _classThis;
1356
- var _staticExtraInitializers = [];
1357
- var _static_setLogLevel_decorators;
1358
- _classThis = /** @class */ (function () {
1359
- function NativeLoggerManager_1() {
1360
- }
1361
- NativeLoggerManager_1.setLogLevel = function (instanceId) {
1362
- throw new Error('not implemented');
1363
- };
1364
- return NativeLoggerManager_1;
1365
- }());
1366
- __setFunctionName$1(_classThis, "NativeLoggerManager");
1367
- (function () {
1368
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1369
- _static_setLogLevel_decorators = [NativeStaticMethod()];
1370
- __esDecorate$1(_classThis, null, _static_setLogLevel_decorators, { kind: "method", name: "setLogLevel", static: true, private: false, access: { has: function (obj) { return "setLogLevel" in obj; }, get: function (obj) { return obj.setLogLevel; } }, metadata: _metadata }, null, _staticExtraInitializers);
1371
- __esDecorate$1(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
1372
- _classThis = _classDescriptor.value;
1373
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1374
- __runInitializers$1(_classThis, _staticExtraInitializers);
1375
- __runInitializers$1(_classThis, _classExtraInitializers);
1376
- })();
1377
- return _classThis;
1378
- }();
1379
-
1380
- var NativeInstanceManager = function () {
1381
- var _classDecorators = [NativeClass('ApiEngineProtocol')];
1382
- var _classDescriptor;
1383
- var _classExtraInitializers = [];
1384
- var _classThis;
1385
- var _staticExtraInitializers = [];
1386
- var _static_isInstanceDestroyed_decorators;
1387
- _classThis = /** @class */ (function () {
1388
- function NativeInstanceManager_1() {
1389
- }
1390
- NativeInstanceManager_1.isInstanceDestroyed = function (instanceId) {
1391
- throw new Error('not implemented');
1392
- };
1393
- return NativeInstanceManager_1;
1394
- }());
1395
- __setFunctionName$1(_classThis, "NativeInstanceManager");
1396
- (function () {
1397
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1398
- _static_isInstanceDestroyed_decorators = [NativeStaticMethodSync('isInstanceDestroyed:')];
1399
- __esDecorate$1(_classThis, null, _static_isInstanceDestroyed_decorators, { kind: "method", name: "isInstanceDestroyed", static: true, private: false, access: { has: function (obj) { return "isInstanceDestroyed" in obj; }, get: function (obj) { return obj.isInstanceDestroyed; } }, metadata: _metadata }, null, _staticExtraInitializers);
1400
- __esDecorate$1(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
1401
- _classThis = _classDescriptor.value;
1402
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1403
- __runInitializers$1(_classThis, _staticExtraInitializers);
1404
- __runInitializers$1(_classThis, _classExtraInitializers);
1405
- })();
1406
- return _classThis;
1407
- }();
1408
-
1409
- var NativeLoggerManager = function () {
1410
- var _classDecorators = [NativeClass('VolcLogger')];
1411
- var _classDescriptor;
1412
- var _classExtraInitializers = [];
1413
- var _classThis;
1414
- var _staticExtraInitializers = [];
1415
- var _static_setLogLevel_decorators;
1416
- _classThis = /** @class */ (function () {
1417
- function NativeLoggerManager_1() {
1418
- }
1419
- NativeLoggerManager_1.setLogLevel = function (level) {
1420
- throw new Error('not implemented');
1421
- };
1422
- return NativeLoggerManager_1;
1423
- }());
1424
- __setFunctionName$1(_classThis, "NativeLoggerManager");
1425
- (function () {
1426
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1427
- _static_setLogLevel_decorators = [NativeStaticMethod('setLogLevel:')];
1428
- __esDecorate$1(_classThis, null, _static_setLogLevel_decorators, { kind: "method", name: "setLogLevel", static: true, private: false, access: { has: function (obj) { return "setLogLevel" in obj; }, get: function (obj) { return obj.setLogLevel; } }, metadata: _metadata }, null, _staticExtraInitializers);
1429
- __esDecorate$1(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
1430
- _classThis = _classDescriptor.value;
1431
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1432
- __runInitializers$1(_classThis, _staticExtraInitializers);
1433
- __runInitializers$1(_classThis, _classExtraInitializers);
1434
- })();
1435
- return _classThis;
1436
- }();
1437
-
1438
- /** @class */ ((function () {
1439
- function InstanceManager() {
1440
- }
1441
- InstanceManager.isInstanceDestroyed = function (instanceOrId) {
1442
- var instanceId = resolveInstance(instanceOrId);
1443
- this.logger.debug('[instance-manager] isInstanceDestroyed', instanceId);
1444
- if (getOS() === 'android') {
1445
- return NativeInstanceManager$1.isInstanceDestroyed(instanceId);
1446
- }
1447
- else if (getOS() === 'ios') {
1448
- return NativeInstanceManager.isInstanceDestroyed(instanceId);
1449
- }
1450
- throw new Error('not implemented');
1451
- };
1452
- InstanceManager.logger = LoggerImpl.getInstance();
1453
- return InstanceManager;
1454
- })());
1455
-
1456
- var LoggerManager = /** @class */ (function () {
1457
- function LoggerManager() {
1458
- }
1459
- LoggerManager.setLogLevel = function (level) {
1460
- this.logger.setLogLevel(level);
1461
- this.logger.debug('[logger-manager] setLogLevel', LogLevel[level]);
1462
- if (getOS() === 'android') {
1463
- NativeLoggerManager$1.setLogLevel(level);
1464
- }
1465
- else if (getOS() === 'ios') {
1466
- NativeLoggerManager.setLogLevel(level);
1467
- }
1468
- else {
1469
- throw new Error('env has not been set');
1470
- }
1471
- };
1472
- LoggerManager.logger = LoggerImpl.getInstance();
1473
- return LoggerManager;
1474
- }());
1475
-
1476
- var logger = LoggerImpl.getInstance();
656
+ const logger = new LoggerImpl();
1477
657
  function setupLogger(opt) {
1478
- if (opt.level !== undefined) {
1479
- LoggerManager.setLogLevel(opt.level);
1480
- }
1481
- if (opt.customer !== undefined) {
1482
- logger.registerConsumer(opt.customer);
1483
- }
658
+ logger.registerConsumer(opt.customer);
1484
659
  }
1485
660
 
1486
- var ApiCallSpan = /** @class */ (function () {
1487
- function ApiCallSpan(tracer, action) {
661
+ class ApiCallSpan {
662
+ constructor(tracer, action) {
1488
663
  this.tracer = tracer;
1489
664
  this.action = action;
1490
665
  this.startTimestamp = Date.now();
1491
666
  this.status = 'unknown';
1492
- var record = {
667
+ const record = {
1493
668
  ts: Date.now(),
1494
669
  type: 'call',
1495
670
  data: action,
1496
671
  traceId: action.traceId,
1497
672
  };
1498
- var msg = "<TO ".concat(action.target, "> ").concat(action.callType, " call:").concat(action.serviceName || '', ".").concat(action.methodName || action.memberName || '');
673
+ const msg = `<TO ${action.target}> ${action.callType} call:${action.serviceName || ''}.${action.methodName || action.memberName || ''} args=${safeStringify(action.args)}`;
1499
674
  this.tracer.report(record, msg, {
1500
675
  serviceName: action.serviceName,
1501
676
  });
1502
677
  }
1503
- ApiCallSpan.prototype.setReturnValue = function (value) {
678
+ setReturnValue(value) {
1504
679
  this.action.return = value;
1505
- };
1506
- ApiCallSpan.prototype.success = function (value) {
680
+ }
681
+ success(value) {
1507
682
  this.setReturnValue(value);
1508
683
  this.status = 'success';
1509
684
  this.finish();
1510
- };
1511
- ApiCallSpan.prototype.fail = function (error) {
685
+ }
686
+ fail(error) {
1512
687
  this.setReturnValue(error);
1513
688
  this.status = 'fail';
1514
689
  this.finish();
1515
- };
1516
- ApiCallSpan.prototype.finish = function () {
690
+ }
691
+ finish() {
1517
692
  this.endTimestamp = Date.now();
1518
693
  this._report();
1519
- };
1520
- ApiCallSpan.prototype._report = function () {
1521
- var _a;
1522
- var _b;
1523
- var action = this.action;
1524
- var record = {
694
+ }
695
+ _report() {
696
+ const { action } = this;
697
+ const record = {
1525
698
  ts: Date.now(),
1526
699
  type: 'call',
1527
700
  data: action,
1528
701
  traceId: this.action.traceId,
1529
702
  };
1530
- var msg = "<".concat(action.target, " Return> ").concat(action.callType, " call:").concat(action.serviceName, ".").concat(action.methodName || action.memberName || '');
1531
- var cost = this.endTimestamp - this.startTimestamp;
1532
- this.tracer.report(record, msg, (_a = {
1533
- level: this.status === 'fail' ||
1534
- ((_b = this.action.return) === null || _b === void 0 ? void 0 : _b.status) === 'failed'
1535
- ? 'warn'
1536
- : 'debug',
1537
- serviceName: action.serviceName,
1538
- cost: cost,
1539
- status: this.status
1540
- },
1541
- _a[this.status] = '1',
1542
- _a));
1543
- };
1544
- return ApiCallSpan;
1545
- }());
1546
- var Tracer = /** @class */ (function () {
1547
- function Tracer() {
1548
- this._logger = LoggerImpl.getInstance();
703
+ const msg = `<${action.target} Return> ${action.callType} call:${action.serviceName}.${action.methodName || action.memberName || ''} args=${safeStringify(action.args)} return=${safeStringify(action.return)}`;
704
+ const cost = this.endTimestamp - this.startTimestamp;
705
+ this.tracer.report(record, msg, {
706
+ level: this.status === 'fail' ||
707
+ this.action.return?.status === 'failed'
708
+ ? 'warn'
709
+ : 'debug',
710
+ serviceName: action.serviceName,
711
+ cost,
712
+ status: this.status,
713
+ [this.status]: '1',
714
+ });
715
+ }
716
+ }
717
+ class Tracer {
718
+ constructor() {
1549
719
  this._consumers = [];
1550
720
  }
1551
- Tracer.prototype.registerConsumer = function (consumer) {
721
+ registerConsumer(consumer) {
1552
722
  this._consumers.push(consumer);
1553
- };
1554
- Tracer.prototype.init = function (opt) {
723
+ }
724
+ init(opt) {
1555
725
  this.options = opt;
1556
- };
1557
- Tracer.prototype.collectApiCall = function (action) {
1558
- var span = new ApiCallSpan(this, action);
726
+ }
727
+ collectApiCall(action) {
728
+ const span = new ApiCallSpan(this, action);
1559
729
  return span;
1560
- };
1561
- Tracer.prototype.collectEventEmit = function (action) {
1562
- var record = {
730
+ }
731
+ collectEventEmit(action) {
732
+ const record = {
1563
733
  ts: Date.now(),
1564
734
  type: 'event_emit',
1565
735
  data: action,
1566
736
  };
1567
- var eventName = action.eventName; action.eventData;
1568
- var msg = "<TO ".concat(action.target, "> emit:").concat(eventName);
737
+ const { eventName, eventData } = action;
738
+ const msg = `<TO ${action.target}> emit:${eventName} event=${safeStringify(eventData)}`;
1569
739
  this.report(record, msg, {
1570
740
  callType: 'event_emit',
1571
741
  eventName: eventName,
1572
742
  });
1573
- };
1574
- Tracer.prototype.collectEventEmitResult = function (action) {
1575
- var record = {
743
+ }
744
+ collectEventEmitResult(action) {
745
+ const record = {
1576
746
  ts: Date.now(),
1577
747
  type: 'event_emit_result',
1578
748
  data: action,
1579
749
  };
1580
- var eventName = action.eventName; action.eventData;
1581
- var msg = "<TO ".concat(action.target, "> emit:").concat(eventName);
750
+ const { eventName, eventData } = action;
751
+ const msg = `<TO ${action.target}> emit:${eventName} result=${safeStringify(eventData)}`;
1582
752
  this.report(record, msg, {
1583
753
  callType: 'event_emit_result',
1584
754
  eventName: eventName,
1585
755
  });
1586
- };
1587
- Tracer.prototype.collectEventOn = function (action) {
1588
- var record = {
756
+ }
757
+ collectEventOn(action) {
758
+ const record = {
1589
759
  ts: Date.now(),
1590
760
  type: 'event_on',
1591
761
  data: action,
1592
762
  };
1593
- var eventName = action.eventName;
1594
- var msg = "<TO ".concat(action.target, "> on:").concat(eventName);
763
+ const { eventName } = action;
764
+ const msg = `<TO ${action.target}> on:${eventName}`;
1595
765
  this.report(record, msg, {
1596
766
  callType: 'event_on',
1597
- eventName: eventName,
767
+ eventName,
1598
768
  });
1599
- };
1600
- Tracer.prototype.collectEventOff = function (action) {
1601
- var record = {
769
+ }
770
+ collectEventOff(action) {
771
+ const record = {
1602
772
  ts: Date.now(),
1603
773
  type: 'event_off',
1604
774
  data: action,
1605
775
  };
1606
- var eventName = action.eventName;
1607
- var msg = "<TO ".concat(action.target, "> off:").concat(eventName);
776
+ const { eventName } = action;
777
+ const msg = `<TO ${action.target}> off:${eventName}`;
1608
778
  this.report(record, msg, {
1609
779
  callType: 'event_off',
1610
- eventName: eventName,
780
+ eventName,
1611
781
  });
1612
- };
1613
- Tracer.prototype.collectCallbackEmit = function (action) {
1614
- var record = {
782
+ }
783
+ collectCallbackEmit(action) {
784
+ const record = {
1615
785
  ts: Date.now(),
1616
786
  type: 'callback_emit',
1617
787
  data: action,
1618
788
  };
1619
- var eventName = action.eventName; action.eventData;
1620
- var msg = "<TO ".concat(action.target, "> emit callback:").concat(eventName);
789
+ const { eventName, eventData } = action;
790
+ const msg = `<TO ${action.target}> emit callback:${eventName} event=${safeStringify(eventData)}`;
1621
791
  this.report(record, msg, {
1622
792
  callType: 'callback_emit',
1623
793
  eventName: eventName,
1624
794
  });
1625
- };
1626
- Tracer.prototype.report = function (record, msg, extra) {
1627
- var _this = this;
1628
- this._consumers.forEach(function (c) { return __awaiter$1(_this, void 0, void 0, function () {
1629
- return __generator$1(this, function (_a) {
1630
- switch (_a.label) {
1631
- case 0:
1632
- _a.trys.push([0, 2, , 3]);
1633
- return [4 /*yield*/, c(record, msg, extra)];
1634
- case 1:
1635
- _a.sent();
1636
- return [3 /*break*/, 3];
1637
- case 2:
1638
- _a.sent();
1639
- return [3 /*break*/, 3];
1640
- case 3: return [2 /*return*/];
1641
- }
1642
- });
1643
- }); });
1644
- try {
1645
- var level = extra.level || 'info';
1646
- if (level === 'warn') {
1647
- this._logger.warn("[Trace] ".concat(msg));
795
+ }
796
+ report(record, msg, extra) {
797
+ this._consumers.forEach(async (c) => {
798
+ try {
799
+ await c(record, msg, extra);
1648
800
  }
1649
- else if (level === 'error') {
1650
- this._logger.error("[Trace] ".concat(msg));
801
+ catch (ignore) {
802
+ //
803
+ }
804
+ });
805
+ try {
806
+ const level = extra.level || 'info';
807
+ if (level === 'warn' || level === 'error') {
808
+ console.warn(`[Trace] ${level} `, msg);
1651
809
  }
1652
810
  else if (false) ;
1653
811
  }
1654
812
  catch (err) {
1655
813
  //
1656
814
  }
1657
- };
1658
- return Tracer;
1659
- }());
815
+ }
816
+ }
1660
817
 
1661
- var globalTracer = new Tracer();
818
+ const globalTracer = new Tracer();
1662
819
 
1663
- var MessageSenderImpl = function () {
820
+ let MessageSenderImpl = (() => {
1664
821
  var _a;
1665
- var _instanceExtraInitializers = [];
1666
- var _sendVarGet_decorators;
1667
- var _sendStaticCall_decorators;
1668
- var _sendStaticCallSync_decorators;
1669
- var _sendNewInstanceCall_decorators;
1670
- var _sendInstanceCall_decorators;
1671
- var _sendInstanceCallSync_decorators;
1672
- var _sendInstanceSet_decorators;
1673
- var _sendInstanceGet_decorators;
1674
- var _sendInstanceEventAdd_decorators;
1675
- var _sendInstanceEventRemove_decorators;
1676
- var _sendDestroyInstance_decorators;
1677
- var _sendEventEmit_decorators;
1678
- var _sendEventEmitResult_decorators;
1679
- return _a = /** @class */ (function () {
1680
- function MessageSenderImpl(proto, bridge) {
822
+ let _instanceExtraInitializers = [];
823
+ let _sendVarGet_decorators;
824
+ let _sendStaticCall_decorators;
825
+ let _sendStaticCallSync_decorators;
826
+ let _sendNewInstanceCall_decorators;
827
+ let _sendInstanceCall_decorators;
828
+ let _sendInstanceCallSync_decorators;
829
+ let _sendInstanceSet_decorators;
830
+ let _sendInstanceGet_decorators;
831
+ let _sendInstanceEventAdd_decorators;
832
+ let _sendInstanceEventRemove_decorators;
833
+ let _sendEventEmit_decorators;
834
+ let _sendEventEmitResult_decorators;
835
+ return _a = class MessageSenderImpl {
836
+ constructor(proto, bridge) {
1681
837
  this.proto = (__runInitializers$1(this, _instanceExtraInitializers), proto);
1682
838
  this.bridge = bridge;
1683
- this.logger = LoggerImpl.getInstance();
839
+ this.logger = logger;
1684
840
  this.tracer = globalTracer;
1685
841
  }
1686
- MessageSenderImpl.prototype.sendVarGet = function (varName, args) {
1687
- return __awaiter$1(this, void 0, void 0, function () {
1688
- var traceId, encodeArgs, params, span, res, err_1;
1689
- return __generator$1(this, function (_b) {
1690
- switch (_b.label) {
1691
- case 0:
1692
- traceId = getUuid('trace');
1693
- encodeArgs = this.proto.encodeArgs(args);
1694
- params = {
1695
- serviceName: varName,
1696
- memberName: varName,
1697
- args: encodeArgs,
1698
- callType: CALL_TYPE$1.VAR_GETTER,
1699
- _traceId: traceId,
1700
- };
1701
- span = this.tracer.collectApiCall({
1702
- source: 'js',
1703
- target: 'native',
1704
- serviceName: '$var',
1705
- memberName: varName,
1706
- args: encodeArgs,
1707
- traceId: traceId,
1708
- callType: params.callType,
1709
- });
1710
- _b.label = 1;
1711
- case 1:
1712
- _b.trys.push([1, 3, , 4]);
1713
- return [4 /*yield*/, this._send(params)];
1714
- case 2:
1715
- res = _b.sent();
1716
- span.success(res);
1717
- return [2 /*return*/, res];
1718
- case 3:
1719
- err_1 = _b.sent();
1720
- span.fail(err_1);
1721
- throw err_1;
1722
- case 4: return [2 /*return*/];
1723
- }
1724
- });
842
+ async sendVarGet(varName, args) {
843
+ const traceId = getUuid('trace');
844
+ const encodeArgs = this.proto.encodeArgs(args);
845
+ const params = {
846
+ serviceName: varName,
847
+ memberName: varName,
848
+ args: encodeArgs,
849
+ callType: CALL_TYPE$1.VAR_GETTER,
850
+ _traceId: traceId,
851
+ };
852
+ const span = this.tracer.collectApiCall({
853
+ source: 'js',
854
+ target: 'native',
855
+ serviceName: '$var',
856
+ memberName: varName,
857
+ args: encodeArgs,
858
+ traceId,
859
+ callType: params.callType,
1725
860
  });
1726
- };
1727
- MessageSenderImpl.prototype.sendStaticCall = function (serviceName, methodName, args) {
1728
- return __awaiter$1(this, void 0, void 0, function () {
1729
- var encodeArgs, traceId, params, span, res, err_2;
1730
- return __generator$1(this, function (_b) {
1731
- switch (_b.label) {
1732
- case 0:
1733
- encodeArgs = this.proto.encodeArgs(args);
1734
- traceId = getUuid('trace');
1735
- params = {
1736
- serviceName: serviceName,
1737
- methodName: methodName,
1738
- args: encodeArgs,
1739
- callType: CALL_TYPE$1.PLAIN_API_CALL,
1740
- _traceId: traceId,
1741
- runOnMainThread: true,
1742
- };
1743
- span = this.tracer.collectApiCall({
1744
- source: 'js',
1745
- target: 'native',
1746
- serviceName: serviceName,
1747
- methodName: methodName,
1748
- args: args,
1749
- traceId: traceId,
1750
- callType: params.callType,
1751
- });
1752
- _b.label = 1;
1753
- case 1:
1754
- _b.trys.push([1, 3, , 4]);
1755
- return [4 /*yield*/, this._send(params)];
1756
- case 2:
1757
- res = _b.sent();
1758
- span.success(res);
1759
- return [2 /*return*/, res];
1760
- case 3:
1761
- err_2 = _b.sent();
1762
- span.fail(err_2);
1763
- throw err_2;
1764
- case 4: return [2 /*return*/];
1765
- }
1766
- });
861
+ try {
862
+ const res = await this._send(params);
863
+ span.success(res);
864
+ return res;
865
+ }
866
+ catch (err) {
867
+ span.fail(err);
868
+ throw err;
869
+ }
870
+ }
871
+ async sendStaticCall(serviceName, methodName, args) {
872
+ const encodeArgs = this.proto.encodeArgs(args);
873
+ const traceId = getUuid('trace');
874
+ const params = {
875
+ serviceName,
876
+ methodName,
877
+ args: encodeArgs,
878
+ callType: CALL_TYPE$1.PLAIN_API_CALL,
879
+ _traceId: traceId,
880
+ };
881
+ const span = this.tracer.collectApiCall({
882
+ source: 'js',
883
+ target: 'native',
884
+ serviceName,
885
+ methodName,
886
+ args,
887
+ traceId,
888
+ callType: params.callType,
1767
889
  });
1768
- };
1769
- MessageSenderImpl.prototype.sendStaticCallSync = function (serviceName, methodName, args) {
1770
- var encodeArgs = this.proto.encodeArgs(args);
1771
- var traceId = getUuid('trace');
1772
- var params = {
1773
- serviceName: serviceName,
1774
- methodName: methodName,
890
+ try {
891
+ const res = await this._send(params);
892
+ span.success(res);
893
+ return res;
894
+ }
895
+ catch (err) {
896
+ span.fail(err);
897
+ throw err;
898
+ }
899
+ }
900
+ sendStaticCallSync(serviceName, methodName, args) {
901
+ const encodeArgs = this.proto.encodeArgs(args);
902
+ const traceId = getUuid('trace');
903
+ const params = {
904
+ serviceName,
905
+ methodName,
1775
906
  args: encodeArgs,
1776
907
  callType: CALL_TYPE$1.PLAIN_API_CALL,
1777
908
  _traceId: traceId,
1778
- runOnMainThread: true,
1779
909
  };
1780
- var span = this.tracer.collectApiCall({
910
+ const span = this.tracer.collectApiCall({
1781
911
  source: 'js',
1782
912
  target: 'native',
1783
- serviceName: serviceName,
1784
- methodName: methodName,
1785
- args: args,
1786
- traceId: traceId,
913
+ serviceName,
914
+ methodName,
915
+ args,
916
+ traceId,
1787
917
  callType: params.callType,
1788
918
  });
1789
919
  try {
1790
- var res = this._sendSync(params);
920
+ const res = this._sendSync(params);
1791
921
  span.success(res);
1792
922
  return res;
1793
923
  }
@@ -1795,30 +925,28 @@ var MessageSenderImpl = function () {
1795
925
  span.fail(err);
1796
926
  throw err;
1797
927
  }
1798
- };
1799
- MessageSenderImpl.prototype.sendNewInstanceCall = function (serviceName, args, instanceId, instance) {
1800
- var encodeArgs = this.proto.encodeArgs(args);
1801
- var traceId = getUuid('trace');
1802
- var params = {
1803
- serviceName: serviceName,
928
+ }
929
+ sendNewInstanceCall(serviceName, args, instanceId, instance) {
930
+ const encodeArgs = this.proto.encodeArgs(args);
931
+ const traceId = getUuid('trace');
932
+ const params = {
933
+ serviceName,
1804
934
  args: encodeArgs,
1805
935
  callType: CALL_TYPE$1.NEW_INSTANCE,
1806
936
  _instanceId: instanceId,
1807
- _instanceType: instance.instanceType,
1808
937
  _traceId: traceId,
1809
- runOnMainThread: true,
1810
938
  };
1811
- var span = this.tracer.collectApiCall({
939
+ const span = this.tracer.collectApiCall({
1812
940
  source: 'js',
1813
941
  target: 'native',
1814
- serviceName: serviceName,
1815
- args: args,
1816
- traceId: traceId,
942
+ serviceName,
943
+ args,
944
+ traceId,
1817
945
  callType: params.callType,
1818
946
  });
1819
947
  try {
1820
948
  this.proto.registerProxyInstance(instanceId, instance);
1821
- var res = this._sendSync(params);
949
+ const res = this._sendSync(params);
1822
950
  span.success(res);
1823
951
  return res;
1824
952
  }
@@ -1826,79 +954,63 @@ var MessageSenderImpl = function () {
1826
954
  span.fail(err);
1827
955
  throw err;
1828
956
  }
1829
- };
1830
- MessageSenderImpl.prototype.sendInstanceCall = function (instanceOrId_1, serviceName_1, methodName_1) {
1831
- return __awaiter$1(this, arguments, void 0, function (instanceOrId, serviceName, methodName, args, meta) {
1832
- var instanceId, encodeArgs, traceId, params, span, res, err_3;
1833
- if (args === void 0) { args = []; }
1834
- return __generator$1(this, function (_b) {
1835
- switch (_b.label) {
1836
- case 0:
1837
- instanceId = this._resolveInstanceId(instanceOrId);
1838
- assert(!!instanceId, 'unknown instance');
1839
- encodeArgs = this.proto.encodeArgs(args);
1840
- traceId = getUuid('trace');
1841
- params = {
1842
- callType: CALL_TYPE$1.INSTANCE_METHOD_INVOKE,
1843
- _instanceId: instanceId,
1844
- serviceName: serviceName,
1845
- methodName: methodName,
1846
- args: encodeArgs,
1847
- _traceId: traceId,
1848
- runOnMainThread: true,
1849
- };
1850
- span = this.tracer.collectApiCall({
1851
- source: 'js',
1852
- target: 'native',
1853
- serviceName: serviceName,
1854
- methodName: methodName,
1855
- args: args,
1856
- traceId: traceId,
1857
- callType: params.callType,
1858
- });
1859
- _b.label = 1;
1860
- case 1:
1861
- _b.trys.push([1, 3, , 4]);
1862
- return [4 /*yield*/, this._send(params)];
1863
- case 2:
1864
- res = _b.sent();
1865
- span.success(res);
1866
- return [2 /*return*/, res];
1867
- case 3:
1868
- err_3 = _b.sent();
1869
- span.fail(err_3);
1870
- throw err_3;
1871
- case 4: return [2 /*return*/];
1872
- }
1873
- });
1874
- });
1875
- };
1876
- MessageSenderImpl.prototype.sendInstanceCallSync = function (instanceOrId, serviceName, methodName, args, meta) {
1877
- if (args === void 0) { args = []; }
1878
- var instanceId = this._resolveInstanceId(instanceOrId);
957
+ }
958
+ async sendInstanceCall(instanceOrId, serviceName, methodName, args = [], meta) {
959
+ const instanceId = this._resolveInstanceId(instanceOrId);
1879
960
  assert(!!instanceId, 'unknown instance');
1880
- var encodeArgs = this.proto.encodeArgs(args);
1881
- var traceId = getUuid('trace');
1882
- var params = {
961
+ const encodeArgs = this.proto.encodeArgs(args);
962
+ const traceId = getUuid('trace');
963
+ const params = {
1883
964
  callType: CALL_TYPE$1.INSTANCE_METHOD_INVOKE,
1884
965
  _instanceId: instanceId,
1885
966
  serviceName: serviceName,
967
+ methodName,
1886
968
  args: encodeArgs,
1887
- methodName: methodName,
1888
969
  _traceId: traceId,
1889
- runOnMainThread: true,
1890
970
  };
1891
- var span = this.tracer.collectApiCall({
971
+ const span = this.tracer.collectApiCall({
1892
972
  source: 'js',
1893
973
  target: 'native',
974
+ serviceName,
975
+ methodName,
976
+ args,
977
+ traceId,
978
+ callType: params.callType,
979
+ });
980
+ try {
981
+ const res = await this._send(params);
982
+ span.success(res);
983
+ return res;
984
+ }
985
+ catch (err) {
986
+ span.fail(err);
987
+ throw err;
988
+ }
989
+ }
990
+ sendInstanceCallSync(instanceOrId, serviceName, methodName, args = [], meta) {
991
+ const instanceId = this._resolveInstanceId(instanceOrId);
992
+ assert(!!instanceId, 'unknown instance');
993
+ const encodeArgs = this.proto.encodeArgs(args);
994
+ const traceId = getUuid('trace');
995
+ const params = {
996
+ callType: CALL_TYPE$1.INSTANCE_METHOD_INVOKE,
997
+ _instanceId: instanceId,
1894
998
  serviceName: serviceName,
1895
- methodName: methodName,
1896
- args: args,
1897
- traceId: traceId,
999
+ args: encodeArgs,
1000
+ methodName,
1001
+ _traceId: traceId,
1002
+ };
1003
+ const span = this.tracer.collectApiCall({
1004
+ source: 'js',
1005
+ target: 'native',
1006
+ serviceName,
1007
+ methodName,
1008
+ args,
1009
+ traceId,
1898
1010
  callType: params.callType,
1899
1011
  });
1900
1012
  try {
1901
- var res = this._sendSync(params);
1013
+ const res = this._sendSync(params);
1902
1014
  span.success(res);
1903
1015
  return res;
1904
1016
  }
@@ -1906,31 +1018,31 @@ var MessageSenderImpl = function () {
1906
1018
  span.fail(err);
1907
1019
  throw err;
1908
1020
  }
1909
- };
1910
- MessageSenderImpl.prototype.sendInstanceSet = function (instanceOrId, serviceName, memberName, value) {
1911
- var arg = this.proto.encodeArg(value);
1912
- var instanceId = this._resolveInstanceId(instanceOrId);
1021
+ }
1022
+ sendInstanceSet(instanceOrId, serviceName, memberName, value) {
1023
+ const arg = this.proto.encodeArg(value);
1024
+ const instanceId = this._resolveInstanceId(instanceOrId);
1913
1025
  assert(!!instanceId, 'unknown instance');
1914
- var traceId = getUuid('trace');
1915
- var params = {
1026
+ const traceId = getUuid('trace');
1027
+ const params = {
1916
1028
  callType: CALL_TYPE$1.INSTANCE_MEMBER_SET,
1917
1029
  _instanceId: instanceId,
1918
- serviceName: serviceName,
1919
- memberName: memberName,
1030
+ serviceName,
1031
+ memberName,
1920
1032
  args: [arg],
1921
1033
  _traceId: traceId,
1922
1034
  };
1923
- var span = this.tracer.collectApiCall({
1035
+ const span = this.tracer.collectApiCall({
1924
1036
  source: 'js',
1925
1037
  target: 'native',
1926
1038
  serviceName: memberName,
1927
- memberName: memberName,
1039
+ memberName,
1928
1040
  args: [arg],
1929
- traceId: traceId,
1041
+ traceId,
1930
1042
  callType: params.callType,
1931
1043
  });
1932
1044
  try {
1933
- var res = this._sendSync(params);
1045
+ const res = this._sendSync(params);
1934
1046
  span.success(res);
1935
1047
  return res;
1936
1048
  }
@@ -1938,30 +1050,30 @@ var MessageSenderImpl = function () {
1938
1050
  span.fail(err);
1939
1051
  throw err;
1940
1052
  }
1941
- };
1942
- MessageSenderImpl.prototype.sendInstanceGet = function (instanceOrId, serviceName, memberName) {
1943
- var instanceId = this._resolveInstanceId(instanceOrId);
1053
+ }
1054
+ sendInstanceGet(instanceOrId, serviceName, memberName) {
1055
+ const instanceId = this._resolveInstanceId(instanceOrId);
1944
1056
  assert(!!instanceId, 'unknown instance');
1945
- var traceId = getUuid('trace');
1946
- var params = {
1057
+ const traceId = getUuid('trace');
1058
+ const params = {
1947
1059
  callType: CALL_TYPE$1.INSTANCE_MEMBER_GET,
1948
1060
  _instanceId: instanceId,
1949
- serviceName: serviceName,
1950
- memberName: memberName,
1061
+ serviceName,
1062
+ memberName,
1951
1063
  args: [],
1952
1064
  _traceId: traceId,
1953
1065
  };
1954
- var span = this.tracer.collectApiCall({
1066
+ const span = this.tracer.collectApiCall({
1955
1067
  source: 'js',
1956
1068
  target: 'native',
1957
1069
  serviceName: memberName,
1958
- memberName: memberName,
1070
+ memberName,
1959
1071
  args: [],
1960
- traceId: traceId,
1072
+ traceId,
1961
1073
  callType: params.callType,
1962
1074
  });
1963
1075
  try {
1964
- var res = this._sendSync(params);
1076
+ const res = this._sendSync(params);
1965
1077
  span.success(res);
1966
1078
  return res;
1967
1079
  }
@@ -1969,12 +1081,12 @@ var MessageSenderImpl = function () {
1969
1081
  span.fail(err);
1970
1082
  throw err;
1971
1083
  }
1972
- };
1973
- MessageSenderImpl.prototype.sendInstanceEventAdd = function (instanceOrId, serviceName, eventName) {
1974
- var instanceId = this._resolveInstanceId(instanceOrId);
1084
+ }
1085
+ sendInstanceEventAdd(instanceOrId, serviceName, eventName) {
1086
+ const instanceId = this._resolveInstanceId(instanceOrId);
1975
1087
  assert(!!instanceId, 'unknown instance');
1976
1088
  // const encodeCallback = this.proto.encodeCallback(callback);
1977
- var params = {
1089
+ const params = {
1978
1090
  callType: CALL_TYPE$1.INSTANCE_EVENT_LISTENER_ADD,
1979
1091
  _instanceId: instanceId,
1980
1092
  serviceName: serviceName,
@@ -1987,12 +1099,12 @@ var MessageSenderImpl = function () {
1987
1099
  eventName: serviceName,
1988
1100
  });
1989
1101
  return this._sendSync(params);
1990
- };
1991
- MessageSenderImpl.prototype.sendInstanceEventRemove = function (instanceOrId, serviceName, eventName) {
1992
- var instanceId = this._resolveInstanceId(instanceOrId);
1102
+ }
1103
+ sendInstanceEventRemove(instanceOrId, serviceName, eventName) {
1104
+ const instanceId = this._resolveInstanceId(instanceOrId);
1993
1105
  assert(!!instanceId, 'unknown instance');
1994
1106
  // const encodeCallback = this.proto.encodeCallback(callback);
1995
- var params = {
1107
+ const params = {
1996
1108
  callType: CALL_TYPE$1.INSTANCE_EVENT_LISTENER_REMOVE,
1997
1109
  _instanceId: instanceId,
1998
1110
  serviceName: serviceName,
@@ -2005,124 +1117,77 @@ var MessageSenderImpl = function () {
2005
1117
  eventName: serviceName,
2006
1118
  });
2007
1119
  return this._sendSync(params);
2008
- };
2009
- MessageSenderImpl.prototype.sendDestroyInstance = function (instanceOrId, serviceName) {
2010
- var instanceId = this._resolveInstanceId(instanceOrId);
2011
- assert(!!instanceId, 'unknown instance');
2012
- var params = {
2013
- callType: CALL_TYPE$1.DESTROY_INSTANCE,
1120
+ }
1121
+ async sendEventEmit(instanceId, serviceName, callbackId, args) {
1122
+ const encodeArgs = this.proto.encodeArgs(args);
1123
+ const params = {
1124
+ callType: CALL_TYPE$1.INSTANCE_EVENT_EMIT,
2014
1125
  _instanceId: instanceId,
2015
1126
  serviceName: serviceName,
1127
+ args: [
1128
+ {
1129
+ callback_id: callbackId,
1130
+ },
1131
+ ...encodeArgs,
1132
+ ],
2016
1133
  };
2017
- return this._sendSync(params);
2018
- };
2019
- MessageSenderImpl.prototype.sendEventEmit = function (instanceId, serviceName, callbackId, args) {
2020
- return __awaiter$1(this, void 0, void 0, function () {
2021
- var encodeArgs, params;
2022
- return __generator$1(this, function (_b) {
2023
- encodeArgs = this.proto.encodeArgs(args);
2024
- params = {
2025
- callType: CALL_TYPE$1.INSTANCE_EVENT_EMIT,
2026
- _instanceId: instanceId,
2027
- serviceName: serviceName,
2028
- args: __spreadArray$1([
2029
- {
2030
- callback_id: callbackId,
2031
- }
2032
- ], encodeArgs, true),
2033
- };
2034
- this.tracer.collectEventEmit({
2035
- source: 'js',
2036
- target: 'native',
2037
- eventName: serviceName,
2038
- eventData: encodeArgs,
2039
- });
2040
- return [2 /*return*/, this._send(params)];
2041
- });
2042
- });
2043
- };
2044
- MessageSenderImpl.prototype.sendEventEmitResult = function (instanceId, serviceName, ret) {
2045
- return __awaiter$1(this, void 0, void 0, function () {
2046
- var params;
2047
- return __generator$1(this, function (_b) {
2048
- params = {
2049
- callType: CALL_TYPE$1.INSTANCE_EVENT_RESULT,
2050
- _instanceId: instanceId,
2051
- serviceName: serviceName,
2052
- args: [ret],
2053
- _traceId: ret._traceId,
2054
- };
2055
- this.tracer.collectEventEmitResult({
2056
- source: 'js',
2057
- target: 'native',
2058
- eventName: serviceName,
2059
- eventData: ret,
2060
- });
2061
- return [2 /*return*/, this._send(params)];
2062
- });
1134
+ this.tracer.collectEventEmit({
1135
+ source: 'js',
1136
+ target: 'native',
1137
+ eventName: serviceName,
1138
+ eventData: encodeArgs,
2063
1139
  });
2064
- };
2065
- MessageSenderImpl.prototype._send = function (params) {
2066
- return __awaiter$1(this, void 0, void 0, function () {
2067
- var traceId, res;
2068
- return __generator$1(this, function (_b) {
2069
- switch (_b.label) {
2070
- case 0:
2071
- traceId = params._traceId || getUuid('trace');
2072
- params._traceId = traceId;
2073
- this.logger.info('[message-sender] Send request:', params);
2074
- return [4 /*yield*/, this.bridge.call(params)];
2075
- case 1:
2076
- res = _b.sent();
2077
- this.logger.info('[message-sender] Received response:', res);
2078
- return [2 /*return*/, this._resolveReturn(res, params)];
2079
- }
2080
- });
1140
+ return this._send(params);
1141
+ }
1142
+ async sendEventEmitResult(instanceId, serviceName, ret) {
1143
+ const params = {
1144
+ callType: CALL_TYPE$1.INSTANCE_EVENT_RESULT,
1145
+ _instanceId: instanceId,
1146
+ serviceName: serviceName,
1147
+ args: [ret],
1148
+ _traceId: ret._traceId,
1149
+ };
1150
+ this.tracer.collectEventEmitResult({
1151
+ source: 'js',
1152
+ target: 'native',
1153
+ eventName: serviceName,
1154
+ eventData: ret,
2081
1155
  });
2082
- };
2083
- MessageSenderImpl.prototype._sendSync = function (params) {
2084
- var traceId = params._traceId || getUuid('trace');
1156
+ return this._send(params);
1157
+ }
1158
+ async _send(params) {
1159
+ const traceId = params._traceId || getUuid('trace');
2085
1160
  params._traceId = traceId;
2086
- this.logger.info('[message-sender] Send sync request:', params);
2087
- var res = this.bridge.callSync(params);
2088
- this.logger.info('[message-sender] Received sync response:', res);
1161
+ const res = await this.bridge.call(params);
2089
1162
  return this._resolveReturn(res, params);
2090
- };
2091
- MessageSenderImpl.prototype._resolveReturn = function (res, req) {
2092
- switch (res.status) {
2093
- case RETURN_STATUS$1.SUCCESS:
2094
- this.logger.info('[message-sender] Decode return:', res.msg);
2095
- if (res.msg) {
2096
- Object.defineProperty(res, 'decoded', {
2097
- value: this.proto.decodeArg(res.msg),
2098
- enumerable: false,
2099
- writable: true,
2100
- });
2101
- }
2102
- break;
2103
- case RETURN_STATUS$1.NOT_IMPLEMENTED:
2104
- this.logger.error('[message-sender] Native method not implemented:', req);
2105
- break;
2106
- case RETURN_STATUS$1.FAILED:
2107
- this.logger.error('[message-sender] Decode return failed:', res);
2108
- break;
2109
- default:
2110
- this.logger.warn('[message-sender] Unknown return status:', res);
2111
- break;
1163
+ }
1164
+ _sendSync(params) {
1165
+ const traceId = params._traceId || getUuid('trace');
1166
+ params._traceId = traceId;
1167
+ const res = this.bridge.callSync(params);
1168
+ return this._resolveReturn(res, params);
1169
+ }
1170
+ _resolveReturn(res, req) {
1171
+ if (res.status === RETURN_STATUS$1.SUCCESS && res.msg) {
1172
+ Object.defineProperty(res, 'decoded', {
1173
+ value: this.proto.decodeArg(res.msg),
1174
+ enumerable: false,
1175
+ writable: true,
1176
+ });
2112
1177
  }
2113
1178
  return res;
2114
- };
2115
- MessageSenderImpl.prototype._resolveInstanceId = function (instanceOrId) {
2116
- var id = resolveInstance(instanceOrId);
2117
- if (!id) {
2118
- this.logger.warn('[message-sender] Failed to resolve instance id:', instanceOrId);
1179
+ }
1180
+ _resolveInstanceId(instanceOrId) {
1181
+ if (typeof instanceOrId === 'string') {
1182
+ return instanceOrId;
2119
1183
  }
2120
- return id;
2121
- };
2122
- return MessageSenderImpl;
2123
- }()),
2124
- (function () {
2125
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1184
+ if (isInstanceArg(instanceOrId)) {
1185
+ return instanceOrId._instanceId;
1186
+ }
1187
+ }
1188
+ },
1189
+ (() => {
1190
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
2126
1191
  _sendVarGet_decorators = [Bind];
2127
1192
  _sendStaticCall_decorators = [Bind];
2128
1193
  _sendStaticCallSync_decorators = [Bind];
@@ -2133,343 +1198,247 @@ var MessageSenderImpl = function () {
2133
1198
  _sendInstanceGet_decorators = [Bind];
2134
1199
  _sendInstanceEventAdd_decorators = [Bind];
2135
1200
  _sendInstanceEventRemove_decorators = [Bind];
2136
- _sendDestroyInstance_decorators = [Bind];
2137
1201
  _sendEventEmit_decorators = [Bind];
2138
1202
  _sendEventEmitResult_decorators = [Bind];
2139
- __esDecorate$1(_a, null, _sendVarGet_decorators, { kind: "method", name: "sendVarGet", static: false, private: false, access: { has: function (obj) { return "sendVarGet" in obj; }, get: function (obj) { return obj.sendVarGet; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2140
- __esDecorate$1(_a, null, _sendStaticCall_decorators, { kind: "method", name: "sendStaticCall", static: false, private: false, access: { has: function (obj) { return "sendStaticCall" in obj; }, get: function (obj) { return obj.sendStaticCall; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2141
- __esDecorate$1(_a, null, _sendStaticCallSync_decorators, { kind: "method", name: "sendStaticCallSync", static: false, private: false, access: { has: function (obj) { return "sendStaticCallSync" in obj; }, get: function (obj) { return obj.sendStaticCallSync; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2142
- __esDecorate$1(_a, null, _sendNewInstanceCall_decorators, { kind: "method", name: "sendNewInstanceCall", static: false, private: false, access: { has: function (obj) { return "sendNewInstanceCall" in obj; }, get: function (obj) { return obj.sendNewInstanceCall; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2143
- __esDecorate$1(_a, null, _sendInstanceCall_decorators, { kind: "method", name: "sendInstanceCall", static: false, private: false, access: { has: function (obj) { return "sendInstanceCall" in obj; }, get: function (obj) { return obj.sendInstanceCall; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2144
- __esDecorate$1(_a, null, _sendInstanceCallSync_decorators, { kind: "method", name: "sendInstanceCallSync", static: false, private: false, access: { has: function (obj) { return "sendInstanceCallSync" in obj; }, get: function (obj) { return obj.sendInstanceCallSync; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2145
- __esDecorate$1(_a, null, _sendInstanceSet_decorators, { kind: "method", name: "sendInstanceSet", static: false, private: false, access: { has: function (obj) { return "sendInstanceSet" in obj; }, get: function (obj) { return obj.sendInstanceSet; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2146
- __esDecorate$1(_a, null, _sendInstanceGet_decorators, { kind: "method", name: "sendInstanceGet", static: false, private: false, access: { has: function (obj) { return "sendInstanceGet" in obj; }, get: function (obj) { return obj.sendInstanceGet; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2147
- __esDecorate$1(_a, null, _sendInstanceEventAdd_decorators, { kind: "method", name: "sendInstanceEventAdd", static: false, private: false, access: { has: function (obj) { return "sendInstanceEventAdd" in obj; }, get: function (obj) { return obj.sendInstanceEventAdd; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2148
- __esDecorate$1(_a, null, _sendInstanceEventRemove_decorators, { kind: "method", name: "sendInstanceEventRemove", static: false, private: false, access: { has: function (obj) { return "sendInstanceEventRemove" in obj; }, get: function (obj) { return obj.sendInstanceEventRemove; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2149
- __esDecorate$1(_a, null, _sendDestroyInstance_decorators, { kind: "method", name: "sendDestroyInstance", static: false, private: false, access: { has: function (obj) { return "sendDestroyInstance" in obj; }, get: function (obj) { return obj.sendDestroyInstance; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2150
- __esDecorate$1(_a, null, _sendEventEmit_decorators, { kind: "method", name: "sendEventEmit", static: false, private: false, access: { has: function (obj) { return "sendEventEmit" in obj; }, get: function (obj) { return obj.sendEventEmit; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2151
- __esDecorate$1(_a, null, _sendEventEmitResult_decorators, { kind: "method", name: "sendEventEmitResult", static: false, private: false, access: { has: function (obj) { return "sendEventEmitResult" in obj; }, get: function (obj) { return obj.sendEventEmitResult; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1203
+ __esDecorate$1(_a, null, _sendVarGet_decorators, { kind: "method", name: "sendVarGet", static: false, private: false, access: { has: obj => "sendVarGet" in obj, get: obj => obj.sendVarGet }, metadata: _metadata }, null, _instanceExtraInitializers);
1204
+ __esDecorate$1(_a, null, _sendStaticCall_decorators, { kind: "method", name: "sendStaticCall", static: false, private: false, access: { has: obj => "sendStaticCall" in obj, get: obj => obj.sendStaticCall }, metadata: _metadata }, null, _instanceExtraInitializers);
1205
+ __esDecorate$1(_a, null, _sendStaticCallSync_decorators, { kind: "method", name: "sendStaticCallSync", static: false, private: false, access: { has: obj => "sendStaticCallSync" in obj, get: obj => obj.sendStaticCallSync }, metadata: _metadata }, null, _instanceExtraInitializers);
1206
+ __esDecorate$1(_a, null, _sendNewInstanceCall_decorators, { kind: "method", name: "sendNewInstanceCall", static: false, private: false, access: { has: obj => "sendNewInstanceCall" in obj, get: obj => obj.sendNewInstanceCall }, metadata: _metadata }, null, _instanceExtraInitializers);
1207
+ __esDecorate$1(_a, null, _sendInstanceCall_decorators, { kind: "method", name: "sendInstanceCall", static: false, private: false, access: { has: obj => "sendInstanceCall" in obj, get: obj => obj.sendInstanceCall }, metadata: _metadata }, null, _instanceExtraInitializers);
1208
+ __esDecorate$1(_a, null, _sendInstanceCallSync_decorators, { kind: "method", name: "sendInstanceCallSync", static: false, private: false, access: { has: obj => "sendInstanceCallSync" in obj, get: obj => obj.sendInstanceCallSync }, metadata: _metadata }, null, _instanceExtraInitializers);
1209
+ __esDecorate$1(_a, null, _sendInstanceSet_decorators, { kind: "method", name: "sendInstanceSet", static: false, private: false, access: { has: obj => "sendInstanceSet" in obj, get: obj => obj.sendInstanceSet }, metadata: _metadata }, null, _instanceExtraInitializers);
1210
+ __esDecorate$1(_a, null, _sendInstanceGet_decorators, { kind: "method", name: "sendInstanceGet", static: false, private: false, access: { has: obj => "sendInstanceGet" in obj, get: obj => obj.sendInstanceGet }, metadata: _metadata }, null, _instanceExtraInitializers);
1211
+ __esDecorate$1(_a, null, _sendInstanceEventAdd_decorators, { kind: "method", name: "sendInstanceEventAdd", static: false, private: false, access: { has: obj => "sendInstanceEventAdd" in obj, get: obj => obj.sendInstanceEventAdd }, metadata: _metadata }, null, _instanceExtraInitializers);
1212
+ __esDecorate$1(_a, null, _sendInstanceEventRemove_decorators, { kind: "method", name: "sendInstanceEventRemove", static: false, private: false, access: { has: obj => "sendInstanceEventRemove" in obj, get: obj => obj.sendInstanceEventRemove }, metadata: _metadata }, null, _instanceExtraInitializers);
1213
+ __esDecorate$1(_a, null, _sendEventEmit_decorators, { kind: "method", name: "sendEventEmit", static: false, private: false, access: { has: obj => "sendEventEmit" in obj, get: obj => obj.sendEventEmit }, metadata: _metadata }, null, _instanceExtraInitializers);
1214
+ __esDecorate$1(_a, null, _sendEventEmitResult_decorators, { kind: "method", name: "sendEventEmitResult", static: false, private: false, access: { has: obj => "sendEventEmitResult" in obj, get: obj => obj.sendEventEmitResult }, metadata: _metadata }, null, _instanceExtraInitializers);
2152
1215
  if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
2153
1216
  })(),
2154
1217
  _a;
2155
- }();
1218
+ })();
2156
1219
 
2157
- var MessageClientImpl = function () {
1220
+ let MessageClientImpl = (() => {
2158
1221
  var _a;
2159
- var _classSuper = MessageSenderImpl;
2160
- var _instanceExtraInitializers = [];
2161
- var _registerService_decorators;
2162
- var _registerInstance_decorators;
2163
- var _handlerMessage_decorators;
2164
- return _a = /** @class */ (function (_super) {
2165
- __extends$1(MessageClientImpl, _super);
2166
- function MessageClientImpl() {
2167
- var _this = _super !== null && _super.apply(this, arguments) || this;
2168
- _this._globalScope = (__runInitializers$1(_this, _instanceExtraInitializers), {});
2169
- return _this;
2170
- }
2171
- MessageClientImpl.prototype.registerService = function (name, service) {
2172
- this.logger.debug("[message-client] Register service: ".concat(name));
1222
+ let _classSuper = MessageSenderImpl;
1223
+ let _instanceExtraInitializers = [];
1224
+ let _registerService_decorators;
1225
+ let _registerInstance_decorators;
1226
+ let _handlerMessage_decorators;
1227
+ return _a = class MessageClientImpl extends _classSuper {
1228
+ constructor() {
1229
+ super(...arguments);
1230
+ this._globalScope = (__runInitializers$1(this, _instanceExtraInitializers), {});
1231
+ }
1232
+ registerService(name, service) {
2173
1233
  this._globalScope[name] = service;
2174
- };
2175
- MessageClientImpl.prototype.registerInstance = function (id, instance) {
2176
- this.logger.debug("[message-client] Register instance: ".concat(id));
1234
+ }
1235
+ registerInstance(id, instance) {
2177
1236
  this.proto.registerProxyInstance(id, instance);
2178
- };
2179
- MessageClientImpl.prototype.handlerMessage = function (req) {
2180
- return __awaiter$1(this, void 0, void 0, function () {
2181
- var callType;
2182
- return __generator$1(this, function (_b) {
2183
- try {
2184
- callType = req.callType;
2185
- switch (callType) {
2186
- case CALL_TYPE$1.PLAIN_API_CALL:
2187
- return [2 /*return*/, this._onCallStaticApi(req)];
2188
- case CALL_TYPE$1.INSTANCE_METHOD_INVOKE:
2189
- return [2 /*return*/, this._onCallInstanceApi(req)];
2190
- case CALL_TYPE$1.INSTANCE_EVENT_LISTENER_ADD:
2191
- return [2 /*return*/, this._onCallEventRegister(req)];
2192
- case CALL_TYPE$1.INSTANCE_EVENT_EMIT:
2193
- return [2 /*return*/, this._onCallEventEmit(req)];
2194
- case CALL_TYPE$1.CALLBACK_EMIT:
2195
- return [2 /*return*/, this._onCallbackEmit(req)];
2196
- default:
2197
- throw new Error("unknown callType \"".concat(callType, "\""));
2198
- }
2199
- }
2200
- catch (err) {
2201
- this.logger.warn('[message-client] handle remote call fail:', req, err);
2202
- throw err;
2203
- }
2204
- return [2 /*return*/];
2205
- });
2206
- });
2207
- };
2208
- MessageClientImpl.prototype._onCallStaticApi = function (req) {
2209
- return __awaiter$1(this, void 0, void 0, function () {
2210
- var serviceName, _b, args, paths, property, root, target, api, decodeArgs, span, value, _c, res, err_1;
2211
- return __generator$1(this, function (_d) {
2212
- switch (_d.label) {
2213
- case 0:
2214
- serviceName = req.serviceName, _b = req.args, args = _b === void 0 ? [] : _b;
2215
- this.logger.debug("[message-client] Call static API: ".concat(serviceName), args);
2216
- paths = serviceName.split('.');
2217
- property = paths.pop();
2218
- root = this._globalScope;
2219
- target = keyPathVisitor(root, paths);
2220
- assert(!!target, "can\"t find static api, please check serviceName ".concat(serviceName));
2221
- api = Reflect.get(target, property);
2222
- assert(!!api, "can\"t find static api ".concat(target, ".").concat(property, ", please check serviceName ").concat(serviceName));
2223
- decodeArgs = this.proto.decodeArgs(args);
2224
- span = this.tracer.collectApiCall({
2225
- source: 'native',
2226
- target: 'js',
2227
- serviceName: serviceName,
2228
- callType: CALL_TYPE$1.PLAIN_API_CALL,
2229
- args: args,
2230
- });
2231
- _d.label = 1;
2232
- case 1:
2233
- _d.trys.push([1, 5, , 6]);
2234
- if (!(typeof api === 'function')) return [3 /*break*/, 3];
2235
- return [4 /*yield*/, api.apply(target, decodeArgs)];
2236
- case 2:
2237
- _c = _d.sent();
2238
- return [3 /*break*/, 4];
2239
- case 3:
2240
- _c = api;
2241
- _d.label = 4;
2242
- case 4:
2243
- value = _c;
2244
- res = this._returnHandler(value);
2245
- span.success(res);
2246
- this.logger.debug("[message-client] Static API call success: ".concat(serviceName));
2247
- return [2 /*return*/, res];
2248
- case 5:
2249
- err_1 = _d.sent();
2250
- this.logger.error("[message-client] Static API call failed: ".concat(serviceName), err_1);
2251
- span.fail(err_1);
2252
- throw err_1;
2253
- case 6: return [2 /*return*/];
2254
- }
2255
- });
1237
+ }
1238
+ async handlerMessage(req) {
1239
+ try {
1240
+ const { callType } = req;
1241
+ switch (callType) {
1242
+ case CALL_TYPE$1.PLAIN_API_CALL:
1243
+ return this._onCallStaticApi(req);
1244
+ case CALL_TYPE$1.INSTANCE_METHOD_INVOKE:
1245
+ return this._onCallInstanceApi(req);
1246
+ case CALL_TYPE$1.INSTANCE_EVENT_LISTENER_ADD:
1247
+ return this._onCallEventRegister(req);
1248
+ case CALL_TYPE$1.INSTANCE_EVENT_EMIT:
1249
+ return this._onCallEventEmit(req);
1250
+ case CALL_TYPE$1.CALLBACK_EMIT:
1251
+ return this._onCallbackEmit(req);
1252
+ default:
1253
+ throw new Error(`unknown callType "${callType}"`);
1254
+ }
1255
+ }
1256
+ catch (err) {
1257
+ this.logger.warn('handle remote call fail:', req, err);
1258
+ throw err;
1259
+ }
1260
+ }
1261
+ async _onCallStaticApi(req) {
1262
+ const { serviceName, args = [] } = req;
1263
+ const paths = serviceName.split('.');
1264
+ const property = paths.pop();
1265
+ const root = this._globalScope;
1266
+ const target = keyPathVisitor(root, paths);
1267
+ assert(!!target, `can"t find static api, please check serviceName ${serviceName}`);
1268
+ const api = Reflect.get(target, property);
1269
+ assert(!!api, `can"t find static api ${target}.${property}, please check serviceName ${serviceName}`);
1270
+ const decodeArgs = this.proto.decodeArgs(args);
1271
+ const span = this.tracer.collectApiCall({
1272
+ source: 'native',
1273
+ target: 'js',
1274
+ serviceName: serviceName,
1275
+ callType: CALL_TYPE$1.PLAIN_API_CALL,
1276
+ args,
2256
1277
  });
2257
- };
2258
- MessageClientImpl.prototype._onCallInstanceApi = function (req) {
2259
- return __awaiter$1(this, void 0, void 0, function () {
2260
- var serviceName, _b, args, _instanceId, paths, instance, property, target, api, decodeArgs, span, value, _c, res, err_2;
2261
- var _this = this;
2262
- return __generator$1(this, function (_d) {
2263
- switch (_d.label) {
2264
- case 0:
2265
- serviceName = req.serviceName, _b = req.args, args = _b === void 0 ? [] : _b, _instanceId = req._instanceId;
2266
- this.logger.debug("[message-client] Call instance API: ".concat(serviceName, ", instanceId: ").concat(_instanceId), args);
2267
- assert(!!_instanceId, 'callType is instanceCall, but missing _instanceId Params');
2268
- paths = serviceName.split('.');
2269
- instance = this.proto.decodeInstance({
2270
- _type: "instance" /* ARG_TYPE.INSTANCE */,
2271
- _instanceId: _instanceId,
2272
- });
2273
- assert(!!instance, "can\"t find instance, instanceId ".concat(_instanceId, " incorrect"));
2274
- paths.shift();
2275
- property = paths.pop();
2276
- assert(typeof property === 'string', "incorrect serviceName \"".concat(serviceName, "\""));
2277
- target = keyPathVisitor(instance, paths);
2278
- assert(!!target, "can\"t find instance@".concat(_instanceId, " api, please check serviceName \"").concat(serviceName, "\" ").concat(target));
2279
- api = Reflect.get(target, property, target);
2280
- assert(!!api, "can\"t find instance@".concat(_instanceId, " api, please check serviceName \"").concat(serviceName, "\" ").concat(target, ".").concat(api));
2281
- decodeArgs = args.map(function (arg) {
2282
- if (isPlainObject(arg) &&
2283
- arg._type === "instance" /* ARG_TYPE.INSTANCE */) {
2284
- return _this.proto.decodeInstance(arg);
2285
- }
2286
- if (isPlainObject(arg) &&
2287
- arg._type === "callback" /* ARG_TYPE.CALLBACK */) {
2288
- return function () {
2289
- var eventData = [];
2290
- for (var _i = 0; _i < arguments.length; _i++) {
2291
- eventData[_i] = arguments[_i];
2292
- }
2293
- _this.sendEventEmit(_instanceId, serviceName, arg._callbackId, eventData);
2294
- };
2295
- }
2296
- return arg;
2297
- });
2298
- span = this.tracer.collectApiCall({
2299
- source: 'native',
2300
- target: 'js',
2301
- serviceName: serviceName,
2302
- callType: CALL_TYPE$1.INSTANCE_METHOD_INVOKE,
2303
- args: args,
2304
- });
2305
- _d.label = 1;
2306
- case 1:
2307
- _d.trys.push([1, 5, , 6]);
2308
- if (!(typeof api === 'function')) return [3 /*break*/, 3];
2309
- return [4 /*yield*/, api.apply(target, decodeArgs)];
2310
- case 2:
2311
- _c = _d.sent();
2312
- return [3 /*break*/, 4];
2313
- case 3:
2314
- _c = api;
2315
- _d.label = 4;
2316
- case 4:
2317
- value = _c;
2318
- res = this._returnHandler(value);
2319
- span.success(res);
2320
- this.logger.debug("[message-client] Instance API call success: ".concat(serviceName));
2321
- return [2 /*return*/, res];
2322
- case 5:
2323
- err_2 = _d.sent();
2324
- this.logger.error("[message-client] Instance API call failed: ".concat(serviceName), err_2);
2325
- span.fail(err_2);
2326
- throw err_2;
2327
- case 6: return [2 /*return*/];
2328
- }
2329
- });
1278
+ try {
1279
+ const value = typeof api === 'function' ? await api.apply(target, decodeArgs) : api;
1280
+ const res = this._returnHandler(value);
1281
+ span.success(res);
1282
+ return res;
1283
+ }
1284
+ catch (err) {
1285
+ span.fail(err);
1286
+ throw err;
1287
+ }
1288
+ }
1289
+ async _onCallInstanceApi(req) {
1290
+ const { serviceName, args = [], _instanceId } = req;
1291
+ const paths = serviceName.split('.');
1292
+ assert(!!_instanceId, 'callType is instanceCall, but missing _instanceId Params');
1293
+ const instance = this.proto.decodeInstance({
1294
+ _type: "instance" /* ARG_TYPE.INSTANCE */,
1295
+ _instanceId,
2330
1296
  });
2331
- };
2332
- MessageClientImpl.prototype._onCallEventRegister = function (req) {
2333
- return __awaiter$1(this, void 0, void 0, function () {
2334
- var _b, args, _instanceId, serviceName, instance, remoteCallbackId, proxyCallback, paths, eventName;
2335
- var _this = this;
2336
- return __generator$1(this, function (_c) {
2337
- _b = req.args, args = _b === void 0 ? [] : _b, _instanceId = req._instanceId, serviceName = req.serviceName;
2338
- this.logger.debug("[message-client] Register event listener: ".concat(serviceName, ", instanceId: ").concat(_instanceId));
2339
- assert(!!_instanceId, 'callType is "instance_event_register", but missing _instanceId Params');
2340
- instance = this.proto.decodeInstance({
2341
- _type: "instance" /* ARG_TYPE.INSTANCE */,
2342
- _instanceId: _instanceId,
2343
- });
2344
- assert(!!instance, "can\"t find instance, instanceId ".concat(_instanceId, " incorrect"));
2345
- assert(typeof instance.on === 'function', 'instance can"t "on"');
2346
- this.tracer.collectEventOn({
2347
- source: 'native',
2348
- target: 'js',
2349
- eventName: serviceName,
2350
- });
2351
- remoteCallbackId = args[0]._callbackId;
2352
- proxyCallback = function () {
2353
- var eventData = [];
2354
- for (var _i = 0; _i < arguments.length; _i++) {
2355
- eventData[_i] = arguments[_i];
2356
- }
2357
- _this.sendEventEmit(_instanceId, serviceName, remoteCallbackId, eventData);
1297
+ assert(!!instance, `can"t find instance, instanceId ${_instanceId} incorrect`);
1298
+ paths.shift();
1299
+ const property = paths.pop();
1300
+ assert(typeof property === 'string', `incorrect serviceName "${serviceName}"`);
1301
+ const target = keyPathVisitor(instance, paths);
1302
+ assert(!!target, `can"t find instance@${_instanceId} api, please check serviceName "${serviceName}" ${target}`);
1303
+ const api = Reflect.get(target, property, target);
1304
+ assert(!!api, `can"t find instance@${_instanceId} api, please check serviceName "${serviceName}" ${target}.${api}`);
1305
+ const decodeArgs = args.map(arg => {
1306
+ if (isPlainObject(arg) &&
1307
+ arg._type === "instance" /* ARG_TYPE.INSTANCE */) {
1308
+ return this.proto.decodeInstance(arg);
1309
+ }
1310
+ if (isPlainObject(arg) &&
1311
+ arg._type === "callback" /* ARG_TYPE.CALLBACK */) {
1312
+ return (...eventData) => {
1313
+ this.sendEventEmit(_instanceId, serviceName, arg._callbackId, eventData);
2358
1314
  };
2359
- paths = serviceName.split('.');
2360
- eventName = paths[paths.length - 1];
2361
- instance.on(eventName, proxyCallback);
2362
- this.logger.debug("[message-client] Event listener registered: ".concat(eventName));
2363
- return [2 /*return*/, this._returnHandler(null)];
2364
- });
1315
+ }
1316
+ return arg;
2365
1317
  });
2366
- };
1318
+ const span = this.tracer.collectApiCall({
1319
+ source: 'native',
1320
+ target: 'js',
1321
+ serviceName: serviceName,
1322
+ callType: CALL_TYPE$1.INSTANCE_METHOD_INVOKE,
1323
+ args,
1324
+ });
1325
+ try {
1326
+ const value = typeof api === 'function' ? await api.apply(target, decodeArgs) : api;
1327
+ const res = this._returnHandler(value);
1328
+ span.success(res);
1329
+ return res;
1330
+ }
1331
+ catch (err) {
1332
+ span.fail(err);
1333
+ throw err;
1334
+ }
1335
+ }
1336
+ async _onCallEventRegister(req) {
1337
+ const { args = [], _instanceId, serviceName } = req;
1338
+ assert(!!_instanceId, 'callType is "instance_event_register", but missing _instanceId Params');
1339
+ const instance = this.proto.decodeInstance({
1340
+ _type: "instance" /* ARG_TYPE.INSTANCE */,
1341
+ _instanceId,
1342
+ });
1343
+ assert(!!instance, `can"t find instance, instanceId ${_instanceId} incorrect`);
1344
+ assert(typeof instance.on === 'function', 'instance can"t "on"');
1345
+ this.tracer.collectEventOn({
1346
+ source: 'native',
1347
+ target: 'js',
1348
+ eventName: serviceName,
1349
+ });
1350
+ const remoteCallbackId = args[0]._callbackId;
1351
+ const proxyCallback = (...eventData) => {
1352
+ this.sendEventEmit(_instanceId, serviceName, remoteCallbackId, eventData);
1353
+ };
1354
+ const paths = serviceName.split('.');
1355
+ const eventName = paths[paths.length - 1];
1356
+ instance.on(eventName, proxyCallback);
1357
+ return this._returnHandler(null);
1358
+ }
2367
1359
  /**
2368
1360
  * 触发事件,优先通过 callbackId 找 callback,找不到通过 instanceId 找实例 emit
2369
1361
  * @param req
2370
1362
  * @returns
2371
1363
  */
2372
- MessageClientImpl.prototype._onCallEventEmit = function (req) {
2373
- return __awaiter$1(this, void 0, void 0, function () {
2374
- var _b, args, serviceName, methodName, waitResult, _traceId, _instanceId, decodeArgs, eventName, instance, returnParams, res;
2375
- return __generator$1(this, function (_c) {
2376
- _b = req.args, args = _b === void 0 ? [] : _b, serviceName = req.serviceName, methodName = req.methodName, waitResult = req.waitResult, _traceId = req._traceId, _instanceId = req._instanceId;
2377
- decodeArgs = this.proto.decodeArgs(args);
2378
- eventName = methodName || serviceName;
2379
- this.logger.debug("[message-client] Emit event: ".concat(eventName, ", instanceId: ").concat(_instanceId), args);
2380
- this.tracer.collectEventEmit({
2381
- source: 'native',
2382
- target: 'js',
2383
- eventName: eventName,
2384
- eventData: decodeArgs,
2385
- });
2386
- assert(!!_instanceId, 'callType is "instance_event_emit", but missing "_instanceId" Params');
2387
- instance = this.proto.decodeInstance({
2388
- _type: "instance" /* ARG_TYPE.INSTANCE */,
2389
- _instanceId: _instanceId,
2390
- });
2391
- assert(!!instance, "can\"t find instance, instanceId ".concat(_instanceId, " incorrect"));
2392
- returnParams = null;
2393
- res = null;
2394
- try {
2395
- if (typeof instance.emit === 'function') {
2396
- res = instance.emit.apply(instance, __spreadArray$1([eventName], decodeArgs, false));
2397
- returnParams = this._returnHandler(res);
2398
- this.logger.debug("[message-client] Event emitted successfully: ".concat(eventName));
2399
- }
2400
- else if (typeof instance[eventName] === 'function') {
2401
- res = instance[eventName].apply(instance, decodeArgs);
2402
- returnParams = this._returnHandler(res);
2403
- this.logger.debug("[message-client] Event handler executed: ".concat(eventName));
2404
- }
2405
- else {
2406
- this.logger.debug("[message-client] Unknown event \"".concat(eventName, "\""));
2407
- returnParams = {
2408
- status: RETURN_STATUS$1.NOT_IMPLEMENTED,
2409
- msg: {},
2410
- };
2411
- }
2412
- }
2413
- catch (err) {
2414
- this.logger.error("[message-client] Event emit failed: ".concat(eventName), err);
2415
- returnParams = {
2416
- status: RETURN_STATUS$1.FAILED,
2417
- msg: {
2418
- errorMessage: (err === null || err === void 0 ? void 0 : err.message) || '',
2419
- errorCode: -1,
2420
- },
2421
- };
2422
- }
2423
- returnParams._traceId = _traceId;
2424
- if (waitResult) {
2425
- this.sendEventEmitResult(_instanceId, serviceName, returnParams);
2426
- }
2427
- return [2 /*return*/, returnParams];
2428
- });
1364
+ async _onCallEventEmit(req) {
1365
+ const { args = [], serviceName, methodName, waitResult, _traceId, _instanceId, } = req;
1366
+ const decodeArgs = this.proto.decodeArgs(args);
1367
+ const eventName = methodName || serviceName;
1368
+ this.tracer.collectEventEmit({
1369
+ source: 'native',
1370
+ target: 'js',
1371
+ eventName: eventName,
1372
+ eventData: decodeArgs,
2429
1373
  });
2430
- };
1374
+ assert(!!_instanceId, 'callType is "instance_event_emit", but missing "_instanceId" Params');
1375
+ const instance = this.proto.decodeInstance({
1376
+ _type: "instance" /* ARG_TYPE.INSTANCE */,
1377
+ _instanceId,
1378
+ });
1379
+ assert(!!instance, `can"t find instance, instanceId ${_instanceId} incorrect`);
1380
+ let returnParams = null;
1381
+ let res = null;
1382
+ try {
1383
+ if (typeof instance.emit === 'function') {
1384
+ res = instance.emit(eventName, ...decodeArgs);
1385
+ returnParams = this._returnHandler(res);
1386
+ }
1387
+ else if (typeof instance[eventName] === 'function') {
1388
+ res = instance[eventName].apply(instance, decodeArgs);
1389
+ returnParams = this._returnHandler(res);
1390
+ }
1391
+ else {
1392
+ this.logger.warn(`unknown event "${eventName}"`);
1393
+ returnParams = {
1394
+ status: RETURN_STATUS$1.NOT_IMPLEMENTED,
1395
+ msg: {},
1396
+ };
1397
+ }
1398
+ }
1399
+ catch (err) {
1400
+ returnParams = {
1401
+ status: RETURN_STATUS$1.FAILED,
1402
+ msg: {
1403
+ errorMessage: err?.message || '',
1404
+ errorCode: -1,
1405
+ },
1406
+ };
1407
+ }
1408
+ returnParams._traceId = _traceId;
1409
+ if (waitResult) {
1410
+ this.sendEventEmitResult(_instanceId, serviceName, returnParams);
1411
+ }
1412
+ return returnParams;
1413
+ }
2431
1414
  /**
2432
1415
  * 触发回调,优先通过 callbackId 找 callback,找不到通过 instanceId 找实例 emit
2433
1416
  * @param req
2434
1417
  * @returns
2435
1418
  */
2436
- MessageClientImpl.prototype._onCallbackEmit = function (req) {
2437
- return __awaiter$1(this, void 0, void 0, function () {
2438
- var _b, args, serviceName, methodName, _instanceId, decodeArgs, eventName, callback;
2439
- return __generator$1(this, function (_c) {
2440
- _b = req.args, args = _b === void 0 ? [] : _b, serviceName = req.serviceName, methodName = req.methodName, _instanceId = req._instanceId;
2441
- decodeArgs = this.proto.decodeArgs(args);
2442
- eventName = methodName || serviceName;
2443
- this.logger.debug("[message-client] Emit callback: ".concat(eventName, ", callbackId: ").concat(_instanceId), args);
2444
- this.tracer.collectCallbackEmit({
2445
- source: 'native',
2446
- target: 'js',
2447
- eventName: eventName,
2448
- eventData: decodeArgs,
2449
- });
2450
- assert(!!_instanceId, 'callType is "callback_emit", but missing "_instanceId" Params');
2451
- callback = this.proto.decodeCallback({
2452
- _type: "callback" /* ARG_TYPE.CALLBACK */,
2453
- _callbackId: _instanceId,
2454
- });
2455
- assert(typeof callback === 'function', "can\"t find callback, callback_id ".concat(_instanceId, " incorrect"));
2456
- try {
2457
- callback.apply(null, decodeArgs);
2458
- this.logger.debug("[message-client] Callback executed successfully: ".concat(eventName));
2459
- return [2 /*return*/, this._returnHandler(null)];
2460
- }
2461
- catch (err) {
2462
- this.logger.error("[message-client] Callback execution failed: ".concat(eventName), err);
2463
- throw err;
2464
- }
2465
- return [2 /*return*/];
2466
- });
1419
+ async _onCallbackEmit(req) {
1420
+ const { args = [], serviceName, methodName, _instanceId } = req;
1421
+ const decodeArgs = this.proto.decodeArgs(args);
1422
+ const eventName = methodName || serviceName;
1423
+ this.tracer.collectCallbackEmit({
1424
+ source: 'native',
1425
+ target: 'js',
1426
+ eventName: eventName,
1427
+ eventData: decodeArgs,
2467
1428
  });
2468
- };
2469
- MessageClientImpl.prototype._returnHandler = function (response) {
2470
- this.logger.debug('[message-client] response:', response);
2471
- var encodeResponse = this.proto.encodeArg(response);
2472
- var returnVal = {
1429
+ assert(!!_instanceId, 'callType is "callback_emit", but missing "_instanceId" Params');
1430
+ const callback = this.proto.decodeCallback({
1431
+ _type: "callback" /* ARG_TYPE.CALLBACK */,
1432
+ _callbackId: _instanceId,
1433
+ });
1434
+ assert(typeof callback === 'function', `can"t find callback, callback_id ${_instanceId} incorrect`);
1435
+ callback.apply(null, decodeArgs);
1436
+ return this._returnHandler(null);
1437
+ }
1438
+ _returnHandler(response) {
1439
+ this.logger.verbose('response:', response);
1440
+ const encodeResponse = this.proto.encodeArg(response);
1441
+ const returnVal = {
2473
1442
  status: RETURN_STATUS$1.SUCCESS,
2474
1443
  msg: encodeResponse === undefined
2475
1444
  ? null
@@ -2478,22 +1447,20 @@ var MessageClientImpl = function () {
2478
1447
  : encodeResponse,
2479
1448
  };
2480
1449
  return returnVal;
2481
- };
2482
- return MessageClientImpl;
2483
- }(_classSuper)),
2484
- (function () {
2485
- var _b;
2486
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
1450
+ }
1451
+ },
1452
+ (() => {
1453
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
2487
1454
  _registerService_decorators = [Bind];
2488
1455
  _registerInstance_decorators = [Bind];
2489
1456
  _handlerMessage_decorators = [Bind];
2490
- __esDecorate$1(_a, null, _registerService_decorators, { kind: "method", name: "registerService", static: false, private: false, access: { has: function (obj) { return "registerService" in obj; }, get: function (obj) { return obj.registerService; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2491
- __esDecorate$1(_a, null, _registerInstance_decorators, { kind: "method", name: "registerInstance", static: false, private: false, access: { has: function (obj) { return "registerInstance" in obj; }, get: function (obj) { return obj.registerInstance; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2492
- __esDecorate$1(_a, null, _handlerMessage_decorators, { kind: "method", name: "handlerMessage", static: false, private: false, access: { has: function (obj) { return "handlerMessage" in obj; }, get: function (obj) { return obj.handlerMessage; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1457
+ __esDecorate$1(_a, null, _registerService_decorators, { kind: "method", name: "registerService", static: false, private: false, access: { has: obj => "registerService" in obj, get: obj => obj.registerService }, metadata: _metadata }, null, _instanceExtraInitializers);
1458
+ __esDecorate$1(_a, null, _registerInstance_decorators, { kind: "method", name: "registerInstance", static: false, private: false, access: { has: obj => "registerInstance" in obj, get: obj => obj.registerInstance }, metadata: _metadata }, null, _instanceExtraInitializers);
1459
+ __esDecorate$1(_a, null, _handlerMessage_decorators, { kind: "method", name: "handlerMessage", static: false, private: false, access: { has: obj => "handlerMessage" in obj, get: obj => obj.handlerMessage }, metadata: _metadata }, null, _instanceExtraInitializers);
2493
1460
  if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
2494
1461
  })(),
2495
1462
  _a;
2496
- }();
1463
+ })();
2497
1464
 
2498
1465
  function createProxyInstance(raw) {
2499
1466
  Object.defineProperty(raw, '$$native', {
@@ -2517,85 +1484,74 @@ function isArrayBuffer(val) {
2517
1484
  function isBuffer(val) {
2518
1485
  return isArrayBuffer(val) || isDateView(val);
2519
1486
  }
2520
- var MessageProtoImpl = function () {
1487
+ let MessageProtoImpl = (() => {
2521
1488
  var _a;
2522
- var _instanceExtraInitializers = [];
2523
- var _encodeArgs_decorators;
2524
- var _encodeInstance_decorators;
2525
- var _decodeInstance_decorators;
2526
- var _encodeCallback_decorators;
2527
- var _decodeCallback_decorators;
2528
- var _encodeBase64_decorators;
2529
- var _decodeBase64_decorators;
2530
- var _encodeArg_decorators;
2531
- var _decodeArgs_decorators;
2532
- var _decodeArg_decorators;
2533
- return _a = /** @class */ (function () {
2534
- function MessageProtoImpl() {
1489
+ let _instanceExtraInitializers = [];
1490
+ let _encodeArgs_decorators;
1491
+ let _encodeInstance_decorators;
1492
+ let _decodeInstance_decorators;
1493
+ let _encodeCallback_decorators;
1494
+ let _decodeCallback_decorators;
1495
+ let _encodeBase64_decorators;
1496
+ let _decodeBase64_decorators;
1497
+ let _encodeArg_decorators;
1498
+ let _decodeArgs_decorators;
1499
+ let _decodeArg_decorators;
1500
+ return _a = class MessageProtoImpl {
1501
+ constructor() {
2535
1502
  this._idMapInstance = (__runInitializers$1(this, _instanceExtraInitializers), {});
2536
1503
  this._instanceMapId = new WeakMap();
2537
1504
  this._idMapCallback = {};
2538
1505
  this._callbackMapId = new WeakMap();
2539
- this._logger = LoggerImpl.getInstance();
2540
1506
  }
2541
- MessageProtoImpl.prototype.registerProxyInstance = function (id, instance) {
2542
- this._logger.debug("[message-proto] Registering proxy instance with id: ".concat(id));
1507
+ registerProxyInstance(id, instance) {
2543
1508
  this._idMapInstance[id] = instance;
2544
1509
  this._instanceMapId.set(instance, id);
2545
- };
2546
- MessageProtoImpl.prototype.encodeArgs = function (args) {
1510
+ }
1511
+ encodeArgs(args) {
2547
1512
  return args.map(this.encodeArg);
2548
- };
2549
- MessageProtoImpl.prototype.encodeInstance = function (arg) {
2550
- var instanceId = this._findOrCreateInstanceId(arg);
2551
- this._logger.debug("[message-proto] Encoding instance with id: ".concat(instanceId));
1513
+ }
1514
+ encodeInstance(arg) {
2552
1515
  return {
2553
1516
  _type: "instance" /* ARG_TYPE.INSTANCE */,
2554
- _instanceId: instanceId,
1517
+ _instanceId: this._findOrCreateInstanceId(arg),
2555
1518
  _serviceName: arg.namespace ||
2556
1519
  arg._namespace ||
2557
1520
  arg._serviceName,
2558
1521
  };
2559
- };
2560
- MessageProtoImpl.prototype.decodeInstance = function (arg) {
2561
- this._logger.debug("[message-proto] Decoding instance with id: ".concat(arg._instanceId));
2562
- var instance = this._findInstance(arg._instanceId);
1522
+ }
1523
+ decodeInstance(arg) {
1524
+ let instance = this._findInstance(arg._instanceId);
2563
1525
  if (!instance) {
2564
- this._logger.debug("[message-proto] Creating new proxy instance for id: ".concat(arg._instanceId));
1526
+ // TODO:
2565
1527
  instance = createProxyInstance(arg);
2566
1528
  this._idMapInstance[arg._instanceId] = instance;
2567
1529
  }
2568
1530
  return instance;
2569
- };
2570
- MessageProtoImpl.prototype.encodeCallback = function (arg) {
2571
- var callbackId = this._findOrCreateCallbackId(arg);
2572
- this._logger.debug("[message-proto] Encoding callback with id: ".concat(callbackId));
1531
+ }
1532
+ encodeCallback(arg) {
2573
1533
  return {
2574
1534
  _type: "callback" /* ARG_TYPE.CALLBACK */,
2575
- _callbackId: callbackId,
1535
+ _callbackId: this._findOrCreateCallbackId(arg),
2576
1536
  };
2577
- };
2578
- MessageProtoImpl.prototype.decodeCallback = function (arg) {
2579
- this._logger.debug("[message-proto] Decoding callback with id: ".concat(arg._callbackId));
1537
+ }
1538
+ decodeCallback(arg) {
2580
1539
  return this._findCallback(arg._callbackId) || arg;
2581
- };
2582
- MessageProtoImpl.prototype.encodeBase64 = function (bufferLike) {
2583
- this._logger.debug('[message-proto] Encoding buffer to base64');
2584
- var buf = bufferLike.buffer || bufferLike;
1540
+ }
1541
+ encodeBase64(bufferLike) {
1542
+ const buf = bufferLike.buffer || bufferLike;
2585
1543
  return {
2586
1544
  _type: "base64" /* ARG_TYPE.BASE64 */,
2587
1545
  _value: buf2base64(buf),
2588
1546
  };
2589
- };
2590
- MessageProtoImpl.prototype.decodeBase64 = function (arg) {
2591
- this._logger.debug('[message-proto] Decoding base64 to buffer');
2592
- var base64 = arg._value;
2593
- var uint8 = gBase64.toUint8Array(base64);
2594
- var buf = uint8.buffer;
1547
+ }
1548
+ decodeBase64(arg) {
1549
+ const base64 = arg._value;
1550
+ const uint8 = gBase64.toUint8Array(base64);
1551
+ const buf = uint8.buffer;
2595
1552
  return buf;
2596
- };
2597
- MessageProtoImpl.prototype.encodeArg = function (arg) {
2598
- var _this = this;
1553
+ }
1554
+ encodeArg(arg) {
2599
1555
  if (isBuffer(arg)) {
2600
1556
  return this.encodeBase64(arg);
2601
1557
  }
@@ -2609,26 +1565,23 @@ var MessageProtoImpl = function () {
2609
1565
  return this.encodeInstance(arg);
2610
1566
  }
2611
1567
  if (isPlainObject(arg)) {
2612
- return mapValues(arg, function (value) {
2613
- return _this.encodeArg(value);
1568
+ return mapValues(arg, (value) => {
1569
+ return this.encodeArg(value);
2614
1570
  });
2615
1571
  }
2616
1572
  return arg;
2617
- };
2618
- MessageProtoImpl.prototype.decodeArgs = function (args) {
1573
+ }
1574
+ decodeArgs(args) {
2619
1575
  return args.map(this.decodeArg);
2620
- };
1576
+ }
2621
1577
  // @CatchError
2622
- MessageProtoImpl.prototype.decodeArg = function (arg) {
2623
- var _this = this;
1578
+ decodeArg(arg) {
2624
1579
  if (isPlainObject(arg) &&
2625
1580
  arg._type === "base64" /* ARG_TYPE.BASE64 */) {
2626
1581
  return this.decodeBase64(arg);
2627
1582
  }
2628
1583
  if (isPlainObject(arg) && arg._type === "instance" /* ARG_TYPE.INSTANCE */) {
2629
- var ins = this.decodeInstance(arg);
2630
- Object.assign(ins, arg);
2631
- return ins;
1584
+ return this.decodeInstance(arg);
2632
1585
  }
2633
1586
  if (isPlainObject(arg) && arg._type === "callback" /* ARG_TYPE.CALLBACK */) {
2634
1587
  return this.decodeCallback(arg);
@@ -2637,54 +1590,42 @@ var MessageProtoImpl = function () {
2637
1590
  return arg.map(this.decodeArg);
2638
1591
  }
2639
1592
  if (isPlainObject(arg)) {
2640
- return mapValues(arg, function (value) {
2641
- return _this.decodeArg(value);
1593
+ return mapValues(arg, (value) => {
1594
+ return this.decodeArg(value);
2642
1595
  });
2643
1596
  }
2644
1597
  return arg;
2645
- };
2646
- MessageProtoImpl.prototype._findInstance = function (id) {
2647
- var instance = this._idMapInstance[id];
2648
- if (!instance) {
2649
- this._logger.debug("[message-proto] Instance not found for id: ".concat(id));
2650
- }
2651
- return instance;
2652
- };
2653
- MessageProtoImpl.prototype._findOrCreateInstanceId = function (instance) {
2654
- var _b;
2655
- var id = this._instanceMapId.get(instance);
1598
+ }
1599
+ _findInstance(id) {
1600
+ return this._idMapInstance[id];
1601
+ }
1602
+ _findOrCreateInstanceId(instance) {
1603
+ let id = this._instanceMapId.get(instance);
2656
1604
  if (id === undefined) {
2657
1605
  id =
2658
- (instance === null || instance === void 0 ? void 0 : instance.instanceId) ||
2659
- (instance === null || instance === void 0 ? void 0 : instance._instanceId) ||
2660
- getUuid((_b = instance === null || instance === void 0 ? void 0 : instance.constructor) === null || _b === void 0 ? void 0 : _b.name);
2661
- this._logger.debug("[message-proto] Created new instance id: ".concat(id));
1606
+ instance?.instanceId ||
1607
+ instance?._instanceId ||
1608
+ getUuid(instance?.constructor?.name);
2662
1609
  this._instanceMapId.set(instance, id);
2663
1610
  this._idMapInstance[id] = instance;
2664
1611
  }
2665
1612
  return id;
2666
- };
2667
- MessageProtoImpl.prototype._findCallback = function (id) {
2668
- var callback = this._idMapCallback[id];
2669
- if (!callback) {
2670
- this._logger.debug("[message-proto] Callback not found for id: ".concat(id));
2671
- }
2672
- return callback;
2673
- };
2674
- MessageProtoImpl.prototype._findOrCreateCallbackId = function (value) {
2675
- var id = this._callbackMapId.get(value);
1613
+ }
1614
+ _findCallback(id) {
1615
+ return this._idMapCallback[id];
1616
+ }
1617
+ _findOrCreateCallbackId(value) {
1618
+ let id = this._callbackMapId.get(value);
2676
1619
  if (id === undefined) {
2677
- id = getUuid(value === null || value === void 0 ? void 0 : value.name);
2678
- this._logger.debug("[message-proto] Created new callback id: ".concat(id));
1620
+ id = getUuid(value?.name);
2679
1621
  this._callbackMapId.set(value, id);
2680
1622
  this._idMapCallback[id] = value;
2681
1623
  }
2682
1624
  return id;
2683
- };
2684
- return MessageProtoImpl;
2685
- }()),
2686
- (function () {
2687
- var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1625
+ }
1626
+ },
1627
+ (() => {
1628
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
2688
1629
  _encodeArgs_decorators = [Bind];
2689
1630
  _encodeInstance_decorators = [Bind];
2690
1631
  _decodeInstance_decorators = [Bind];
@@ -2695,50 +1636,48 @@ var MessageProtoImpl = function () {
2695
1636
  _encodeArg_decorators = [Bind];
2696
1637
  _decodeArgs_decorators = [Bind];
2697
1638
  _decodeArg_decorators = [Bind];
2698
- __esDecorate$1(_a, null, _encodeArgs_decorators, { kind: "method", name: "encodeArgs", static: false, private: false, access: { has: function (obj) { return "encodeArgs" in obj; }, get: function (obj) { return obj.encodeArgs; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2699
- __esDecorate$1(_a, null, _encodeInstance_decorators, { kind: "method", name: "encodeInstance", static: false, private: false, access: { has: function (obj) { return "encodeInstance" in obj; }, get: function (obj) { return obj.encodeInstance; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2700
- __esDecorate$1(_a, null, _decodeInstance_decorators, { kind: "method", name: "decodeInstance", static: false, private: false, access: { has: function (obj) { return "decodeInstance" in obj; }, get: function (obj) { return obj.decodeInstance; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2701
- __esDecorate$1(_a, null, _encodeCallback_decorators, { kind: "method", name: "encodeCallback", static: false, private: false, access: { has: function (obj) { return "encodeCallback" in obj; }, get: function (obj) { return obj.encodeCallback; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2702
- __esDecorate$1(_a, null, _decodeCallback_decorators, { kind: "method", name: "decodeCallback", static: false, private: false, access: { has: function (obj) { return "decodeCallback" in obj; }, get: function (obj) { return obj.decodeCallback; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2703
- __esDecorate$1(_a, null, _encodeBase64_decorators, { kind: "method", name: "encodeBase64", static: false, private: false, access: { has: function (obj) { return "encodeBase64" in obj; }, get: function (obj) { return obj.encodeBase64; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2704
- __esDecorate$1(_a, null, _decodeBase64_decorators, { kind: "method", name: "decodeBase64", static: false, private: false, access: { has: function (obj) { return "decodeBase64" in obj; }, get: function (obj) { return obj.decodeBase64; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2705
- __esDecorate$1(_a, null, _encodeArg_decorators, { kind: "method", name: "encodeArg", static: false, private: false, access: { has: function (obj) { return "encodeArg" in obj; }, get: function (obj) { return obj.encodeArg; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2706
- __esDecorate$1(_a, null, _decodeArgs_decorators, { kind: "method", name: "decodeArgs", static: false, private: false, access: { has: function (obj) { return "decodeArgs" in obj; }, get: function (obj) { return obj.decodeArgs; } }, metadata: _metadata }, null, _instanceExtraInitializers);
2707
- __esDecorate$1(_a, null, _decodeArg_decorators, { kind: "method", name: "decodeArg", static: false, private: false, access: { has: function (obj) { return "decodeArg" in obj; }, get: function (obj) { return obj.decodeArg; } }, metadata: _metadata }, null, _instanceExtraInitializers);
1639
+ __esDecorate$1(_a, null, _encodeArgs_decorators, { kind: "method", name: "encodeArgs", static: false, private: false, access: { has: obj => "encodeArgs" in obj, get: obj => obj.encodeArgs }, metadata: _metadata }, null, _instanceExtraInitializers);
1640
+ __esDecorate$1(_a, null, _encodeInstance_decorators, { kind: "method", name: "encodeInstance", static: false, private: false, access: { has: obj => "encodeInstance" in obj, get: obj => obj.encodeInstance }, metadata: _metadata }, null, _instanceExtraInitializers);
1641
+ __esDecorate$1(_a, null, _decodeInstance_decorators, { kind: "method", name: "decodeInstance", static: false, private: false, access: { has: obj => "decodeInstance" in obj, get: obj => obj.decodeInstance }, metadata: _metadata }, null, _instanceExtraInitializers);
1642
+ __esDecorate$1(_a, null, _encodeCallback_decorators, { kind: "method", name: "encodeCallback", static: false, private: false, access: { has: obj => "encodeCallback" in obj, get: obj => obj.encodeCallback }, metadata: _metadata }, null, _instanceExtraInitializers);
1643
+ __esDecorate$1(_a, null, _decodeCallback_decorators, { kind: "method", name: "decodeCallback", static: false, private: false, access: { has: obj => "decodeCallback" in obj, get: obj => obj.decodeCallback }, metadata: _metadata }, null, _instanceExtraInitializers);
1644
+ __esDecorate$1(_a, null, _encodeBase64_decorators, { kind: "method", name: "encodeBase64", static: false, private: false, access: { has: obj => "encodeBase64" in obj, get: obj => obj.encodeBase64 }, metadata: _metadata }, null, _instanceExtraInitializers);
1645
+ __esDecorate$1(_a, null, _decodeBase64_decorators, { kind: "method", name: "decodeBase64", static: false, private: false, access: { has: obj => "decodeBase64" in obj, get: obj => obj.decodeBase64 }, metadata: _metadata }, null, _instanceExtraInitializers);
1646
+ __esDecorate$1(_a, null, _encodeArg_decorators, { kind: "method", name: "encodeArg", static: false, private: false, access: { has: obj => "encodeArg" in obj, get: obj => obj.encodeArg }, metadata: _metadata }, null, _instanceExtraInitializers);
1647
+ __esDecorate$1(_a, null, _decodeArgs_decorators, { kind: "method", name: "decodeArgs", static: false, private: false, access: { has: obj => "decodeArgs" in obj, get: obj => obj.decodeArgs }, metadata: _metadata }, null, _instanceExtraInitializers);
1648
+ __esDecorate$1(_a, null, _decodeArg_decorators, { kind: "method", name: "decodeArg", static: false, private: false, access: { has: obj => "decodeArg" in obj, get: obj => obj.decodeArg }, metadata: _metadata }, null, _instanceExtraInitializers);
2708
1649
  if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
2709
1650
  })(),
2710
1651
  _a;
2711
- }();
1652
+ })();
2712
1653
 
2713
- var createMessageClient = function (jsBridge) {
2714
- var proto = new MessageProtoImpl();
2715
- var client = new MessageClientImpl(proto, jsBridge);
1654
+ const createMessageClient = (jsBridge) => {
1655
+ const proto = new MessageProtoImpl();
1656
+ const client = new MessageClientImpl(proto, jsBridge);
2716
1657
  return client;
2717
1658
  };
2718
1659
 
2719
- var jsBridge = createJSBridge();
2720
- var globalMessageClient = createMessageClient(jsBridge);
1660
+ let jsBridge = createJSBridge();
1661
+ const globalMessageClient = createMessageClient(jsBridge);
2721
1662
  function getGlobalMessageClient() {
2722
1663
  return globalMessageClient;
2723
1664
  }
2724
1665
  function setupJSBridge(impl) {
2725
1666
  jsBridge = impl;
2726
1667
  globalMessageClient.bridge = impl;
2727
- impl.registerAsyncHandler('emitEvent', function (params) {
1668
+ impl.registerAsyncHandler('emitEvent', (params) => {
2728
1669
  return globalMessageClient.handlerMessage(params);
2729
1670
  });
2730
1671
  }
2731
1672
 
2732
- var NativeProxyService = /** @class */ (function () {
2733
- function NativeProxyService(messageClient) {
2734
- if (messageClient === void 0) { messageClient = getGlobalMessageClient(); }
1673
+ class NativeProxyService {
1674
+ constructor(messageClient = getGlobalMessageClient()) {
2735
1675
  this.messageClient = messageClient;
2736
1676
  this.namespace = '';
2737
1677
  this.instanceId = getUuid(this.namespace);
2738
1678
  this._instanced = this.instanceId;
2739
1679
  }
2740
- return NativeProxyService;
2741
- }());
1680
+ }
2742
1681
  function getMessageClient(impl) {
2743
1682
  if (typeof impl === 'object' &&
2744
1683
  !!impl &&
@@ -2758,8 +1697,8 @@ function isNativeCreatedInstance(val) {
2758
1697
  return false;
2759
1698
  }
2760
1699
  function proxyValue(val, ctor) {
2761
- var client = getMessageClient(val);
2762
- var service = new ctor(DISABLE_INIT);
1700
+ const client = getMessageClient(val);
1701
+ const service = new ctor(DISABLE_INIT);
2763
1702
  service.messageClient = client;
2764
1703
  service.instanceId = val._instanceId;
2765
1704
  // @ts-ignore
@@ -2774,6 +1713,324 @@ function proxyNativeInstance(value, ctor) {
2774
1713
  return value;
2775
1714
  }
2776
1715
 
1716
+ function assertReturn(ret) {
1717
+ if (!ret || typeof ret !== 'object') {
1718
+ return;
1719
+ }
1720
+ if (ret.status === RETURN_STATUS$1.FAILED) {
1721
+ throw new Error(String(ret.msg));
1722
+ }
1723
+ return ret.decoded || ret.msg;
1724
+ }
1725
+ function isPromiseLike(val) {
1726
+ if (typeof val === 'object' && val !== null) {
1727
+ if (typeof val.then === 'function') {
1728
+ return true;
1729
+ }
1730
+ }
1731
+ return false;
1732
+ }
1733
+
1734
+ const KEY_NAMESPACE = Symbol.for('#namespace');
1735
+ const KEY_NATIVE_CLASS_NAME = Symbol.for('#nativeClassName');
1736
+ function findNamespace(ctor) {
1737
+ let obj = ctor;
1738
+ let desc;
1739
+ while (!desc && obj) {
1740
+ desc = Object.getOwnPropertyDescriptor(obj, KEY_NAMESPACE);
1741
+ obj = Object.getPrototypeOf(obj);
1742
+ }
1743
+ return desc?.value;
1744
+ }
1745
+ function findMethods(ins, opt = {}) {
1746
+ let methodNames = [];
1747
+ let proto = Object.getPrototypeOf(ins);
1748
+ while (proto && proto !== Object.prototype) {
1749
+ const ownMethods = Object.getOwnPropertyNames(proto)
1750
+ .filter(name => name !== 'constructor')
1751
+ .map(name => opt[name] || name);
1752
+ methodNames.push(...ownMethods);
1753
+ proto = Object.getPrototypeOf(proto);
1754
+ }
1755
+ return methodNames;
1756
+ }
1757
+ const NativeObserverClass = (className, opt = {}) => (target, ctx) => {
1758
+ ctx.addInitializer(function () {
1759
+ Object.defineProperty(this, KEY_NAMESPACE, {
1760
+ value: className,
1761
+ writable: true,
1762
+ });
1763
+ Object.defineProperty(this, KEY_NATIVE_CLASS_NAME, { value: className });
1764
+ });
1765
+ // @ts-ignore
1766
+ return class extends target {
1767
+ constructor(...args) {
1768
+ super(...args);
1769
+ const t = this;
1770
+ const instanceId = getUuid(className);
1771
+ t.namespace = className;
1772
+ t.instanceId = instanceId;
1773
+ t.messageClient = getMessageClient(t);
1774
+ t.options = opt;
1775
+ // custom consume native event
1776
+ /**
1777
+ * @param this
1778
+ * @param name native method name
1779
+ * @param params
1780
+ */
1781
+ t.emit = function (name, ...params) {
1782
+ const curName = Object.entries(opt).find(([, v]) => v === name)?.[0] || name;
1783
+ const fn = this[curName];
1784
+ if (typeof fn === 'function') {
1785
+ return fn.apply(this, params);
1786
+ }
1787
+ };
1788
+ const _init = () => {
1789
+ const events = findMethods(this, opt);
1790
+ t.messageClient.sendNewInstanceCall(className, [events], instanceId, this);
1791
+ };
1792
+ // proxy native created class
1793
+ if (!args.includes(DISABLE_INIT)) {
1794
+ _init();
1795
+ }
1796
+ }
1797
+ };
1798
+ };
1799
+ const NativeClass = (className, opt = {}) => (target, ctx) => {
1800
+ ctx.addInitializer(function () {
1801
+ Object.defineProperty(this, KEY_NAMESPACE, {
1802
+ value: className,
1803
+ writable: true,
1804
+ });
1805
+ Object.defineProperty(this, KEY_NATIVE_CLASS_NAME, { value: className });
1806
+ });
1807
+ // @ts-ignore
1808
+ return class extends target {
1809
+ constructor(...args) {
1810
+ super(...args);
1811
+ const t = this;
1812
+ const instanceId = getUuid(className);
1813
+ t.namespace = className;
1814
+ t.instanceId = instanceId;
1815
+ t.messageClient = getMessageClient(t);
1816
+ const _init = () => {
1817
+ t.messageClient.sendNewInstanceCall(className, args.filter(v => v !== undefined), instanceId, this);
1818
+ if (getOS() === "ios" /* OS.ios */ &&
1819
+ typeof this.init === 'function') {
1820
+ this.init();
1821
+ }
1822
+ };
1823
+ // proxy native created class
1824
+ if (!args.includes(DISABLE_INIT)) {
1825
+ _init();
1826
+ }
1827
+ }
1828
+ };
1829
+ };
1830
+ const NativeStaticMethodSync = (methodSelector) => (target, ctx) => {
1831
+ const name = ctx.name;
1832
+ return function impl(...args) {
1833
+ const namespace = findNamespace(this);
1834
+ const client = getMessageClient(this);
1835
+ const returnValue = client.sendStaticCallSync(namespace || '', methodSelector || name, args);
1836
+ const data = assertReturn(returnValue);
1837
+ return data;
1838
+ };
1839
+ };
1840
+ const ReturnClass = (getCtor) => (target, ctx) => {
1841
+ // TODO: impl
1842
+ return function impl(...args) {
1843
+ const returnValue = target.apply(this, args);
1844
+ if (isPromiseLike(returnValue)) {
1845
+ return returnValue.then(v => {
1846
+ return proxyNativeInstance(v, getCtor());
1847
+ });
1848
+ }
1849
+ return proxyNativeInstance(returnValue, getCtor());
1850
+ };
1851
+ };
1852
+ const NativeMember = ({ cache, readonly } = {}) => (_, ctx) => {
1853
+ ctx.addInitializer(function () {
1854
+ const field = ctx.name;
1855
+ const key = Symbol.for(ctx.name);
1856
+ Object.defineProperty(this, field, {
1857
+ get: () => {
1858
+ if (cache && this[key] !== undefined) {
1859
+ return this[key];
1860
+ }
1861
+ const { instanceId, namespace } = this;
1862
+ const ret = getMessageClient(this).sendInstanceGet(instanceId, namespace || '', field);
1863
+ const value = assertReturn(ret);
1864
+ this[key] = value;
1865
+ return value;
1866
+ },
1867
+ set: v => {
1868
+ if (readonly) {
1869
+ throw new Error(`field ${field} is readonly.`);
1870
+ }
1871
+ this[key] = v;
1872
+ const { instanceId, namespace } = this;
1873
+ getMessageClient(this).sendInstanceSet(instanceId, namespace || '', field, v);
1874
+ },
1875
+ });
1876
+ });
1877
+ return _;
1878
+ };
1879
+
1880
+ const key = Symbol.for('args');
1881
+ function NativeArgType(argIndex, type) {
1882
+ return function (method, ctx) {
1883
+ const args = (method[key] ?? (method[key] = []));
1884
+ args[argIndex] = type;
1885
+ };
1886
+ }
1887
+ function processArg(method) {
1888
+ const args = method[key] ?? [];
1889
+ return (arg, idx) => {
1890
+ return args[idx]?.transform(arg) ?? arg;
1891
+ };
1892
+ }
1893
+ const NativeMethod = (methodSelector, opt) => (_, ctx) => {
1894
+ const name = ctx.name;
1895
+ async function impl(...args) {
1896
+ const { instanceId, namespace } = this;
1897
+ const returnValue = await getMessageClient(this).sendInstanceCall(instanceId, namespace || '', methodSelector || name, args.map(processArg(_)).filter(v => v !== undefined), opt);
1898
+ const data = assertReturn(returnValue);
1899
+ return data;
1900
+ }
1901
+ return impl;
1902
+ };
1903
+ const NativeMethodSync = (methodSelector, opt) => (_, ctx) => {
1904
+ const name = ctx.name;
1905
+ function impl(...args) {
1906
+ const { instanceId, namespace } = this;
1907
+ const returnValue = getMessageClient(this).sendInstanceCallSync(instanceId, namespace || '', methodSelector || name, args.map(processArg(_)).filter(v => v !== undefined), opt);
1908
+ const data = assertReturn(returnValue);
1909
+ return data;
1910
+ }
1911
+ return impl;
1912
+ };
1913
+
1914
+ const NativeVar = (varName, ctor) => (_, ctx) => {
1915
+ return async function impl(...args) {
1916
+ const client = getMessageClient(this);
1917
+ const ret = await client.sendVarGet(varName, args);
1918
+ const ins = new ctor(DISABLE_INIT);
1919
+ ins.instanceId = ret.msg._instanceId;
1920
+ ins.messageClient = client;
1921
+ ins.namespace = '$var';
1922
+ return ins;
1923
+ };
1924
+ };
1925
+
1926
+ (() => {
1927
+ var _a;
1928
+ let _instanceExtraInitializers = [];
1929
+ let _on_decorators;
1930
+ let _emit_decorators;
1931
+ return _a = class NativeObserver {
1932
+ constructor(className) {
1933
+ this._events = __runInitializers$1(this, _instanceExtraInitializers);
1934
+ this.namespace = className;
1935
+ this.instanceId = getUuid(className);
1936
+ this.messageClient = getGlobalMessageClient();
1937
+ this._events = {};
1938
+ }
1939
+ on(ev, handler) {
1940
+ let handlers = this._events[ev];
1941
+ if (!handlers) {
1942
+ handlers = [];
1943
+ this._events[ev] = handlers;
1944
+ }
1945
+ if (handlers.length === 0) {
1946
+ // 第一次,通知 native 注册
1947
+ this.messageClient.sendInstanceEventAdd(this.instanceId, this.namespace || '', ev);
1948
+ }
1949
+ handlers.push(handler);
1950
+ }
1951
+ emit(ev, ...args) {
1952
+ const handlers = this._events[ev];
1953
+ // console.log('emit:', ev, args.length);
1954
+ handlers?.forEach(cb => {
1955
+ cb(...args);
1956
+ });
1957
+ }
1958
+ },
1959
+ (() => {
1960
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1961
+ _on_decorators = [Bind];
1962
+ _emit_decorators = [Bind];
1963
+ __esDecorate$1(_a, null, _on_decorators, { kind: "method", name: "on", static: false, private: false, access: { has: obj => "on" in obj, get: obj => obj.on }, metadata: _metadata }, null, _instanceExtraInitializers);
1964
+ __esDecorate$1(_a, null, _emit_decorators, { kind: "method", name: "emit", static: false, private: false, access: { has: obj => "emit" in obj, get: obj => obj.emit }, metadata: _metadata }, null, _instanceExtraInitializers);
1965
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1966
+ })(),
1967
+ _a;
1968
+ })();
1969
+ (() => {
1970
+ var _a;
1971
+ let _instanceExtraInitializers = [];
1972
+ let _on_decorators;
1973
+ let _emit_decorators;
1974
+ return _a = class NativeObserverProxy {
1975
+ constructor() {
1976
+ this.__observer = __runInitializers$1(this, _instanceExtraInitializers);
1977
+ }
1978
+ on(ev, handler) {
1979
+ this.__observer.on(ev, handler);
1980
+ }
1981
+ emit(ev, ...args) {
1982
+ this.__observer.emit(ev, ...args);
1983
+ }
1984
+ },
1985
+ (() => {
1986
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1987
+ _on_decorators = [Bind];
1988
+ _emit_decorators = [Bind];
1989
+ __esDecorate$1(_a, null, _on_decorators, { kind: "method", name: "on", static: false, private: false, access: { has: obj => "on" in obj, get: obj => obj.on }, metadata: _metadata }, null, _instanceExtraInitializers);
1990
+ __esDecorate$1(_a, null, _emit_decorators, { kind: "method", name: "emit", static: false, private: false, access: { has: obj => "emit" in obj, get: obj => obj.emit }, metadata: _metadata }, null, _instanceExtraInitializers);
1991
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1992
+ })(),
1993
+ _a;
1994
+ })();
1995
+
1996
+ class NativeView {
1997
+ static getView(viewId, ctor) {
1998
+ const _ins = new ctor(viewId);
1999
+ const ins = initViewProxyObject(_ins, viewId);
2000
+ return ins;
2001
+ }
2002
+ constructor(viewId) {
2003
+ this.viewId = viewId;
2004
+ initViewProxyObject(this, viewId);
2005
+ }
2006
+ }
2007
+ function initViewProxyObject(obj, viewId) {
2008
+ obj.instanceId = obj._instanceId = viewId;
2009
+ obj.namespace = obj._serviceName = '$View';
2010
+ obj._type = "instance" /* ARG_TYPE.INSTANCE */;
2011
+ return obj;
2012
+ }
2013
+
2014
+ const NativeImageResource = {
2015
+ transform(origin) {
2016
+ const r = {
2017
+ ...resolveImageResource(origin),
2018
+ };
2019
+ return r;
2020
+ },
2021
+ };
2022
+ // ios
2023
+ const UIImage = NativeImageResource;
2024
+ // android
2025
+ const Bitmap = NativeImageResource;
2026
+
2027
+ var nativeType = /*#__PURE__*/Object.freeze({
2028
+ __proto__: null,
2029
+ Bitmap: Bitmap,
2030
+ NativeImageResource: NativeImageResource,
2031
+ UIImage: UIImage
2032
+ });
2033
+
2777
2034
  var BRIDGE_NATIVE_API;
2778
2035
  (function (BRIDGE_NATIVE_API) {
2779
2036
  BRIDGE_NATIVE_API["CALL_API"] = "callApi";
@@ -2821,10 +2078,6 @@ var CALL_TYPE;
2821
2078
  * 事件执行后的返回值
2822
2079
  */
2823
2080
  CALL_TYPE["INSTANCE_EVENT_RESULT"] = "instance_event_result";
2824
- /**
2825
- * 销毁实例
2826
- */
2827
- CALL_TYPE["DESTROY_INSTANCE"] = "destroy_instance";
2828
2081
  /**
2829
2082
  * 触发事件
2830
2083
  */
@@ -2836,58 +2089,44 @@ var RETURN_STATUS;
2836
2089
  RETURN_STATUS["FAILED"] = "failed";
2837
2090
  RETURN_STATUS["NOT_IMPLEMENTED"] = "not_implemented";
2838
2091
  })(RETURN_STATUS || (RETURN_STATUS = {}));
2839
- var INSTANCE_TYPE;
2840
- (function (INSTANCE_TYPE) {
2841
- /**
2842
- * 自动 GC 类型
2843
- */
2844
- INSTANCE_TYPE[INSTANCE_TYPE["AUTOMATIC"] = 0] = "AUTOMATIC";
2845
- /**
2846
- * 手动 GC 类型
2847
- */
2848
- INSTANCE_TYPE[INSTANCE_TYPE["MANUAL"] = 1] = "MANUAL";
2849
- })(INSTANCE_TYPE || (INSTANCE_TYPE = {}));
2850
2092
 
2851
- var ReactNativeBridge = /** @class */ (function () {
2852
- function ReactNativeBridge(BridgeModule, NativeEventName) {
2093
+ class ReactNativeBridge {
2094
+ constructor(BridgeModule, NativeEventName) {
2853
2095
  this.BridgeModule = BridgeModule;
2854
2096
  this.NativeEventName = NativeEventName;
2855
2097
  this._handlers = {};
2856
2098
  if (BridgeModule === undefined) {
2857
- throw new Error("can't find module \"".concat(BridgeModule, "\", please enure install the module correctly"));
2099
+ throw new Error(`can't find module "${BridgeModule}", please enure install the module correctly`);
2858
2100
  }
2859
2101
  this._nativeEventEmitter = new NativeEventEmitter(BridgeModule);
2860
2102
  this._init();
2861
2103
  }
2862
- ReactNativeBridge.prototype._init = function () {
2863
- var _this = this;
2864
- this._nativeEventEmitter.addListener(this.NativeEventName, function (ev) {
2865
- var _a, _b;
2104
+ _init() {
2105
+ this._nativeEventEmitter.addListener(this.NativeEventName, (ev) => {
2866
2106
  try {
2867
- var eventName = ev.event;
2868
- var eventData = typeof ev.data === 'string' ? JSON.parse(ev.data) : ev.data;
2107
+ const eventName = ev.event;
2108
+ const eventData = typeof ev.data === 'string' ? JSON.parse(ev.data) : ev.data;
2869
2109
  // console.log(`handle native event:`, ev, eventData);
2870
- (_b = (_a = _this._handlers)[eventName]) === null || _b === void 0 ? void 0 : _b.call(_a, eventData);
2110
+ this._handlers[eventName]?.(eventData);
2871
2111
  }
2872
2112
  catch (err) {
2873
2113
  console.error('handle native event fail:', err);
2874
2114
  }
2875
2115
  });
2876
- };
2877
- ReactNativeBridge.prototype.call = function (params) {
2878
- var _this = this;
2879
- return new Promise(function (resolve, reject) {
2116
+ }
2117
+ call(params) {
2118
+ return new Promise((resolve, reject) => {
2880
2119
  // console.debug(`<Bridge> js call native "${handlerName}()":`, ...args);
2881
2120
  try {
2882
- var resolved_1 = false;
2883
- _this.BridgeModule[BRIDGE_NATIVE_API.CALL_API]({ params: JSON.stringify(params) }, function (res) {
2121
+ let resolved = false;
2122
+ this.BridgeModule[BRIDGE_NATIVE_API.CALL_API]({ params: JSON.stringify(params) }, (res) => {
2884
2123
  // console.log('async call value:', res);
2885
- var val = typeof res === 'string' ? JSON.parse(res) : res;
2886
- resolved_1 = true;
2124
+ const val = typeof res === 'string' ? JSON.parse(res) : res;
2125
+ resolved = true;
2887
2126
  resolve(val);
2888
2127
  });
2889
- setTimeout(function () {
2890
- if (resolved_1) {
2128
+ setTimeout(() => {
2129
+ if (resolved) {
2891
2130
  return;
2892
2131
  }
2893
2132
  resolve({
@@ -2901,11 +2140,11 @@ var ReactNativeBridge = /** @class */ (function () {
2901
2140
  reject(err);
2902
2141
  }
2903
2142
  });
2904
- };
2905
- ReactNativeBridge.prototype.callSync = function (params) {
2143
+ }
2144
+ callSync(params) {
2906
2145
  // console.debug(`<Bridge> js call native "${handlerName}()":`, ...args);
2907
2146
  try {
2908
- var res = this.BridgeModule[BRIDGE_NATIVE_API.CALL_API_SYNC]({
2147
+ const res = this.BridgeModule[BRIDGE_NATIVE_API.CALL_API_SYNC]({
2909
2148
  params: JSON.stringify(params),
2910
2149
  });
2911
2150
  // console.debug(`<Bridge> native return "${handlerName}()":`, res, args)
@@ -2915,61 +2154,27 @@ var ReactNativeBridge = /** @class */ (function () {
2915
2154
  // console.error(`<RNBridge> call native "${handlerName}()" fail`, err);
2916
2155
  throw err;
2917
2156
  }
2918
- };
2919
- ReactNativeBridge.prototype.registerHandler = function (handlerName, handler) {
2157
+ }
2158
+ registerHandler(handlerName, handler) {
2920
2159
  this._handlers[handlerName] = handler;
2921
- };
2922
- ReactNativeBridge.prototype.registerAsyncHandler = function (handlerName, handler) {
2160
+ }
2161
+ registerAsyncHandler(handlerName, handler) {
2923
2162
  this._handlers[handlerName] = handler;
2924
- };
2925
- return ReactNativeBridge;
2926
- }());
2927
-
2928
- /******************************************************************************
2929
- Copyright (c) Microsoft Corporation.
2930
-
2931
- Permission to use, copy, modify, and/or distribute this software for any
2932
- purpose with or without fee is hereby granted.
2933
-
2934
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2935
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2936
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2937
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2938
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2939
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2940
- PERFORMANCE OF THIS SOFTWARE.
2941
- ***************************************************************************** */
2942
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
2943
-
2944
-
2945
- var __assign = function() {
2946
- __assign = Object.assign || function __assign(t) {
2947
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2948
- s = arguments[i];
2949
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
2950
- }
2951
- return t;
2952
- };
2953
- return __assign.apply(this, arguments);
2954
- };
2955
-
2956
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2957
- var e = new Error(message);
2958
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2959
- };
2163
+ }
2164
+ }
2960
2165
 
2961
- var ReactNativeEnv = /** @class */ (function () {
2962
- function ReactNativeEnv() {
2166
+ class ReactNativeEnv {
2167
+ resolveImageResource(input) {
2168
+ const r = Image.resolveAssetSource(input);
2169
+ return {
2170
+ ...r,
2171
+ _type: "image_resource" /* ARG_TYPE.IMAGE_RESOURCE */,
2172
+ };
2963
2173
  }
2964
- ReactNativeEnv.prototype.resolveImageResource = function (input) {
2965
- var r = Image.resolveAssetSource(input);
2966
- return __assign(__assign({}, r), { _type: "image_resource" /* ARG_TYPE.IMAGE_RESOURCE */ });
2967
- };
2968
- ReactNativeEnv.prototype.os = function () {
2174
+ os() {
2969
2175
  return Platform.OS;
2970
- };
2971
- return ReactNativeEnv;
2972
- }());
2176
+ }
2177
+ }
2973
2178
 
2974
2179
  /******************************************************************************
2975
2180
  Copyright (c) Microsoft Corporation.
@@ -12322,57 +11527,57 @@ var VeLivePusherErrorCode$2;
12322
11527
  * @brief License 错误,可能 License 集成错误或 License 过期,请检查 License 集成方式和有效性。
12323
11528
  *
12324
11529
  */
12325
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidLicense"] = 1] = "VeLivePusherInvalidLicense";
11530
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidLicense"] = -1] = "VeLivePusherInvalidLicense";
12326
11531
  /** {zh}
12327
11532
  * @brief 参数错误,请检查入参,并重新调用。
12328
11533
  *
12329
11534
  */
12330
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidParameter"] = 2] = "VeLivePusherInvalidParameter";
11535
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidParameter"] = -2] = "VeLivePusherInvalidParameter";
12331
11536
  /** {zh}
12332
11537
  * @brief 视频采集错误,可能未开启设备视频采集权限,请检查权限是否获取。
12333
11538
  *
12334
11539
  */
12335
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoCaptureError"] = 3] = "VeLivePusherVideoCaptureError";
11540
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoCaptureError"] = -3] = "VeLivePusherVideoCaptureError";
12336
11541
  /** {zh}
12337
11542
  * @brief 音频采集错误,可能未开启设备麦克风采集权限,请检查权限是否获取。
12338
11543
  *
12339
11544
  */
12340
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioCaptureError"] = 4] = "VeLivePusherAudioCaptureError";
11545
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioCaptureError"] = -4] = "VeLivePusherAudioCaptureError";
12341
11546
  /** {zh}
12342
11547
  * @brief 视频编码错误,可能配置了当前设备不支持的视频编码方式,请检查编码参数,并重新调用。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
12343
11548
  *
12344
11549
  */
12345
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEncoderError"] = 5] = "VeLivePusherVideoEncoderError";
11550
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEncoderError"] = -5] = "VeLivePusherVideoEncoderError";
12346
11551
  /** {zh}
12347
11552
  * @brief 音频编码错误,可能配置了当前设备不支持的音频编码方式,请检查编码参数,并重新调用。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
12348
11553
  *
12349
11554
  */
12350
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioEncoderError"] = 6] = "VeLivePusherAudioEncoderError";
11555
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioEncoderError"] = -6] = "VeLivePusherAudioEncoderError";
12351
11556
  /** {zh}
12352
11557
  * @brief 网络发送错误,可能当前网络链路不通,或者开启了代理和关闭了网络权限,请检查网络后重新调用。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
12353
11558
  *
12354
11559
  */
12355
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherTransportError"] = 7] = "VeLivePusherTransportError";
11560
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherTransportError"] = -7] = "VeLivePusherTransportError";
12356
11561
  /** {zh}
12357
11562
  * @brief 视频特效错误,请检查视频特效 SDK 是否已经集成并且初试化成功。检查特效资源路径是否配置正确。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
12358
11563
  *
12359
11564
  */
12360
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEffectError"] = 8] = "VeLivePusherVideoEffectError";
11565
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEffectError"] = -8] = "VeLivePusherVideoEffectError";
12361
11566
  /** {zh}
12362
11567
  * @brief 音频模块错误,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
12363
11568
  *
12364
11569
  */
12365
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioDeviceError"] = 9] = "VeLivePusherAudioDeviceError";
11570
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioDeviceError"] = -9] = "VeLivePusherAudioDeviceError";
12366
11571
  /** {zh}
12367
11572
  * @brief 您使用的基础版 License 暂不支持 H.265 硬件编码,请登录火山引擎控制台获取高级版 License。
12368
11573
  *
12369
11574
  */
12370
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherLicenseUnsupportedH265"] = 10] = "VeLivePusherLicenseUnsupportedH265";
11575
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherLicenseUnsupportedH265"] = -10] = "VeLivePusherLicenseUnsupportedH265";
12371
11576
  /** {zh}
12372
11577
  * @brief 其他错误类型,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
12373
11578
  *
12374
11579
  */
12375
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherError"] = 11] = "VeLivePusherError";
11580
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherError"] = -100] = "VeLivePusherError";
12376
11581
  })(VeLivePusherErrorCode$2 || (VeLivePusherErrorCode$2 = {}));
12377
11582
 
12378
11583
  (function () {
@@ -16851,39 +16056,6 @@ var VeLiveAudioBufferType;
16851
16056
  */
16852
16057
  VeLiveAudioBufferType[VeLiveAudioBufferType["VeLiveAudioBufferTypeNSData"] = 3] = "VeLiveAudioBufferTypeNSData";
16853
16058
  })(VeLiveAudioBufferType || (VeLiveAudioBufferType = {}));
16854
- /** {zh}
16855
- * @detail keytype
16856
- * @brief 定义了推流中首帧的类型,包括音视频的采集首帧、渲染首帧、编码完成首帧和发送首帧。
16857
- *
16858
- */
16859
- var VeLiveFirstFrameType;
16860
- (function (VeLiveFirstFrameType) {
16861
- /** {zh}
16862
- * @brief 视频/音频采集首帧,采集首帧是从音频设备或视频设备(如麦克风、摄像头)获取的第一帧数据。
16863
- *
16864
- */
16865
- VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstCaptureFrame"] = 0] = "VeLiveFirstCaptureFrame";
16866
- /** {zh}
16867
- * @brief 视频渲染首帧,渲染首帧是在渲染过程中在屏幕上显示的第一帧视频数据。
16868
- *
16869
- */
16870
- VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstRenderFrame"] = 1] = "VeLiveFirstRenderFrame";
16871
- /** {zh}
16872
- * @brief 视频/音频编码完成首帧,编码完成首帧是编码为某种特定格式的第一帧数据。
16873
- *
16874
- */
16875
- VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstEncodedFrame"] = 2] = "VeLiveFirstEncodedFrame";
16876
- /** {zh}
16877
- * @brief 视频/音频发送首帧,发送首帧是在发送过程中,通过网络传输的第一帧数据。
16878
- *
16879
- */
16880
- VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstSendFrame"] = 3] = "VeLiveFirstSendFrame";
16881
- /** {zh}
16882
- * @platform ios
16883
- * @brief 录屏采集开始后,获得的第一个 app 音频帧。
16884
- */
16885
- VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstAppAudioCaptureFrame"] = 4] = "VeLiveFirstAppAudioCaptureFrame";
16886
- })(VeLiveFirstFrameType || (VeLiveFirstFrameType = {}));
16887
16059
  /** {zh}
16888
16060
  * @detail keytype
16889
16061
  * @brief 视频采集类型。
@@ -18529,6 +17701,39 @@ var VeLiveAudioChannel;
18529
17701
  */
18530
17702
  VeLiveAudioChannel[VeLiveAudioChannel["VeLiveAudioChannelStereo"] = 1] = "VeLiveAudioChannelStereo";
18531
17703
  })(VeLiveAudioChannel || (VeLiveAudioChannel = {}));
17704
+ /** {zh}
17705
+ * @detail keytype
17706
+ * @brief 定义了推流中首帧的类型,包括音视频的采集首帧、渲染首帧、编码完成首帧和发送首帧。
17707
+ *
17708
+ */
17709
+ var VeLiveFirstFrameType;
17710
+ (function (VeLiveFirstFrameType) {
17711
+ /** {zh}
17712
+ * @brief 视频/音频采集首帧,采集首帧是从音频设备或视频设备(如麦克风、摄像头)获取的第一帧数据。
17713
+ *
17714
+ */
17715
+ VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstCaptureFrame"] = 0] = "VeLiveFirstCaptureFrame";
17716
+ /** {zh}
17717
+ * @brief 视频渲染首帧,渲染首帧是在渲染过程中在屏幕上显示的第一帧视频数据。
17718
+ *
17719
+ */
17720
+ VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstRenderFrame"] = 1] = "VeLiveFirstRenderFrame";
17721
+ /** {zh}
17722
+ * @brief 视频/音频编码完成首帧,编码完成首帧是编码为某种特定格式的第一帧数据。
17723
+ *
17724
+ */
17725
+ VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstEncodedFrame"] = 2] = "VeLiveFirstEncodedFrame";
17726
+ /** {zh}
17727
+ * @brief 视频/音频发送首帧,发送首帧是在发送过程中,通过网络传输的第一帧数据。
17728
+ *
17729
+ */
17730
+ VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstSendFrame"] = 3] = "VeLiveFirstSendFrame";
17731
+ /** {zh}
17732
+ * @platform ios
17733
+ * @brief 录屏采集开始后,获得的第一个 app 音频帧。
17734
+ */
17735
+ VeLiveFirstFrameType[VeLiveFirstFrameType["VeLiveFirstAppAudioCaptureFrame"] = 4] = "VeLiveFirstAppAudioCaptureFrame";
17736
+ })(VeLiveFirstFrameType || (VeLiveFirstFrameType = {}));
18532
17737
  /** {zh}
18533
17738
  * @detail keytype
18534
17739
  * @brief 视频帧来源。
@@ -20371,69 +19576,6 @@ var t_VeLiveAudioBufferType = /** @class */ (function () {
20371
19576
  };
20372
19577
  return t_VeLiveAudioBufferType;
20373
19578
  }());
20374
- var t_VeLiveFirstFrameType = /** @class */ (function () {
20375
- function t_VeLiveFirstFrameType() {
20376
- }
20377
- t_VeLiveFirstFrameType.ts_to_android = function (value) {
20378
- var _a;
20379
- var $m = (_a = {},
20380
- _a[VeLiveFirstFrameType.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType$2.VeLiveFirstCaptureFrame,
20381
- _a[VeLiveFirstFrameType.VeLiveFirstRenderFrame] = VeLiveFirstFrameType$2.VeLiveFirstRenderFrame,
20382
- _a[VeLiveFirstFrameType.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType$2.VeLiveFirstEncodedFrame,
20383
- _a[VeLiveFirstFrameType.VeLiveFirstSendFrame] = VeLiveFirstFrameType$2.VeLiveFirstSendFrame,
20384
- _a);
20385
- if (!(value in $m)) {
20386
- throw new Error('android not support:' + value);
20387
- }
20388
- // @ts-ignore
20389
- return $m[value];
20390
- };
20391
- t_VeLiveFirstFrameType.android_to_ts = function (value) {
20392
- var _a;
20393
- var $m = (_a = {},
20394
- _a[VeLiveFirstFrameType$2.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType.VeLiveFirstCaptureFrame,
20395
- _a[VeLiveFirstFrameType$2.VeLiveFirstRenderFrame] = VeLiveFirstFrameType.VeLiveFirstRenderFrame,
20396
- _a[VeLiveFirstFrameType$2.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType.VeLiveFirstEncodedFrame,
20397
- _a[VeLiveFirstFrameType$2.VeLiveFirstSendFrame] = VeLiveFirstFrameType.VeLiveFirstSendFrame,
20398
- _a);
20399
- if (!(value in $m)) {
20400
- throw new Error('invalid value:' + value);
20401
- }
20402
- // @ts-ignore
20403
- return $m[value];
20404
- };
20405
- t_VeLiveFirstFrameType.ts_to_ios = function (value) {
20406
- var _a;
20407
- var $m = (_a = {},
20408
- _a[VeLiveFirstFrameType.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType$1.VeLiveFirstCaptureFrame,
20409
- _a[VeLiveFirstFrameType.VeLiveFirstRenderFrame] = VeLiveFirstFrameType$1.VeLiveFirstRenderFrame,
20410
- _a[VeLiveFirstFrameType.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType$1.VeLiveFirstEncodedFrame,
20411
- _a[VeLiveFirstFrameType.VeLiveFirstSendFrame] = VeLiveFirstFrameType$1.VeLiveFirstSendFrame,
20412
- _a[VeLiveFirstFrameType.VeLiveFirstAppAudioCaptureFrame] = VeLiveFirstFrameType$1.VeLiveFirstAppAudioCaptureFrame,
20413
- _a);
20414
- if (!(value in $m)) {
20415
- throw new Error('ios not support:' + value);
20416
- }
20417
- // @ts-ignore
20418
- return $m[value];
20419
- };
20420
- t_VeLiveFirstFrameType.ios_to_ts = function (value) {
20421
- var _a;
20422
- var $m = (_a = {},
20423
- _a[VeLiveFirstFrameType$1.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType.VeLiveFirstCaptureFrame,
20424
- _a[VeLiveFirstFrameType$1.VeLiveFirstRenderFrame] = VeLiveFirstFrameType.VeLiveFirstRenderFrame,
20425
- _a[VeLiveFirstFrameType$1.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType.VeLiveFirstEncodedFrame,
20426
- _a[VeLiveFirstFrameType$1.VeLiveFirstSendFrame] = VeLiveFirstFrameType.VeLiveFirstSendFrame,
20427
- _a[VeLiveFirstFrameType$1.VeLiveFirstAppAudioCaptureFrame] = VeLiveFirstFrameType.VeLiveFirstAppAudioCaptureFrame,
20428
- _a);
20429
- if (!(value in $m)) {
20430
- throw new Error('invalid value:' + value);
20431
- }
20432
- // @ts-ignore
20433
- return $m[value];
20434
- };
20435
- return t_VeLiveFirstFrameType;
20436
- }());
20437
19579
  var t_VeLiveVideoCaptureType = /** @class */ (function () {
20438
19580
  function t_VeLiveVideoCaptureType() {
20439
19581
  }
@@ -21023,6 +20165,69 @@ var t_VeLiveVideoCodec = /** @class */ (function () {
21023
20165
  };
21024
20166
  return t_VeLiveVideoCodec;
21025
20167
  }());
20168
+ var t_VeLiveFirstFrameType = /** @class */ (function () {
20169
+ function t_VeLiveFirstFrameType() {
20170
+ }
20171
+ t_VeLiveFirstFrameType.ts_to_android = function (value) {
20172
+ var _a;
20173
+ var $m = (_a = {},
20174
+ _a[VeLiveFirstFrameType.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType$2.VeLiveFirstCaptureFrame,
20175
+ _a[VeLiveFirstFrameType.VeLiveFirstRenderFrame] = VeLiveFirstFrameType$2.VeLiveFirstRenderFrame,
20176
+ _a[VeLiveFirstFrameType.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType$2.VeLiveFirstEncodedFrame,
20177
+ _a[VeLiveFirstFrameType.VeLiveFirstSendFrame] = VeLiveFirstFrameType$2.VeLiveFirstSendFrame,
20178
+ _a);
20179
+ if (!(value in $m)) {
20180
+ throw new Error('android not support:' + value);
20181
+ }
20182
+ // @ts-ignore
20183
+ return $m[value];
20184
+ };
20185
+ t_VeLiveFirstFrameType.android_to_ts = function (value) {
20186
+ var _a;
20187
+ var $m = (_a = {},
20188
+ _a[VeLiveFirstFrameType$2.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType.VeLiveFirstCaptureFrame,
20189
+ _a[VeLiveFirstFrameType$2.VeLiveFirstRenderFrame] = VeLiveFirstFrameType.VeLiveFirstRenderFrame,
20190
+ _a[VeLiveFirstFrameType$2.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType.VeLiveFirstEncodedFrame,
20191
+ _a[VeLiveFirstFrameType$2.VeLiveFirstSendFrame] = VeLiveFirstFrameType.VeLiveFirstSendFrame,
20192
+ _a);
20193
+ if (!(value in $m)) {
20194
+ throw new Error('invalid value:' + value);
20195
+ }
20196
+ // @ts-ignore
20197
+ return $m[value];
20198
+ };
20199
+ t_VeLiveFirstFrameType.ts_to_ios = function (value) {
20200
+ var _a;
20201
+ var $m = (_a = {},
20202
+ _a[VeLiveFirstFrameType.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType$1.VeLiveFirstCaptureFrame,
20203
+ _a[VeLiveFirstFrameType.VeLiveFirstRenderFrame] = VeLiveFirstFrameType$1.VeLiveFirstRenderFrame,
20204
+ _a[VeLiveFirstFrameType.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType$1.VeLiveFirstEncodedFrame,
20205
+ _a[VeLiveFirstFrameType.VeLiveFirstSendFrame] = VeLiveFirstFrameType$1.VeLiveFirstSendFrame,
20206
+ _a[VeLiveFirstFrameType.VeLiveFirstAppAudioCaptureFrame] = VeLiveFirstFrameType$1.VeLiveFirstAppAudioCaptureFrame,
20207
+ _a);
20208
+ if (!(value in $m)) {
20209
+ throw new Error('ios not support:' + value);
20210
+ }
20211
+ // @ts-ignore
20212
+ return $m[value];
20213
+ };
20214
+ t_VeLiveFirstFrameType.ios_to_ts = function (value) {
20215
+ var _a;
20216
+ var $m = (_a = {},
20217
+ _a[VeLiveFirstFrameType$1.VeLiveFirstCaptureFrame] = VeLiveFirstFrameType.VeLiveFirstCaptureFrame,
20218
+ _a[VeLiveFirstFrameType$1.VeLiveFirstRenderFrame] = VeLiveFirstFrameType.VeLiveFirstRenderFrame,
20219
+ _a[VeLiveFirstFrameType$1.VeLiveFirstEncodedFrame] = VeLiveFirstFrameType.VeLiveFirstEncodedFrame,
20220
+ _a[VeLiveFirstFrameType$1.VeLiveFirstSendFrame] = VeLiveFirstFrameType.VeLiveFirstSendFrame,
20221
+ _a[VeLiveFirstFrameType$1.VeLiveFirstAppAudioCaptureFrame] = VeLiveFirstFrameType.VeLiveFirstAppAudioCaptureFrame,
20222
+ _a);
20223
+ if (!(value in $m)) {
20224
+ throw new Error('invalid value:' + value);
20225
+ }
20226
+ // @ts-ignore
20227
+ return $m[value];
20228
+ };
20229
+ return t_VeLiveFirstFrameType;
20230
+ }());
21026
20231
  var t_VeLiveVideoMirrorType = /** @class */ (function () {
21027
20232
  function t_VeLiveVideoMirrorType() {
21028
20233
  }
@@ -27322,58 +26527,58 @@ var VeLivePusherErrorCode;
27322
26527
  * @brief License 错误,可能 License 集成错误或 License 过期,请检查 License 集成方式和有效性。
27323
26528
  *
27324
26529
  */
27325
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidLicense"] = 1] = "VeLivePusherInvalidLicense";
26530
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidLicense"] = -1] = "VeLivePusherInvalidLicense";
27326
26531
  /** {zh}
27327
26532
  * @brief 参数错误,请检查入参,并重新调用。
27328
26533
  *
27329
26534
  */
27330
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidParameter"] = 2] = "VeLivePusherInvalidParameter";
26535
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherInvalidParameter"] = -2] = "VeLivePusherInvalidParameter";
27331
26536
  /** {zh}
27332
26537
  * @brief 视频采集错误,可能未开启设备视频采集权限,请检查权限是否获取。
27333
26538
  *
27334
26539
  */
27335
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoCaptureError"] = 3] = "VeLivePusherVideoCaptureError";
26540
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoCaptureError"] = -3] = "VeLivePusherVideoCaptureError";
27336
26541
  /** {zh}
27337
26542
  * @brief 音频采集错误,可能未开启设备麦克风采集权限,请检查权限是否获取。
27338
26543
  *
27339
26544
  */
27340
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioCaptureError"] = 4] = "VeLivePusherAudioCaptureError";
26545
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioCaptureError"] = -4] = "VeLivePusherAudioCaptureError";
27341
26546
  /** {zh}
27342
26547
  * @brief 视频编码错误,可能配置了当前设备不支持的视频编码方式,请检查编码参数,并重新调用。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
27343
26548
  *
27344
26549
  */
27345
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEncoderError"] = 5] = "VeLivePusherVideoEncoderError";
26550
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEncoderError"] = -5] = "VeLivePusherVideoEncoderError";
27346
26551
  /** {zh}
27347
26552
  * @brief 音频编码错误,可能配置了当前设备不支持的音频编码方式,请检查编码参数,并重新调用。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
27348
26553
  *
27349
26554
  */
27350
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioEncoderError"] = 6] = "VeLivePusherAudioEncoderError";
26555
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioEncoderError"] = -6] = "VeLivePusherAudioEncoderError";
27351
26556
  /** {zh}
27352
26557
  * @brief 网络发送错误,可能当前网络链路不通,或者开启了代理和关闭了网络权限,请检查网络后重新调用。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
27353
26558
  *
27354
26559
  */
27355
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherTransportError"] = 7] = "VeLivePusherTransportError";
26560
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherTransportError"] = -7] = "VeLivePusherTransportError";
27356
26561
  /** {zh}
27357
26562
  * @brief 视频特效错误,请检查视频特效 SDK 是否已经集成并且初试化成功。检查特效资源路径是否配置正确。如果故障未排除,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
27358
26563
  *
27359
26564
  */
27360
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEffectError"] = 8] = "VeLivePusherVideoEffectError";
26565
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherVideoEffectError"] = -8] = "VeLivePusherVideoEffectError";
27361
26566
  /** {zh}
27362
26567
  * @brief 音频模块错误,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
27363
26568
  *
27364
26569
  */
27365
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioDeviceError"] = 9] = "VeLivePusherAudioDeviceError";
26570
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherAudioDeviceError"] = -9] = "VeLivePusherAudioDeviceError";
27366
26571
  /** {zh}
27367
26572
  * @platform android
27368
26573
  * @brief 您使用的基础版 License 暂不支持 H.265 硬件编码,请登录火山引擎控制台获取高级版 License。
27369
26574
  *
27370
26575
  */
27371
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherLicenseUnsupportedH265"] = 10] = "VeLivePusherLicenseUnsupportedH265";
26576
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherLicenseUnsupportedH265"] = -10] = "VeLivePusherLicenseUnsupportedH265";
27372
26577
  /** {zh}
27373
26578
  * @brief 其他错误类型,请联系火山引擎[技术支持](https://console.volcengine.com/workorder/create?step=3&SubProductID=P00000076)。
27374
26579
  *
27375
26580
  */
27376
- VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherError"] = 11] = "VeLivePusherError";
26581
+ VeLivePusherErrorCode[VeLivePusherErrorCode["VeLivePusherError"] = -100] = "VeLivePusherError";
27377
26582
  })(VeLivePusherErrorCode || (VeLivePusherErrorCode = {}));
27378
26583
 
27379
26584
  var AndroidSurfaceView = function () {
@@ -28051,10 +27256,7 @@ function initAndroidPusher(options) {
28051
27256
  case 2:
28052
27257
  _d.sent();
28053
27258
  viewTag = findNodeHandle(element);
28054
- UIManager.dispatchViewManagerCommand(viewTag, 'setVisible', [false]);
28055
- setTimeout(function () {
28056
- UIManager.dispatchViewManagerCommand(viewTag, 'setVisible', [true]);
28057
- }, 1000);
27259
+ UIManager.dispatchViewManagerCommand(viewTag, 'resetSurface', []);
28058
27260
  return [2 /*return*/, packObject(pusher, VeLivePusher)];
28059
27261
  }
28060
27262
  });