Skip to content

Commit 5252ef8

Browse files
committed
lostConnection popup
1 parent f9bc2d3 commit 5252ef8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/client/scripts/Socket.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { encode, decode, decodeAsync } from "@msgpack/msgpack";
2+
import swal from "sweetalert";
23

34
class Socket {
45
constructor(game, url) {
@@ -15,6 +16,20 @@ class Socket {
1516
console.log(err);
1617
}
1718
};
19+
this.ws.onclose = () => {
20+
console.log("Lost connection!");
21+
swal({
22+
title: "You have lost connection!",
23+
text: "Websocket connection have been closed!",
24+
icon: "error",
25+
button: "Rejoin",
26+
}).then(function () {
27+
document.location.reload();
28+
});
29+
};
30+
this.ws.onerror = (err) => {
31+
console.log(err);
32+
};
1833
}
1934
emit(type, ...data) {
2035
this.ws.send(

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ wss.on("connection", (socket, req) => {
216216
bot.stopDigging();
217217
});
218218

219-
socket.onclose = () => {
219+
socket.on("close", () => {
220220
try {
221221
clearInterval(interval);
222222
console.log(`[\x1b[31m-\x1b[0m] ${query.nick}`);
223223
bot.end();
224224
} catch (error) {}
225-
};
225+
});
226226

227227
socket.on("message", (message) => {
228228
try {

0 commit comments

Comments
 (0)