PHP code example of kanata-php / conveyor-laravel-broadcaster

1. Go to this page and download the library: Download kanata-php/conveyor-laravel-broadcaster library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kanata-php / conveyor-laravel-broadcaster example snippets



return [
    // ...
    'providers' => [
        // ...
        Kanata\LaravelBroadcaster\ConveyorServiceProvider::class,
    ],
    // ...
];



return [
    // ...
    'conveyor' => [
        'driver' => 'conveyor',
    ],
];

use App\Models\User;
use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('actions-channel', function (User $user) {
    return true; // we are authorizing any user here - update according to your needs!
});

App\Models\User::factory()->create(['email' => '[email protected]', 'password' => Hash::make('password')]);

> 
> 
> namespace App\Events;
> 
> use Illuminate\Broadcasting\InteractsWithBroadcasting;
> use Illuminate\Broadcasting\PrivateChannel;
> use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
> 
> class TestEvent implements ShouldBroadcastNow
> {
>     use InteractsWithBroadcasting;
> 
>     public function __construct(
>         public string $message,
>         public string $channel,
>     ) {
>         $this->broadcastVia('conveyor');
>     }
> 
>     public function broadcastOn(): array
>     {
>         return [
>             new PrivateChannel($this->channel),
>         ];
>     }
> }
> 

> event(new App\Events\TestEvent( message: 'my message', channel: 'my-channel'));
> 

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

Route::get('/ws-client', function () {
    Auth::loginUsingId(1); // here we authorize for the sake of the example.

    $protocol = config('jacked-server.ssl-enabled') ? 'wss' : 'ws';
    $port = config('jacked-server.ssl-enabled') ? config('jacked-server.ssl-port') : config('jacked-server.port');

    return view('ws-client', [
        'protocol' => $protocol,
        'uri' => '127.0.0.1',
        'wsPort' => $port,
        'channel' => 'private-my-channel',
    ]);
});
bash
php artisan vendor:publish --provider="Kanata\LaravelBroadcaster\ConveyorServiceProvider"
shell
php artisan install:broadcasting
bash
php artisan tinker