@havue/solutions 1.1.1 → 1.2.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/bc-connect/__tests__/bc-connect.spec.ts +73 -0
- package/bc-connect/dist/bc-connect.mjs +89 -73
- package/bc-connect/dist/bc-connect.umd.js +89 -73
- package/bc-connect/dist/types/src/manager.d.ts +72 -62
- package/bc-connect/package.json +1 -1
- package/bc-connect/src/manager.ts +103 -78
- package/dist/solutions.full.js +156 -127
- 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 +72 -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
|
@@ -6,14 +6,14 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
7
|
|
|
8
8
|
var BcConnectEventTypeEnum = /* @__PURE__ */ ((BcConnectEventTypeEnum2) => {
|
|
9
|
-
BcConnectEventTypeEnum2["Broadcast"] = "
|
|
10
|
-
BcConnectEventTypeEnum2["Broadcast_Reply"] = "
|
|
11
|
-
BcConnectEventTypeEnum2["Main_Node_Hearbeat"] = "
|
|
12
|
-
BcConnectEventTypeEnum2["Res_Main_Node_Hearbeat"] = "
|
|
13
|
-
BcConnectEventTypeEnum2["Req_Be_Main_Node"] = "
|
|
14
|
-
BcConnectEventTypeEnum2["Res_Be_Main_Node"] = "
|
|
15
|
-
BcConnectEventTypeEnum2["Node_Type_Change"] = "
|
|
16
|
-
BcConnectEventTypeEnum2["Friend_List_Update"] = "
|
|
9
|
+
BcConnectEventTypeEnum2["Broadcast"] = "__BCM_INIT__";
|
|
10
|
+
BcConnectEventTypeEnum2["Broadcast_Reply"] = "__BCM_INIT_REPLY__";
|
|
11
|
+
BcConnectEventTypeEnum2["Main_Node_Hearbeat"] = "__BCM_MAIN_NODE_HEARBEAT__";
|
|
12
|
+
BcConnectEventTypeEnum2["Res_Main_Node_Hearbeat"] = "__BCM_MAIN_NODE_HEARBEAT_REPLY__";
|
|
13
|
+
BcConnectEventTypeEnum2["Req_Be_Main_Node"] = "__BCM_REQ_BE_MAIN_NODE__";
|
|
14
|
+
BcConnectEventTypeEnum2["Res_Be_Main_Node"] = "__BCM_REQ_BE_MAIN_NODE_REJECT__";
|
|
15
|
+
BcConnectEventTypeEnum2["Node_Type_Change"] = "__BCM_NODE_TYPE_CHANGE__";
|
|
16
|
+
BcConnectEventTypeEnum2["Friend_List_Update"] = "__BCM_FRIEND_LIST_UPDATE__";
|
|
17
17
|
return BcConnectEventTypeEnum2;
|
|
18
18
|
})(BcConnectEventTypeEnum || {});
|
|
19
19
|
var BcConnectNodeTypeEnum = /* @__PURE__ */ ((BcConnectNodeTypeEnum2) => {
|
|
@@ -24,25 +24,30 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
24
24
|
const MessageTimeout = 300;
|
|
25
25
|
class BroadcastChannelManager {
|
|
26
26
|
constructor(name, debug = false) {
|
|
27
|
-
/** 通道名称 */
|
|
27
|
+
/** 通道名称 | Channel name */
|
|
28
28
|
__publicField(this, "_bcName");
|
|
29
|
-
/** BroadcastChannel
|
|
29
|
+
/** BroadcastChannel instance */
|
|
30
30
|
__publicField(this, "_broadcastChannel");
|
|
31
|
-
/**
|
|
31
|
+
/** Event map */
|
|
32
32
|
__publicField(this, "_eventMap");
|
|
33
|
-
/** 主节点发送心跳的interval */
|
|
33
|
+
/** 主节点发送心跳的interval | The interval at which the master node sends the heartbeat */
|
|
34
34
|
__publicField(this, "_mainNodeMsgInterval", null);
|
|
35
|
-
/** 认为主节点掉线的timeout */
|
|
36
|
-
__publicField(this, "
|
|
37
|
-
/**
|
|
35
|
+
/** 认为主节点掉线的timeout | timeout to consider the primary node to be offline */
|
|
36
|
+
__publicField(this, "_mainNodeMsgTimeoutTimer", null);
|
|
37
|
+
/** 更新友方列表的timeout | Update the timeout of the friend list */
|
|
38
|
+
__publicField(this, "_updateFriendListTimer", null);
|
|
39
|
+
/** 当前实例id | Current instance id */
|
|
38
40
|
__publicField(this, "id", Date.now() + Math.random());
|
|
39
|
-
/**
|
|
41
|
+
/** 其他广播通道id列表 | List of other broadcast channel ids */
|
|
40
42
|
__publicField(this, "_oldFrendChannelIdList", []);
|
|
41
|
-
/**
|
|
43
|
+
/** 正在更新的id数组 | The id array being updated */
|
|
42
44
|
__publicField(this, "_friendChannelIdSet", /* @__PURE__ */ new Set());
|
|
43
|
-
/** 当前节点类型 */
|
|
45
|
+
/** 当前节点类型 | Current node type */
|
|
44
46
|
__publicField(this, "_nodeType");
|
|
45
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* 是否开启调试模式,会在控制台打印相关信息
|
|
49
|
+
* If debug mode is enabled, it will print information to the console
|
|
50
|
+
*/
|
|
46
51
|
__publicField(this, "_debug", false);
|
|
47
52
|
this._debug = debug;
|
|
48
53
|
this._bcName = name;
|
|
@@ -65,9 +70,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
65
70
|
close() {
|
|
66
71
|
this._debug && console.log("BC:bc close");
|
|
67
72
|
this._broadcastChannel && this._broadcastChannel.close();
|
|
73
|
+
this._broadcastChannel = void 0;
|
|
74
|
+
this._updateFriendListTimer && clearTimeout(this._updateFriendListTimer);
|
|
75
|
+
this._updateFriendListTimer = null;
|
|
76
|
+
this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
|
|
77
|
+
this._mainNodeMsgInterval = null;
|
|
78
|
+
this._mainNodeMsgTimeoutTimer && clearTimeout(this._mainNodeMsgTimeoutTimer);
|
|
79
|
+
this._mainNodeMsgTimeoutTimer = null;
|
|
80
|
+
this._oldFrendChannelIdList = [];
|
|
81
|
+
this._friendChannelIdSet.clear();
|
|
82
|
+
this._nodeType = void 0;
|
|
68
83
|
}
|
|
69
84
|
/**
|
|
70
|
-
* 切换节点类型
|
|
85
|
+
* 切换节点类型 | Switching node type
|
|
71
86
|
* @param {BcConnectNodeTypeEnum} type
|
|
72
87
|
* @returns
|
|
73
88
|
*/
|
|
@@ -76,30 +91,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
76
91
|
return;
|
|
77
92
|
}
|
|
78
93
|
this._nodeType = type;
|
|
79
|
-
this.emit("
|
|
80
|
-
type: "
|
|
94
|
+
this.emit("__BCM_NODE_TYPE_CHANGE__", {
|
|
95
|
+
type: "__BCM_NODE_TYPE_CHANGE__",
|
|
81
96
|
data: type,
|
|
82
97
|
id: this.id
|
|
83
98
|
});
|
|
84
99
|
}
|
|
85
|
-
/**
|
|
100
|
+
/** 更新广播id列表 | Update the list of broadcast ids */
|
|
86
101
|
_updateFriendList() {
|
|
87
102
|
this.send(
|
|
88
|
-
"
|
|
103
|
+
"__BCM_INIT__"
|
|
89
104
|
/* Broadcast */
|
|
90
105
|
);
|
|
91
|
-
|
|
106
|
+
this._updateFriendListTimer && clearTimeout(this._updateFriendListTimer);
|
|
107
|
+
this._updateFriendListTimer = setTimeout(() => {
|
|
92
108
|
this._oldFrendChannelIdList = this._getNewFriendList();
|
|
93
109
|
this._debug && console.log("BC:connect:updateFriendChannelIdList:", this._oldFrendChannelIdList);
|
|
94
|
-
this.emit("
|
|
95
|
-
type: "
|
|
110
|
+
this.emit("__BCM_FRIEND_LIST_UPDATE__", {
|
|
111
|
+
type: "__BCM_FRIEND_LIST_UPDATE__",
|
|
96
112
|
data: [...this._oldFrendChannelIdList],
|
|
97
113
|
id: this.id
|
|
98
114
|
});
|
|
99
115
|
this._updataNodeType();
|
|
100
116
|
}, MessageTimeout);
|
|
101
117
|
}
|
|
102
|
-
/** 绑定事件 */
|
|
118
|
+
/** 绑定事件 | Bind event */
|
|
103
119
|
_bindBroadcastChannelEvent() {
|
|
104
120
|
this._broadcastChannel && (this._broadcastChannel.onmessage = (event) => {
|
|
105
121
|
const { type, targetId } = event.data;
|
|
@@ -108,63 +124,63 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
108
124
|
}
|
|
109
125
|
this.emit(type, event.data);
|
|
110
126
|
});
|
|
111
|
-
this.on("
|
|
127
|
+
this.on("__BCM_INIT__", (data) => {
|
|
112
128
|
const { id } = data;
|
|
113
129
|
if (!this._friendChannelIdSet.has(id)) {
|
|
114
130
|
this._friendChannelIdSet.add(id);
|
|
115
131
|
}
|
|
116
|
-
this.sendToTarget("
|
|
132
|
+
this.sendToTarget("__BCM_INIT_REPLY__", id);
|
|
117
133
|
});
|
|
118
|
-
this.on("
|
|
134
|
+
this.on("__BCM_INIT_REPLY__", (data) => {
|
|
119
135
|
const { id } = data;
|
|
120
136
|
this._addFriend(id);
|
|
121
137
|
});
|
|
122
|
-
this.on("
|
|
138
|
+
this.on("__BCM_REQ_BE_MAIN_NODE__", (data) => {
|
|
123
139
|
const { id } = data;
|
|
124
140
|
if (id > this.id) {
|
|
125
|
-
this.sendToTarget("
|
|
141
|
+
this.sendToTarget("__BCM_REQ_BE_MAIN_NODE_REJECT__", id);
|
|
126
142
|
}
|
|
127
143
|
});
|
|
128
|
-
this.on("
|
|
144
|
+
this.on("__BCM_MAIN_NODE_HEARBEAT_REPLY__", (data) => {
|
|
129
145
|
this._addFriend(data.id);
|
|
130
146
|
});
|
|
131
147
|
this._bindNodeEvent();
|
|
132
148
|
}
|
|
133
|
-
/** 监听节点类型切换事件 */
|
|
149
|
+
/** 监听节点类型切换事件 | */
|
|
134
150
|
_bindNodeEvent() {
|
|
135
151
|
const onMainNodeHearbeat = (data) => {
|
|
136
152
|
this._timeoutToBeMainNode();
|
|
137
153
|
this._catchOldFriend();
|
|
138
154
|
this._addFriend(data.id);
|
|
139
155
|
this.send(
|
|
140
|
-
"
|
|
156
|
+
"__BCM_MAIN_NODE_HEARBEAT_REPLY__"
|
|
141
157
|
/* Res_Main_Node_Hearbeat */
|
|
142
158
|
);
|
|
143
159
|
};
|
|
144
|
-
this.on("
|
|
160
|
+
this.on("__BCM_NODE_TYPE_CHANGE__", (info) => {
|
|
145
161
|
const { data } = info;
|
|
146
162
|
this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
|
|
147
|
-
this._debug && console.log("BC
|
|
163
|
+
this._debug && console.log("BC:NODE_TYPE_CHANGE:", info.data);
|
|
148
164
|
if (data === "main") {
|
|
149
165
|
this._mainNodeMsgInterval = setInterval(() => {
|
|
150
166
|
this._catchOldFriend();
|
|
151
167
|
this.send(
|
|
152
|
-
"
|
|
168
|
+
"__BCM_MAIN_NODE_HEARBEAT__"
|
|
153
169
|
/* Main_Node_Hearbeat */
|
|
154
170
|
);
|
|
155
171
|
}, MessageTimeout);
|
|
156
172
|
} else if (data === "normal") {
|
|
157
173
|
this._timeoutToBeMainNode();
|
|
158
174
|
}
|
|
159
|
-
this.on("
|
|
175
|
+
this.on("__BCM_MAIN_NODE_HEARBEAT__", onMainNodeHearbeat);
|
|
160
176
|
});
|
|
161
177
|
}
|
|
162
|
-
/**
|
|
178
|
+
/** 获取最新的节点列表 | Get the latest node list */
|
|
163
179
|
_getNewFriendList() {
|
|
164
180
|
return [...this._friendChannelIdSet].sort((a, b) => a - b);
|
|
165
181
|
}
|
|
166
182
|
/**
|
|
167
|
-
* 更新当前节点类型
|
|
183
|
+
* 更新当前节点类型 | Update the current node type
|
|
168
184
|
*/
|
|
169
185
|
_updataNodeType() {
|
|
170
186
|
this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
|
|
@@ -187,21 +203,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
187
203
|
}
|
|
188
204
|
}
|
|
189
205
|
_timeoutToBeMainNode() {
|
|
190
|
-
this.
|
|
191
|
-
this.
|
|
206
|
+
this._mainNodeMsgTimeoutTimer && clearTimeout(this._mainNodeMsgTimeoutTimer);
|
|
207
|
+
this._mainNodeMsgTimeoutTimer = setTimeout(() => {
|
|
192
208
|
this._req_beMainNode();
|
|
193
209
|
}, MessageTimeout * 3);
|
|
194
210
|
}
|
|
195
211
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
212
|
+
* 保存最新的节点列表到_oldFrendChannelIdList,清空_friendChannelIdSet
|
|
213
|
+
* Save the latest node list to _oldFrendChannelIdList and clear _friendChannelIdSet
|
|
198
214
|
*/
|
|
199
215
|
_catchOldFriend() {
|
|
200
216
|
const newFriendList = this._getNewFriendList();
|
|
201
217
|
if (this._oldFrendChannelIdList.join() !== newFriendList.join()) {
|
|
202
218
|
this._debug && console.log("BC:updateFriendChannelIdList:", newFriendList);
|
|
203
|
-
this.emit("
|
|
204
|
-
type: "
|
|
219
|
+
this.emit("__BCM_FRIEND_LIST_UPDATE__", {
|
|
220
|
+
type: "__BCM_FRIEND_LIST_UPDATE__",
|
|
205
221
|
data: [...newFriendList],
|
|
206
222
|
id: this.id
|
|
207
223
|
});
|
|
@@ -216,12 +232,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
216
232
|
this._friendChannelIdSet.clear();
|
|
217
233
|
}
|
|
218
234
|
/**
|
|
219
|
-
* 申请成为主节点
|
|
235
|
+
* 申请成为主节点 | Apply to be a master node
|
|
220
236
|
*/
|
|
221
237
|
_req_beMainNode() {
|
|
222
238
|
this._debug && console.log("BC:req_beMainNode");
|
|
223
239
|
this.send(
|
|
224
|
-
"
|
|
240
|
+
"__BCM_REQ_BE_MAIN_NODE__"
|
|
225
241
|
/* Req_Be_Main_Node */
|
|
226
242
|
);
|
|
227
243
|
const timer = setTimeout(() => {
|
|
@@ -232,13 +248,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
232
248
|
}, MessageTimeout);
|
|
233
249
|
const handleRes_beMainNode = () => {
|
|
234
250
|
clearTimeout(timer);
|
|
235
|
-
this.off("
|
|
251
|
+
this.off("__BCM_REQ_BE_MAIN_NODE_REJECT__", handleRes_beMainNode);
|
|
236
252
|
};
|
|
237
|
-
this.on("
|
|
253
|
+
this.on("__BCM_REQ_BE_MAIN_NODE_REJECT__", handleRes_beMainNode);
|
|
238
254
|
}
|
|
239
255
|
/**
|
|
240
|
-
*
|
|
241
|
-
* @param id
|
|
256
|
+
* add node
|
|
257
|
+
* @param id id
|
|
242
258
|
*/
|
|
243
259
|
_addFriend(id) {
|
|
244
260
|
if (!this._friendChannelIdSet.has(id)) {
|
|
@@ -246,9 +262,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
246
262
|
}
|
|
247
263
|
}
|
|
248
264
|
/**
|
|
249
|
-
* 广播消息
|
|
250
|
-
* @param type 消息类型
|
|
251
|
-
* @param data 数据
|
|
265
|
+
* 广播消息 | Send Broadcast message
|
|
266
|
+
* @param type 消息类型 | Message type
|
|
267
|
+
* @param data 数据 | data
|
|
252
268
|
*/
|
|
253
269
|
send(type, data) {
|
|
254
270
|
var _a;
|
|
@@ -259,10 +275,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
259
275
|
});
|
|
260
276
|
}
|
|
261
277
|
/**
|
|
262
|
-
* 给特定id的节点发送消息
|
|
263
|
-
* @param type 消息类型
|
|
264
|
-
* @param targetId 目标节点id
|
|
265
|
-
* @param data 数据
|
|
278
|
+
* 给特定id的节点发送消息 | Send a message to a node with a specific id
|
|
279
|
+
* @param type 消息类型 | Message type
|
|
280
|
+
* @param targetId 目标节点id | Target Node id
|
|
281
|
+
* @param data 数据 | data
|
|
266
282
|
*/
|
|
267
283
|
sendToTarget(type, targetId, data) {
|
|
268
284
|
var _a;
|
|
@@ -274,9 +290,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
274
290
|
});
|
|
275
291
|
}
|
|
276
292
|
/**
|
|
277
|
-
* 注册事件
|
|
278
|
-
* @param { string } event 事件类型
|
|
279
|
-
* @param callback 回调
|
|
293
|
+
* 注册事件 | Registering events
|
|
294
|
+
* @param { string } event 事件类型 | Event type
|
|
295
|
+
* @param callback 回调 | callback
|
|
280
296
|
* @returns void
|
|
281
297
|
*/
|
|
282
298
|
on(event, callback) {
|
|
@@ -291,9 +307,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
291
307
|
callbacks.push(callback);
|
|
292
308
|
}
|
|
293
309
|
/**
|
|
294
|
-
* 注销事件
|
|
295
|
-
* @param { string } event 事件类型
|
|
296
|
-
* @param callback 事件回调
|
|
310
|
+
* 注销事件 | Remove events
|
|
311
|
+
* @param { string } event 事件类型 | Event type
|
|
312
|
+
* @param callback 事件回调 | callback
|
|
297
313
|
* @returns
|
|
298
314
|
*/
|
|
299
315
|
off(event, callback) {
|
|
@@ -309,9 +325,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
309
325
|
callbacks.splice(index, 1);
|
|
310
326
|
}
|
|
311
327
|
/**
|
|
312
|
-
* 触发事件
|
|
313
|
-
* @param { string } event 事件类型
|
|
314
|
-
* @param data 数据
|
|
328
|
+
* 触发事件 | Triggering events
|
|
329
|
+
* @param { string } event 事件类型 | Event type
|
|
330
|
+
* @param data 数据 | data
|
|
315
331
|
*/
|
|
316
332
|
emit(event, data) {
|
|
317
333
|
const callbacks = this._eventMap.get(event) || [];
|
|
@@ -320,7 +336,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
320
336
|
});
|
|
321
337
|
}
|
|
322
338
|
/**
|
|
323
|
-
* 销毁
|
|
339
|
+
* 销毁 | destroy
|
|
324
340
|
*/
|
|
325
341
|
destroy() {
|
|
326
342
|
var _a;
|
|
@@ -334,8 +350,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
334
350
|
this._nodeType = void 0;
|
|
335
351
|
this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
|
|
336
352
|
this._mainNodeMsgInterval = null;
|
|
337
|
-
this.
|
|
338
|
-
this.
|
|
353
|
+
this._mainNodeMsgTimeoutTimer && clearInterval(this._mainNodeMsgTimeoutTimer);
|
|
354
|
+
this._mainNodeMsgTimeoutTimer = null;
|
|
339
355
|
this._debug && console.log("BC:destroy");
|
|
340
356
|
}
|
|
341
357
|
}
|
|
@@ -1,61 +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 */
|
|
49
|
-
private
|
|
50
|
-
/**
|
|
53
|
+
/** 认为主节点掉线的timeout | timeout to consider the primary node to be offline */
|
|
54
|
+
private _mainNodeMsgTimeoutTimer;
|
|
55
|
+
/** 更新友方列表的timeout | Update the timeout of the friend list */
|
|
56
|
+
private _updateFriendListTimer;
|
|
57
|
+
/** 当前实例id | Current instance id */
|
|
51
58
|
id: number;
|
|
52
|
-
/**
|
|
59
|
+
/** 其他广播通道id列表 | List of other broadcast channel ids */
|
|
53
60
|
private _oldFrendChannelIdList;
|
|
54
|
-
/**
|
|
61
|
+
/** 正在更新的id数组 | The id array being updated */
|
|
55
62
|
private _friendChannelIdSet;
|
|
56
|
-
/** 当前节点类型 */
|
|
63
|
+
/** 当前节点类型 | Current node type */
|
|
57
64
|
private _nodeType;
|
|
58
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* 是否开启调试模式,会在控制台打印相关信息
|
|
67
|
+
* If debug mode is enabled, it will print information to the console
|
|
68
|
+
*/
|
|
59
69
|
private _debug;
|
|
60
70
|
constructor(name: string, debug?: boolean);
|
|
61
71
|
get nodeType(): BcConnectNodeTypeEnum | undefined;
|
|
@@ -63,73 +73,73 @@ export declare class BroadcastChannelManager {
|
|
|
63
73
|
connect(): void;
|
|
64
74
|
close(): void;
|
|
65
75
|
/**
|
|
66
|
-
* 切换节点类型
|
|
76
|
+
* 切换节点类型 | Switching node type
|
|
67
77
|
* @param {BcConnectNodeTypeEnum} type
|
|
68
78
|
* @returns
|
|
69
79
|
*/
|
|
70
80
|
private _setNodeType;
|
|
71
|
-
/**
|
|
81
|
+
/** 更新广播id列表 | Update the list of broadcast ids */
|
|
72
82
|
private _updateFriendList;
|
|
73
|
-
/** 绑定事件 */
|
|
83
|
+
/** 绑定事件 | Bind event */
|
|
74
84
|
private _bindBroadcastChannelEvent;
|
|
75
|
-
/** 监听节点类型切换事件 */
|
|
85
|
+
/** 监听节点类型切换事件 | */
|
|
76
86
|
private _bindNodeEvent;
|
|
77
|
-
/**
|
|
87
|
+
/** 获取最新的节点列表 | Get the latest node list */
|
|
78
88
|
private _getNewFriendList;
|
|
79
89
|
/**
|
|
80
|
-
* 更新当前节点类型
|
|
90
|
+
* 更新当前节点类型 | Update the current node type
|
|
81
91
|
*/
|
|
82
92
|
private _updataNodeType;
|
|
83
93
|
private _timeoutToBeMainNode;
|
|
84
94
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
95
|
+
* 保存最新的节点列表到_oldFrendChannelIdList,清空_friendChannelIdSet
|
|
96
|
+
* Save the latest node list to _oldFrendChannelIdList and clear _friendChannelIdSet
|
|
87
97
|
*/
|
|
88
98
|
private _catchOldFriend;
|
|
89
99
|
/**
|
|
90
|
-
* 申请成为主节点
|
|
100
|
+
* 申请成为主节点 | Apply to be a master node
|
|
91
101
|
*/
|
|
92
102
|
private _req_beMainNode;
|
|
93
103
|
/**
|
|
94
|
-
*
|
|
95
|
-
* @param id
|
|
104
|
+
* add node
|
|
105
|
+
* @param id id
|
|
96
106
|
*/
|
|
97
107
|
_addFriend(id: number): void;
|
|
98
108
|
/**
|
|
99
|
-
* 广播消息
|
|
100
|
-
* @param type 消息类型
|
|
101
|
-
* @param data 数据
|
|
109
|
+
* 广播消息 | Send Broadcast message
|
|
110
|
+
* @param type 消息类型 | Message type
|
|
111
|
+
* @param data 数据 | data
|
|
102
112
|
*/
|
|
103
113
|
send(type: string, data?: any): void;
|
|
104
114
|
/**
|
|
105
|
-
* 给特定id的节点发送消息
|
|
106
|
-
* @param type 消息类型
|
|
107
|
-
* @param targetId 目标节点id
|
|
108
|
-
* @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
|
|
109
119
|
*/
|
|
110
120
|
sendToTarget(type: string, targetId: number, data?: any): void;
|
|
111
121
|
/**
|
|
112
|
-
* 注册事件
|
|
113
|
-
* @param { string } event 事件类型
|
|
114
|
-
* @param callback 回调
|
|
122
|
+
* 注册事件 | Registering events
|
|
123
|
+
* @param { string } event 事件类型 | Event type
|
|
124
|
+
* @param callback 回调 | callback
|
|
115
125
|
* @returns void
|
|
116
126
|
*/
|
|
117
127
|
on(event: string, callback: (_: BcConnectSendMessageType) => void): void;
|
|
118
128
|
/**
|
|
119
|
-
* 注销事件
|
|
120
|
-
* @param { string } event 事件类型
|
|
121
|
-
* @param callback 事件回调
|
|
129
|
+
* 注销事件 | Remove events
|
|
130
|
+
* @param { string } event 事件类型 | Event type
|
|
131
|
+
* @param callback 事件回调 | callback
|
|
122
132
|
* @returns
|
|
123
133
|
*/
|
|
124
134
|
off(event: string, callback?: (_: BcConnectSendMessageType) => void): void;
|
|
125
135
|
/**
|
|
126
|
-
* 触发事件
|
|
127
|
-
* @param { string } event 事件类型
|
|
128
|
-
* @param data 数据
|
|
136
|
+
* 触发事件 | Triggering events
|
|
137
|
+
* @param { string } event 事件类型 | Event type
|
|
138
|
+
* @param data 数据 | data
|
|
129
139
|
*/
|
|
130
140
|
emit(event: string, data: BcConnectSendMessageType): void;
|
|
131
141
|
/**
|
|
132
|
-
* 销毁
|
|
142
|
+
* 销毁 | destroy
|
|
133
143
|
*/
|
|
134
144
|
destroy(): void;
|
|
135
145
|
}
|