New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

larahook/simple-centrifugo

Connection and subscription tokens for centrifugo
2,502 1
Install
composer require larahook/simple-centrifugo
Latest Version:v0.0.13
PHP:^8.0
Laravel:10 – 13
License:MIT
Last Updated:Mar 25, 2026
Links: GitHub  ·  Packagist
Maintainer: Mishanki

Connection and subscription tokens for centrifugo

Install

composer require larahook/simple-centrifugo

Driver

Add centrifugo connection with simple-centrifugo driver to config/broadcasting.php

'connections' => [
    'centrifugo' => [
        'driver' => 'simple-centrifugo',
        'token_hmac_secret_key' => env('CENTRIFUGO_TOKEN_HMAC_SECRET_KEY', ''),
        'api_key' => env('CENTRIFUGO_API_KEY', ''),
        'url' => env('CENTRIFUGO_URL', 'http://localhost:8000'), // centrifugo api url
        'verify' => env('CENTRIFUGO_VERIFY', false), // Verify host ssl if centrifugo uses this
        'ssl_key' => env('CENTRIFUGO_SSL_KEY', null), // Self-Signed SSl Key for Host (require verify=true)
    ],
]

Usage

Get tokens for client

  • Add SimpleCentrifugo trait to your class
  • Use method getConnectionToken for get connection token
  • And use method getSubscriptionToken for get subscription tokens
use Carbon\Carbon;
use Larahook\SimpleCentrifugo\Trait\SimpleCentrifugo;

class ChannelService
{
    use SimpleCentrifugo;

    /**
     * @param int $userId
     * @param Carbon $exp
     *
     * @return array
     */
    public function getConnToken(int $userId, Carbon $exp): array
    {
        return $this->getConnectionToken($userId, $exp);
    }

    /**
     * @param int $userId
     * @param array $channels
     * @param Carbon $exp
     *
     * @return array
     */
    public function getSubsToken(int $userId, array $channels, Carbon $exp): array
    {
        return $this->getSubscriptionToken($userId, $channels, $exp);
    }
}

Event example

Push message to centrifugo channel via laravel events


namespace App\Events;

use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;

class PersonalEvent implements ShouldBroadcastNow
{
    use Dispatchable;
    use SerializesModels;

    /**
     * @param array $message
     */
    public function __construct(public array $message) {}

    /**
     * Get the channels the event should broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['personal:#'.Auth::id()];
    }

    public function broadcastAs()
    {
        return 'PersonalEvent';
    }
}

Event execute

PersonalEvent::dispatch(['info']);

Related Packages

agenter-labs/illuminate-token

Token manager Laravel

3,112 1
xaamin/jwt

PHP Implementation of JSON Web token with RSA

10,404 2
alexusmai/laravel-centrifugo

Centrifugo broadcaster for laravel 9 and Centrifugo 4

6,888 8
alex-hnydiuk/laracent

Centrifugo broadcaster for laravel >= 5.7 and Centrifugo >= 2.1.0

4,395 13
laragear/token-action

Use tokens to accept or reject actions a limited number of times.

1,188 4

Version History

Version Released PHP Laravel License
v0.0.13 ^8.0 ^10.0|^11.0|^12.0|^13.0 MIT
v0.0.12 ^8.0 ^10.0|^11.0|^12.0|^13.0 MIT
v0.0.11 ^8.0 ^10.0|^11.0|^12.0|^13.0 MIT
v0.0.10 ^8.0 ^10.0|^11.0|^12.0 MIT
v0.0.9 ^8.0 ^10.0|^11.0|^12.0 MIT