update:新增比赛服断线重连机制

This commit is contained in:
2026-07-10 15:11:45 +08:00
parent b5373bee31
commit 98ca638b63
4 changed files with 339 additions and 38 deletions
+15
View File
@@ -17,6 +17,7 @@ import {
closeMatchWebSocket,
connectMatchWebSocket,
MATCH_WS_AUDIO_ACK_EVENT,
MATCH_WS_STATE_EVENT,
} from "@/matchWebsocket";
import { MESSAGETYPESV2 } from "@/constants";
import { getDirectionText } from "@/util";
@@ -1227,6 +1228,18 @@ function scheduleRestoreLatestBattle() {
}, RESTORE_EMPTY_ID_RETRY_DELAY);
}
function onMatchSocketState(event) {
if (event?.state !== "open" || event?.reconnected !== true) return;
if (
event.matchId &&
battleId.value &&
String(event.matchId) !== String(battleId.value)
) {
return;
}
scheduleRestoreLatestBattle();
}
// 页面统一的 socket 回调,只负责把消息送进战况队列。
function onReceiveMessage(message) {
enqueueBattleMessage(message);
@@ -1302,6 +1315,7 @@ onMounted(async () => {
uni.$on(AUDIO_INTERRUPTION_END_EVENT, handleBattleRecovered);
uni.$on(PROGRESS_ZERO_EVENT, onProgressZero);
uni.$on(COUNTDOWN_READY_EVENT, hideRestoreLoading);
uni.$on(MATCH_WS_STATE_EVENT, onMatchSocketState);
await laserCloseAPI();
});
@@ -1314,6 +1328,7 @@ onBeforeUnmount(() => {
uni.$off("audioEnded", onAudioEnded);
uni.$off(PROGRESS_ZERO_EVENT, onProgressZero);
uni.$off(COUNTDOWN_READY_EVENT, hideRestoreLoading);
uni.$off(MATCH_WS_STATE_EVENT, onMatchSocketState);
if (pendingRestoreTimer) {
clearTimeout(pendingRestoreTimer);
pendingRestoreTimer = null;