23 lines
577 B
TypeScript
23 lines
577 B
TypeScript
import { Socket as ServerSocket } from "socket.io";
|
|
import { Socket as ClientSocket } from "socket.io-client";
|
|
import { ServerEvent } from "./ServerEvent";
|
|
|
|
export type UpdateLobbyEvent = {
|
|
playerNames: Array<string>;
|
|
gameCode: string;
|
|
};
|
|
|
|
export const emitUpdateLobbyEvent = (
|
|
socket: ServerSocket,
|
|
payload: UpdateLobbyEvent,
|
|
) => {
|
|
socket.emit(ServerEvent.LOBBY_UPDATE, payload);
|
|
};
|
|
|
|
export function attachHandlerToUpdateLobbyEvent(
|
|
socket: ClientSocket,
|
|
handler: (event: UpdateLobbyEvent) => void,
|
|
): void {
|
|
socket.once(ServerEvent.LOBBY_UPDATE, handler);
|
|
}
|