Renamed events in GroupManager
This commit is contained in:
parent
3abdced846
commit
054e052da7
22
README.md
22
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.
|
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
|
## 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.
|
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
|
#### connection
|
||||||
|
|
||||||
@ -82,3 +90,15 @@ This event will be emitted when a binary data frame have been received and decod
|
|||||||
#### close
|
#### close
|
||||||
|
|
||||||
#### error
|
#### error
|
||||||
|
|
||||||
|
### GroupManager events
|
||||||
|
|
||||||
|
### create
|
||||||
|
|
||||||
|
### destroy
|
||||||
|
|
||||||
|
### ConnectionGroup events
|
||||||
|
|
||||||
|
### join
|
||||||
|
|
||||||
|
### leave
|
@ -36,6 +36,14 @@ $groupManager->on('created', function (ConnectionGroup $group) {
|
|||||||
$middleware = new WebSocketMiddleware($groupManager);
|
$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
|
## Future
|
||||||
|
|
||||||
* Add a GroupManagerImplementation so custom logic can be provided.
|
* Add a GroupManagerImplementation so custom logic can be provided.
|
||||||
|
@ -13,11 +13,11 @@ class GroupManager implements EventEmitterInterface
|
|||||||
/**
|
/**
|
||||||
* @var string emitted when a new group is created
|
* @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
|
* @var string emitted after the last member leaves, when the group is destroyed
|
||||||
*/
|
*/
|
||||||
const EVENT_DESTROYED = 'destroyed';
|
const EVENT_DESTROY = 'destroy';
|
||||||
|
|
||||||
/** @var array<string,ConnectionGroup> */
|
/** @var array<string,ConnectionGroup> */
|
||||||
private array $groups = [];
|
private array $groups = [];
|
||||||
@ -31,13 +31,13 @@ class GroupManager implements EventEmitterInterface
|
|||||||
$group->on(ConnectionGroup::EVENT_LEAVE, function () use ($group) {
|
$group->on(ConnectionGroup::EVENT_LEAVE, function () use ($group) {
|
||||||
Loop::futureTick(function () use ($group) {
|
Loop::futureTick(function () use ($group) {
|
||||||
if (count($group) === 0) {
|
if (count($group) === 0) {
|
||||||
$this->emit(self::EVENT_DESTROYED, [ $group ]);
|
$this->emit(self::EVENT_DESTROY, [ $group ]);
|
||||||
$group->removeAllListeners();
|
$group->removeAllListeners();
|
||||||
unset($this->groups[$group->getName()]);
|
unset($this->groups[$group->getName()]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$this->emit(self::EVENT_CREATED, [ $group ]);
|
$this->emit(self::EVENT_CREATE, [ $group ]);
|
||||||
} else {
|
} else {
|
||||||
$group = $this->groups[$name];
|
$group = $this->groups[$name];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user