naturalweb/laravel-socketcluster

This package is abandoned and no longer maintained. The author suggests using the soleon/sc-php package instead.

SocketCluster.io library Broadcaster for Laravel.

1.0.0 2015-09-09 14:11 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:51:07 UTC


README

WARNING: This package is no longer maintained. Use soleon/sc-php instead.

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version License

SocketCluster.io library broadcaster for Laravel.

Requirements

  • laravel >= 5.1
  • textalk/websocket 1.0.* (retrieved automatically via Composer)

Installation

Using Composer:

composer require naturalweb/laravel-socketcluster

In your config/app.php file add the following provider to your service providers array:

'providers' => [
    ...
    LaravelSocketCluster\SCBroadcastServiceProvider::class,
    ...
]

In your config/broadcasting.php file set the default driver to 'socketcluster' and add the connection configuration like so:

'default' => 'socketcluster',

'connections' => [
    ...
    'socketcluster' => [
      'driver' => 'socketcluster',
      'secure' => env('BROADCAST_SOCKETCLUSTER_SECURE', false),
      'host'   => env('BROADCAST_SOCKETCLUSTER_HOST', '127.0.0.1'),
      'port'   => env('BROADCAST_SOCKETCLUSTER_PORT', '3000'),
      'path'   => env('BROADCAST_SOCKETCLUSTER_PATH', '/socketcluster/'),
    ],
    ...
]

Usage

Add a custom broadcast event to your application like so:

namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PublishToSocketClusterEvent implements ShouldBroadcast
{
    use SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return ['<channel>'];
    }
}

Now to publish in your application simply fire the event:

event(new App\Events\PublishToSocketClusterEvent('Test publish!!'));