添加新通知处理
This commit is contained in:
@@ -14,7 +14,7 @@ function createWebSocket(token, onMessage) {
|
||||
|
||||
switch (envVersion) {
|
||||
case "develop": // 开发版
|
||||
// url = "ws://192.168.1.242:8000/socket";
|
||||
// url = "ws://192.168.1.30:8000/socket";
|
||||
url = "wss://apitest.shelingxingqiu.com/socket";
|
||||
break;
|
||||
case "trial": // 体验版
|
||||
@@ -45,44 +45,50 @@ function createWebSocket(token, onMessage) {
|
||||
|
||||
// 接收消息
|
||||
uni.onSocketMessage((res) => {
|
||||
const data = JSON.parse(res.data);
|
||||
if (data.event === "pong" || !data.data.updates) return;
|
||||
if (onMessage) onMessage(data.data.updates);
|
||||
const msg = data.data.updates[0];
|
||||
if (!msg) return;
|
||||
console.log("收到消息:", getMessageTypeName(msg.constructor), msg);
|
||||
if (msg.constructor === MESSAGETYPES.BackToGame) {
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
if (
|
||||
currentPage.route === "pages/battle-room" ||
|
||||
currentPage.route === "pages/team-battle" ||
|
||||
currentPage.route === "pages/melee-match"
|
||||
) {
|
||||
return;
|
||||
const { data, event } = JSON.parse(res.data);
|
||||
if (event === "pong") return;
|
||||
if (data.type && data.data) {
|
||||
console.log("收到消息:", getMessageTypeName(data.type), data.data);
|
||||
if (onMessage) onMessage({ ...data.data, type: data.type });
|
||||
return;
|
||||
}
|
||||
if (onMessage && data.updates) onMessage(data.updates);
|
||||
const msg = data.updates[0];
|
||||
if (msg) {
|
||||
console.log("收到消息:", getMessageTypeName(msg.constructor), msg);
|
||||
if (msg.constructor === MESSAGETYPES.BackToGame) {
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
if (
|
||||
currentPage.route === "pages/battle-room" ||
|
||||
currentPage.route === "pages/team-battle" ||
|
||||
currentPage.route === "pages/melee-match"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const { battleInfo } = msg;
|
||||
uni.setStorageSync("current-battle", battleInfo);
|
||||
// console.log("----battleInfo", battleInfo);
|
||||
if (battleInfo.config.mode === 1) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/team-battle?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`,
|
||||
});
|
||||
} else if (battleInfo.config.mode === 2) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/melee-match?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`,
|
||||
});
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
uni.$emit("game-over");
|
||||
} else if (msg.constructor === MESSAGETYPES.RankUpdate) {
|
||||
uni.setStorageSync("latestRank", msg.lvl);
|
||||
} else if (msg.constructor === MESSAGETYPES.LvlUpdate) {
|
||||
uni.setStorageSync("latestLvl", msg.lvl);
|
||||
} else if (msg.constructor === MESSAGETYPES.DeviceOnline) {
|
||||
uni.$emit("update-online");
|
||||
} else if (msg.constructor === MESSAGETYPES.DeviceOffline) {
|
||||
uni.$emit("update-online");
|
||||
}
|
||||
const { battleInfo } = msg;
|
||||
uni.setStorageSync("current-battle", battleInfo);
|
||||
// console.log("----battleInfo", battleInfo);
|
||||
if (battleInfo.config.mode === 1) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/team-battle?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`,
|
||||
});
|
||||
} else if (battleInfo.config.mode === 2) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/melee-match?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`,
|
||||
});
|
||||
}
|
||||
} else if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
uni.$emit("game-over");
|
||||
} else if (msg.constructor === MESSAGETYPES.RankUpdate) {
|
||||
uni.setStorageSync("latestRank", msg.lvl);
|
||||
} else if (msg.constructor === MESSAGETYPES.LvlUpdate) {
|
||||
uni.setStorageSync("latestLvl", msg.lvl);
|
||||
} else if (msg.constructor === MESSAGETYPES.DeviceOnline) {
|
||||
uni.$emit("update-online");
|
||||
} else if (msg.constructor === MESSAGETYPES.DeviceOffline) {
|
||||
uni.$emit("update-online");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user