Chat with presence
This room is private to its link. Join, then open the invite link in another window or send it to someone to chat with them.
Room
ConnectingHow it works
Joining calls this site's backend, which signs a join token with your name and a colour, using the app's
private key. The server replies to the join with the member list (members), then keeps it current
with member_joined and member_left messages.
Messages and typing indicators are client messages, named client-message and
client-typing. A message is sent to everyone including yourself, so the echo doubles as a
delivery receipt and the round trip can be timed. Typing goes to everyone else only.
The greeting is different: the backend publishes it with an HTTP POST, so it arrives as an event
message, not a client_event. Clients cannot forge those.
const room = pikoman.listenPresence(`presence-chat-${roomId}`, authenticator);
room.members((members) => renderMembers(members));
// Members' events are named client-…; the backend's never are.
room.on("client-message", (senderId, { text }) => {
addMessage(room.getMember(senderId), text);
});
// Third argument true: the sender gets the message back too.
form.addEventListener("submit", () => {
room.send("client-message", { text: input.value }, true);
});
// Server messages have no sender id.
room.on("bot", ({ text }) => addBotMessage(text));