Skip to content

Commit aacd8c8

Browse files
committed
fix: refactor reconnect logic
1 parent 4e8f70a commit aacd8c8

16 files changed

+427
-25
lines changed

Diff for: reference/PK_BATTLE_END.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_END", "pk_id": "324795709", "pk_status": 401, "timestamp": 1684595895, "data": { "battle_type": 1, "timer": 10, "init_info": { "room_id": 958617, "votes": 372, "winner_type": -1, "best_uname": "塔达林坚果" }, "match_info": { "room_id": 27487691, "votes": 684, "winner_type": 2, "best_uname": "carriebobo" } } }

Diff for: reference/PK_BATTLE_FINAL_PROCESS.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_FINAL_PROCESS", "data": { "battle_type": 1, "pk_frozen_time": 1684596223 }, "pk_id": 324796166, "pk_status": 301, "timestamp": 1684596044 }

Diff for: reference/PK_BATTLE_PRE.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_PRE", "pk_status": 101, "pk_id": 324796166, "timestamp": 1684595913, "data": { "battle_type": 1, "match_type": 1, "uname": "雪兔三千-冲舰奖励版", "face": "https://i0.hdslb.com/bfs/face/3e981c85ada2f1f155ddca354e4e9c6b1c63f281.jpg", "uid": 1870523466, "room_id": 25186244, "season_id": 61, "pre_timer": 10, "pk_votes_name": "乱斗值", "end_win_task": null }, "roomid": 958617 }

Diff for: reference/PK_BATTLE_PRE_NEW.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_PRE_NEW", "pk_status": 101, "pk_id": 324796166, "timestamp": 1684595913, "data": { "battle_type": 1, "match_type": 1, "uname": "雪兔三千-冲舰奖励版", "face": "https://i0.hdslb.com/bfs/face/3e981c85ada2f1f155ddca354e4e9c6b1c63f281.jpg", "uid": 1870523466, "room_id": 25186244, "season_id": 61, "pre_timer": 10, "pk_votes_name": "乱斗值", "end_win_task": null }, "roomid": 958617 }

Diff for: reference/PK_BATTLE_PROCESS.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_PROCESS", "data": { "battle_type": 1, "init_info": { "room_id": 958617, "votes": 372, "best_uname": "塔达林坚果", "vision_desc": 1 }, "match_info": { "room_id": 27487691, "votes": 25, "best_uname": "_阿栾", "vision_desc": -1 } }, "pk_id": 324795709, "pk_status": 201, "timestamp": 1684595825 }

Diff for: reference/PK_BATTLE_PROCESS_NEW.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_PROCESS_NEW", "data": { "battle_type": 1, "init_info": { "room_id": 958617, "votes": 372, "best_uname": "塔达林坚果", "vision_desc": 1 }, "match_info": { "room_id": 27487691, "votes": 25, "best_uname": "_阿栾", "vision_desc": -1 } }, "pk_id": 324795709, "pk_status": 201, "timestamp": 1684595825 }

Diff for: reference/PK_BATTLE_SETTLE.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_SETTLE", "pk_id": 324795709, "pk_status": 401, "settle_status": 1, "timestamp": 1684595895, "data": { "battle_type": 1, "result_type": -1, "star_light_msg": "" }, "roomid": "958617" }

