Quellcode durchsuchen

fix: 优化细节bug

shuisheng vor 2 Jahren
Ursprung
Commit
cb3c5cbb03
4 geänderte Dateien mit 15 neuen und 5 gelöschten Zeilen
  1. 7 1
      src/hooks/use-play.ts
  2. 2 2
      src/hooks/use-pull.ts
  3. 5 1
      src/views/home/index.vue
  4. 1 1
      src/views/rank/index.vue

+ 7 - 1
src/hooks/use-play.ts

@@ -14,6 +14,12 @@ export function useFlvPlay() {
     }
   });
 
+  function destroy() {
+    if (flvPlayer.value) {
+      flvPlayer.value.destroy();
+    }
+  }
+
   async function startPlay(data: {
     flvurl: string;
     videoEl: HTMLVideoElement;
@@ -39,5 +45,5 @@ export function useFlvPlay() {
     }
   }
 
-  return { startPlay };
+  return { startPlay, destroy };
 }

+ 2 - 2
src/hooks/use-pull.ts

@@ -352,10 +352,10 @@ export function usePull({
       });
       rtc.rtcStatus.joined = true;
       rtc.update();
-      if (track.video) {
+      if (track.video === 1) {
         rtc.peerConnection?.addTransceiver('video', { direction: 'recvonly' });
       }
-      if (track.audio) {
+      if (track.audio === 1) {
         rtc.peerConnection?.addTransceiver('audio', { direction: 'recvonly' });
       }
       try {

+ 5 - 1
src/views/home/index.vue

@@ -128,7 +128,7 @@ const liveRoomList = ref<ILive[]>([]);
 const currentLiveRoom = ref<ILive>();
 const localVideoRef = ref<HTMLVideoElement>();
 
-const { startPlay } = useFlvPlay();
+const { startPlay, destroy } = useFlvPlay();
 
 function changeLiveRoom(item: ILive) {
   currentLiveRoom.value = item;
@@ -142,6 +142,8 @@ function changeLiveRoom(item: ILive) {
         flvurl: item.live_room.flv_url!,
         videoEl: localVideoRef.value!,
       });
+    } else {
+      destroy();
     }
   });
 }
@@ -168,6 +170,8 @@ async function getLiveRoomList() {
               flvurl: currentLiveRoom.value.live_room.flv_url!,
               videoEl: localVideoRef.value!,
             });
+          } else {
+            destroy();
           }
         });
       }

+ 1 - 1
src/views/rank/index.vue

@@ -34,7 +34,7 @@
             <Avatar
               :size="100"
               :avatar="item.user.avatar"
-              :living="!!item.live"
+              :living="!!item.live?.live"
             ></Avatar>
           </div>
           <div class="username">{{ item.user.username }}</div>