Files
zombie-game/app/Events/GameRoomError.php
T
2026-09-07 20:37:40 +02:00

46 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
/**
* Tells a client why its room control frame was rejected (e.g. joining a
* room that does not exist). Broadcast to game.{room}, which the requesting
* client is already subscribed to.
*/
final class GameRoomError implements ShouldBroadcastNow
{
use Dispatchable;
use InteractsWithSockets;
public function __construct(
public readonly string $room,
public readonly string $code,
) {}
public function broadcastOn(): Channel
{
return new Channel('game.'.$this->room);
}
public function broadcastAs(): string
{
return 'room-error';
}
/** @return array{code: string, room: string} */
public function broadcastWith(): array
{
return [
'code' => $this->code,
'room' => $this->room,
];
}
}