diff --git a/app/process/WebmanPushServer.php b/app/process/WebmanPushServer.php deleted file mode 100644 index 25169f8..0000000 --- a/app/process/WebmanPushServer.php +++ /dev/null @@ -1,41 +0,0 @@ -apiListen; - $self = $this; - Timer::add( - 0.01, - static function () use ($apiListen, $self): void { - try { - $apiWorker = new Worker($apiListen); - $apiWorker->onMessage = [$self, 'onApiClientMessage']; - $apiWorker->listen(); - } catch (Throwable $e) { - Log::error('WebmanPushServer HTTP API listen failed: ' . $e->getMessage()); - } - }, - [], - false - ); - - Timer::add($this->keepAliveTimeout / 2, [$this, 'checkHeartbeat']); - Timer::add($this->webHookDelay, [$this, 'webHookCheck']); - } -} diff --git a/config/plugin/webman/push/process.php b/config/plugin/webman/push/process.php index 3126e5a..01c545d 100644 --- a/config/plugin/webman/push/process.php +++ b/config/plugin/webman/push/process.php @@ -1,10 +1,10 @@ [ - 'handler' => WebmanPushServer::class, + 'handler' => Server::class, 'listen' => config('plugin.webman.push.app.websocket'), 'count' => 1, // 必须是1 'reloadable' => false, // 执行reload不重启 diff --git a/web/src/views/backend/game/live/index.vue b/web/src/views/backend/game/live/index.vue index 2d4cc52..72b2d5d 100644 --- a/web/src/views/backend/game/live/index.vue +++ b/web/src/views/backend/game/live/index.vue @@ -134,7 +134,6 @@ interface Snapshot { const { t } = useI18n() const loading = ref(false) const pushConnected = ref(false) -const lastPushAt = ref(0) const snapshot = reactive({ record: null, bets: [], @@ -271,10 +270,12 @@ async function initPush() { pushClient = new PushCtor({ url, app_key }) pushChannel = pushClient.subscribe(channel) pushConnected.value = false + pushChannel.on('pusher:subscription_succeeded', () => { + pushConnected.value = true + }) startPushWatchdog() stopPolling() pushChannel.on(event, (payload: anyObj) => { - lastPushAt.value = Date.now() pushConnected.value = true snapshot.record = payload.record || null snapshot.bets = payload.bets || [] @@ -417,10 +418,14 @@ function startPushWatchdog() { return } pushWatchdogTimer = window.setInterval(() => { - const state = pushClient && pushClient.connection ? String(pushClient.connection.state || '') : '' - const stateConnected = state === 'connected' || state === 'connecting' - const hasRecentPush = lastPushAt.value > 0 && Date.now() - lastPushAt.value <= 6000 - if (!stateConnected || !hasRecentPush) { + if (!pushClient || !pushClient.connection) { + pushConnected.value = false + return + } + const state = String(pushClient.connection.state || '') + // push.js:onOpen 后长期为 connecting,必须收到 pusher:connection_established 才变 connected。 + // 把 connecting 当「已连接」会误报绿条(Nginx 只完成握手、帧未透传时 DevTools 消息列表为空)。 + if (state === 'disconnected') { pushConnected.value = false } }, 1000)