fix: 修正即時聊天室 presence channel 間歇性失效

三個根本原因:
1. updateEchoToken() 呼叫 disconnect/connect 會中斷已訂閱的
   presence channel,改為只更新 auth header(不重連)。
   同時將 setAuth() 的呼叫順序改為先 updateEchoToken() 再
   startRealtime(),確保訂閱時使用最新 token。
2. BookingPresenceChannel::join() 未對 schedule null 做防守,
   載入後若 schedule 不存在會 500,導致 auth 靜默失敗。
3. WebSocket 重連後 presence channel 不會自動恢復,
   在 BookingChat 加入 reconnected 事件處理,重連後重訂閱。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 17:46:15 +08:00
parent 6286399a3b
commit 1ba4ca893a
5 changed files with 21 additions and 7 deletions
+9
View File
@@ -170,15 +170,24 @@ function subscribeChannel() {
})
}
function handleReconnected() {
if (!isConfirmed.value) return
echo.leave(`booking.${props.bookingId}`)
channel.value = null
subscribeChannel()
}
onMounted(async () => {
await requestBrowserNotificationPermission()
await loadHistory()
if (isConfirmed.value) {
subscribeChannel()
echo.connector.pusher.connection.bind('reconnected', handleReconnected)
}
})
onUnmounted(() => {
echo.connector.pusher.connection.unbind('reconnected', handleReconnected)
if (channel.value) {
channel.value.whisper('presence', { user_type: props.currentUserType, online: false })
echo.leave(`booking.${props.bookingId}`)