修复推送报错:确定为服务端没有安装webman/push扩展,移除冗余代码
This commit is contained in:
@@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace app\process;
|
|
||||||
|
|
||||||
use support\Log;
|
|
||||||
use Throwable;
|
|
||||||
use Webman\Push\Server;
|
|
||||||
use Workerman\Timer;
|
|
||||||
use Workerman\Worker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Workerman 5 在 Fiber 中拉起 Push 时,内嵌 HTTP API(默认 3232)可能与事件循环初始化时序冲突,导致本机无法连接、业务 trigger 全部失败。
|
|
||||||
* 延后一拍再 listen;Timer 第四参数须为 false,否则会按 repeat 每 0.01s 重复创建 Worker。
|
|
||||||
*/
|
|
||||||
final class WebmanPushServer extends Server
|
|
||||||
{
|
|
||||||
public function onWorkerStart($worker): void
|
|
||||||
{
|
|
||||||
$apiListen = $this->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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use app\process\WebmanPushServer;
|
use Webman\Push\Server;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'server' => [
|
'server' => [
|
||||||
'handler' => WebmanPushServer::class,
|
'handler' => Server::class,
|
||||||
'listen' => config('plugin.webman.push.app.websocket'),
|
'listen' => config('plugin.webman.push.app.websocket'),
|
||||||
'count' => 1, // 必须是1
|
'count' => 1, // 必须是1
|
||||||
'reloadable' => false, // 执行reload不重启
|
'reloadable' => false, // 执行reload不重启
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ interface Snapshot {
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const pushConnected = ref(false)
|
const pushConnected = ref(false)
|
||||||
const lastPushAt = ref(0)
|
|
||||||
const snapshot = reactive<Snapshot>({
|
const snapshot = reactive<Snapshot>({
|
||||||
record: null,
|
record: null,
|
||||||
bets: [],
|
bets: [],
|
||||||
@@ -271,10 +270,12 @@ async function initPush() {
|
|||||||
pushClient = new PushCtor({ url, app_key })
|
pushClient = new PushCtor({ url, app_key })
|
||||||
pushChannel = pushClient.subscribe(channel)
|
pushChannel = pushClient.subscribe(channel)
|
||||||
pushConnected.value = false
|
pushConnected.value = false
|
||||||
|
pushChannel.on('pusher:subscription_succeeded', () => {
|
||||||
|
pushConnected.value = true
|
||||||
|
})
|
||||||
startPushWatchdog()
|
startPushWatchdog()
|
||||||
stopPolling()
|
stopPolling()
|
||||||
pushChannel.on(event, (payload: anyObj) => {
|
pushChannel.on(event, (payload: anyObj) => {
|
||||||
lastPushAt.value = Date.now()
|
|
||||||
pushConnected.value = true
|
pushConnected.value = true
|
||||||
snapshot.record = payload.record || null
|
snapshot.record = payload.record || null
|
||||||
snapshot.bets = payload.bets || []
|
snapshot.bets = payload.bets || []
|
||||||
@@ -417,10 +418,14 @@ function startPushWatchdog() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
pushWatchdogTimer = window.setInterval(() => {
|
pushWatchdogTimer = window.setInterval(() => {
|
||||||
const state = pushClient && pushClient.connection ? String(pushClient.connection.state || '') : ''
|
if (!pushClient || !pushClient.connection) {
|
||||||
const stateConnected = state === 'connected' || state === 'connecting'
|
pushConnected.value = false
|
||||||
const hasRecentPush = lastPushAt.value > 0 && Date.now() - lastPushAt.value <= 6000
|
return
|
||||||
if (!stateConnected || !hasRecentPush) {
|
}
|
||||||
|
const state = String(pushClient.connection.state || '')
|
||||||
|
// push.js:onOpen 后长期为 connecting,必须收到 pusher:connection_established 才变 connected。
|
||||||
|
// 把 connecting 当「已连接」会误报绿条(Nginx 只完成握手、帧未透传时 DevTools 消息列表为空)。
|
||||||
|
if (state === 'disconnected') {
|
||||||
pushConnected.value = false
|
pushConnected.value = false
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user