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 {useI18n} from 'vue-i18n'
|
||||||
import floating2 from '@/components/floating2/index.vue'
|
import floating2 from '@/components/floating2/index.vue'
|
||||||
import { useThrottleFn } from '@vueuse/core'
|
import { useThrottleFn } from '@vueuse/core'
|
||||||
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { auctionDetail,getAuctionDetail} = goodStore();
|
const { auctionDetail,getAuctionDetail} = goodStore();
|
||||||
const player = ref(null)
|
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 pullLink = ref('')
|
||||||
const handlePlayerError = (error) => {
|
const handlePlayerError = (error) => {
|
||||||
showConfirmDialog({
|
showConfirmDialog({
|
||||||
@ -115,7 +113,10 @@ onBeforeUnmount(() => {
|
|||||||
player.value = null
|
player.value = null
|
||||||
})
|
})
|
||||||
watch(() => fullLive.value, async (newVal) => {
|
watch(() => fullLive.value, async (newVal) => {
|
||||||
if (!newVal) return
|
if (!newVal) {
|
||||||
|
wsClient.value?.disconnect()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await getSocketData()
|
await getSocketData()
|
||||||
|
|
||||||
|
@ -149,13 +149,13 @@ export const liveStore = createGlobalState(() => {
|
|||||||
...extraStyle
|
...extraStyle
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
const wsClient=ref(null)
|
||||||
const getSocketData = async () => {
|
const getSocketData = async () => {
|
||||||
const wsClient = new WebSocketClient(
|
wsClient.value = new WebSocketClient(
|
||||||
config.public.NUXT_PUBLIC_SOCKET_URL,
|
config.public.NUXT_PUBLIC_SOCKET_URL,
|
||||||
token.value
|
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,
|
auctionUuid: auctionDetail.value.uuid,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -248,6 +248,7 @@ export const liveStore = createGlobalState(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return{
|
return{
|
||||||
|
wsClient,
|
||||||
fullLive,
|
fullLive,
|
||||||
isMinWindow,
|
isMinWindow,
|
||||||
lastSnapshot,
|
lastSnapshot,
|
||||||
|
Loading…
Reference in New Issue
Block a user