// the emitter setup

import type { RoomId } from "./types.socket.js";

let addDataToRoom: ((roomId: RoomId, payload: unknown[]) => void) | null = null;

export const registerEmitter = (
	fn: (roomId: RoomId, payload: unknown[]) => void,
) => {
	addDataToRoom = fn;
};

export const emitToRoom = (roomId: RoomId, payload: unknown[]) => {
	if (!addDataToRoom) {
		console.error("Socket emitter not initialized");
		return;
	}

	addDataToRoom(roomId, payload);
};

/*
import { emitToRoom } from "../socket/socketEmitter.js";
// room name
// its payload
emitToRoom("logs", newLogRow);
*/
