修复推送报错:确定为服务端没有安装webman/push扩展,移除冗余代码
This commit is contained in:
@@ -134,7 +134,6 @@ interface Snapshot {
|
||||
const { t } = useI18n()
|
||||
const loading = ref(false)
|
||||
const pushConnected = ref(false)
|
||||
const lastPushAt = ref(0)
|
||||
const snapshot = reactive<Snapshot>({
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user