WebSocket Middleware for react/http
Run chat_ws_server.php from the examples directory and navigate a few browser windows to http://127.0.0.1:4321/ (only tested briefly in Chrome)
A simple echo server:
useRatchet\RFC6455\Messaging\Message; useReact\EventLoop\Factory; useReact\Http\Server; useVoryx\WebSocketMiddleware\WebSocketConnection; useVoryx\WebSocketMiddleware\WebSocketMiddleware; require__DIR__ . '/../../vendor/autoload.php'; $loop = Factory::create(); $ws = newWebSocketMiddleware([], function (WebSocketConnection$conn){$conn->on('message', function (Message$message) use ($conn){$conn->send($message)})}); $server = newServer($loop, $ws); $server->listen(new \React\Socket\Server('127.0.0.1:4321', $loop)); $loop->run();By default WebSocketMiddleware uses the ratchet/rfc6455 default max sizes for messages and frames and also disables compression. These settings can be overridden with the WebSocketOptions object.
$ws = newWebSocketMiddleware( [], $connectionHandler, [], WebSocketOptions::getDefault() ->withMaxFramePayloadSize(2048) ->withMaxMessagePayloadSize(4096) ->withPermessageDeflate());