Diff for: reference/PK_BATTLE_SETTLE_USER.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_SETTLE_USER", "pk_id": 324795709, "pk_status": 401, "settle_status": 1, "timestamp": 1684595896, "data": { "pk_id": "324795709", "season_id": 61, "settle_status": 1, "result_type": -1, "battle_type": 0, "result_info": { "total_score": -6, "result_type_score": -6, "pk_votes": 372, "pk_votes_name": "乱斗值", "pk_crit_score": -1, "pk_resist_crit_score": -1, "pk_extra_score_slot": "", "pk_extra_value": 0, "pk_extra_score": 0, "pk_task_score": 0, "pk_times_score": 0, "pk_done_times": 18, "pk_total_times": -1, "win_count": 5, "win_final_hit": -1, "winner_count_score": 0, "task_score_list": [] }, "winner": { "room_id": 27487691, "uid": 3493271342942375, "uname": "苏欲_优秀版", "face": "https://i2.hdslb.com/bfs/face/405ac2e773bae10359fd316e127f49fc800740ee.jpg", "face_frame": "https://i0.hdslb.com/bfs/live/13a91b141bbd675062302e893e1207d298adef88.png", "exp": { "color": 9868950, "user_level": 1, "master_level": { "color": 5805790, "level": 20 } }, "best_user": { "uid": 234420930, "uname": "carriebobo", "face": "https://i0.hdslb.com/bfs/face/917be06245a6888a857d7f729a9392148bbcc3a8.jpg", "pk_votes": 659, "pk_votes_name": "乱斗值", "exp": { "color": 6406234, "level": 1 }, "face_frame": "https://i0.hdslb.com/bfs/live/80f732943cc3367029df65e267960d56736a82ee.png", "badge": { "url": "", "desc": "", "position": 0 }, "award_info": null, "award_info_list": [], "end_win_award_info_list": { "list": [] } } }, "my_info": { "room_id": 958617, "uid": 140378, "uname": "梦音茶糯", "face": "https://i2.hdslb.com/bfs/face/ea50e0c20017f5d5fab3d10d322a2a514a6c13c5.jpg", "face_frame": "https://i0.hdslb.com/bfs/live/3cddb16e2a5e035be127a9e245d613082456a4dc.png", "exp": { "color": 6406234, "user_level": 16, "master_level": { "color": 16746162, "level": 37 } }, "best_user": { "uid": 5227591, "uname": "塔达林坚果", "face": "http://i1.hdslb.com/bfs/face/a1a8a5fba8233d08c13a6c3d260b553d11a3e002.jpg", "pk_votes": 360, "pk_votes_name": "乱斗值", "exp": { "color": 6406234, "level": 1 }, "face_frame": "", "badge": { "url": "http://i0.hdslb.com/bfs/live/b5e9ebd5ddb979a482421ca4ea2f8c1cc593370b.png", "desc": "", "position": 3 }, "award_info": null, "award_info_list": [], "end_win_award_info_list": { "list": [] } } }, "level_info": { "first_rank_name": "黄金战神", "second_rank_num": 1, "first_rank_img": "https://i0.hdslb.com/bfs/live/ae44e555f005f2e1dd4c6c54efa24aff68607692.png", "second_rank_icon": "https://i0.hdslb.com/bfs/live/1f8c2a959f92592407514a1afeb705ddc55429cd.png" } } }

Diff for: reference/PK_BATTLE_SETTLE_V2.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_SETTLE_V2", "pk_id": 324795709, "pk_status": 401, "settle_status": 1, "timestamp": 1684595896, "data": { "pk_id": "324795709", "season_id": 61, "pk_type": 1, "result_type": -1, "result_info": { "total_score": -6, "pk_votes": 372, "pk_votes_name": "乱斗值", "pk_extra_value": 0 }, "level_info": { "uid": "140378", "first_rank_name": "黄金战神", "second_rank_num": 1, "first_rank_img": "https://i0.hdslb.com/bfs/live/ae44e555f005f2e1dd4c6c54efa24aff68607692.png", "second_rank_icon": "https://i0.hdslb.com/bfs/live/1f8c2a959f92592407514a1afeb705ddc55429cd.png" }, "assist_list": [{ "id": 5227591, "uname": "塔达林坚果", "face": "http://i1.hdslb.com/bfs/face/a1a8a5fba8233d08c13a6c3d260b553d11a3e002.jpg", "score": 360 }, { "id": 441853467, "uname": "有何相干-", "face": "https://i0.hdslb.com/bfs/face/6b7b0fe4db50f75c43f18fbd61090b8e2f6dc800.jpg", "score": 8 }, { "id": 396759728, "uname": "3b3a3s", "face": "http://i2.hdslb.com/bfs/face/72f4b8fe66fe02cfd8f2f93db6e7518f80060eab.jpg", "score": 1 }, { "id": 37241098, "uname": "云上琅琅杏花开", "face": "https://i1.hdslb.com/bfs/face/00614b4bb556e50d314a969c073f596c0ef38c44.jpg", "score": 1 }, { "id": 478167101, "uname": "12道菜的晚餐", "face": "http://i2.hdslb.com/bfs/face/f9e258ef406d077a7012d2d4d037c83860fbe635.jpg", "score": 1 }], "star_light_msg": "" } }

