后台直播:修复信令误断(onclose 提示与严格模式 onUnmounted)

Made-with: Cursor
This commit is contained in:
whm
2026-03-25 16:01:22 +08:00
parent 7811adca66
commit 996dc3778d
2 changed files with 31 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { onBeforeRouteLeave } from 'vue-router'
import { useAuthStore } from '../../stores/auth'
import { startPublishing } from '../../utils/liveWebRTC'
@@ -54,11 +55,21 @@ function stop() {
status.value = '已停止'
}
function onBeforeUnload() {
session.value?.stop()
}
onMounted(() => {
document.title = '视频直播开播 - 管理后台'
window.addEventListener('beforeunload', onBeforeUnload)
})
onUnmounted(() => {
window.removeEventListener('beforeunload', onBeforeUnload)
})
/** 离开本页时再结束推流;勿在 onUnmounted 里 stop避免 Vue 开发严格模式双挂载误关 WebSocket */
onBeforeRouteLeave(() => {
stop()
})
</script>