Updated readme, example

This commit is contained in:
Chris 2024-02-24 14:18:26 +01:00
parent 899dd3b7e4
commit 7154b1baed
2 changed files with 8 additions and 7 deletions

View File

@ -4,12 +4,12 @@ This is a library that implements WebSocket support on top of ReactPHPs HttpServ
## Missing Features ## Missing Features
The following features are missing, or work in progress: This library is under development, and should not be used in any projects yet. The API and implementation may change in the future, and some features are still not implemented, or work in progress:
* Idle timeout and ping timeout * Timeouts -- Disconnect the client on ping/pong timeout, and optionally on inactivity/idle.
* Protocol errors should close with error codes * Error Handling -- Protocol errors should close the connection etc.
* Exceptions * Exceptions -- Exceptions should be thrown when relevant errors are encountered, such as bad encoding or data.
* Full tested support for fragmented frames * Fragmented Messages -- Sending and receiving messages fragmented over multiple frames need work.
## Installing ## Installing

View File

@ -19,17 +19,18 @@ $websockets->on('connection', function (WebSocketInterface $websocket) {
// This just echoes text received, unless the websocket is part of a group. // This just echoes text received, unless the websocket is part of a group.
// In this case the message is sent to all websockets in the group. // In this case the message is sent to all websockets in the group.
$websocket->on('text', function ($text) use ($websocket) { $websocket->on('text', function ($text) use ($websocket) {
// Send a message with the group name starting with '#' to join a group.
if (str_starts_with($text, '#')) { if (str_starts_with($text, '#')) {
$websocket->setGroup(substr($text,1)); $websocket->setGroup(substr($text,1));
$websocket->write("joined group {$text}"); $websocket->write("joined group {$text}");
} else { } else {
// Echo back if not in group, send to group otherwise
if (!$websocket->getGroup()) if (!$websocket->getGroup())
$websocket->write($text); $websocket->write($text);
else else
foreach ($websocket->getGroup() as $member) { foreach ($websocket->getGroup() as $member)
$member->write($text); $member->write($text);
} }
}
}); });
}); });