作る

FunnableChat

Real-time lobby chat powered by the platform's WebSocket infrastructure. Handles connection retries, ping/pong heartbeats, and exposes ergonomic hooks for reacting to new messages or membership changes.

FunnableChat

Real-time lobby chat powered by the platform's WebSocket infrastructure. Handles connection retries, ping/pong heartbeats, and exposes ergonomic hooks for reacting to new messages or membership changes.

Examples

const sdk = Funnable.init();
const stop = sdk.chat.onMessage((msg) => console.log(msg.content));
sdk.chat.connect(lobbyId, authToken);
sdk.chat.send("GLHF!");

Members

connect

connect(lobbyId: string, token: string): void

Opens a chat socket for the provided lobby. Automatically starts a heartbeat every 30 seconds to avoid idle disconnects.

send

send(content: string): void

Broadcasts a text message into the connected lobby.

onMessage

onMessage(cb: MessageCallback): () => void

Registers a callback that fires whenever another player sends a message. Returns an unsubscribe function for teardown.

Examples

const unsubscribe = sdk.chat.onMessage((msg) => {
  ui.append(`${msg.name}: ${msg.content}`);
});

onUserJoined

onUserJoined(cb: SystemCallback): () => void

Registers a handler that fires when a player joins the lobby.

onUserLeft

onUserLeft(cb: SystemCallback): () => void

Registers a handler that fires when a player leaves the lobby.

disconnect

disconnect(): void

Stops the heartbeat and closes the socket. Safe to call even if no connection exists.