From b87e8d334609d47f56c48c90b20e3647cee19887 Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Fri, 7 Mar 2025 17:27:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(live):=20=E4=BF=AE=E5=A4=8D=E7=A6=BB?= =?UTF-8?q?=E5=BC=80=E7=9B=B4=E6=92=AD=E9=97=B4=E6=97=B6=20WebSocket=20?= =?UTF-8?q?=E6=9C=AA=E6=96=AD=E5=BC=80=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 liveRoom 组件中添加离开直播间时断开 WebSocket 连接的逻辑 - 在 liveStore 中添加 wsClient ref 以存储 WebSocket 客户端实例 - 更新 getSocketData 方法,使用 wsClient.value 连接 WebSocket --- app/pages/liveRoom/index.client.vue | 9 +++++---- app/stores/live/index.js | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/pages/liveRoom/index.client.vue b/app/pages/liveRoom/index.client.vue index 5e59590..cca6073 100644 --- a/app/pages/liveRoom/index.client.vue +++ b/app/pages/liveRoom/index.client.vue @@ -15,12 +15,10 @@ import {artworkBuy} from "@/api/goods/index.js" import {useI18n} from 'vue-i18n' import floating2 from '@/components/floating2/index.vue' import { useThrottleFn } from '@vueuse/core' - - const { t } = useI18n() const { auctionDetail,getAuctionDetail} = goodStore(); const player = ref(null) -const {quoteStatus, show, playerId, show1, auctionData, getSocketData, getLiveLink, fullLive} = liveStore() +const {quoteStatus, show, playerId, show1, auctionData, getSocketData, getLiveLink, fullLive,wsClient} = liveStore() const pullLink = ref('') const handlePlayerError = (error) => { showConfirmDialog({ @@ -115,7 +113,10 @@ onBeforeUnmount(() => { player.value = null }) watch(() => fullLive.value, async (newVal) => { - if (!newVal) return + if (!newVal) { + wsClient.value?.disconnect() + return + } await getSocketData() diff --git a/app/stores/live/index.js b/app/stores/live/index.js index c9b1b52..adab290 100644 --- a/app/stores/live/index.js +++ b/app/stores/live/index.js @@ -149,13 +149,13 @@ export const liveStore = createGlobalState(() => { ...extraStyle } }) - + const wsClient=ref(null) const getSocketData = async () => { - const wsClient = new WebSocketClient( + wsClient.value = new WebSocketClient( config.public.NUXT_PUBLIC_SOCKET_URL, token.value ) - const ws = wsClient.connect('/api/v1/m/auction/live', { + const ws = wsClient.value.connect('/api/v1/m/auction/live', { auctionUuid: auctionDetail.value.uuid, }) @@ -248,6 +248,7 @@ export const liveStore = createGlobalState(() => { } } return{ + wsClient, fullLive, isMinWindow, lastSnapshot,