olexin-pro/cenrtifuge

centrifuge for roadrunner laravel-bridge

Maintainers

Package info

github.com/olexin-pro/cenrtifuge

pkg:composer/olexin-pro/cenrtifuge

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.1 2026-03-27 12:41 UTC

This package is not auto-updated.

Last update: 2026-03-28 10:59:41 UTC


README

EXPERIMENTAL This package is an experiment and a work in progress. Use it at your own risk. The API may change without notice and there are no stability guarantees.

Laravel package for integrating Centrifugo WebSocket server with RoadRunner via the roadrunner-php/laravel-bridge.

Requirements

  • PHP 8.3+
  • Laravel 10, 11, or 12
  • RoadRunner with roadrunner-php/laravel-bridge ^6.0
  • roadrunner-php/centrifugo ^2.2

Installation

composer require olexin-pro/cenrtifuge

Publish the config and route stubs:

php artisan vendor:publish --tag=centrifuge-config
php artisan vendor:publish --tag=centrifuge-routes

Configuration

Config file: config/centrifuge.php

Key Default Description
use_broadcasting_channels false Use routes/channels.php (Laravel Broadcasting) instead of routes/centrifuge.php
guards ['sanctum', 'session'] Auth guards tried in order during connection
rpc.routes_path routes/rpc.php Path to RPC routes file
channels.routes_path routes/centrifuge.php Path to channel routes file
handlers see below Map of Centrifugo request types to handler classes

Environment variables

CENTRIFUGE_USE_BROADCASTING=false

RoadRunner Worker

Register CentrifugoWorker in your RoadRunner configuration:

# .rr.yaml
centrifuge:
  proxy_connect_timeout: 1s
  # ...

Point RoadRunner to CentrifugoWorker::class as the worker implementation in your bootstrap.

Channel Authorization

By default, channels are authorized via routes/centrifuge.php:

use Illuminate\Contracts\Auth\Authenticatable;
use OlexinPro\Centrifuge\Routing\ChannelRouter;

/** @var ChannelRouter $centrifuge */

// Private channel with a parameter
$centrifuge->channel('private-user.{userId}', function (?Authenticatable $user, string $userId) {
    return $user && (int) $user->getAuthIdentifier() === (int) $userId;
});

// Public channel
$centrifuge->channel('public.chat', function () {
    return true;
});

To use Laravel's standard routes/channels.php instead, set CENTRIFUGE_USE_BROADCASTING=true.

RPC

Register RPC handlers in routes/rpc.php:

use OlexinPro\Centrifuge\Routing\RpcRouter;

/** @var RpcRouter $rpc */

// Global middleware
$rpc->middleware([\App\Centrifuge\Middleware\LogRpcRequest::class]);

// Single method
$rpc->register('ping', \App\Centrifuge\Handlers\PingHandler::class);

// Grouped methods with middleware
$rpc->group('', [\App\Centrifuge\Middleware\RequireAuth::class], function (RpcRouter $rpc) {
    $rpc->group('posts', [], function (RpcRouter $rpc) {
        $rpc->register('create', \App\Centrifuge\Handlers\CreatePostHandler::class);
    });
});

Registered method name for nested groups is built as prefix.method, e.g. posts.create.

Implementing an RPC handler

use Illuminate\Contracts\Auth\Authenticatable;
use OlexinPro\Centrifuge\Contracts\RpcHandlerContract;
use RoadRunner\Centrifugo\Request\RPC;

class PingHandler implements RpcHandlerContract
{
    public function handle(array $data, ?Authenticatable $user, RPC $request): mixed
    {
        return ['pong' => true];
    }
}

Custom Handlers

Override any built-in request handler by rebinding it in config/centrifuge.php:

'handlers' => [
    \RoadRunner\Centrifugo\Request\Connect::class   => \App\Centrifuge\Handlers\MyConnectHandler::class,
    \RoadRunner\Centrifugo\Request\Subscribe::class => \OlexinPro\Centrifuge\Handlers\SubscribeHandler::class,
    // ...
],

All handler classes must implement OlexinPro\Centrifuge\Contracts\RequestHandler.

License

MIT