Browse Source

离线后提示刷新

wolyshaw 3 years ago
parent
commit
945df68933
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/components/live-broadcast/index.tsx

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

@@ -12,6 +12,7 @@ import { requireMedia } from "./helpers";
 import styles from "./index.module.less";
 import request from "/src/helpers/request";
 import dayjs from "dayjs";
+import { ElMessageBox } from "element-plus";
 
 const videoRef = ref<HTMLVideoElement | null>(null);
 
@@ -44,6 +45,16 @@ export default defineComponent({
     RuntimeUtils.loopSyncLike();
     event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Like"], this.onLikeMessage);
     window.onbeforeunload = this.beforeunload;
+    window.addEventListener('offline', () => {
+      if (!navigator.onLine) {
+        runtime.videoStatus = 'stream';
+        ElMessageBox.alert('请检查网络设置,并请在网络连接成功后点击确定刷新页面', '网络断开', {
+          callback: () => {
+            location.reload();
+          }
+        });
+      }
+    })
     // window.addEventListener('focus', this.visibilitychange)
     // window.addEventListener('blur', this.visibilitychange)
   },