diff --git a/README.md b/README.md index 3fa40e0..f07e38e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ Ratchet is great! I've used Ratchet in the past, and it is a fantastic piece of TL;DR - If you need to build an application with neatly wrapped classes without caring to much about the internals, go with Ratchet. If you want to work with websockets in the same way you work with sockets in ReactPHP, go with this library. +## Missing Features + +The following features are missing, or work in progress: + +* Idle timeout and ping timeout +* Protocol errors should close with error codes +* Exceptions + ## Server The WebSocket handler is built as a HttpServer middleware. This makes sense as WebSocket as a protocol is running over HTTP. Connections are set up by the middleware and exposed via the `connect` event. @@ -55,7 +63,7 @@ $http->listen($socket); ``` -### Server Events +### WebSocketMiddleware Events #### connection @@ -82,3 +90,15 @@ This event will be emitted when a binary data frame have been received and decod #### close #### error + +### GroupManager events + +### create + +### destroy + +### ConnectionGroup events + +### join + +### leave \ No newline at end of file diff --git a/doc/ConnectionGroups.md b/doc/ConnectionGroups.md index a5829df..5a8e861 100644 --- a/doc/ConnectionGroups.md +++ b/doc/ConnectionGroups.md @@ -36,6 +36,14 @@ $groupManager->on('created', function (ConnectionGroup $group) { $middleware = new WebSocketMiddleware($groupManager); ``` +## Sending messages + +You can use the `ConnectionGoup::writeAll(string $payload)` method to send the payload to all members of the group. + +## Disconnecting clients + +You can disconnect clients cleanly on shutdown by using the `GroupManager::closeAll(string $reason, int $code)` method. You can also call on `ConnectionGrroup::closeAll` manually do disconnect a whole group. + ## Future * Add a GroupManagerImplementation so custom logic can be provided. diff --git a/src/Group/GroupManager.php b/src/Group/GroupManager.php index 545065e..40d2830 100644 --- a/src/Group/GroupManager.php +++ b/src/Group/GroupManager.php @@ -13,11 +13,11 @@ class GroupManager implements EventEmitterInterface /** * @var string emitted when a new group is created */ - const EVENT_CREATED = 'created'; + const EVENT_CREATE = 'create'; /** * @var string emitted after the last member leaves, when the group is destroyed */ - const EVENT_DESTROYED = 'destroyed'; + const EVENT_DESTROY = 'destroy'; /** @var array */ private array $groups = []; @@ -31,13 +31,13 @@ class GroupManager implements EventEmitterInterface $group->on(ConnectionGroup::EVENT_LEAVE, function () use ($group) { Loop::futureTick(function () use ($group) { if (count($group) === 0) { - $this->emit(self::EVENT_DESTROYED, [ $group ]); + $this->emit(self::EVENT_DESTROY, [ $group ]); $group->removeAllListeners(); unset($this->groups[$group->getName()]); } }); }); - $this->emit(self::EVENT_CREATED, [ $group ]); + $this->emit(self::EVENT_CREATE, [ $group ]); } else { $group = $this->groups[$name]; }