@yagolive/event-kit 1.0.6 → 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 +27 -0
- package/README.md +4 -0
- package/dist/js/action_bridge.umd.js +20 -11
- package/dist/js/action_creator.umd.js +1 -1
- package/package.json +1 -1
- package/src/adapters/MockAdapter.js +2 -1
- package/src/adapters/RNWebViewAdapter.js +10 -6
- package/src/adapters/index.d.ts +8 -4
- package/src/bridge/ActionBridge.js +6 -2
- package/src/bridge/index.d.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
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
|
+
|
|
3
30
|
## @1.0.6 (2026-06-09)
|
|
4
31
|
|
|
5
32
|
### 新增
|
package/README.md
CHANGED
|
@@ -363,6 +363,10 @@ enterRoom.addOpenGiftPopupCallback(
|
|
|
363
363
|
const action = bridge.createEnterRoomActionWithData(enterRoom);
|
|
364
364
|
const result = await bridge.sendAction(action);
|
|
365
365
|
|
|
366
|
+
// 自定义单次超时(毫秒);timeout<=0 表示禁用超时
|
|
367
|
+
const result2 = await bridge.sendAction(action, { timeout: 5000 });
|
|
368
|
+
const result3 = await bridge.sendAction(action, { timeout: -1 }); // 不超时
|
|
369
|
+
|
|
366
370
|
// 销毁
|
|
367
371
|
bridge.destroy();
|
|
368
372
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* YAGO Event Kit - Action Bridge (Full)
|
|
3
|
-
* @version 1.0.
|
|
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
|
|
@@ -806,17 +806,21 @@ var RNWebViewAdapter = class {
|
|
|
806
806
|
}
|
|
807
807
|
this._callbacks = {};
|
|
808
808
|
}
|
|
809
|
-
sendAction(action) {
|
|
809
|
+
sendAction(action, option) {
|
|
810
810
|
var self = this;
|
|
811
811
|
var messageId = "msg_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
812
812
|
action.messageId = messageId;
|
|
813
|
+
var timeout = option && option.timeout != null ? option.timeout : self._timeout;
|
|
813
814
|
return new Promise(function(resolve, reject) {
|
|
814
|
-
var timer =
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
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
|
+
}
|
|
818
822
|
self._callbacks[messageId] = function(result, error) {
|
|
819
|
-
clearTimeout(timer);
|
|
823
|
+
if (timer) clearTimeout(timer);
|
|
820
824
|
delete self._callbacks[messageId];
|
|
821
825
|
if (error) reject(error);
|
|
822
826
|
else resolve(result);
|
|
@@ -882,13 +886,14 @@ var MockAdapter = class {
|
|
|
882
886
|
this._calls = [];
|
|
883
887
|
this._mockResults = {};
|
|
884
888
|
}
|
|
885
|
-
sendAction(action) {
|
|
889
|
+
sendAction(action, option) {
|
|
886
890
|
var self = this;
|
|
887
891
|
this._calls.push({
|
|
888
892
|
type: action.type,
|
|
889
893
|
data: action.data != null ? action.data.toMap() : {},
|
|
890
894
|
messageId: action.messageId,
|
|
891
|
-
timestamp: Date.now()
|
|
895
|
+
timestamp: Date.now(),
|
|
896
|
+
option
|
|
892
897
|
});
|
|
893
898
|
return new Promise(function(resolve, reject) {
|
|
894
899
|
var mockResult = self._mockResults[action.type];
|
|
@@ -930,8 +935,12 @@ var ActionBridge = class _ActionBridge {
|
|
|
930
935
|
get ActionData() {
|
|
931
936
|
return ActionData;
|
|
932
937
|
}
|
|
933
|
-
sendAction(action, callback) {
|
|
934
|
-
|
|
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);
|
|
935
944
|
if (callback) {
|
|
936
945
|
promise.then(
|
|
937
946
|
function(result) {
|
package/package.json
CHANGED
|
@@ -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 =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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);
|
package/src/adapters/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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) {
|
package/src/bridge/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
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>;
|