@yagolive/event-kit 1.0.5 → 1.0.7

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # Changelog
2
2
 
3
+ ## @1.0.7 (2026-06-10)
4
+
5
+ ### 新增
6
+
7
+ - **sendAction 单次超时配置**: `ActionBridge.sendAction` 与适配器 `sendAction` 新增 `option?: { timeout?: number }` 参数
8
+ - `timeout` 默认使用全局 `timeout`(适配器构造时传入,默认 30000ms)
9
+ - 仅当 `timeout > 0` 时启用超时检测;传 `0` 或负值可禁用单次超时
10
+ - `ActionBridge.sendAction` 支持以下调用方式(向后兼容):
11
+ - `sendAction(action)`
12
+ - `sendAction(action, callback)` — 旧的回调风格
13
+ - `sendAction(action, option)` — 第二个参数为对象时识别为 option
14
+ - `sendAction(action, callback, option)`
15
+ - 类型新增:`SendActionOption` 接口由 `@yagolive/event-kit/adapters` 导出
16
+ - `MockAdapter` 的 `MockCall` 新增可选 `option` 字段,便于测试断言
17
+
18
+ ### 使用示例
19
+
20
+ ```javascript
21
+ // 自定义单次超时(毫秒)
22
+ await bridge.sendAction(action, { timeout: 5000 });
23
+
24
+ // 禁用单次超时
25
+ await bridge.sendAction(action, { timeout: -1 });
26
+ ```
27
+
28
+ ---
29
+
30
+ ## @1.0.6 (2026-06-09)
31
+
32
+ ### 新增
33
+
34
+ - **Close Action(addon 附加类型)**: 新增关闭 WebView 窗口动作类型
35
+ - `ActionType.CLOSE` = `'close'`
36
+ - `Close` 数据类:仅含 `text` 可选字段(继承自 `Base`)
37
+ - `ActionCreator.buildClose()`、`createCloseAction()`、`createCloseActionWithData()`
38
+ - `ActionBridge.close()`、`buildClose()`、`createCloseAction()`、`createCloseActionWithData()`
39
+ - 来源:`packages/@yagolive/event_kit/addon.ts` 中的 `AddonAction`,由宿主容器扩展
40
+
41
+ - **Config Action(addon 附加类型)**: 新增配置 WebView 主题/品牌色动作类型
42
+ - `ActionType.CONFIG` = `'config'`
43
+ - `Config` 数据类:可选字段 `theme`(`'dark' | 'light'`)、`brandColor`(string)、`tintColor`(string)、`title`(string,页面标题)、`text`
44
+ - `Config.Theme` 枚举:`DARK = 'dark'`、`LIGHT = 'light'`
45
+ - `ActionCreator.buildConfig()`、`createConfigAction()`、`createConfigActionWithData()`
46
+ - `ActionBridge.config(options?)`、`buildConfig()`、`createConfigAction()`、`createConfigActionWithData()`
47
+ - `bridge.config()` 便捷方法接受 `{ theme?, brandColor?, tintColor?, title? }` 配置对象
48
+ - 来源:`packages/@yagolive/event_kit/addon.ts` 中的 `AddonAction`,由宿主容器扩展
49
+
50
+ ### Action 类型完整列表
51
+
52
+ | 类型 | 字段 | 说明 |
53
+ |------|------|------|
54
+ | jump | path: string, text?: string | 页面跳转 |
55
+ | navigate | screen: string, params?: Record, text?: string | 导航到指定屏幕 |
56
+ | replace | screen: string, params?: Record, text?: string | 替换当前页面 |
57
+ | goback | text?: string | 返回上一页 |
58
+ | enter_room | id?: number, match?: string, callbacks?: Record, useReplace?: boolean, text?: string | 进入房间 |
59
+ | live_detect | text?: string | 活体检测 |
60
+ | onelink | url: string, share?: boolean, text?: string | 分享链接 |
61
+ | agency_invite | id: number, type: string, title?: string, message?: string, agencyInfo?: AgencyInfo, accepted?: boolean, text?: string | 工会邀请 |
62
+ | recharge | text?: string | 充值操作 |
63
+ | close | text?: string | 关闭 WebView 窗口(addon 附加) |
64
+ | config | theme?: 'dark' \| 'light', brandColor?: string, tintColor?: string, title?: string, text?: string | 配置 WebView 主题(addon 附加) |
65
+
66
+ ---
67
+
3
68
  ## @1.0.5 (2026-06-08)
4
69
 
5
70
  ### 新增
package/README.md CHANGED
@@ -169,8 +169,8 @@ import { ActionCreator } from '@yagolive/event-kit';
169
169
 
170
170
  | 属性 | 类型 | 说明 |
171
171
  |------|------|------|
