Skip to content

kanata-php/socket-conveyor

Repository files navigation

Socket Conveyor

This package enables PHP 8.2+ applications to work with WebSocket messages using a routing strategy. Add an action handler implementing ActionInterface to the SocketMessageRouter, or run Conveyor in Pusher/Reverb-compatible mode for Laravel Echo clients.

Socket Conveyor is built on OpenSwoole. You can find out more about using WebSockets with OpenSwoole here.

Built for PHP 8.2+.

Documentation

Using Conveyor as a Pusher/Reverb server

Conveyor can run in a Pusher-compatible mode for Laravel's stock pusher or reverb broadcaster and the standard pusher-js / Laravel Echo client.

use Conveyor\Constants;
use Conveyor\ConveyorServer;

(new ConveyorServer())
    ->port(8080)
    ->conveyorOptions([
        Constants::WEBSOCKET_SUBPROTOCOL => Constants::PUSHER,
        Constants::USE_PRESENCE => true,
        Constants::APPS => [[
            'app_id' => 'local',
            'key' => env('REVERB_APP_KEY'),
            'secret' => env('REVERB_APP_SECRET'),
            'enable_client_messages' => true,
            'enabled' => true,
        ]],
    ])
    ->start();

Point Laravel at the Conveyor host and port with the normal Reverb/Pusher env values:

BROADCAST_CONNECTION=reverb
REVERB_APP_ID=local
REVERB_APP_KEY=your-app-key
REVERB_APP_SECRET=your-app-secret
REVERB_HOST=127.0.0.1
REVERB_PORT=8080
REVERB_SCHEME=http

The Pusher mode accepts WebSocket clients at /app/{key} and exposes the signed REST publish API at /apps/{app_id}/events, /apps/{app_id}/batch_events, and the channel info endpoints under /apps/{app_id}/channels.

About

WebSocket servers, fully featured and capable of independently managing rules and customizations.

Topics

Resources

License

Stars

Watchers

Forks

Contributors