From 0ce00227a44b714f7f3524801bc0078ce3564302 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Wed, 4 Nov 2026 12:30:52 +0100 Subject: [PATCH] D AGENTS.md: channel membership, client events, refused connections New section 10 for consumers that override Websocket\Handler or write a client: a socket joins only through a (signed) subscribe, the auth step cannot add members, client events need membership and stop there, refused connections close with 4001/4009/1011, and AppManager::findByKey() must return a settled promise. The source map moves to section 11. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 | |---------|------|