172
- | `ActionData` | Object | 包含所有数据类型类:Jump, Navigate, Replace, Goback, EnterRoom, LiveDetect, Onelink, AgencyInvite, Recharge |
173
- | `ActionType` | Object | Action 类型枚举:JUMP, NAVIGATE, REPLACE, GOBACK, ENTER_ROOM, LIVE_DETECT, ONELINK, AGENCY_INVITE, RECHARGE |
172
+ | `ActionData` | Object | 包含所有数据类型类:Jump, Navigate, Replace, Goback, EnterRoom, LiveDetect, Onelink, AgencyInvite, Recharge, Close, Config |
173
+ | `ActionType` | Object | Action 类型枚举:JUMP, NAVIGATE, REPLACE, GOBACK, ENTER_ROOM, LIVE_DETECT, ONELINK, AGENCY_INVITE, RECHARGE, CLOSE, CONFIG |
174
174
 
175
175
  #### 工厂方法
176
176
 
@@ -205,6 +205,12 @@ import { ActionCreator } from '@yagolive/event-kit';
205
205
  | `buildRecharge()` | - | Recharge | 构建 Recharge 对象(链式配置) |
206
206
  | `createRechargeAction()` | - | Action | 创建充值 Action |
207
207
  | `createRechargeActionWithData(recharge)` | recharge: Recharge | Action | 从 Recharge 对象创建 Action |
208
+ | `buildClose()` | - | Close | 构建 Close 对象(链式配置,addon) |
209
+ | `createCloseAction()` | - | Action | 创建关闭 Action(addon) |
210
+ | `createCloseActionWithData(close)` | close: Close | Action | 从 Close 对象创建 Action(addon) |
211
+ | `buildConfig()` | - | Config | 构建 Config 对象(链式配置,addon) |
212
+ | `createConfigAction()` | - | Action | 创建配置 Action(addon) |
213
+ | `createConfigActionWithData(config)` | config: Config | Action | 从 Config 对象创建 Action(addon) |
208
214
 
209
215
  #### 使用示例
210
216
 
@@ -247,6 +253,8 @@ ActionType.LIVE_DETECT // 'live_detect'
247
253
  ActionType.ONELINK // 'onelink'
248
254
  ActionType.AGENCY_INVITE // 'agency_invite'
249
255
  ActionType.RECHARGE // 'recharge'
256
+ ActionType.CLOSE // 'close' (addon)
257
+ ActionType.CONFIG // 'config' (addon)
250
258
  ```
251
259
 
252
260
  ### ActionBridge
@@ -320,6 +328,12 @@ new ActionBridge(adapter, options?)
320
328
  | `recharge()` | - | Promise | 充值操作 |
321
329
  | `buildRecharge()` | - | Recharge | 构建 Recharge 对象(链式配置) |
322
330
  | `createRechargeActionWithData(recharge)` | recharge: Recharge | Action | 从 Recharge 对象创建 Action(不自动发送) |
331
+ | `close()` | - | Promise | 关闭 WebView 窗口(addon) |
332
+ | `buildClose()` | - | Close | 构建 Close 对象(链式配置,addon) |
333
+ | `createCloseActionWithData(close)` | close: Close | Action | 从 Close 对象创建 Action(addon) |
334
+ | `config(options?)` | options?: { theme?: 'dark' \| 'light', brandColor?: string, tintColor?: string, title?: string } | Promise | 配置 WebView 主题色(addon) |
335
+ | `buildConfig()` | - | Config | 构建 Config 对象(链式配置,addon) |
336
+ | `createConfigActionWithData(config)` | config: Config | Action | 从 Config 对象创建 Action(addon) |
323
337
 
324
338
  #### 静态方法
325
339
 
@@ -349,6 +363,10 @@ enterRoom.addOpenGiftPopupCallback(
349
363
  const action = bridge.createEnterRoomActionWithData(enterRoom);
350
364
  const result = await bridge.sendAction(action);
351
365
 
366
+ // 自定义单次超时(毫秒);timeout<=0 表示禁用超时
367
+ const result2 = await bridge.sendAction(action, { timeout: 5000 });
368
+ const result3 = await bridge.sendAction(action, { timeout: -1 }); // 不超时
369
+
352
370
  // 销毁
353
371
  bridge.destroy();
354
372
  ```
@@ -688,6 +706,33 @@ Onelink Action 数据。
688
706
  | `constructor()` | - | 创建充值数据 |
689
707
  | `setText(text)` | text: string | 设置显示文本,返回 this |
690
708
 
709
+ ### Close(addon 附加)
710
+
711
+ 关闭 WebView 窗口 Action 数据。来源于 `addon.ts` 的 `AddonAction`,由宿主容器扩展。
712
+
713
+ | 方法 | 参数 | 说明 |
714
+ |------|------|------|
715
+ | `constructor()` | - | 创建 Close 数据 |
716
+ | `setText(text)` | text: string | 设置显示文本,返回 this |
717
+
718
+ ### Config(addon 附加)
719
+
720
+ 配置 WebView 主题色等参数 Action 数据。来源于 `addon.ts` 的 `AddonAction`,由宿主容器扩展。
721
+
722
+ | 方法 | 参数 | 说明 |
723
+ |------|------|------|
724
+ | `constructor()` | - | 创建 Config 数据 |
725
+ | `setText(text)` | text: string | 设置显示文本,返回 this |
726
+ | `setTheme(theme)` | theme: 'dark' \| 'light' | 设置主题,返回 this |
727
+ | `setBrandColor(brandColor)` | brandColor: string | 设置品牌色,返回 this |
728
+ | `setTintColor(tintColor)` | tintColor: string | 设置主题色,返回 this |
729
+ | `setTitle(title)` | title: string | 设置页面标题,返回 this |
730
+
731
+ **静态属性**:
732
+
733
+ - `Config.Theme.DARK` = `'dark'`
734
+ - `Config.Theme.LIGHT` = `'light'`
735
+
691
736
  ### Action
