move to public repo
This commit is contained in:
34
server/src/socket/index.ts
Normal file
34
server/src/socket/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { Socket } from "socket.io";
|
||||
import { io } from "../server";
|
||||
import { joinLobby, leaveLobby, getLatestGame, sendMove, joinAsPlayer, chat } from "./game.socket";
|
||||
|
||||
const socketConnect = (socket: Socket) => {
|
||||
const req = socket.request;
|
||||
|
||||
// re-analyze if this is necessary, or if io.use will handle logout
|
||||
socket.use((__, next) => {
|
||||
req.session.reload((err) => {
|
||||
if (err) {
|
||||
console.log("reload: disconnecting socket.");
|
||||
console.log(err);
|
||||
socket.disconnect();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on("disconnect", leaveLobby);
|
||||
|
||||
socket.on("joinLobby", joinLobby);
|
||||
socket.on("leaveLobby", leaveLobby);
|
||||
|
||||
socket.on("getLatestGame", getLatestGame);
|
||||
socket.on("sendMove", sendMove);
|
||||
socket.on("joinAsPlayer", joinAsPlayer);
|
||||
socket.on("chat", chat);
|
||||
};
|
||||
|
||||
export const init = () => {
|
||||
io.on("connection", socketConnect);
|
||||
};
|
||||
Reference in New Issue
Block a user