feat: 添加实时广播功能,支持风险预警、玩法切换和赔率更新,增强大厅公共频道的广播能力
This commit is contained in:
48
app/Services/PlayerRealtimeBroadcaster.php
Normal file
48
app/Services/PlayerRealtimeBroadcaster.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Events\BalanceUpdateBroadcast;
|
||||
|
||||
/**
|
||||
* 玩家私有频道实时广播。
|
||||
*
|
||||
* 对齐界面文档 §2.1:balance.update(频道 `player.{id}`)。
|
||||
* 注意:玩家私有频道广播与大厅公共频道分开管理。
|
||||
*/
|
||||
final class PlayerRealtimeBroadcaster
|
||||
{
|
||||
/** `balance.update` —— 钱包余额变动 */
|
||||
public function notifyBalanceUpdate(
|
||||
int $playerId,
|
||||
string $currencyCode,
|
||||
int $balanceMinor,
|
||||
int $changeMinor,
|
||||
string $reason,
|
||||
): void {
|
||||
if (! $this->driverSupportsRealtime()) {
|
||||
return;
|
||||
}
|
||||
|
||||
broadcast(new BalanceUpdateBroadcast(
|
||||
$playerId,
|
||||
$currencyCode,
|
||||
$balanceMinor,
|
||||
$changeMinor,
|
||||
$reason,
|
||||
(int) floor(microtime(true) * 1000),
|
||||
));
|
||||
}
|
||||
|
||||
private function driverSupportsRealtime(): bool
|
||||
{
|
||||
$default = config('broadcasting.default');
|
||||
if ($default === null || $default === 'null') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$driver = config("broadcasting.connections.{$default}.driver") ?? $default;
|
||||
|
||||
return ! in_array($driver, ['null', 'log'], true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user