692
737
 
693
738
  Action 对象,封装类型和数据。
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * YAGO Event Kit - Action Bridge (Full)
3
- * @version 1.0.5
3
+ * @version 1.0.7
4
4
  *
5
5
  * Generated by build script - do not edit manually.
6
6
  * Supports: Browser script tag, CommonJS, AMD
@@ -513,6 +513,86 @@ var Recharge = class {
513
513
  };
514
514
  var Recharge_default = Recharge;
515
515
 
516
+ // src/core/types/Close.js
517
+ var Close = class {
518
+ constructor() {
519
+ this.text = null;
520
+ }
521
+ getText() {
522
+ return this.text;
523
+ }
524
+ setText(text) {
525
+ this.text = text;
526
+ return this;
527
+ }
528
+ toMap() {
529
+ const map = {};
530
+ if (this.text != null) map.text = this.text;
531
+ return map;
532
+ }
533
+ };
534
+ var Close_default = Close;
535
+
536
+ // src/core/types/Config.js
537
+ var Config = class {
538
+ constructor() {
539
+ this.text = null;
540
+ this.theme = null;
541
+ this.brandColor = null;
542
+ this.tintColor = null;
543
+ this.title = null;
544
+ }
545
+ getText() {
546
+ return this.text;
547
+ }
548
+ setText(text) {
549
+ this.text = text;
550
+ return this;
551
+ }
552
+ getTheme() {
553
+ return this.theme;
554
+ }
555
+ setTheme(theme) {
556
+ this.theme = theme;
557
+ return this;
558
+ }
559
+ getBrandColor() {
560
+ return this.brandColor;
561
+ }
562
+ setBrandColor(brandColor) {
563
+ this.brandColor = brandColor;
564
+ return this;
565
+ }
566
+ getTintColor() {
567
+ return this.tintColor;
568
+ }
569
+ setTintColor(tintColor) {
570
+ this.tintColor = tintColor;
571
+ return this;
572
+ }
573
+ getTitle() {
574
+ return this.title;
575
+ }
576
+ setTitle(title) {
577
+ this.title = title;
578
+ return this;
579
+ }
580
+ toMap() {
581
+ const map = {};
582
+ if (this.text != null) map.text = this.text;
583
+ if (this.theme != null) map.theme = this.theme;
584
+ if (this.brandColor != null) map.brandColor = this.brandColor;
585
+ if (this.tintColor != null) map.tintColor = this.tintColor;
586
+ if (this.title != null) map.title = this.title;
587
+ return map;
588
+ }
589
+ };
590
+ Config.Theme = {
591
+ DARK: "dark",
592
+ LIGHT: "light"
593
+ };
594
+ var Config_default = Config;
595
+
516
596
  // src/core/types/Action.js
