← 所有消息

Reaching every screen except your own

Broadcasts gained an except, and the daemon's health endpoint began reporting presence per token instead of counting sockets.

Both come from the same realisation: a token is a principal, not a connection. One user, or one register, can easily have three sockets open. That makes token:not: the wrong tool for the common case, because it excludes every screen that person has rather than the one that triggered the change. Right for reaching other people, wrong for reaching your own second tab.

So wsExcept names a socket id and sits beside the target rather than inside it. The daemon cannot work this out on its own: a cast is a separate HTTP call to the bridge, with no link back to the socket whose handler produced it, so the app has to say which one it is. Inside a hook that socket id is right there as an argument:

function wsReceive($wsHost, $wsToken, $wsSocket, ...$data){
    wsCast(wsTarget: 'all', wsExcept: $wsSocket, outer: ['#board' => %app->board])
}

The presence half is the same lesson from the other side. An app that keeps its own count of who is online drifts, and always in the same direction: on a hard restart the close events never fire, and a late close from an old connection cancels out a fresh one. The daemon holds the sockets, so the daemon answers the question. /health now reports a breakdown per token, keyed on a SHA-256 hash of it, because that endpoint is readable by any local process and a token is a credential. An app hashes its own tokens the same way to look them up.

Engine 1.0.1. See the WebSocket chapter.

我们使用必要的cookie来使该网站正常工作。在您的许可下,我们还使用分析工具来改善网站。