- Added game settings - Reworked GamePropsSchema for only relevant information -> Prisma schema and zod object - Imporved toast notifications - No duplicate socket connections anymore - Using now Zustand for the gameProps instead of React Context & State
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { GameSettings } from "@components/Lobby/SettingsFrame/Setting"
|
|
import { GamePropsSchema } from "@lib/zodSchemas"
|
|
import { User } from "@prisma/client"
|
|
import type { Server as HTTPServer } from "http"
|
|
import type { Socket as NetSocket } from "net"
|
|
import type { NextApiResponse } from "next"
|
|
import type { Server as IOServer, Server } from "socket.io"
|
|
import { Socket } from "socket.io-client"
|
|
|
|
interface SocketServer extends HTTPServer {
|
|
io?: IOServer
|
|
}
|
|
|
|
interface SocketWithIO extends NetSocket {
|
|
server: SocketServer
|
|
}
|
|
|
|
export interface NextApiResponseWithSocket extends NextApiResponse {
|
|
socket: SocketWithIO
|
|
}
|
|
|
|
export interface ServerToClientEvents {
|
|
// noArg: () => void
|
|
// basicEmit: (a: number, b: string, c: Buffer) => void
|
|
// withAck: (d: string, ) => void
|
|
update: (game: GamePropsSchema) => void
|
|
}
|
|
|
|
export interface ClientToServerEvents {
|
|
ping: (count: number, callback: (count: number) => void) => void
|
|
join: (withAck: ({ ack }: { ack: boolean }) => void) => void
|
|
gameSetting: (
|
|
payload: GameSettings,
|
|
withAck: ({ ack }: { ack: boolean }) => void
|
|
) => void
|
|
}
|
|
|
|
interface InterServerEvents {
|
|
// ping: () => void
|
|
}
|
|
|
|
interface SocketData {
|
|
user: User | null
|
|
gameId: string | null
|
|
}
|
|
|
|
export type cServer = Server<
|
|
ClientToServerEvents,
|
|
ServerToClientEvents,
|
|
InterServerEvents,
|
|
SocketData
|
|
>
|
|
|
|
export type cSocket = Socket<ServerToClientEvents, ClientToServerEvents>
|