import { Socket } from "socket.io-client";
import { ServerEvent } from "./ServerEvent";

export type UpdateLobbyEvent = {
  playerNames: Array<string>;
};

export function attachHandlerToUpdateLobbyEvent(
  socket: Socket,
  handler: (event: UpdateLobbyEvent) => void,
): () => void {
  socket.on(ServerEvent.LOBBY_UPDATE, handler);
  return () => socket.off(ServerEvent.LOBBY_UPDATE, handler);
}
