fix(live): 修复离开直播间时 WebSocket 未断开的问题
- 在 liveRoom 组件中添加离开直播间时断开 WebSocket 连接的逻辑 - 在 liveStore 中添加 wsClient ref 以存储 WebSocket 客户端实例 - 更新 getSocketData 方法,使用 wsClient.value 连接 WebSocket
This commit is contained in:
parent
e0f195bdb1
commit
b87e8d3346
@ -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()
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user