Change disconnect behavior to avoid practice disconnect.

This commit is contained in:
yukirij 2024-08-17 15:39:22 -07:00
parent 354868446e
commit dc4827c982
2 changed files with 29 additions and 5 deletions

View File

@ -101,6 +101,9 @@ const SCENES = {
} }
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
Authenticate:{ Authenticate:{
@ -170,6 +173,9 @@ const SCENES = {
} }
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
Browse:{ Browse:{
@ -227,6 +233,9 @@ const SCENES = {
} break; } break;
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
Continue:{ Continue:{
@ -286,6 +295,9 @@ const SCENES = {
} break; } break;
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
Join:{ Join:{
@ -345,6 +357,9 @@ const SCENES = {
} break; } break;
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
Live:{ Live:{
@ -402,6 +417,9 @@ const SCENES = {
} break; } break;
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
History:{ History:{
@ -443,7 +461,10 @@ const SCENES = {
table.appendChild(UI.session_table(data.records)); table.appendChild(UI.session_table(data.records));
} }
} }
} },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
Guide:{ Guide:{
@ -509,6 +530,9 @@ const SCENES = {
} break; } break;
} }
}, },
disconnect() {
LOAD_STACK(SCENES.Offline);
},
}, },
GamePractice:{ GamePractice:{

View File

@ -3,9 +3,9 @@ function RECONNECT() {
console.log("Websocket connecting.."); console.log("Websocket connecting..");
SOCKET = new WebSocket("wss://omen.kirisame.com:38612"); SOCKET = new WebSocket("wss://omen.kirisame.com:38612");
SOCKET.binaryType = "arraybuffer"; SOCKET.binaryType = "arraybuffer";
SOCKET.addEventListener("error", (event) => { SOCKET.addEventListener("error", () => {
SOCKET = null; SOCKET = null;
LOAD_STACK(SCENES.Offline); if(SCENE.disconnect !== undefined) { SCENE.disconnect(); }
}); });
SOCKET.addEventListener("open", (event) => { SOCKET.addEventListener("open", (event) => {
if(SOCKET.readyState === WebSocket.OPEN) { if(SOCKET.readyState === WebSocket.OPEN) {
@ -13,10 +13,10 @@ function RECONNECT() {
SOCKET.addEventListener("message", MESSAGE); SOCKET.addEventListener("message", MESSAGE);
SOCKET.addEventListener("close", (event) => { SOCKET.addEventListener("close", () => {
console.log("Websocket closed."); console.log("Websocket closed.");
SOCKET = null; SOCKET = null;
LOAD_STACK(SCENES.Offline); if(SCENE.disconnect !== undefined) { SCENE.disconnect(); }
RECONNECT(); RECONNECT();
}); });