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 your name and a colour with the app secret. The server
replies to the join with the member list (opcode 16), then keeps it current with join
(2) and leave (4) frames.
Messages and typing indicators are client messages. 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 a server message
(opcode 1). Clients cannot forge those.
const room = pikoman.listenPresence(`presence-chat-${roomId}`, authenticator);
room.members((members) => renderMembers(members));
room.on("message", (senderId, { text }) => {
addMessage(room.getMember(senderId), text);
});
// Third argument true: the sender gets the message back too.
form.addEventListener("submit", () => {
room.send("message", { text: input.value }, true);
});
// Server messages have no sender id.
room.on("bot", ({ text }) => addBotMessage(text));