2.0.0 RC1
Pre-release
Pre-release
This library has been refactored to use the new amphp/websocket
library containing components that can be shared between server and clients.
Note: This is a pre-release, there might be breaking changes in the final stable version.
Websocket
now contains only two abstract methods that must be implemented:
onHandshake()
: This method acts as before, being invoked when a WebSocket connection attempt is made. The application may alter the given Response to deny the connection attempt or set application-specific headers.onConnect()
: This method is invoked upon a successful WebSocket connection. This method should use a loop to receive messages from the WebSocket connection.
protected function onConnect(Client $client, Request $request, Response $response): Promise
{
return Amp\call(function () use ($client) {
while ($message = yield $client->receive()) {
$payload = yield $message->buffer();
yield $client->send('Message of length ' . \strlen($payload) . 'received');
}
});
}
WebSocket clients are now represented by a Client
object. This object contains several methods for getting information about the client and for sending messages to a single client.