use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('conveyor_tokens', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->foreignId('user_id');
$table->string('aud')->nullable();
$table->text('token');
$table->string('aud_protocol')->nullable();
$table->integer('allowed_uses')->nullable();
$table->integer('uses')->nullable();
$table->dateTime('expire_at')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('conveyor_tokens');
}
};
>
>
> 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),
> ];
> }
> }
>
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.
return view('ws-client', [
'protocol' => config('broadcasting.connections.conveyor.protocol'),
'uri' => config('broadcasting.connections.conveyor.host'),
'wsPort' => config('broadcasting.connections.conveyor.port'),
'channel' => 'private-my-channel',
]);
});
// file: server.php
er;
use Conveyor\Events\MessageReceivedEvent;
use Conveyor\Events\PreServerStartEvent;
(new ConveyorServer())
// if you want to see messages in the console
->eventListeners([
Conveyor\Constants::WEBSOCKET_SERVER_TOKEN => 'my-secure-conveyor-token',
Conveyor\Constants::EVENT_MESSAGE_RECEIVED => function (MessageReceivedEvent $event) {
var_dump($event->data);
},
])
->port(8181)
->start();