@havue/solutions 1.1.2 → 1.2.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.
- package/bc-connect/dist/bc-connect.mjs +71 -68
- package/bc-connect/dist/bc-connect.umd.js +71 -68
- package/bc-connect/dist/types/src/manager.d.ts +70 -62
- package/bc-connect/package.json +1 -1
- package/bc-connect/src/manager.ts +84 -73
- package/dist/solutions.full.js +138 -122
- package/dist/solutions.full.min.js +4 -4
- package/dist/solutions.full.min.js.map +1 -1
- package/dist/types/bc-connect/src/manager.d.ts +70 -62
- package/dist/types/ws-video-manager/src/loader/websocket-loader.d.ts +13 -10
- package/dist/types/ws-video-manager/src/manager/index.d.ts +54 -37
- package/dist/types/ws-video-manager/src/render/drawer.d.ts +7 -7
- package/dist/types/ws-video-manager/src/render/index.d.ts +35 -19
- package/package.json +4 -4
- package/vite.config.ts +1 -1
- package/ws-video-manager/dist/types/src/loader/websocket-loader.d.ts +13 -10
- package/ws-video-manager/dist/types/src/manager/index.d.ts +54 -37
- package/ws-video-manager/dist/types/src/render/drawer.d.ts +7 -7
- package/ws-video-manager/dist/types/src/render/index.d.ts +35 -19
- package/ws-video-manager/dist/ws-video-manager.mjs +67 -54
- package/ws-video-manager/dist/ws-video-manager.umd.js +67 -54
- package/ws-video-manager/package.json +1 -1
- package/ws-video-manager/src/loader/websocket-loader.ts +15 -11
- package/ws-video-manager/src/manager/index.ts +57 -40
- package/ws-video-manager/src/render/drawer.ts +22 -20
- package/ws-video-manager/src/render/index.ts +61 -27
- package/ws-video-manager/src/render/mp4box.ts +1 -1
|
@@ -1,63 +1,71 @@
|
|
|
1
|
-
/** 事件数据类型 */
|
|
1
|
+
/** 事件数据类型 | Event Datatypes */
|
|
2
2
|
export type BcConnectSendMessageType = {
|
|
3
|
-
/** 事件类型 */
|
|
3
|
+
/** 事件类型 | type */
|
|
4
4
|
type: string;
|
|
5
|
-
/** 数据 */
|
|
5
|
+
/** 数据 | data */
|
|
6
6
|
data: any;
|
|
7
|
-
/** 发送事件的实例id */
|
|
7
|
+
/** 发送事件的实例id | BroadcastChannelManager instance id */
|
|
8
8
|
id: number;
|
|
9
|
-
/**
|
|
9
|
+
/** 此消息的目标实例id | The target instance id for this message */
|
|
10
10
|
targetId?: number;
|
|
11
11
|
};
|
|
12
|
-
/** 事件类型 */
|
|
12
|
+
/** 事件类型 | Event types */
|
|
13
13
|
export declare enum BcConnectEventTypeEnum {
|
|
14
|
-
/** 初始广播 */
|
|
15
|
-
Broadcast = "
|
|
16
|
-
/** 回复初始广播 */
|
|
17
|
-
Broadcast_Reply = "
|
|
18
|
-
/** 主节点心跳 */
|
|
19
|
-
Main_Node_Hearbeat = "
|
|
20
|
-
/** 回复主节点心跳 */
|
|
21
|
-
Res_Main_Node_Hearbeat = "
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
14
|
+
/** 初始广播 | Initial broadcast */
|
|
15
|
+
Broadcast = "__BCM_INIT__",
|
|
16
|
+
/** 回复初始广播 | Reply to initial broadcast */
|
|
17
|
+
Broadcast_Reply = "__BCM_INIT_REPLY__",
|
|
18
|
+
/** 主节点心跳 | Master node heartbeat */
|
|
19
|
+
Main_Node_Hearbeat = "__BCM_MAIN_NODE_HEARBEAT__",
|
|
20
|
+
/** 回复主节点心跳 | Reply to the master node heartbeat */
|
|
21
|
+
Res_Main_Node_Hearbeat = "__BCM_MAIN_NODE_HEARBEAT_REPLY__",
|
|
22
|
+
/**
|
|
23
|
+
* 长时间未收到主节点心跳,申请成为主节点
|
|
24
|
+
* It has not received the heartbeat of the master node for a long time.
|
|
25
|
+
* Apply to become the master node
|
|
26
|
+
*/
|
|
27
|
+
Req_Be_Main_Node = "__BCM_REQ_BE_MAIN_NODE__",
|
|
28
|
+
/** 拒绝其他节点成为主节点 | Reject other nodes as master nodes */
|
|
29
|
+
Res_Be_Main_Node = "__BCM_REQ_BE_MAIN_NODE_REJECT__",
|
|
30
|
+
/** 当前节点类型更改 | The current node type has changed */
|
|
31
|
+
Node_Type_Change = "__BCM_NODE_TYPE_CHANGE__",
|
|
32
|
+
/** 其他标签页BC节点id列表更新 | Other TAB node id list updated */
|
|
33
|
+
Friend_List_Update = "__BCM_FRIEND_LIST_UPDATE__"
|
|
30
34
|
}
|
|
31
|
-
/**
|
|
35
|
+
/** BroadcastChannel节点类型 | BroadcastChannel node type */
|
|
32
36
|
export declare enum BcConnectNodeTypeEnum {
|
|
33
37
|
Main = "main",
|
|
34
38
|
Normal = "normal"
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* 使用BroadcastChannel与其他标签页进行通信
|
|
42
|
+
* Use BroadcastChannel to communicate with other tabs
|
|
38
43
|
*/
|
|
39
44
|
export declare class BroadcastChannelManager {
|
|
40
|
-
/** 通道名称 */
|
|
45
|
+
/** 通道名称 | Channel name */
|
|
41
46
|
private _bcName;
|
|
42
|
-
/** BroadcastChannel
|
|
47
|
+
/** BroadcastChannel instance */
|
|
43
48
|
private _broadcastChannel;
|
|
44
|
-
/**
|
|
49
|
+
/** Event map */
|
|
45
50
|
private _eventMap;
|
|
46
|
-
/** 主节点发送心跳的interval */
|
|
51
|
+
/** 主节点发送心跳的interval | The interval at which the master node sends the heartbeat */
|
|
47
52
|
private _mainNodeMsgInterval;
|
|
48
|
-
/** 认为主节点掉线的timeout */
|
|
53
|
+
/** 认为主节点掉线的timeout | timeout to consider the primary node to be offline */
|
|
49
54
|
private _mainNodeMsgTimeoutTimer;
|
|
50
|
-
/** 更新友方列表的timeout */
|
|
55
|
+
/** 更新友方列表的timeout | Update the timeout of the friend list */
|
|
51
56
|
private _updateFriendListTimer;
|
|
52
|
-
/** 当前实例id */
|
|
57
|
+
/** 当前实例id | Current instance id */
|
|
53
58
|
id: number;
|
|
54
|
-
/**
|
|
59
|
+
/** 其他广播通道id列表 | List of other broadcast channel ids */
|
|
55
60
|
private _oldFrendChannelIdList;
|
|
56
|
-
/**
|
|
61
|
+
/** 正在更新的id数组 | The id array being updated */
|
|
57
62
|
private _friendChannelIdSet;
|
|
58
|
-
/** 当前节点类型 */
|
|
63
|
+
/** 当前节点类型 | Current node type */
|
|
59
64
|
private _nodeType;
|
|
60
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* 是否开启调试模式,会在控制台打印相关信息
|
|
67
|
+
* If debug mode is enabled, it will print information to the console
|
|
68
|
+
*/
|
|
61
69
|
private _debug;
|
|
62
70
|
constructor(name: string, debug?: boolean);
|
|
63
71
|
get nodeType(): BcConnectNodeTypeEnum | undefined;
|
|
@@ -65,73 +73,73 @@ export declare class BroadcastChannelManager {
|
|
|
65
73
|
connect(): void;
|
|
66
74
|
close(): void;
|
|
67
75
|
/**
|
|
68
|
-
* 切换节点类型
|
|
76
|
+
* 切换节点类型 | Switching node type
|
|
69
77
|
* @param {BcConnectNodeTypeEnum} type
|
|
70
78
|
* @returns
|
|
71
79
|
*/
|
|
72
80
|
private _setNodeType;
|
|
73
|
-
/**
|
|
81
|
+
/** 更新广播id列表 | Update the list of broadcast ids */
|
|
74
82
|
private _updateFriendList;
|
|
75
|
-
/** 绑定事件 */
|
|
83
|
+
/** 绑定事件 | Bind event */
|
|
76
84
|
private _bindBroadcastChannelEvent;
|
|
77
|
-
/** 监听节点类型切换事件 */
|
|
85
|
+
/** 监听节点类型切换事件 | */
|
|
78
86
|
private _bindNodeEvent;
|
|
79
|
-
/**
|
|
87
|
+
/** 获取最新的节点列表 | Get the latest node list */
|
|
80
88
|
private _getNewFriendList;
|
|
81
89
|
/**
|
|
82
|
-
* 更新当前节点类型
|
|
90
|
+
* 更新当前节点类型 | Update the current node type
|
|
83
91
|
*/
|
|
84
92
|
private _updataNodeType;
|
|
85
93
|
private _timeoutToBeMainNode;
|
|
86
94
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
95
|
+
* 保存最新的节点列表到_oldFrendChannelIdList,清空_friendChannelIdSet
|
|
96
|
+
* Save the latest node list to _oldFrendChannelIdList and clear _friendChannelIdSet
|
|
89
97
|
*/
|
|
90
98
|
private _catchOldFriend;
|
|
91
99
|
/**
|
|
92
|
-
* 申请成为主节点
|
|
100
|
+
* 申请成为主节点 | Apply to be a master node
|
|
93
101
|
*/
|
|
94
102
|
private _req_beMainNode;
|
|
95
103
|
/**
|
|
96
|
-
*
|
|
97
|
-
* @param id
|
|
104
|
+
* add node
|
|
105
|
+
* @param id id
|
|
98
106
|
*/
|
|
99
107
|
_addFriend(id: number): void;
|
|
100
108
|
/**
|
|
101
|
-
* 广播消息
|
|
102
|
-
* @param type 消息类型
|
|
103
|
-
* @param data 数据
|
|
109
|
+
* 广播消息 | Send Broadcast message
|
|
110
|
+
* @param type 消息类型 | Message type
|
|
111
|
+
* @param data 数据 | data
|
|
104
112
|
*/
|
|
105
113
|
send(type: string, data?: any): void;
|
|
106
114
|
/**
|
|
107
|
-
* 给特定id的节点发送消息
|
|
108
|
-
* @param type 消息类型
|
|
109
|
-
* @param targetId 目标节点id
|
|
110
|
-
* @param data 数据
|
|
115
|
+
* 给特定id的节点发送消息 | Send a message to a node with a specific id
|
|
116
|
+
* @param type 消息类型 | Message type
|
|
117
|
+
* @param targetId 目标节点id | Target Node id
|
|
118
|
+
* @param data 数据 | data
|
|
111
119
|
*/
|
|
112
120
|
sendToTarget(type: string, targetId: number, data?: any): void;
|
|
113
121
|
/**
|
|
114
|
-
* 注册事件
|
|
115
|
-
* @param { string } event 事件类型
|
|
116
|
-
* @param callback 回调
|
|
122
|
+
* 注册事件 | Registering events
|
|
123
|
+
* @param { string } event 事件类型 | Event type
|
|
124
|
+
* @param callback 回调 | callback
|
|
117
125
|
* @returns void
|
|
118
126
|
*/
|
|
119
127
|
on(event: string, callback: (_: BcConnectSendMessageType) => void): void;
|
|
120
128
|
/**
|
|
121
|
-
* 注销事件
|
|
122
|
-
* @param { string } event 事件类型
|
|
123
|
-
* @param callback 事件回调
|
|
129
|
+
* 注销事件 | Remove events
|
|
130
|
+
* @param { string } event 事件类型 | Event type
|
|
131
|
+
* @param callback 事件回调 | callback
|
|
124
132
|
* @returns
|
|
125
133
|
*/
|
|
126
134
|
off(event: string, callback?: (_: BcConnectSendMessageType) => void): void;
|
|
127
135
|
/**
|
|
128
|
-
* 触发事件
|
|
129
|
-
* @param { string } event 事件类型
|
|
130
|
-
* @param data 数据
|
|
136
|
+
* 触发事件 | Triggering events
|
|
137
|
+
* @param { string } event 事件类型 | Event type
|
|
138
|
+
* @param data 数据 | data
|
|
131
139
|
*/
|
|
132
140
|
emit(event: string, data: BcConnectSendMessageType): void;
|
|
133
141
|
/**
|
|
134
|
-
* 销毁
|
|
142
|
+
* 销毁 | destroy
|
|
135
143
|
*/
|
|
136
144
|
destroy(): void;
|
|
137
145
|
}
|
package/bc-connect/package.json
CHANGED
|
@@ -1,72 +1,80 @@
|
|
|
1
1
|
// #region typedefine
|
|
2
|
-
/** 事件数据类型 */
|
|
2
|
+
/** 事件数据类型 | Event Datatypes */
|
|
3
3
|
export type BcConnectSendMessageType = {
|
|
4
|
-
/** 事件类型 */
|
|
4
|
+
/** 事件类型 | type */
|
|
5
5
|
type: string
|
|
6
|
-
/** 数据 */
|
|
6
|
+
/** 数据 | data */
|
|
7
7
|
data: any
|
|
8
|
-
/** 发送事件的实例id */
|
|
8
|
+
/** 发送事件的实例id | BroadcastChannelManager instance id */
|
|
9
9
|
id: number
|
|
10
|
-
/**
|
|
10
|
+
/** 此消息的目标实例id | The target instance id for this message */
|
|
11
11
|
targetId?: number
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** 事件类型 */
|
|
14
|
+
/** 事件类型 | Event types */
|
|
15
15
|
export enum BcConnectEventTypeEnum {
|
|
16
|
-
/** 初始广播 */
|
|
17
|
-
Broadcast = '
|
|
18
|
-
/** 回复初始广播 */
|
|
19
|
-
Broadcast_Reply = '
|
|
20
|
-
/** 主节点心跳 */
|
|
21
|
-
Main_Node_Hearbeat = '
|
|
22
|
-
/** 回复主节点心跳 */
|
|
23
|
-
Res_Main_Node_Hearbeat = '
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
|
|
16
|
+
/** 初始广播 | Initial broadcast */
|
|
17
|
+
Broadcast = '__BCM_INIT__',
|
|
18
|
+
/** 回复初始广播 | Reply to initial broadcast */
|
|
19
|
+
Broadcast_Reply = '__BCM_INIT_REPLY__',
|
|
20
|
+
/** 主节点心跳 | Master node heartbeat */
|
|
21
|
+
Main_Node_Hearbeat = '__BCM_MAIN_NODE_HEARBEAT__',
|
|
22
|
+
/** 回复主节点心跳 | Reply to the master node heartbeat */
|
|
23
|
+
Res_Main_Node_Hearbeat = '__BCM_MAIN_NODE_HEARBEAT_REPLY__',
|
|
24
|
+
/**
|
|
25
|
+
* 长时间未收到主节点心跳,申请成为主节点
|
|
26
|
+
* It has not received the heartbeat of the master node for a long time.
|
|
27
|
+
* Apply to become the master node
|
|
28
|
+
*/
|
|
29
|
+
Req_Be_Main_Node = '__BCM_REQ_BE_MAIN_NODE__',
|
|
30
|
+
/** 拒绝其他节点成为主节点 | Reject other nodes as master nodes */
|
|
31
|
+
Res_Be_Main_Node = '__BCM_REQ_BE_MAIN_NODE_REJECT__',
|
|
32
|
+
/** 当前节点类型更改 | The current node type has changed */
|
|
33
|
+
Node_Type_Change = '__BCM_NODE_TYPE_CHANGE__',
|
|
34
|
+
/** 其他标签页BC节点id列表更新 | Other TAB node id list updated */
|
|
35
|
+
Friend_List_Update = '__BCM_FRIEND_LIST_UPDATE__'
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
/**
|
|
38
|
+
/** BroadcastChannel节点类型 | BroadcastChannel node type */
|
|
35
39
|
export enum BcConnectNodeTypeEnum {
|
|
36
40
|
Main = 'main',
|
|
37
41
|
Normal = 'normal'
|
|
38
42
|
}
|
|
39
43
|
// #endregion typedefine
|
|
40
44
|
|
|
41
|
-
// 消息超时时间
|
|
45
|
+
// 消息超时时间 | Message timeout time
|
|
42
46
|
const MessageTimeout = 300
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
49
|
* 使用BroadcastChannel与其他标签页进行通信
|
|
50
|
+
* Use BroadcastChannel to communicate with other tabs
|
|
46
51
|
*/
|
|
47
52
|
export class BroadcastChannelManager {
|
|
48
|
-
/** 通道名称 */
|
|
53
|
+
/** 通道名称 | Channel name */
|
|
49
54
|
private _bcName: string
|
|
50
|
-
/** BroadcastChannel
|
|
55
|
+
/** BroadcastChannel instance */
|
|
51
56
|
private _broadcastChannel: BroadcastChannel | undefined = undefined
|
|
52
|
-
/**
|
|
57
|
+
/** Event map */
|
|
53
58
|
private _eventMap: Map<string, Array<(_: BcConnectSendMessageType) => void>>
|
|
54
|
-
/** 主节点发送心跳的interval */
|
|
59
|
+
/** 主节点发送心跳的interval | The interval at which the master node sends the heartbeat */
|
|
55
60
|
private _mainNodeMsgInterval: number | null = null
|
|
56
|
-
/** 认为主节点掉线的timeout */
|
|
61
|
+
/** 认为主节点掉线的timeout | timeout to consider the primary node to be offline */
|
|
57
62
|
private _mainNodeMsgTimeoutTimer: number | null = null
|
|
58
|
-
/** 更新友方列表的timeout */
|
|
63
|
+
/** 更新友方列表的timeout | Update the timeout of the friend list */
|
|
59
64
|
private _updateFriendListTimer: number | null = null
|
|
60
|
-
/** 当前实例id */
|
|
65
|
+
/** 当前实例id | Current instance id */
|
|
61
66
|
public id: number = Date.now() + Math.random()
|
|
62
|
-
/**
|
|
67
|
+
/** 其他广播通道id列表 | List of other broadcast channel ids */
|
|
63
68
|
private _oldFrendChannelIdList: Array<number> = []
|
|
64
|
-
/**
|
|
69
|
+
/** 正在更新的id数组 | The id array being updated */
|
|
65
70
|
private _friendChannelIdSet: Set<number> = new Set()
|
|
66
|
-
/** 当前节点类型 */
|
|
71
|
+
/** 当前节点类型 | Current node type */
|
|
67
72
|
private _nodeType: BcConnectNodeTypeEnum | undefined = undefined
|
|
68
73
|
|
|
69
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* 是否开启调试模式,会在控制台打印相关信息
|
|
76
|
+
* If debug mode is enabled, it will print information to the console
|
|
77
|
+
*/
|
|
70
78
|
private _debug: boolean = false
|
|
71
79
|
|
|
72
80
|
constructor(name: string, debug: boolean = false) {
|
|
@@ -108,7 +116,7 @@ export class BroadcastChannelManager {
|
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
/**
|
|
111
|
-
* 切换节点类型
|
|
119
|
+
* 切换节点类型 | Switching node type
|
|
112
120
|
* @param {BcConnectNodeTypeEnum} type
|
|
113
121
|
* @returns
|
|
114
122
|
*/
|
|
@@ -124,9 +132,9 @@ export class BroadcastChannelManager {
|
|
|
124
132
|
})
|
|
125
133
|
}
|
|
126
134
|
|
|
127
|
-
/**
|
|
135
|
+
/** 更新广播id列表 | Update the list of broadcast ids */
|
|
128
136
|
private _updateFriendList() {
|
|
129
|
-
// 广播告知己方存在
|
|
137
|
+
// 广播告知己方存在 | Broadcast your presence
|
|
130
138
|
this.send(BcConnectEventTypeEnum.Broadcast)
|
|
131
139
|
|
|
132
140
|
this._updateFriendListTimer && clearTimeout(this._updateFriendListTimer)
|
|
@@ -142,7 +150,7 @@ export class BroadcastChannelManager {
|
|
|
142
150
|
this._updataNodeType()
|
|
143
151
|
}, MessageTimeout)
|
|
144
152
|
}
|
|
145
|
-
/** 绑定事件 */
|
|
153
|
+
/** 绑定事件 | Bind event */
|
|
146
154
|
private _bindBroadcastChannelEvent() {
|
|
147
155
|
this._broadcastChannel &&
|
|
148
156
|
(this._broadcastChannel.onmessage = (event) => {
|
|
@@ -153,7 +161,7 @@ export class BroadcastChannelManager {
|
|
|
153
161
|
this.emit(type, event.data)
|
|
154
162
|
})
|
|
155
163
|
|
|
156
|
-
//
|
|
164
|
+
// 收到初始广播 | Receiving the initial broadcast
|
|
157
165
|
this.on(BcConnectEventTypeEnum.Broadcast, (data) => {
|
|
158
166
|
const { id } = data
|
|
159
167
|
if (!this._friendChannelIdSet.has(id)) {
|
|
@@ -163,13 +171,13 @@ export class BroadcastChannelManager {
|
|
|
163
171
|
this.sendToTarget(BcConnectEventTypeEnum.Broadcast_Reply, id)
|
|
164
172
|
})
|
|
165
173
|
|
|
166
|
-
//
|
|
174
|
+
// 收到初始广播回复 | The initial broadcast reply is received
|
|
167
175
|
this.on(BcConnectEventTypeEnum.Broadcast_Reply, (data) => {
|
|
168
176
|
const { id } = data
|
|
169
177
|
this._addFriend(id)
|
|
170
178
|
})
|
|
171
179
|
|
|
172
|
-
//
|
|
180
|
+
// 收到其他节点申请为主节点 | Others apply for the master node
|
|
173
181
|
this.on(BcConnectEventTypeEnum.Req_Be_Main_Node, (data) => {
|
|
174
182
|
const { id } = data
|
|
175
183
|
if (id > this.id) {
|
|
@@ -177,7 +185,7 @@ export class BroadcastChannelManager {
|
|
|
177
185
|
}
|
|
178
186
|
})
|
|
179
187
|
|
|
180
|
-
//
|
|
188
|
+
// 收到主节点心跳回复 | Received the master node heartbeat reply
|
|
181
189
|
this.on(BcConnectEventTypeEnum.Res_Main_Node_Hearbeat, (data) => {
|
|
182
190
|
this._addFriend(data.id)
|
|
183
191
|
})
|
|
@@ -185,7 +193,7 @@ export class BroadcastChannelManager {
|
|
|
185
193
|
this._bindNodeEvent()
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
/** 监听节点类型切换事件 */
|
|
196
|
+
/** 监听节点类型切换事件 | */
|
|
189
197
|
private _bindNodeEvent() {
|
|
190
198
|
const onMainNodeHearbeat = (data: BcConnectSendMessageType) => {
|
|
191
199
|
this._timeoutToBeMainNode()
|
|
@@ -197,9 +205,9 @@ export class BroadcastChannelManager {
|
|
|
197
205
|
this.on(BcConnectEventTypeEnum.Node_Type_Change, (info) => {
|
|
198
206
|
const { data } = info
|
|
199
207
|
this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval)
|
|
200
|
-
this._debug && console.log('BC
|
|
208
|
+
this._debug && console.log('BC:NODE_TYPE_CHANGE:', info.data)
|
|
201
209
|
if (data === BcConnectNodeTypeEnum.Main) {
|
|
202
|
-
// 定时发送主节点心跳
|
|
210
|
+
// 定时发送主节点心跳 | The heartbeat of the master node is sent periodically
|
|
203
211
|
this._mainNodeMsgInterval = setInterval(() => {
|
|
204
212
|
this._catchOldFriend()
|
|
205
213
|
this.send(BcConnectEventTypeEnum.Main_Node_Hearbeat)
|
|
@@ -207,17 +215,17 @@ export class BroadcastChannelManager {
|
|
|
207
215
|
} else if (data === BcConnectNodeTypeEnum.Normal) {
|
|
208
216
|
this._timeoutToBeMainNode()
|
|
209
217
|
}
|
|
210
|
-
// 收到主节点心跳, 重新更新友方列表
|
|
218
|
+
// 收到主节点心跳, 重新更新友方列表 | Update the friend list after receiving the heartbeat of the master node
|
|
211
219
|
this.on(BcConnectEventTypeEnum.Main_Node_Hearbeat, onMainNodeHearbeat)
|
|
212
220
|
})
|
|
213
221
|
}
|
|
214
222
|
|
|
215
|
-
/**
|
|
223
|
+
/** 获取最新的节点列表 | Get the latest node list */
|
|
216
224
|
private _getNewFriendList() {
|
|
217
225
|
return [...this._friendChannelIdSet].sort((a, b) => a - b)
|
|
218
226
|
}
|
|
219
227
|
/**
|
|
220
|
-
* 更新当前节点类型
|
|
228
|
+
* 更新当前节点类型 | Update the current node type
|
|
221
229
|
*/
|
|
222
230
|
private _updataNodeType() {
|
|
223
231
|
this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval)
|
|
@@ -237,14 +245,15 @@ export class BroadcastChannelManager {
|
|
|
237
245
|
private _timeoutToBeMainNode() {
|
|
238
246
|
this._mainNodeMsgTimeoutTimer && clearTimeout(this._mainNodeMsgTimeoutTimer)
|
|
239
247
|
// 超时未收到心跳,认为主节点掉线,申请为主节点
|
|
248
|
+
// If no heartbeat is received after the timeout, the master node is considered to be offline and the master node is applied
|
|
240
249
|
this._mainNodeMsgTimeoutTimer = setTimeout(() => {
|
|
241
250
|
this._req_beMainNode()
|
|
242
251
|
}, MessageTimeout * 3)
|
|
243
252
|
}
|
|
244
253
|
|
|
245
254
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
255
|
+
* 保存最新的节点列表到_oldFrendChannelIdList,清空_friendChannelIdSet
|
|
256
|
+
* Save the latest node list to _oldFrendChannelIdList and clear _friendChannelIdSet
|
|
248
257
|
*/
|
|
249
258
|
private _catchOldFriend() {
|
|
250
259
|
const newFriendList = this._getNewFriendList()
|
|
@@ -259,7 +268,7 @@ export class BroadcastChannelManager {
|
|
|
259
268
|
}
|
|
260
269
|
|
|
261
270
|
if (this._nodeType === BcConnectNodeTypeEnum.Main && Math.min(...this._oldFrendChannelIdList) < this.id) {
|
|
262
|
-
// 有更小的id,不再为主节点
|
|
271
|
+
// 有更小的id,不再为主节点 | Has a smaller id and is no longer a master node
|
|
263
272
|
this._setNodeType(BcConnectNodeTypeEnum.Normal)
|
|
264
273
|
}
|
|
265
274
|
|
|
@@ -267,20 +276,22 @@ export class BroadcastChannelManager {
|
|
|
267
276
|
}
|
|
268
277
|
|
|
269
278
|
/**
|
|
270
|
-
* 申请成为主节点
|
|
279
|
+
* 申请成为主节点 | Apply to be a master node
|
|
271
280
|
*/
|
|
272
281
|
private _req_beMainNode() {
|
|
273
282
|
this._debug && console.log('BC:req_beMainNode')
|
|
274
283
|
|
|
275
|
-
//
|
|
284
|
+
// 向所有节点申请成为主节点 | Apply to all nodes to become master nodes
|
|
276
285
|
this.send(BcConnectEventTypeEnum.Req_Be_Main_Node)
|
|
277
286
|
|
|
278
287
|
// 如果长时间未回复,认为自己可以当主节点
|
|
288
|
+
// If there is no reply for a long time, it considers itself to be the master
|
|
279
289
|
const timer = setTimeout(() => {
|
|
280
290
|
this._setNodeType(BcConnectNodeTypeEnum.Main)
|
|
281
291
|
}, MessageTimeout)
|
|
282
292
|
|
|
283
293
|
// 收到拒绝回复,清空timeout
|
|
294
|
+
// Clear the timeout when you receive a rejection reply
|
|
284
295
|
const handleRes_beMainNode = () => {
|
|
285
296
|
clearTimeout(timer)
|
|
286
297
|
this.off(BcConnectEventTypeEnum.Res_Be_Main_Node, handleRes_beMainNode)
|
|
@@ -290,8 +301,8 @@ export class BroadcastChannelManager {
|
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
/**
|
|
293
|
-
*
|
|
294
|
-
* @param id
|
|
304
|
+
* add node
|
|
305
|
+
* @param id id
|
|
295
306
|
*/
|
|
296
307
|
public _addFriend(id: number) {
|
|
297
308
|
if (!this._friendChannelIdSet.has(id)) {
|
|
@@ -300,9 +311,9 @@ export class BroadcastChannelManager {
|
|
|
300
311
|
}
|
|
301
312
|
|
|
302
313
|
/**
|
|
303
|
-
* 广播消息
|
|
304
|
-
* @param type 消息类型
|
|
305
|
-
* @param data 数据
|
|
314
|
+
* 广播消息 | Send Broadcast message
|
|
315
|
+
* @param type 消息类型 | Message type
|
|
316
|
+
* @param data 数据 | data
|
|
306
317
|
*/
|
|
307
318
|
public send(type: string, data?: any) {
|
|
308
319
|
this._broadcastChannel?.postMessage({
|
|
@@ -313,10 +324,10 @@ export class BroadcastChannelManager {
|
|
|
313
324
|
}
|
|
314
325
|
|
|
315
326
|
/**
|
|
316
|
-
* 给特定id的节点发送消息
|
|
317
|
-
* @param type 消息类型
|
|
318
|
-
* @param targetId 目标节点id
|
|
319
|
-
* @param data 数据
|
|
327
|
+
* 给特定id的节点发送消息 | Send a message to a node with a specific id
|
|
328
|
+
* @param type 消息类型 | Message type
|
|
329
|
+
* @param targetId 目标节点id | Target Node id
|
|
330
|
+
* @param data 数据 | data
|
|
320
331
|
*/
|
|
321
332
|
public sendToTarget(type: string, targetId: number, data?: any) {
|
|
322
333
|
this._broadcastChannel?.postMessage({
|
|
@@ -328,9 +339,9 @@ export class BroadcastChannelManager {
|
|
|
328
339
|
}
|
|
329
340
|
|
|
330
341
|
/**
|
|
331
|
-
* 注册事件
|
|
332
|
-
* @param { string } event 事件类型
|
|
333
|
-
* @param callback 回调
|
|
342
|
+
* 注册事件 | Registering events
|
|
343
|
+
* @param { string } event 事件类型 | Event type
|
|
344
|
+
* @param callback 回调 | callback
|
|
334
345
|
* @returns void
|
|
335
346
|
*/
|
|
336
347
|
public on(event: string, callback: (_: BcConnectSendMessageType) => void) {
|
|
@@ -347,9 +358,9 @@ export class BroadcastChannelManager {
|
|
|
347
358
|
}
|
|
348
359
|
|
|
349
360
|
/**
|
|
350
|
-
* 注销事件
|
|
351
|
-
* @param { string } event 事件类型
|
|
352
|
-
* @param callback 事件回调
|
|
361
|
+
* 注销事件 | Remove events
|
|
362
|
+
* @param { string } event 事件类型 | Event type
|
|
363
|
+
* @param callback 事件回调 | callback
|
|
353
364
|
* @returns
|
|
354
365
|
*/
|
|
355
366
|
public off(event: string, callback?: (_: BcConnectSendMessageType) => void) {
|
|
@@ -368,9 +379,9 @@ export class BroadcastChannelManager {
|
|
|
368
379
|
}
|
|
369
380
|
|
|
370
381
|
/**
|
|
371
|
-
* 触发事件
|
|
372
|
-
* @param { string } event 事件类型
|
|
373
|
-
* @param data 数据
|
|
382
|
+
* 触发事件 | Triggering events
|
|
383
|
+
* @param { string } event 事件类型 | Event type
|
|
384
|
+
* @param data 数据 | data
|
|
374
385
|
*/
|
|
375
386
|
public emit(event: string, data: BcConnectSendMessageType) {
|
|
376
387
|
const callbacks = this._eventMap.get(event) || []
|
|
@@ -381,7 +392,7 @@ export class BroadcastChannelManager {
|
|
|
381
392
|
}
|
|
382
393
|
|
|
383
394
|
/**
|
|
384
|
-
* 销毁
|
|
395
|
+
* 销毁 | destroy
|
|
385
396
|
*/
|
|
386
397
|
public destroy() {
|
|
387
398
|
this._bcName = ''
|