瀏覽代碼

添加离开页面前确认

wolyshaw 3 年之前
父節點
當前提交
9a061b9dd4
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 7 0
      src/components/live-broadcast/index.tsx
  2. 1 0
      src/components/live-broadcast/runtime.ts

+ 7 - 0
src/components/live-broadcast/index.tsx

@@ -21,11 +21,18 @@ export default defineComponent({
     this.initializeRoom()
     RuntimeUtils.loopSyncLike()
     event.on(LIVE_EVENT_MESSAGE['RC:Chatroom:Like'], this.onLikeMessage)
+    window.onbeforeunload = this.beforeunload
   },
   beforeUnmount() {
     event.off(LIVE_EVENT_MESSAGE['RC:Chatroom:Like'], this.onLikeMessage)
+    window.onbeforeunload = null
   },
   methods: {
+    beforeunload() {
+      if (runtime.videoStatus === 'liveing') {
+        return '当前正在直播中是否确认关闭页面?'
+      }
+    },
     onLikeMessage(msg: any) {
       runtime.likeCount += msg.counts
     },

+ 1 - 0
src/components/live-broadcast/runtime.ts

@@ -530,6 +530,7 @@ export const toggleDevice = async (trackType: TrackType) => {
 }
 
 export const leaveIMRoom = async () => {
+  await closeLive()
   if (runtime.joinedRoom) {
     // @ts-ignore
     await runtime.rtcClient?.leaveRoom(runtime.joinedRoom)