@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.
@@ -2,14 +2,14 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  var BcConnectEventTypeEnum = /* @__PURE__ */ ((BcConnectEventTypeEnum2) => {
5
- BcConnectEventTypeEnum2["Broadcast"] = "Hello world";
6
- BcConnectEventTypeEnum2["Broadcast_Reply"] = "I can hear you";
7
- BcConnectEventTypeEnum2["Main_Node_Hearbeat"] = "苍天还在,别立黄天";
8
- BcConnectEventTypeEnum2["Res_Main_Node_Hearbeat"] = "苍天在上,受我一拜";
9
- BcConnectEventTypeEnum2["Req_Be_Main_Node"] = "苍天已死,黄天当立";
10
- BcConnectEventTypeEnum2["Res_Be_Main_Node"] = "我是黄天,尔等退下";
11
- BcConnectEventTypeEnum2["Node_Type_Change"] = "node type change";
12
- BcConnectEventTypeEnum2["Friend_List_Update"] = "friend list update";
5
+ BcConnectEventTypeEnum2["Broadcast"] = "__BCM_INIT__";
6
+ BcConnectEventTypeEnum2["Broadcast_Reply"] = "__BCM_INIT_REPLY__";
7
+ BcConnectEventTypeEnum2["Main_Node_Hearbeat"] = "__BCM_MAIN_NODE_HEARBEAT__";
8
+ BcConnectEventTypeEnum2["Res_Main_Node_Hearbeat"] = "__BCM_MAIN_NODE_HEARBEAT_REPLY__";
9
+ BcConnectEventTypeEnum2["Req_Be_Main_Node"] = "__BCM_REQ_BE_MAIN_NODE__";
10
+ BcConnectEventTypeEnum2["Res_Be_Main_Node"] = "__BCM_REQ_BE_MAIN_NODE_REJECT__";
11
+ BcConnectEventTypeEnum2["Node_Type_Change"] = "__BCM_NODE_TYPE_CHANGE__";
12
+ BcConnectEventTypeEnum2["Friend_List_Update"] = "__BCM_FRIEND_LIST_UPDATE__";
13
13
  return BcConnectEventTypeEnum2;
14
14
  })(BcConnectEventTypeEnum || {});
