后台直播:修复信令误断(onclose 提示与严格模式 onUnmounted)
Made-with: Cursor
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user