517
597
  var Action = class {
518
598
  constructor(type, data) {
@@ -559,7 +639,9 @@ var ActionType = {
559
639
  LIVE_DETECT: "live_detect",
560
640
  ONELINK: "onelink",
561
641
  AGENCY_INVITE: "agency_invite",
562
- RECHARGE: "recharge"
642
+ RECHARGE: "recharge",
643
+ CLOSE: "close",
644
+ CONFIG: "config"
563
645
  };
564
646
  var ActionData = {
565
647
  Jump: Jump_default,
@@ -570,7 +652,9 @@ var ActionData = {
570
652
  LiveDetect: LiveDetect_default,
571
653
  Onelink: Onelink_default,
572
654
  AgencyInvite: AgencyInvite_default,
573
- Recharge: Recharge_default
655
+ Recharge: Recharge_default,
656
+ Close: Close_default,
657
+ Config: Config_default
574
658
  };
575
659
  var ActionCreator = {
576
660
  ActionData,
@@ -672,6 +756,26 @@ var ActionCreator = {
672
756
  },
673
757
  createRechargeActionWithData(recharge) {
674
758
  return new Action_default(ActionType.RECHARGE, recharge);
759
+ },
760
+ // Close
761
+ buildClose() {
762
+ return new Close_default();
763
+ },
764
+ createCloseAction() {
765
+ return new Action_default(ActionType.CLOSE, new Close_default());
766
+ },
767
+ createCloseActionWithData(close) {
768
+ return new Action_default(ActionType.CLOSE, close);
769
+ },
770
+ // Config
771
+ buildConfig() {
772
+ return new Config_default();
773
+ },
774
+ createConfigAction() {
775
+ return new Action_default(ActionType.CONFIG, new Config_default());
776
+ },
777
+ createConfigActionWithData(config) {
778
+ return new Action_default(ActionType.CONFIG, config);
675
779
  }
676
780
  };
677
781
 
@@ -702,17 +806,21 @@ var RNWebViewAdapter = class {
702
806
  }
703
807
  this._callbacks = {};
704
808
  }
705
- sendAction(action) {
809
+ sendAction(action, option) {
706
810
  var self = this;
707
811
  var messageId = "msg_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
708
812
  action.messageId = messageId;
813
+ var timeout = option && option.timeout != null ? option.timeout : self._timeout;
709
814
  return new Promise(function(resolve, reject) {
710
- var timer = setTimeout(function() {
711
- delete self._callbacks[messageId];
712
- reject(new Error("[ActionBridge] Timeout: no response for action " + action.type));
713
- }, self._timeout);
815
+ var timer = null;
816
+ if (timeout > 0) {
817
+ timer = setTimeout(function() {
818
+ delete self._callbacks[messageId];
819
+ reject(new Error("[ActionBridge] Timeout: no response for action " + action.type));
820
+ }, timeout);
821
+ }
714
822
  self._callbacks[messageId] = function(result, error) {
715
- clearTimeout(timer);
823
+ if (timer) clearTimeout(timer);
716
824
  delete self._callbacks[messageId];
717
825
  if (error) reject(error);
718
826
  else resolve(result);
@@ -778,13 +886,14 @@ var MockAdapter = class {
778
886
  this._calls = [];
779
887
  this._mockResults = {};
780
888
  }
781
- sendAction(action) {
889
+ sendAction(action, option) {
782
890
  var self = this;
783
891
  this._calls.push({
784
892
  type: action.type,
785
893
  data: action.data != null ? action.data.toMap() : {},
786
894
  messageId: action.messageId,
787
- timestamp: Date.now()
895
+ timestamp: Date.now(),
896
+ option
788
897
  });
789
898
  return new Promise(function(resolve, reject) {
790
899
  var mockResult = self._mockResults[action.type];
@@ -826,8 +935,12 @@ var ActionBridge = class _ActionBridge {
826
935
  get ActionData() {
827
936
  return ActionData;
828
937
  }
829
- sendAction(action, callback) {
830
- var promise = this._adapter.sendAction(action);
938
+ sendAction(action, callback, option) {
939
+ if (callback && typeof callback === "object" && option === void 0) {
940
+ option = callback;
941
+ callback = void 0;
942
+ }
943
+ var promise = this._adapter.sendAction(action, option);
831
944
  if (callback) {
832
945
  promise.then(
833
946
  function(result) {
@@ -959,6 +1072,37 @@ var ActionBridge = class _ActionBridge {
959
1072
  createRechargeActionWithData(recharge) {
960
1073
  return ActionCreator.createRechargeActionWithData(recharge);
961
1074
  }
1075
+ close() {
1076
+ return this._adapter.sendAction(ActionCreator.createCloseAction());
1077
+ }
1078
+ buildClose() {
1079
+ return ActionCreator.buildClose();
1080
+ }
1081
+ createCloseAction() {
1082
+ return ActionCreator.createCloseAction();
1083
+ }
1084
+ createCloseActionWithData(close) {
1085
+ return ActionCreator.createCloseActionWithData(close);
1086
+ }
1087
+ config(options) {
1088
+ var data = ActionCreator.buildConfig();
1089
+ if (options) {
1090
+ if (options.theme != null) data.setTheme(options.theme);
1091
+ if (options.brandColor != null) data.setBrandColor(options.brandColor);
1092
+ if (options.tintColor != null) data.setTintColor(options.tintColor);
1093
+ if (options.title != null) data.setTitle(options.title);
1094
+ }
1095
+ return this._adapter.sendAction(ActionCreator.createConfigActionWithData(data));
1096
+ }
1097
+ buildConfig() {
1098
+ return ActionCreator.buildConfig();
1099
+ }
1100
+ createConfigAction() {
1101
+ return ActionCreator.createConfigAction();
1102
+ }
1103
+ createConfigActionWithData(config) {
1104
+ return ActionCreator.createConfigActionWithData(config);
1105
+ }
962
1106
  destroy() {
963
1107
  if (typeof this._adapter.destroy === "function") {
964
1108
  this._adapter.destroy();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * YAGO Event Kit - Action Creator (Core Only)
3
- * @version 1.0.5
3
+ * @version 1.0.7
4
4
  *
5
5
  * Generated by build script - do not edit manually.
6
6
  * Supports: Browser script tag, CommonJS, AMD
@@ -513,6 +513,86 @@ var Recharge = class {
513
513
  };
514
514
  var Recharge_default = Recharge;
515
515
 
516
+ // src/core/types/Close.js
517
+ var Close = class {
518
+ constructor() {
519
+ this.text = null;
520
+ }
521
+ getText() {
522
+ return this.text;
523
+ }
524
+ setText(text) {
525
+ this.text = text;
526
+ return this;
527
+ }
528
+ toMap() {
529
+ const map = {};
530
+ if (this.text != null) map.text = this.text;
531
+ return map;
532
+ }
533
+ };
534
+ var Close_default = Close;
535
+
536
+ // src/core/types/Config.js
537
+ var Config = class {
538
+ constructor() {
539
+ this.text = null;
540
+ this.theme = null;
541
+ this.brandColor = null;
542
+ this.tintColor = null;
543
+ this.title = null;
544
+ }
545
+ getText() {
546
+ return this.text;
547
+ }
548
+ setText(text) {
549
+ this.text = text;
550
+ return this;
551
+ }
552
+ getTheme() {
553
+ return this.theme;
554
+ }
555
+ setTheme(theme) {
556
+ this.theme = theme;
557
+ return this;
558
+ }
559
+ getBrandColor() {
560
+ return this.brandColor;
561
+ }
562
+ setBrandColor(brandColor) {
563
+ this.brandColor = brandColor;
564
+ return this;
565
+ }
566
+ getTintColor() {
567
+ return this.tintColor;
568
+ }
569
+ setTintColor(tintColor) {
570
+ this.tintColor = tintColor;
571
+ return this;
572
+ }
573
+ getTitle() {
574
+ return this.title;
575
+ }
576
+ setTitle(title) {
577
+ this.title = title;
578
+ return this;
579
+ }
580
+ toMap() {
581
+ const map = {};
582
+ if (this.text != null) map.text = this.text;
583
+ if (this.theme != null) map.theme = this.theme;
584
+ if (this.brandColor != null) map.brandColor = this.brandColor;
585
+ if (this.tintColor != null) map.tintColor = this.tintColor;
586
+ if (this.title != null) map.title = this.title;
587
+ return map;
588
+ }
589
+ };
590
+ Config.Theme = {
591
+ DARK: "dark",
592
+ LIGHT: "light"
593
+ };
594
+ var Config_default = Config;
595
+
516
596
  // src/core/types/Action.js
517
597
  var Action = class {
518
598
  constructor(type, data) {
@@ -559,7 +639,9 @@ var ActionType = {
559
639
  LIVE_DETECT: "live_detect",
560
640
  ONELINK: "onelink",
561
641
  AGENCY_INVITE: "agency_invite",
562
- RECHARGE: "recharge"
642
+ RECHARGE: "recharge",
643
+ CLOSE: "close",
644
+ CONFIG: "config"
563
645
  };
564
646
  var ActionData = {
565
647
  Jump: Jump_default,
@@ -570,7 +652,9 @@ var ActionData = {
570
652
  LiveDetect: LiveDetect_default,
571
653
  Onelink: Onelink_default,
572
654
  AgencyInvite: AgencyInvite_default,
573
- Recharge: Recharge_default
655
+ Recharge: Recharge_default,
656
+ Close: Close_default,
657
+ Config: Config_default
574
658
  };
575
659
  var ActionCreator = {
576
660
  ActionData,
@@ -672,6 +756,26 @@ var ActionCreator = {
672
756
  },
673
757
  createRechargeActionWithData(recharge) {
674
758
  return new Action_default(ActionType.RECHARGE, recharge);
759
+ },
760
+ // Close
761
+ buildClose() {
762
+ return new Close_default();
763
+ },
764
+ createCloseAction() {
765
+ return new Action_default(ActionType.CLOSE, new Close_default());
766
+ },
767
+ createCloseActionWithData(close) {
768
+ return new Action_default(ActionType.CLOSE, close);
769
+ },
770
+ // Config
771
+ buildConfig() {
772
+ return new Config_default();
773
+ },
774
+ createConfigAction() {
775
+ return new Action_default(ActionType.CONFIG, new Config_default());
776
+ },
777
+ createConfigActionWithData(config) {
778
+ return new Action_default(ActionType.CONFIG, config);
675
779
  }
676
780
  };
677
781
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagolive/event-kit",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "YAGO Event Kit - 跨环境 Action 创建与通信工具库,支持浏览器、React、Vue",
5
5
  "main": "src/index.js",
6
6
  "browser": "dist/js/action_bridge.umd.js",
@@ -15,13 +15,14 @@ export default class MockAdapter {
15
15
  init() {}
16
16
  destroy() { this._calls = []; this._mockResults = {}; }
17
17
 
18
- sendAction(action) {
18
+ sendAction(action, option) {
19
19
  var self = this;
20
20
  this._calls.push({
21
21
  type: action.type,
22
22
  data: action.data != null ? action.data.toMap() : {},
23
23
  messageId: action.messageId,
24
24
  timestamp: Date.now(),
25
+ option: option,
25
26
  });
26
27
  return new Promise(function (resolve, reject) {
27
28
  var mockResult = self._mockResults[action.type];
@@ -29,17 +29,21 @@ export default class RNWebViewAdapter {
29
29
  this._callbacks = {};
30
30
  }
31
31
 
32
- sendAction(action) {
32
+ sendAction(action, option) {
33
33
  var self = this;
34
34
  var messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
35
35
  action.messageId = messageId;
36
+ var timeout = option && option.timeout != null ? option.timeout : self._timeout;
36
37
  return new Promise(function (resolve, reject) {
37
- var timer = setTimeout(function () {
38
- delete self._callbacks[messageId];
39
- reject(new Error('[ActionBridge] Timeout: no response for action ' + action.type));
40
- }, self._timeout);
38
+ var timer = null;
39
+ if (timeout > 0) {
40
+ timer = setTimeout(function () {
41
+ delete self._callbacks[messageId];
42
+ reject(new Error('[ActionBridge] Timeout: no response for action ' + action.type));
43
+ }, timeout);
44
+ }
41
45
  self._callbacks[messageId] = function (result, error) {
42
- clearTimeout(timer);
46
+ if (timer) clearTimeout(timer);
43
47
  delete self._callbacks[messageId];
44
48
  if (error) reject(error);
45
49
  else resolve(result);
@@ -1,7 +1,10 @@
1
- import { Action, Jump, Navigate, Replace, EnterRoom, LiveDetect, Onelink, ActionType, ActionData, ActionCreator } from '../core/index.js';
1
+ export interface SendActionOption {
2
+ /** 单次发送的超时时间(毫秒)。默认使用全局 timeout,仅当 timeout>0 时启用超时检测 */
3
+ timeout?: number;
4
+ }
2
5
 
3
6
  export interface IActionAdapter {
4
- sendAction(action: any): Promise<any>;
7
+ sendAction(action: any, option?: SendActionOption): Promise<any>;
5
8
  sendActionNoReply?(action: any): void;
6
9
  init?(): void;
7
10
  destroy?(): void;
@@ -13,7 +16,7 @@ export interface AdapterOptions {
13
16
 
14
17
  export declare class RNWebViewAdapter implements IActionAdapter {
15
18
  constructor(options?: AdapterOptions);
16
- sendAction(action: any): Promise<any>;
19
+ sendAction(action: any, option?: SendActionOption): Promise<any>;
17
20
  sendActionNoReply(action: any): void;
18
21
  init(): void;
19
22
  destroy(): void;
@@ -24,6 +27,7 @@ export interface MockCall {
24
27
  data: Record<string, any>;
25
28
  messageId: string;
26
29
  timestamp: number;
30
+ option?: SendActionOption;
27
31
  }
28
32
 
29
33
  export interface MockAdapterOptions extends AdapterOptions {
@@ -37,7 +41,7 @@ export declare class MockAdapter implements IActionAdapter {
37
41
  getCalls(): MockCall[];
38
42
  clearCalls(): this;
39
43
  clearMocks(): this;
40
- sendAction(action: any): Promise<any>;
44
+ sendAction(action: any, option?: SendActionOption): Promise<any>;
41
45
  sendActionNoReply(action: any): void;
42
46
  init(): void;
43
47
  destroy(): void;
@@ -24,8 +24,12 @@ export default class ActionBridge {
24
24
  return ActionData;
25
25
  }
26
26
 
27
- sendAction(action, callback) {
28
- var promise = this._adapter.sendAction(action);
27
+ sendAction(action, callback, option) {
28
+ if (callback && typeof callback === 'object' && option === undefined) {
29
+ option = callback;
30
+ callback = undefined;
31
+ }
32
+ var promise = this._adapter.sendAction(action, option);
29
33
  if (callback) {
30
34
  promise.then(
31
35
  function (result) {
@@ -181,6 +185,41 @@ export default class ActionBridge {
181
185
  return ActionCreator.createRechargeActionWithData(recharge);
182
186
  }
183
187
 
188
+ close() {
189
+ return this._adapter.sendAction(ActionCreator.createCloseAction());
190
+ }
191
+
192
+ buildClose() {
193
+ return ActionCreator.buildClose();
194
+ }
195
+ createCloseAction() {
196
+ return ActionCreator.createCloseAction();
197
+ }
198
+ createCloseActionWithData(close) {
199
+ return ActionCreator.createCloseActionWithData(close);
200
+ }
201
+
202
+ config(options) {
203
+ var data = ActionCreator.buildConfig();
204
+ if (options) {
205
+ if (options.theme != null) data.setTheme(options.theme);
206
+ if (options.brandColor != null) data.setBrandColor(options.brandColor);
207
+ if (options.tintColor != null) data.setTintColor(options.tintColor);
208
+ if (options.title != null) data.setTitle(options.title);
209
+ }
210
+ return this._adapter.sendAction(ActionCreator.createConfigActionWithData(data));
211
+ }
212
+
213
+ buildConfig() {
214
+ return ActionCreator.buildConfig();
215
+ }
216
+ createConfigAction() {
217
+ return ActionCreator.createConfigAction();
218
+ }
219
+ createConfigActionWithData(config) {
220
+ return ActionCreator.createConfigActionWithData(config);
221
+ }
222
+
184
223
  destroy() {
185
224
  if (typeof this._adapter.destroy === 'function') {
186
225
  this._adapter.destroy();
@@ -1,8 +1,8 @@
1
1
  import {
2
- Action, Jump, Navigate, Replace, Goback, EnterRoom, LiveDetect, Onelink, AgencyInvite, Recharge,
2
+ Action, Jump, Navigate, Replace, Goback, EnterRoom, LiveDetect, Onelink, AgencyInvite, Recharge, Close, Config,
3
3
  ActionType, ActionData, ActionCreator,
4
4
  } from '../core/index.js';
5
- import { IActionAdapter, RNWebViewAdapter, MockAdapter, AdapterOptions } from '../adapters/index.js';
5
+ import { IActionAdapter, RNWebViewAdapter, MockAdapter, AdapterOptions, SendActionOption } from '../adapters/index.js';
6
6
 
7
7
  export declare class ActionBridge {
8
8
  constructor(adapter: IActionAdapter, options?: AdapterOptions);
@@ -11,7 +11,8 @@ export declare class ActionBridge {
11
11
  readonly ActionType: typeof ActionType;
12
12
  readonly ActionData: typeof ActionData;
13
13
 
14
- sendAction(action: any, callback?: (result: any, error: any) => void): Promise<any>;
14
+ sendAction(action: any, callback?: (result: any, error: any) => void, option?: SendActionOption): Promise<any>;
15
+ sendAction(action: any, option?: SendActionOption): Promise<any>;
15
16
  sendActionNoReply(action: any): void;
16
17
 
17
18
  jump(path: string): Promise<any>;
@@ -61,6 +62,16 @@ export declare class ActionBridge {
61
62
  createRechargeAction(): Action;
62
63
  createRechargeActionWithData(recharge: Recharge): Action;
63
64
 
65
+ close(): Promise<any>;
66
+ buildClose(): Close;
67
+ createCloseAction(): Action;
68
+ createCloseActionWithData(close: Close): Action;
69
+
70
+ config(options?: { theme?: 'dark' | 'light'; brandColor?: string; tintColor?: string; title?: string }): Promise<any>;
71
+ buildConfig(): Config;
72
+ createConfigAction(): Action;
73
+ createConfigActionWithData(config: Config): Action;
74
+
64
75
  destroy(): void;
65
76
 
66
77
  static ActionCreator: typeof ActionCreator;
@@ -7,6 +7,8 @@ import LiveDetect from './types/LiveDetect.js';
7
7
  import Onelink from './types/Onelink.js';
8
8
  import AgencyInvite from './types/AgencyInvite.js';
9
9
  import Recharge from './types/Recharge.js';
10
+ import Close from './types/Close.js';
11
+ import Config from './types/Config.js';
10
12
  import Action from './types/Action.js';
11
13
 
12
14
  const ActionType = {
@@ -19,6 +21,8 @@ const ActionType = {
19
21
  ONELINK: 'onelink',
20
22
  AGENCY_INVITE: 'agency_invite',
21
23
  RECHARGE: 'recharge',
24
+ CLOSE: 'close',
25
+ CONFIG: 'config',
22
26
  };
23
27
 
24
28
  const ActionData = {
@@ -31,6 +35,8 @@ const ActionData = {
31
35
  Onelink,
32
36
  AgencyInvite,
33
37
  Recharge,
38
+ Close,
39
+ Config,
34
40
  };
35
41
 
36
42
  const ActionCreator = {
@@ -163,6 +169,32 @@ const ActionCreator = {
163
169
  createRechargeActionWithData(recharge) {
164
170
  return new Action(ActionType.RECHARGE, recharge);
165
171
  },
172
+
173
+ // Close
174
+ buildClose() {
175
+ return new Close();
176
+ },
177
+
178
+ createCloseAction() {
179
+ return new Action(ActionType.CLOSE, new Close());
180
+ },
181
+
182
+ createCloseActionWithData(close) {
183
+ return new Action(ActionType.CLOSE, close);
184
+ },
185
+
186
+ // Config
187
+ buildConfig() {
188
+ return new Config();
189
+ },
190
+
191
+ createConfigAction() {
192
+ return new Action(ActionType.CONFIG, new Config());
193
+ },
194
+
195
+ createConfigActionWithData(config) {
196
+ return new Action(ActionType.CONFIG, config);
197
+ },
166
198
  };
167
199
 
168
200
  export { ActionCreator, ActionData, ActionType };
@@ -191,6 +191,40 @@ export class Recharge {
191
191
  toMap(): Record<string, any>;
192
192
  }
193
193
 
194
+ export class Close {
195
+ constructor();
196
+ text: string | null;
197
+ getText(): string | null;
198
+ setText(text: string): this;
199
+ toMap(): Record<string, any>;
200
+ }
201
+
202
+ export const ConfigTheme: {
203
+ DARK: 'dark';
204
+ LIGHT: 'light';
205
+ };
206
+
207
+ export class Config {
208
+ constructor();
209
+ text: string | null;
210
+ theme: 'dark' | 'light' | null;
211
+ brandColor: string | null;
212
+ tintColor: string | null;
213
+ title: string | null;
214
+ static Theme: typeof ConfigTheme;
215
+ getText(): string | null;
216
+ setText(text: string): this;
217
+ getTheme(): 'dark' | 'light' | null;
218
+ setTheme(theme: 'dark' | 'light'): this;
219
+ getBrandColor(): string | null;
220
+ setBrandColor(brandColor: string): this;
221
+ getTintColor(): string | null;
222
+ setTintColor(tintColor: string): this;
223
+ getTitle(): string | null;
224
+ setTitle(title: string): this;
225
+ toMap(): Record<string, any>;
226
+ }
227
+
194
228
  export class Action {
195
229
  constructor(type: ActionTypeValue, data: any);
196
230
  type: ActionTypeValue;
@@ -204,7 +238,7 @@ export class Action {
204
238
  toJson(): string;
205
239
  }
206
240
 
207
- export type ActionTypeValue = 'jump' | 'navigate' | 'replace' | 'goback' | 'enter_room' | 'live_detect' | 'onelink' | 'agency_invite' | 'recharge';
241
+ export type ActionTypeValue = 'jump' | 'navigate' | 'replace' | 'goback' | 'enter_room' | 'live_detect' | 'onelink' | 'agency_invite' | 'recharge' | 'close' | 'config';
208
242
 
209
243
  export const ActionType: {
210
244
  JUMP: 'jump';
@@ -216,6 +250,8 @@ export const ActionType: {
216
250
  ONELINK: 'onelink';
217
251
  AGENCY_INVITE: 'agency_invite';
218
252
  RECHARGE: 'recharge';
253
+ CLOSE: 'close';
254
+ CONFIG: 'config';
219
255
  };
220
256
 
221
257
  export const ActionData: {
@@ -228,6 +264,8 @@ export const ActionData: {
228
264
  Onelink: typeof Onelink;
229
265
  AgencyInvite: typeof AgencyInvite;
230
266
  Recharge: typeof Recharge;
267
+ Close: typeof Close;
268
+ Config: typeof Config;
231
269
  };
232
270
 
233
271
  export const ActionCreator: {
@@ -262,4 +300,10 @@ export const ActionCreator: {
262
300
  buildRecharge(): Recharge;
263
301
  createRechargeAction(): Action;
264
302
  createRechargeActionWithData(recharge: Recharge): Action;
303
+ buildClose(): Close;
304
+ createCloseAction(): Action;
305
+ createCloseActionWithData(close: Close): Action;
306
+ buildConfig(): Config;
307
+ createConfigAction(): Action;
308
+ createConfigActionWithData(config: Config): Action;
265
309
  };
package/src/core/index.js CHANGED
@@ -8,4 +8,6 @@ export { default as LiveDetect } from './types/LiveDetect.js';
8
8
  export { default as Onelink } from './types/Onelink.js';
9
9
  export { default as AgencyInvite } from './types/AgencyInvite.js';
10
10
  export { default as Recharge } from './types/Recharge.js';
11
+ export { default as Close } from './types/Close.js';
12
+ export { default as Config } from './types/Config.js';
11
13
  export { default as Action } from './types/Action.js';
@@ -0,0 +1,16 @@
1
+ class Close {
2
+ constructor() {
3
+ this.text = null;
4
+ }
5
+
6
+ getText() { return this.text; }
7
+ setText(text) { this.text = text; return this; }
8
+
9
+ toMap() {
10
+ const map = {};
11
+ if (this.text != null) map.text = this.text;
12
+ return map;
13
+ }
14
+ }
15
+
16
+ export default Close;
@@ -0,0 +1,37 @@
1
+ class Config {
2
+ constructor() {
3
+ this.text = null;
4
+ this.theme = null;
5
+ this.brandColor = null;
6
+ this.tintColor = null;
7
+ this.title = null;
8
+ }
9
+
10
+ getText() { return this.text; }
11
+ setText(text) { this.text = text; return this; }
12
+ getTheme() { return this.theme; }
13
+ setTheme(theme) { this.theme = theme; return this; }
14
+ getBrandColor() { return this.brandColor; }
15
+ setBrandColor(brandColor) { this.brandColor = brandColor; return this; }
16
+ getTintColor() { return this.tintColor; }
17
+ setTintColor(tintColor) { this.tintColor = tintColor; return this; }
18
+ getTitle() { return this.title; }
19
+ setTitle(title) { this.title = title; return this; }
20
+
21
+ toMap() {
22
+ const map = {};
23
+ if (this.text != null) map.text = this.text;
24
+ if (this.theme != null) map.theme = this.theme;
25
+ if (this.brandColor != null) map.brandColor = this.brandColor;
26
+ if (this.tintColor != null) map.tintColor = this.tintColor;
27
+ if (this.title != null) map.title = this.title;
28
+ return map;
29
+ }
30
+ }
31
+
32
+ Config.Theme = {
33
+ DARK: 'dark',
34
+ LIGHT: 'light',
35
+ };
36
+
37
+ export default Config;
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ActionBridge } from './bridge/index.js';
2
- export { ActionCreator, ActionData, ActionType, Jump, Navigate, Replace, Goback, EnterRoom, LiveDetect, Onelink, AgencyInvite, Recharge, Action } from './core/index.js';
2
+ export { ActionCreator, ActionData, ActionType, Jump, Navigate, Replace, Goback, EnterRoom, LiveDetect, Onelink, AgencyInvite, Recharge, Close, Config, Action } from './core/index.js';
3
3
  export { RNWebViewAdapter, MockAdapter, IActionAdapter, MockCall } from './adapters/index.js';
4
4
  export { ActionBridgeProvider, useActionBridge } from './integrations/react/index.js';
package/src/index.js CHANGED
@@ -10,4 +10,6 @@ export { LiveDetect } from './core/index.js';
10
10
  export { Onelink } from './core/index.js';
11
11
  export { AgencyInvite } from './core/index.js';
12
12
  export { Recharge } from './core/index.js';
13
+ export { Close } from './core/index.js';
14
+ export { Config } from './core/index.js';
13
15
  export { Action } from './core/index.js';