update:分包、对接个人练习
This commit is contained in:
+30
-1
@@ -42,6 +42,7 @@ const BUSINESS_TYPE_BY_SERVER_TYPE = {
|
||||
[ServerMessageType.SERVER_MSG_TIMEOUT]: MESSAGETYPESV2.BattleEnd,
|
||||
[ServerMessageType.SERVER_MSG_CHECK]: MESSAGETYPESV2.TestDistance,
|
||||
[ServerMessageType.SERVER_MSG_NOT_ENOUGH_DISTANCE]: MESSAGETYPESV2.InvalidShot,
|
||||
[ServerMessageType.SERVER_MSG_PRACTICE_END]: MESSAGETYPESV2.BattleEnd,
|
||||
};
|
||||
|
||||
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
|
||||
@@ -57,27 +58,53 @@ function normalizeShootData(shootData) {
|
||||
}
|
||||
|
||||
// 兼容普通接口通知的 camelCase 和 protobuf 解码后的 snake_case。
|
||||
function normalizePracticeInfo(practiceInfo = {}) {
|
||||
if (!practiceInfo || typeof practiceInfo !== "object") return {};
|
||||
|
||||
const normalized = normalizePlainObject(practiceInfo);
|
||||
if (practiceInfo.shoot_data || normalized.shootData) {
|
||||
normalized.shootData = normalizeShootData(
|
||||
normalizePlainObject(practiceInfo.shoot_data || normalized.shootData)
|
||||
);
|
||||
}
|
||||
if (Array.isArray(practiceInfo.details || normalized.details)) {
|
||||
normalized.details = (practiceInfo.details || normalized.details)
|
||||
.map(normalizePlainObject)
|
||||
.map(normalizeShootData);
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function buildBusinessMessage(message) {
|
||||
const businessType = BUSINESS_TYPE_BY_SERVER_TYPE[message.type];
|
||||
if (!businessType) return null;
|
||||
|
||||
const matchInfo = normalizeMatchInfo(message.match_info);
|
||||
const practiceInfo = normalizePracticeInfo(message.practice_info);
|
||||
const matchId = normalizeId(
|
||||
pickField(message, "matchId", "match_id") ||
|
||||
matchInfo.matchId ||
|
||||
practiceInfo.id ||
|
||||
currentContext?.matchId
|
||||
);
|
||||
const shootData = normalizeShootData(
|
||||
matchInfo.shootData ||
|
||||
practiceInfo.shootData ||
|
||||
(message.shoot_data ? normalizePlainObject(message.shoot_data) : undefined)
|
||||
);
|
||||
const details = Array.isArray(practiceInfo.details)
|
||||
? practiceInfo.details
|
||||
: matchInfo.details;
|
||||
|
||||
return {
|
||||
...matchInfo,
|
||||
...practiceInfo,
|
||||
type: businessType,
|
||||
id: matchId,
|
||||
matchId,
|
||||
shootData,
|
||||
details,
|
||||
sequence: message.sequence,
|
||||
timestamp: message.timestamp,
|
||||
matchWsType: message.type,
|
||||
@@ -230,6 +257,7 @@ function getAckAudioKeys(message, businessMessage) {
|
||||
return getShootResultAudioKeys(businessMessage?.shootData);
|
||||
case ServerMessageType.SERVER_MSG_MATCH_END:
|
||||
case ServerMessageType.SERVER_MSG_TIMEOUT:
|
||||
case ServerMessageType.SERVER_MSG_PRACTICE_END:
|
||||
return ["比赛结束"];
|
||||
case ServerMessageType.SERVER_MSG_CHECK:
|
||||
return getTestDistanceAudioKeys(businessMessage?.shootData);
|
||||
@@ -243,7 +271,8 @@ function getAckAudioKeys(message, businessMessage) {
|
||||
function shouldCloseAfterAck(message) {
|
||||
return (
|
||||
message.type === ServerMessageType.SERVER_MSG_MATCH_END ||
|
||||
message.type === ServerMessageType.SERVER_MSG_TIMEOUT
|
||||
message.type === ServerMessageType.SERVER_MSG_TIMEOUT ||
|
||||
message.type === ServerMessageType.SERVER_MSG_PRACTICE_END
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user