kanata-php/socket-conveyor

A WebSocket/Socket message Router

Maintainers

Package info

github.com/kanata-php/socket-conveyor

pkg:composer/kanata-php/socket-conveyor

Fund package maintenance!

kanata-php

Statistics

Installs: 929

Dependents: 4

Suggesters: 0

Stars: 11

Open Issues: 0

3.0.1-beta 2024-04-23 17:08 UTC

README

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.