@yagolive/event-kit 1.0.0
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 +70 -0
- package/README.md +651 -0
- package/build/js/action_bridge.umd.js +744 -0
- package/build/js/action_creator.umd.js +479 -0
- package/package.json +84 -0
- package/src/adapters/MockAdapter.js +44 -0
- package/src/adapters/RNWebViewAdapter.js +76 -0
- package/src/adapters/index.d.ts +44 -0
- package/src/adapters/index.js +2 -0
- package/src/bridge/ActionBridge.js +164 -0
- package/src/bridge/index.d.ts +59 -0
- package/src/bridge/index.js +1 -0
- package/src/core/ActionCreator.js +121 -0
- package/src/core/index.d.ts +182 -0
- package/src/core/index.js +8 -0
- package/src/core/types/Action.js +28 -0
- package/src/core/types/EnterRoom.js +92 -0
- package/src/core/types/Jump.js +27 -0
- package/src/core/types/LiveDetect.js +16 -0
- package/src/core/types/Navigate.js +31 -0
- package/src/core/types/Onelink.js +28 -0
- package/src/core/types/Replace.js +9 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +10 -0
- package/src/integrations/react/index.d.ts +13 -0
- package/src/integrations/react/index.js +41 -0
- package/src/integrations/vue/index.d.ts +13 -0
- package/src/integrations/vue/index.js +28 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
class OpenGiftPopupCallback {
|
|
2
|
+
constructor() { this.id = null; this.type = null; this.count = null; }
|
|
3
|
+
getId() { return this.id; } setId(id) { this.id = id; return this; }
|
|
4
|
+
getType() { return this.type; } setType(type) { this.type = type; return this; }
|
|
5
|
+
getCount() { return this.count; } setCount(count) { this.count = count; return this; }
|
|
6
|
+
toMap() { const map = {}; if (this.id != null) map.id = this.id; if (this.type != null) map.type = this.type; if (this.count != null) map.count = this.count; return map; }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class OpenGameCallback {
|
|
10
|
+
constructor() { this.id = null; }
|
|
11
|
+
getId() { return this.id; }
|
|
12
|
+
setId(id) { if (id == null) throw new Error('id cannot be null'); this.id = id; return this; }
|
|
13
|
+
toMap() { const map = {}; if (this.id != null) map.id = this.id; return map; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class OpenActivityCallback {
|
|
17
|
+
constructor() { this.id = null; }
|
|
18
|
+
getId() { return this.id; }
|
|
19
|
+
setId(id) { if (id == null) throw new Error('id cannot be null'); this.id = id; return this; }
|
|
20
|
+
toMap() { const map = {}; if (this.id != null) map.id = this.id; return map; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class SwitchRoomTypeCallback {
|
|
24
|
+
constructor() { this.type = null; }
|
|
25
|
+
getType() { return this.type; }
|
|
26
|
+
setType(type) { if (type == null) throw new Error('type cannot be null'); this.type = type; return this; }
|
|
27
|
+
toMap() { const map = {}; if (this.type != null) map.type = this.type; return map; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const CallbackType = {
|
|
31
|
+
OPEN_GIFT_POPUP: 'open_gift_popup',
|
|
32
|
+
OPEN_GAME: 'open_game',
|
|
33
|
+
OPEN_ACTIVITY: 'open_activity',
|
|
34
|
+
SWITCH_ROOM_TYPE: 'switch_room_type',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
class EnterRoom {
|
|
38
|
+
constructor() { this.text = null; this.id = null; this.match = null; this.callbacks = null; this.useReplace = null; }
|
|
39
|
+
getText() { return this.text; } setText(text) { this.text = text; return this; }
|
|
40
|
+
getId() { return this.id; } setId(id) { this.id = id; return this; }
|
|
41
|
+
getMatch() { return this.match; } setMatch(match) { this.match = match; return this; }
|
|
42
|
+
getUseReplace() { return this.useReplace; } setUseReplace(useReplace) { this.useReplace = useReplace; return this; }
|
|
43
|
+
|
|
44
|
+
addOpenGiftPopupCallback(cb) {
|
|
45
|
+
if (!(cb instanceof OpenGiftPopupCallback)) throw new Error('callback must be an instance of OpenGiftPopupCallback');
|
|
46
|
+
if (this.callbacks == null) this.callbacks = {};
|
|
47
|
+
this.callbacks[CallbackType.OPEN_GIFT_POPUP] = cb;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
addOpenGameCallback(cb) {
|
|
51
|
+
if (!(cb instanceof OpenGameCallback)) throw new Error('callback must be an instance of OpenGameCallback');
|
|
52
|
+
if (this.callbacks == null) this.callbacks = {};
|
|
53
|
+
this.callbacks[CallbackType.OPEN_GAME] = cb;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
addOpenActivityCallback(cb) {
|
|
57
|
+
if (!(cb instanceof OpenActivityCallback)) throw new Error('callback must be an instance of OpenActivityCallback');
|
|
58
|
+
if (this.callbacks == null) this.callbacks = {};
|
|
59
|
+
this.callbacks[CallbackType.OPEN_ACTIVITY] = cb;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
addSwitchRoomTypeCallback(cb) {
|
|
63
|
+
if (!(cb instanceof SwitchRoomTypeCallback)) throw new Error('callback must be an instance of SwitchRoomTypeCallback');
|
|
64
|
+
if (this.callbacks == null) this.callbacks = {};
|
|
65
|
+
this.callbacks[CallbackType.SWITCH_ROOM_TYPE] = cb;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
toMap() {
|
|
70
|
+
const map = {};
|
|
71
|
+
if (this.text != null) map.text = this.text;
|
|
72
|
+
if (this.id != null) map.id = this.id;
|
|
73
|
+
if (this.match != null) map.match = this.match;
|
|
74
|
+
if (this.callbacks != null && Object.keys(this.callbacks).length > 0) {
|
|
75
|
+
const callbacksMap = {};
|
|
76
|
+
for (const [key, value] of Object.entries(this.callbacks)) {
|
|
77
|
+
callbacksMap[key] = value.toMap();
|
|
78
|
+
}
|
|
79
|
+
map.callbacks = callbacksMap;
|
|
80
|
+
}
|
|
81
|
+
if (this.useReplace != null) map.useReplace = this.useReplace;
|
|
82
|
+
return map;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
EnterRoom.CallbackType = CallbackType;
|
|
87
|
+
EnterRoom.OpenGiftPopupCallback = OpenGiftPopupCallback;
|
|
88
|
+
EnterRoom.OpenGameCallback = OpenGameCallback;
|
|
89
|
+
EnterRoom.OpenActivityCallback = OpenActivityCallback;
|
|
90
|
+
EnterRoom.SwitchRoomTypeCallback = SwitchRoomTypeCallback;
|
|
91
|
+
|
|
92
|
+
export default EnterRoom;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class Jump {
|
|
2
|
+
constructor(path) {
|
|
3
|
+
this.text = null;
|
|
4
|
+
if (path == null) {
|
|
5
|
+
throw new Error('path cannot be null');
|
|
6
|
+
}
|
|
7
|
+
this.path = path;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getText() { return this.text; }
|
|
11
|
+
setText(text) { this.text = text; return this; }
|
|
12
|
+
getPath() { return this.path; }
|
|
13
|
+
setPath(path) {
|
|
14
|
+
if (path == null) throw new Error('path cannot be null');
|
|
15
|
+
this.path = path;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
toMap() {
|
|
20
|
+
const map = {};
|
|
21
|
+
if (this.text != null) map.text = this.text;
|
|
22
|
+
if (this.path != null) map.path = this.path;
|
|
23
|
+
return map;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default Jump;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class LiveDetect {
|
|
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 LiveDetect;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class Navigate {
|
|
2
|
+
constructor(screen, params) {
|
|
3
|
+
this.text = null;
|
|
4
|
+
if (screen == null) {
|
|
5
|
+
throw new Error('screen cannot be null');
|
|
6
|
+
}
|
|
7
|
+
this.screen = screen;
|
|
8
|
+
this.params = params != null ? params : {};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getText() { return this.text; }
|
|
12
|
+
setText(text) { this.text = text; return this; }
|
|
13
|
+
getScreen() { return this.screen; }
|
|
14
|
+
setScreen(screen) {
|
|
15
|
+
if (screen == null) throw new Error('screen cannot be null');
|
|
16
|
+
this.screen = screen;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
getParams() { return this.params; }
|
|
20
|
+
setParams(params) { this.params = params != null ? params : {}; return this; }
|
|
21
|
+
|
|
22
|
+
toMap() {
|
|
23
|
+
const map = {};
|
|
24
|
+
if (this.text != null) map.text = this.text;
|
|
25
|
+
if (this.screen != null) map.screen = this.screen;
|
|
26
|
+
if (this.params != null && Object.keys(this.params).length > 0) map.params = this.params;
|
|
27
|
+
return map;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default Navigate;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Onelink {
|
|
2
|
+
constructor(url) {
|
|
3
|
+
this.text = null;
|
|
4
|
+
this.url = url != null ? url : null;
|
|
5
|
+
this.share = null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getText() { return this.text; }
|
|
9
|
+
setText(text) { this.text = text; return this; }
|
|
10
|
+
getUrl() { return this.url; }
|
|
11
|
+
setUrl(url) {
|
|
12
|
+
if (url == null) throw new Error('url cannot be null');
|
|
13
|
+
this.url = url;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
getShare() { return this.share; }
|
|
17
|
+
setShare(share) { this.share = share; return this; }
|
|
18
|
+
|
|
19
|
+
toMap() {
|
|
20
|
+
const map = {};
|
|
21
|
+
if (this.text != null) map.text = this.text;
|
|
22
|
+
if (this.url != null) map.url = this.url;
|
|
23
|
+
if (this.share != null) map.share = this.share;
|
|
24
|
+
return map;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default Onelink;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ActionBridge } from './bridge/index.js';
|
|
2
|
+
export { ActionCreator, ActionData, ActionType, Jump, Navigate, Replace, EnterRoom, LiveDetect, Onelink, Action } from './core/index.js';
|
|
3
|
+
export { RNWebViewAdapter, MockAdapter, IActionAdapter, MockCall } from './adapters/index.js';
|
|
4
|
+
export { ActionBridgeProvider, useActionBridge } from './integrations/react/index.js';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ActionBridge } from './bridge/index.js';
|
|
2
|
+
export { ActionCreator, ActionData, ActionType } from './core/index.js';
|
|
3
|
+
export { RNWebViewAdapter, MockAdapter } from './adapters/index.js';
|
|
4
|
+
export { Jump } from './core/index.js';
|
|
5
|
+
export { Navigate } from './core/index.js';
|
|
6
|
+
export { Replace } from './core/index.js';
|
|
7
|
+
export { EnterRoom } from './core/index.js';
|
|
8
|
+
export { LiveDetect } from './core/index.js';
|
|
9
|
+
export { Onelink } from './core/index.js';
|
|
10
|
+
export { Action } from './core/index.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ActionBridge } from '../../bridge/index.js';
|
|
3
|
+
import { IActionAdapter, AdapterOptions } from '../../adapters/index.js';
|
|
4
|
+
|
|
5
|
+
export interface ActionBridgeProviderProps {
|
|
6
|
+
adapter?: IActionAdapter;
|
|
7
|
+
bridge?: ActionBridge;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare function ActionBridgeProvider(props: ActionBridgeProviderProps): JSX.Element;
|
|
12
|
+
|
|
13
|
+
export declare function useActionBridge(): ActionBridge;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ActionBridge from '../../bridge/ActionBridge.js';
|
|
3
|
+
|
|
4
|
+
var BridgeContext = React.createContext(null);
|
|
5
|
+
|
|
6
|
+
export function ActionBridgeProvider(props) {
|
|
7
|
+
var bridgeRef = React.useRef(null);
|
|
8
|
+
|
|
9
|
+
if (!bridgeRef.current) {
|
|
10
|
+
if (props.adapter) {
|
|
11
|
+
bridgeRef.current = new ActionBridge(props.adapter);
|
|
12
|
+
} else if (props.bridge) {
|
|
13
|
+
bridgeRef.current = props.bridge;
|
|
14
|
+
} else {
|
|
15
|
+
bridgeRef.current = ActionBridge.createDefault();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
React.useEffect(function () {
|
|
20
|
+
return function () {
|
|
21
|
+
if (bridgeRef.current && !props.bridge) {
|
|
22
|
+
bridgeRef.current.destroy();
|
|
23
|
+
bridgeRef.current = null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return React.createElement(
|
|
29
|
+
BridgeContext.Provider,
|
|
30
|
+
{ value: bridgeRef.current },
|
|
31
|
+
props.children
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useActionBridge() {
|
|
36
|
+
var bridge = React.useContext(BridgeContext);
|
|
37
|
+
if (!bridge) {
|
|
38
|
+
throw new Error('useActionBridge must be used within an ActionBridgeProvider');
|
|
39
|
+
}
|
|
40
|
+
return bridge;
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { App, Plugin } from 'vue';
|
|
2
|
+
import { ActionBridge } from '../../bridge/index.js';
|
|
3
|
+
import { IActionAdapter } from '../../adapters/index.js';
|
|
4
|
+
|
|
5
|
+
export declare function createActionBridgePlugin(adapterOrBridge: IActionAdapter | ActionBridge): Plugin;
|
|
6
|
+
|
|
7
|
+
export declare function useActionBridge(): ActionBridge;
|
|
8
|
+
|
|
9
|
+
declare module 'vue' {
|
|
10
|
+
interface ComponentCustomProperties {
|
|
11
|
+
$actionBridge: ActionBridge;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { inject } from 'vue';
|
|
2
|
+
import ActionBridge from '../../bridge/ActionBridge.js';
|
|
3
|
+
|
|
4
|
+
var BRIDGE_KEY = Symbol('__action_bridge__');
|
|
5
|
+
|
|
6
|
+
export function createActionBridgePlugin(adapterOrBridge) {
|
|
7
|
+
var bridge;
|
|
8
|
+
if (adapterOrBridge instanceof ActionBridge) {
|
|
9
|
+
bridge = adapterOrBridge;
|
|
10
|
+
} else {
|
|
11
|
+
bridge = new ActionBridge(adapterOrBridge);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
install: function (app) {
|
|
16
|
+
app.provide(BRIDGE_KEY, bridge);
|
|
17
|
+
app.config.globalProperties.$actionBridge = bridge;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useActionBridge() {
|
|
23
|
+
var bridge = inject(BRIDGE_KEY);
|
|
24
|
+
if (!bridge) {
|
|
25
|
+
throw new Error('useActionBridge must be used after installing createActionBridgePlugin');
|
|
26
|
+
}
|
|
27
|
+
return bridge;
|
|
28
|
+
}
|