mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 19:12:10 +00:00
Implement instant websocket room updates
This commit is contained in:
@@ -5,18 +5,22 @@ namespace App\Events;
|
||||
use App\Enums\RoomStateChange;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class RoomStateChanged implements ShouldBroadcast
|
||||
class RoomStateChanged implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $state
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $roomId,
|
||||
public readonly int $version,
|
||||
public readonly RoomStateChange $change,
|
||||
public readonly ?array $state = null,
|
||||
) {}
|
||||
|
||||
public function broadcastOn(): Channel
|
||||
@@ -30,13 +34,14 @@ class RoomStateChanged implements ShouldBroadcast
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{version: int, change: string}
|
||||
* @return array{version: int, change: string, state: array<string, mixed>|null}
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'version' => $this->version,
|
||||
'change' => $this->change->value,
|
||||
'state' => $this->state,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user