diff --git a/AGENTS.md b/AGENTS.md index bd2652a..006423d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -326,7 +326,32 @@ migrated to real queued **Jobs** (which also get retry semantics + show up in to --- -## 10. Source map (read these, not your memory) +## 10. Channel membership, client events, refused connections + +Rules for anyone overriding `Websocket\Handler` (a consumer's `App\Websocket\Handler`) or +writing a client. All in `src/Websocket/Handler.php`. + +- **A socket joins a channel only through a subscribe.** `private-*` (incl. + `private-encrypted-*`) and `presence-*` need a valid `auth` signature; a bad one gets + `:error` `{message: "Invalid Signature", code: 4009}` and the socket stays off the + channel. A Success reply names the channel: `{event: ":response", channel, data}`. +- **`authenticateConnection()` cannot add members.** `processFullMessage()` takes the socket + off the channel again if the auth step (or your override calling `saveConnection()`) put it + on a channel it was not on. Your override still receives the frame's channel, so + `$channel->saveConnection()` stays safe to call; it only refreshes an existing member. On + `onClose()` the channel is `null`: null-check it. +- **Client events (`client-*`)** need `enable_client_messages` and a sender that is on the + channel. A non-member gets `:error` "Subscription not established". Either way the + frame ends there and never reaches a controller. +- **Refused connections are closed** with the code from the `websocket.error` frame: 4001 + unknown app key, 4009 origin not allowed, 1011 anything else that failed in `onOpen`. + Clients should not reconnect on 4000-4099. +- **A custom `AppManager::findByKey()` must return an already settled promise.** The handler + reads it inside `onOpen` on the event loop; a pending promise refuses the connection (1011). + +--- + +## 11. Source map (read these, not your memory) | Concern | File | |---------|------|