WebSocket Middleware for React

2.0.0 2020-08-17 16:34 UTC

This package is auto-updated.

Last update: 2021-06-16 19:07:46 UTC


WebSocket Middleware for react/http

Try it out

Run chat_ws_server.php from the examples directory and navigate a few browser windows to (only tested briefly in Chrome)

Simple Usage

A simple echo server:

use Ratchet\RFC6455\Messaging\Message;
use React\EventLoop\Factory;
use React\Http\Server;
use Voryx\WebSocketMiddleware\WebSocketConnection;
use Voryx\WebSocketMiddleware\WebSocketMiddleware;

require __DIR__ . '/../../vendor/autoload.php';

$loop = Factory::create();

$ws = new WebSocketMiddleware([], function (WebSocketConnection $conn) {
    $conn->on('message', function (Message $message) use ($conn) {

$server = new Server($loop, $ws);

$server->listen(new \React\Socket\Server('', $loop));



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 = new WebSocketMiddleware(