Diff for: reference/PK_BATTLE_START.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_START", "pk_id": 324796166, "pk_status": 201, "timestamp": 1684595923, "data": { "battle_type": 1, "final_hit_votes": 0, "pk_start_time": 1684595923, "pk_frozen_time": 1684596223, "pk_end_time": 1684596233, "pk_votes_type": 0, "pk_votes_add": 0, "pk_votes_name": "乱斗值", "star_light_msg": "", "pk_countdown": 1684596163, "final_conf": { "switch": 1, "start_time": 1684596043, "end_time": 1684596103 }, "init_info": { "room_id": 958617, "date_streak": 0 }, "match_info": { "room_id": 25186244, "date_streak": 0 } }, "roomid": "958617" }

Diff for: reference/PK_BATTLE_START_NEW.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "PK_BATTLE_START_NEW", "pk_id": 324796166, "pk_status": 201, "timestamp": 1684595923, "data": { "battle_type": 1, "final_hit_votes": 0, "pk_start_time": 1684595923, "pk_frozen_time": 1684596223, "pk_end_time": 1684596233, "pk_votes_type": 0, "pk_votes_add": 0, "pk_votes_name": "乱斗值", "star_light_msg": "", "pk_countdown": 1684596163, "final_conf": { "switch": 1, "start_time": 1684596043, "end_time": 1684596103 }, "init_info": { "room_id": 958617, "date_streak": 0 }, "match_info": { "room_id": 25186244, "date_streak": 0 } }, "roomid": "958617" }

Diff for: reference/VOICE_JOIN_STATUS.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "VOICE_JOIN_STATUS", "data": { "room_id": 13233348, "status": 1, "channel": "11679739", "channel_type": "voice", "uid": 23986644, "user_name": "乱花钱的人", "head_pic": "https://i0.hdslb.com/bfs/face/71035b609045f0faff8b11303c9ec4258cec430a.jpg", "guard": 0, "start_at": 1684600192, "current_time": 1684600192, "web_share_link": "https://live.bilibili.com/h5/13233348" }, "room_id": 13233348 }

Diff for: reference/VOICE_JOIN_SWITCH.json5

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cmd": "VOICE_JOIN_SWITCH", "data": { "room_id": 13233348, "room_status": 1, "root_status": 1 }, "roomid": 13233348 }

Diff for: src/base/base.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@ export class LiveClient<E extends Record<EventKey, any>> extends EventEmitter<Me
162162
})
163163

164164
// @ts-expect-error CLOSE Event ok
165-
this.on(CLOSE_EVENT, () => {
166-
this.close()
165+
this.on(CLOSE_EVENT, (e) => {
166+
// @ts-expect-error close event
167+
this.emit('close', e)
168+
169+
if (this.options.keepalive)
170+
this.socket.reconnect()
167171
})
168172
}
169173

@@ -200,11 +204,6 @@ export class LiveClient<E extends Record<EventKey, any>> extends EventEmitter<Me
200204
if (!this.live)
201205
return
202206

203-
if (this.options.keepalive) {
204-
this.socket.reconnect()
205-
return
206-
}
207-
208207
this.live = false
209208
clearTimeout(this.timeout)
210209

0 commit comments

Comments
 (0)