feat: 添加实时广播功能,支持风险预警、玩法切换和赔率更新,增强大厅公共频道的广播能力
This commit is contained in:
62
app/Events/PlayToggleBroadcast.php
Normal file
62
app/Events/PlayToggleBroadcast.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
|
||||
/**
|
||||
* 界面文档 §2.1:`play.toggle` —— 玩法开关变更推送。
|
||||
*
|
||||
* 触发时机:后台开启或关闭某玩法时。
|
||||
* 前端处理:玩法列显示/隐藏或置灰/启用。
|
||||
*/
|
||||
final class PlayToggleBroadcast implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param string $playCode 玩法代码(如 straight_4d, box_2d 等)
|
||||
* @param bool $enabled 是否启用
|
||||
* @param string|null $reason 变更原因(可选)
|
||||
* @param int $emittedAtMs 发送时间戳(毫秒)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $playCode,
|
||||
public readonly bool $enabled,
|
||||
public readonly ?string $reason,
|
||||
public readonly int $emittedAtMs,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 公共频道,所有在大厅的玩家都能收到。
|
||||
*
|
||||
* @return array<int, Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new Channel('lottery-hall')];
|
||||
}
|
||||
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'play.toggle';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{play_code: string, enabled: bool, reason: string|null, action: string, emitted_at_ms: int}
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'play_code' => $this->playCode,
|
||||
'enabled' => $this->enabled,
|
||||
'reason' => $this->reason,
|
||||
'action' => $this->enabled ? 'enabled' : 'disabled',
|
||||
'emitted_at_ms' => $this->emittedAtMs,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user