15
15
  var BcConnectNodeTypeEnum = /* @__PURE__ */ ((BcConnectNodeTypeEnum2) => {
@@ -20,27 +20,30 @@ var BcConnectNodeTypeEnum = /* @__PURE__ */ ((BcConnectNodeTypeEnum2) => {
20
20
  const MessageTimeout = 300;
21
21
  class BroadcastChannelManager {
22
22
  constructor(name, debug = false) {
23
- /** 通道名称 */
23
+ /** 通道名称 | Channel name */
24
24
  __publicField(this, "_bcName");
25
- /** BroadcastChannel实例 */
25
+ /** BroadcastChannel instance */
26
26
  __publicField(this, "_broadcastChannel");
27
- /** 事件map */
27
+ /** Event map */
28
28
  __publicField(this, "_eventMap");
29
- /** 主节点发送心跳的interval */
29
+ /** 主节点发送心跳的interval | The interval at which the master node sends the heartbeat */
30
30
  __publicField(this, "_mainNodeMsgInterval", null);
31
- /** 认为主节点掉线的timeout */
31
+ /** 认为主节点掉线的timeout | timeout to consider the primary node to be offline */
32
32
  __publicField(this, "_mainNodeMsgTimeoutTimer", null);
33
- /** 更新友方列表的timeout */
33
+ /** 更新友方列表的timeout | Update the timeout of the friend list */
34
34
  __publicField(this, "_updateFriendListTimer", null);
35
- /** 当前实例id */
35
+ /** 当前实例id | Current instance id */
36
36
  __publicField(this, "id", Date.now() + Math.random());
37
- /** 记录的友方id数组 */
37
+ /** 其他广播通道id列表 | List of other broadcast channel ids */
38
38
  __publicField(this, "_oldFrendChannelIdList", []);
39
- /** 正在更新的右方id数组 */
39
+ /** 正在更新的id数组 | The id array being updated */
40
40
  __publicField(this, "_friendChannelIdSet", /* @__PURE__ */ new Set());
41
- /** 当前节点类型 */
41
+ /** 当前节点类型 | Current node type */
42
42
  __publicField(this, "_nodeType");
43
- /** 是否开启调试模式,会在控制台打印相关信息 */
43
+ /**
44
+ * 是否开启调试模式,会在控制台打印相关信息
45
+ * If debug mode is enabled, it will print information to the console
46
+ */
44
47
  __publicField(this, "_debug", false);
45
48
  this._debug = debug;
46
49
  this._bcName = name;
@@ -75,7 +78,7 @@ class BroadcastChannelManager {
75
78
  this._nodeType = void 0;
76
79
  }
77
80
  /**
78
- * 切换节点类型
81
+ * 切换节点类型 | Switching node type
79
82
  * @param {BcConnectNodeTypeEnum} type
80
83
  * @returns
81
84
  */
@@ -84,31 +87,31 @@ class BroadcastChannelManager {
84
87
  return;
85
88
  }
86
89
  this._nodeType = type;
87
- this.emit("node type change", {
88
- type: "node type change",
90
+ this.emit("__BCM_NODE_TYPE_CHANGE__", {
91
+ type: "__BCM_NODE_TYPE_CHANGE__",
89
92
  data: type,
90
93
  id: this.id
91
94
  });
92
95
  }
93
- /** 更新友方列表 */
96
+ /** 更新广播id列表 | Update the list of broadcast ids */
94
97
  _updateFriendList() {
95
98
  this.send(
96
- "Hello world"
99
+ "__BCM_INIT__"
97
100
  /* Broadcast */
98
101
  );
99
102
  this._updateFriendListTimer && clearTimeout(this._updateFriendListTimer);
100
103
  this._updateFriendListTimer = setTimeout(() => {
101
104
  this._oldFrendChannelIdList = this._getNewFriendList();
102
105
  this._debug && console.log("BC:connect:updateFriendChannelIdList:", this._oldFrendChannelIdList);
103
- this.emit("friend list update", {
104
- type: "friend list update",
106
+ this.emit("__BCM_FRIEND_LIST_UPDATE__", {
107
+ type: "__BCM_FRIEND_LIST_UPDATE__",
105
108
  data: [...this._oldFrendChannelIdList],
106
109
  id: this.id
107
110
  });
108
111
  this._updataNodeType();
109
112
  }, MessageTimeout);
110
113
  }
111
- /** 绑定事件 */
114
+ /** 绑定事件 | Bind event */
112
115
  _bindBroadcastChannelEvent() {
113
116
  this._broadcastChannel && (this._broadcastChannel.onmessage = (event) => {
114
117
  const { type, targetId } = event.data;
@@ -117,63 +120,63 @@ class BroadcastChannelManager {
117
120
  }
118
121
  this.emit(type, event.data);
119
122
  });
120
- this.on("Hello world", (data) => {
123
+ this.on("__BCM_INIT__", (data) => {
121
124
  const { id } = data;
122
125
  if (!this._friendChannelIdSet.has(id)) {
123
126
  this._friendChannelIdSet.add(id);
124
127
  }
125
- this.sendToTarget("I can hear you", id);
128
+ this.sendToTarget("__BCM_INIT_REPLY__", id);
126
129
  });
127
- this.on("I can hear you", (data) => {
130
+ this.on("__BCM_INIT_REPLY__", (data) => {
128
131
  const { id } = data;
129
132
  this._addFriend(id);
130
133
  });
131
- this.on("苍天已死,黄天当立", (data) => {
134
+ this.on("__BCM_REQ_BE_MAIN_NODE__", (data) => {
132
135
  const { id } = data;
133
136
  if (id > this.id) {
134
- this.sendToTarget("我是黄天,尔等退下", id);
137
+ this.sendToTarget("__BCM_REQ_BE_MAIN_NODE_REJECT__", id);
135
138
  }
136
139
  });
137
- this.on("苍天在上,受我一拜", (data) => {
140
+ this.on("__BCM_MAIN_NODE_HEARBEAT_REPLY__", (data) => {
138
141
  this._addFriend(data.id);
139
142
  });
140
143
  this._bindNodeEvent();
141
144
  }
142
- /** 监听节点类型切换事件 */
145
+ /** 监听节点类型切换事件 | */
143
146
  _bindNodeEvent() {
144
147
  const onMainNodeHearbeat = (data) => {
145
148
  this._timeoutToBeMainNode();
146
149
  this._catchOldFriend();
147
150
  this._addFriend(data.id);
148
151
  this.send(
149
- "苍天在上,受我一拜"
152
+ "__BCM_MAIN_NODE_HEARBEAT_REPLY__"
150
153
  /* Res_Main_Node_Hearbeat */
151
154
  );
152
155
  };
153
- this.on("node type change", (info) => {
156
+ this.on("__BCM_NODE_TYPE_CHANGE__", (info) => {
154
157
  const { data } = info;
155
158
  this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
156
- this._debug && console.log("BC:代理类型切换:", info.data);
159
+ this._debug && console.log("BC:NODE_TYPE_CHANGE:", info.data);
157
160
  if (data === "main") {
158
161
  this._mainNodeMsgInterval = setInterval(() => {
159
162
  this._catchOldFriend();
160
163
  this.send(
161
- "苍天还在,别立黄天"
164
+ "__BCM_MAIN_NODE_HEARBEAT__"
162
165
  /* Main_Node_Hearbeat */
163
166
  );
164
167
  }, MessageTimeout);
165
168
  } else if (data === "normal") {
166
169
  this._timeoutToBeMainNode();
167
170
  }
168
- this.on("苍天还在,别立黄天", onMainNodeHearbeat);
171
+ this.on("__BCM_MAIN_NODE_HEARBEAT__", onMainNodeHearbeat);
169
172
  });
170
173
  }
171
- /** 获取最新的友方列表 */
174
+ /** 获取最新的节点列表 | Get the latest node list */
172
175
  _getNewFriendList() {
173
176
  return [...this._friendChannelIdSet].sort((a, b) => a - b);
174
177
  }
175
178
  /**
176
- * 更新当前节点类型
179
+ * 更新当前节点类型 | Update the current node type
177
180
  */
178
181
  _updataNodeType() {
179
182
  this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
@@ -202,15 +205,15 @@ class BroadcastChannelManager {
202
205
  }, MessageTimeout * 3);
203
206
  }
204
207
  /**
205
- * 保持记录的活跃的友方id列表
206
- * 清空正在记录的友方id列表
208
+ * 保存最新的节点列表到_oldFrendChannelIdList,清空_friendChannelIdSet
209
+ * Save the latest node list to _oldFrendChannelIdList and clear _friendChannelIdSet
207
210
  */
208
211
  _catchOldFriend() {
209
212
  const newFriendList = this._getNewFriendList();
210
213
  if (this._oldFrendChannelIdList.join() !== newFriendList.join()) {
211
214
  this._debug && console.log("BC:updateFriendChannelIdList:", newFriendList);
212
- this.emit("friend list update", {
213
- type: "friend list update",
215
+ this.emit("__BCM_FRIEND_LIST_UPDATE__", {
216
+ type: "__BCM_FRIEND_LIST_UPDATE__",
214
217
  data: [...newFriendList],
215
218
  id: this.id
216
219
  });
@@ -225,12 +228,12 @@ class BroadcastChannelManager {
225
228
  this._friendChannelIdSet.clear();
226
229
  }
227
230
  /**
228
- * 申请成为主节点
231
+ * 申请成为主节点 | Apply to be a master node
229
232
  */
230
233
  _req_beMainNode() {
231
234
  this._debug && console.log("BC:req_beMainNode");
232
235
  this.send(
233
- "苍天已死,黄天当立"
236
+ "__BCM_REQ_BE_MAIN_NODE__"
234
237
  /* Req_Be_Main_Node */
235
238
  );
236
239
  const timer = setTimeout(() => {
@@ -241,13 +244,13 @@ class BroadcastChannelManager {
241
244
  }, MessageTimeout);
242
245
  const handleRes_beMainNode = () => {
243
246
  clearTimeout(timer);
244
- this.off("我是黄天,尔等退下", handleRes_beMainNode);
247
+ this.off("__BCM_REQ_BE_MAIN_NODE_REJECT__", handleRes_beMainNode);
245
248
  };
246
- this.on("我是黄天,尔等退下", handleRes_beMainNode);
249
+ this.on("__BCM_REQ_BE_MAIN_NODE_REJECT__", handleRes_beMainNode);
247
250
  }
248
251
  /**
249
- * 添加友方
250
- * @param id 节点id
252
+ * add node
253
+ * @param id id
251
254
  */
252
255
  _addFriend(id) {
253
256
  if (!this._friendChannelIdSet.has(id)) {
@@ -255,9 +258,9 @@ class BroadcastChannelManager {
255
258
  }
256
259
  }
257
260
  /**
258
- * 广播消息
259
- * @param type 消息类型
260
- * @param data 数据
261
+ * 广播消息 | Send Broadcast message
262
+ * @param type 消息类型 | Message type
263
+ * @param data 数据 | data
261
264
  */
262
265
  send(type, data) {
263
266
  var _a;
@@ -268,10 +271,10 @@ class BroadcastChannelManager {
268
271
  });
269
272
  }
270
273
  /**
271
- * 给特定id的节点发送消息
272
- * @param type 消息类型
273
- * @param targetId 目标节点id
274
- * @param data 数据
274
+ * 给特定id的节点发送消息 | Send a message to a node with a specific id
275
+ * @param type 消息类型 | Message type
276
+ * @param targetId 目标节点id | Target Node id
277
+ * @param data 数据 | data
275
278
  */
276
279
  sendToTarget(type, targetId, data) {
277
280
  var _a;
@@ -283,9 +286,9 @@ class BroadcastChannelManager {
283
286
  });
284
287
  }
285
288
  /**
286
- * 注册事件
287
- * @param { string } event 事件类型
288
- * @param callback 回调
289
+ * 注册事件 | Registering events
290
+ * @param { string } event 事件类型 | Event type
291
+ * @param callback 回调 | callback
289
292
  * @returns void
290
293
  */
291
294
  on(event, callback) {
@@ -300,9 +303,9 @@ class BroadcastChannelManager {
300
303
  callbacks.push(callback);
301
304
  }
302
305
  /**
303
- * 注销事件
304
- * @param { string } event 事件类型
305
- * @param callback 事件回调
306
+ * 注销事件 | Remove events
307
+ * @param { string } event 事件类型 | Event type
308
+ * @param callback 事件回调 | callback
306
309
  * @returns
307
310
  */
308
311
  off(event, callback) {
@@ -318,9 +321,9 @@ class BroadcastChannelManager {
318
321
  callbacks.splice(index, 1);
319
322
  }
320
323
  /**
321
- * 触发事件
322
- * @param { string } event 事件类型
323
- * @param data 数据
324
+ * 触发事件 | Triggering events
325
+ * @param { string } event 事件类型 | Event type
326
+ * @param data 数据 | data
324
327
  */
325
328
  emit(event, data) {
326
329
  const callbacks = this._eventMap.get(event) || [];
@@ -329,7 +332,7 @@ class BroadcastChannelManager {
329
332
  });
330
333
  }
331
334
  /**
332
- * 销毁
335
+ * 销毁 | destroy
333
336
  */
334
337
  destroy() {
335
338
  var _a;
@@ -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"] = "Hello world";
10
- BcConnectEventTypeEnum2["Broadcast_Reply"] = "I can hear you";
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"] = "node type change";
16
- BcConnectEventTypeEnum2["Friend_List_Update"] = "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,27 +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
- /** 事件map */
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 */
35
+ /** 认为主节点掉线的timeout | timeout to consider the primary node to be offline */
36
36
  __publicField(this, "_mainNodeMsgTimeoutTimer", null);
37
- /** 更新友方列表的timeout */
37
+ /** 更新友方列表的timeout | Update the timeout of the friend list */
38
38
  __publicField(this, "_updateFriendListTimer", null);
39
- /** 当前实例id */
39
+ /** 当前实例id | Current instance id */
40
40
  __publicField(this, "id", Date.now() + Math.random());
41
- /** 记录的友方id数组 */
41
+ /** 其他广播通道id列表 | List of other broadcast channel ids */
42
42
  __publicField(this, "_oldFrendChannelIdList", []);
43
- /** 正在更新的右方id数组 */
43
+ /** 正在更新的id数组 | The id array being updated */
44
44
  __publicField(this, "_friendChannelIdSet", /* @__PURE__ */ new Set());
45
- /** 当前节点类型 */
45
+ /** 当前节点类型 | Current node type */
46
46
  __publicField(this, "_nodeType");
47
- /** 是否开启调试模式,会在控制台打印相关信息 */
47
+ /**
48
+ * 是否开启调试模式,会在控制台打印相关信息
49
+ * If debug mode is enabled, it will print information to the console
50
+ */
48
51
  __publicField(this, "_debug", false);
49
52
  this._debug = debug;
50
53
  this._bcName = name;
@@ -79,7 +82,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
79
82
  this._nodeType = void 0;
80
83
  }
81
84
  /**
82
- * 切换节点类型
85
+ * 切换节点类型 | Switching node type
83
86
  * @param {BcConnectNodeTypeEnum} type
84
87
  * @returns
85
88
  */
@@ -88,31 +91,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
88
91
  return;
89
92
  }
90
93
  this._nodeType = type;
91
- this.emit("node type change", {
92
- type: "node type change",
94
+ this.emit("__BCM_NODE_TYPE_CHANGE__", {
95
+ type: "__BCM_NODE_TYPE_CHANGE__",
93
96
  data: type,
94
97
  id: this.id
95
98
  });
96
99
  }
97
- /** 更新友方列表 */
100
+ /** 更新广播id列表 | Update the list of broadcast ids */
98
101
  _updateFriendList() {
99
102
  this.send(
100
- "Hello world"
103
+ "__BCM_INIT__"
101
104
  /* Broadcast */
102
105
  );
103
106
  this._updateFriendListTimer && clearTimeout(this._updateFriendListTimer);
104
107
  this._updateFriendListTimer = setTimeout(() => {
105
108
  this._oldFrendChannelIdList = this._getNewFriendList();
106
109
  this._debug && console.log("BC:connect:updateFriendChannelIdList:", this._oldFrendChannelIdList);
107
- this.emit("friend list update", {
108
- type: "friend list update",
110
+ this.emit("__BCM_FRIEND_LIST_UPDATE__", {
111
+ type: "__BCM_FRIEND_LIST_UPDATE__",
109
112
  data: [...this._oldFrendChannelIdList],
110
113
  id: this.id
111
114
  });
112
115
  this._updataNodeType();
113
116
  }, MessageTimeout);
114
117
  }
115
- /** 绑定事件 */
118
+ /** 绑定事件 | Bind event */
116
119
  _bindBroadcastChannelEvent() {
117
120
  this._broadcastChannel && (this._broadcastChannel.onmessage = (event) => {
118
121
  const { type, targetId } = event.data;
@@ -121,63 +124,63 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
121
124
  }
122
125
  this.emit(type, event.data);
123
126
  });
124
- this.on("Hello world", (data) => {
127
+ this.on("__BCM_INIT__", (data) => {
125
128
  const { id } = data;
126
129
  if (!this._friendChannelIdSet.has(id)) {
127
130
  this._friendChannelIdSet.add(id);
128
131
  }
129
- this.sendToTarget("I can hear you", id);
132
+ this.sendToTarget("__BCM_INIT_REPLY__", id);
130
133
  });
131
- this.on("I can hear you", (data) => {
134
+ this.on("__BCM_INIT_REPLY__", (data) => {
132
135
  const { id } = data;
133
136
  this._addFriend(id);
134
137
  });
135
- this.on("苍天已死,黄天当立", (data) => {
138
+ this.on("__BCM_REQ_BE_MAIN_NODE__", (data) => {
136
139
  const { id } = data;
137
140
  if (id > this.id) {
138
- this.sendToTarget("我是黄天,尔等退下", id);
141
+ this.sendToTarget("__BCM_REQ_BE_MAIN_NODE_REJECT__", id);
139
142
  }
140
143
  });
141
- this.on("苍天在上,受我一拜", (data) => {
144
+ this.on("__BCM_MAIN_NODE_HEARBEAT_REPLY__", (data) => {
142
145
  this._addFriend(data.id);
143
146
  });
144
147
  this._bindNodeEvent();
145
148
  }
146
- /** 监听节点类型切换事件 */
149
+ /** 监听节点类型切换事件 | */
147
150
  _bindNodeEvent() {
148
151
  const onMainNodeHearbeat = (data) => {
149
152
  this._timeoutToBeMainNode();
150
153
  this._catchOldFriend();
151
154
  this._addFriend(data.id);
152
155
  this.send(
153
- "苍天在上,受我一拜"
156
+ "__BCM_MAIN_NODE_HEARBEAT_REPLY__"
154
157
  /* Res_Main_Node_Hearbeat */
155
158
  );
156
159
  };
157
- this.on("node type change", (info) => {
160
+ this.on("__BCM_NODE_TYPE_CHANGE__", (info) => {
158
161
  const { data } = info;
159
162
  this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
160
- this._debug && console.log("BC:代理类型切换:", info.data);
163
+ this._debug && console.log("BC:NODE_TYPE_CHANGE:", info.data);
161
164
  if (data === "main") {
162
165
  this._mainNodeMsgInterval = setInterval(() => {
163
166
  this._catchOldFriend();
164
167
  this.send(
165
- "苍天还在,别立黄天"
168
+ "__BCM_MAIN_NODE_HEARBEAT__"
166
169
  /* Main_Node_Hearbeat */
167
170
  );
168
171
  }, MessageTimeout);
169
172
  } else if (data === "normal") {
170
173
  this._timeoutToBeMainNode();
171
174
  }
172
- this.on("苍天还在,别立黄天", onMainNodeHearbeat);
175
+ this.on("__BCM_MAIN_NODE_HEARBEAT__", onMainNodeHearbeat);
173
176
  });
174
177
  }
175
- /** 获取最新的友方列表 */
178
+ /** 获取最新的节点列表 | Get the latest node list */
176
179
  _getNewFriendList() {
177
180
  return [...this._friendChannelIdSet].sort((a, b) => a - b);
178
181
  }
179
182
  /**
180
- * 更新当前节点类型
183
+ * 更新当前节点类型 | Update the current node type
181
184
  */
182
185
  _updataNodeType() {
183
186
  this._mainNodeMsgInterval && clearInterval(this._mainNodeMsgInterval);
@@ -206,15 +209,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
206
209
  }, MessageTimeout * 3);
207
210
  }
208
211
  /**
209
- * 保持记录的活跃的友方id列表
210
- * 清空正在记录的友方id列表
212
+ * 保存最新的节点列表到_oldFrendChannelIdList,清空_friendChannelIdSet
213
+ * Save the latest node list to _oldFrendChannelIdList and clear _friendChannelIdSet
211
214
  */
212
215
  _catchOldFriend() {
213
216
  const newFriendList = this._getNewFriendList();
214
217
  if (this._oldFrendChannelIdList.join() !== newFriendList.join()) {
215
218
  this._debug && console.log("BC:updateFriendChannelIdList:", newFriendList);
216
- this.emit("friend list update", {
217
- type: "friend list update",
219
+ this.emit("__BCM_FRIEND_LIST_UPDATE__", {
220
+ type: "__BCM_FRIEND_LIST_UPDATE__",
218
221
  data: [...newFriendList],
219
222
  id: this.id
220
223
  });
@@ -229,12 +232,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
229
232
  this._friendChannelIdSet.clear();
230
233
  }
231
234
  /**
232
- * 申请成为主节点
235
+ * 申请成为主节点 | Apply to be a master node
233
236
  */
234
237
  _req_beMainNode() {
235
238
  this._debug && console.log("BC:req_beMainNode");
236
239
  this.send(
237
- "苍天已死,黄天当立"
240
+ "__BCM_REQ_BE_MAIN_NODE__"
238
241
  /* Req_Be_Main_Node */
239
242
  );
240
243
  const timer = setTimeout(() => {
@@ -245,13 +248,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
245
248
  }, MessageTimeout);
246
249
  const handleRes_beMainNode = () => {
247
250
  clearTimeout(timer);
248
- this.off("我是黄天,尔等退下", handleRes_beMainNode);
251
+ this.off("__BCM_REQ_BE_MAIN_NODE_REJECT__", handleRes_beMainNode);
249
252
  };
250
- this.on("我是黄天,尔等退下", handleRes_beMainNode);
253
+ this.on("__BCM_REQ_BE_MAIN_NODE_REJECT__", handleRes_beMainNode);
251
254
  }
252
255
  /**
253
- * 添加友方
254
- * @param id 节点id
256
+ * add node
257
+ * @param id id
255
258
  */
256
259
  _addFriend(id) {
257
260
  if (!this._friendChannelIdSet.has(id)) {
@@ -259,9 +262,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
259
262
  }
260
263
  }
261
264
  /**
262
- * 广播消息
263
- * @param type 消息类型
264
- * @param data 数据
265
+ * 广播消息 | Send Broadcast message
266
+ * @param type 消息类型 | Message type
267
+ * @param data 数据 | data
265
268
  */
266
269
  send(type, data) {
267
270
  var _a;
@@ -272,10 +275,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
272
275
  });
273
276
  }
274
277
  /**
275
- * 给特定id的节点发送消息
276
- * @param type 消息类型
277
- * @param targetId 目标节点id
278
- * @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
279
282
  */
280
283
  sendToTarget(type, targetId, data) {
281
284
  var _a;
@@ -287,9 +290,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
287
290
  });
288
291
  }
289
292
  /**
290
- * 注册事件
291
- * @param { string } event 事件类型
292
- * @param callback 回调
293
+ * 注册事件 | Registering events
294
+ * @param { string } event 事件类型 | Event type
295
+ * @param callback 回调 | callback
293
296
  * @returns void
294
297
  */
295
298
  on(event, callback) {
@@ -304,9 +307,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
304
307
  callbacks.push(callback);
305
308
  }
306
309
  /**
307
- * 注销事件
308
- * @param { string } event 事件类型
309
- * @param callback 事件回调
310
+ * 注销事件 | Remove events
311
+ * @param { string } event 事件类型 | Event type
312
+ * @param callback 事件回调 | callback
310
313
  * @returns
311
314
  */
312
315
  off(event, callback) {
@@ -322,9 +325,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
322
325
  callbacks.splice(index, 1);
323
326
  }
324
327
  /**
325
- * 触发事件
326
- * @param { string } event 事件类型
327
- * @param data 数据
328
+ * 触发事件 | Triggering events
329
+ * @param { string } event 事件类型 | Event type
330
+ * @param data 数据 | data
328
331
  */
329
332
  emit(event, data) {
330
333
  const callbacks = this._eventMap.get(event) || [];
@@ -333,7 +336,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
333
336
  });
334
337
  }
335
338
  /**
336
- * 销毁
339
+ * 销毁 | destroy
337
340
  */
338
341
  destroy() {
339
342
  var _a;