Răsfoiți Sursa

fix: 直播状态

shuisheng 2 ani în urmă
părinte
comite
91c209ce14
4 a modificat fișierele cu 43 adăugiri și 30 ștergeri
  1. 6 3
      src/hooks/use-pull.ts
  2. 2 0
      src/interface.ts
  3. 5 1
      src/views/home/index.vue
  4. 30 26
      src/views/rank/index.vue

+ 6 - 3
src/hooks/use-pull.ts

@@ -461,9 +461,13 @@ export function usePull({
           'webrtc'
         );
         if (route.query.liveType === liveTypeEnum.srsWebrtcPull) {
-          console.log('');
+          instance.send({ msgType: WsMsgTypeEnum.getLiveUser });
+        } else if (route.query.liveType === liveTypeEnum.srsFlvPull) {
+          await startPlay({
+            flvurl: flvurl.value,
+            videoEl: remoteVideoRef.value!,
+          });
         } else if (
-          data.data.live_room?.type === LiveRoomTypeEnum.user_srs ||
           data.data.live_room?.type === LiveRoomTypeEnum.user_obs ||
           data.data.live_room?.type === LiveRoomTypeEnum.system
         ) {
@@ -472,7 +476,6 @@ export function usePull({
             videoEl: remoteVideoRef.value!,
           });
         }
-        instance.send({ msgType: WsMsgTypeEnum.getLiveUser });
       }
     );
 

+ 2 - 0
src/interface.ts

@@ -151,6 +151,8 @@ export interface ILiveRoom {
   user?: IUser;
   /** 直播间名字 */
   name?: string;
+  /** 联表(live表) */
+  live?: string;
   user_live_room?: IUserLiveRoom & { user: IUser };
   /** 权重 */
   weight?: number;

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

@@ -45,7 +45,9 @@
           >
             <div
               v-if="
-                currentLiveRoom.live_room?.type !== LiveRoomTypeEnum.user_obs
+                currentLiveRoom.live_room?.type ===
+                  LiveRoomTypeEnum.user_wertc ||
+                currentLiveRoom.live_room?.type === LiveRoomTypeEnum.user_srs
               "
               class="btn webrtc"
               @click="joinRoom()"
@@ -54,6 +56,8 @@
             </div>
             <div
               v-if="
+                currentLiveRoom.live_room?.type === LiveRoomTypeEnum.system ||
+                currentLiveRoom.live_room?.type === LiveRoomTypeEnum.user_obs ||
                 currentLiveRoom?.live_room?.type === LiveRoomTypeEnum.user_srs
               "
               class="btn flv"

+ 30 - 26
src/views/rank/index.vue

@@ -41,19 +41,9 @@
           <div class="rank">
             <i>0{{ item.rank }}</i>
             <div
-              v-if="item.live && currRankType === RankTypeEnum.liveRoom"
+              v-if="item.live?.live && currRankType === RankTypeEnum.liveRoom"
               class="living"
-              @click="
-                router.push({
-                  name: routerName.pull,
-                  params: { roomId: item.live.live_room_id },
-                  query: {
-                    liveType: item.live.flvurl
-                      ? liveTypeEnum.srsFlvPull
-                      : liveTypeEnum.webrtcPull,
-                  },
-                })
-              "
+              @click="handleJoin(item.live)"
             >
               直播中
             </div>
@@ -85,19 +75,9 @@
               </div>
             </div>
             <div
-              v-if="item.live && currRankType === RankTypeEnum.liveRoom"
+              v-if="item.live?.live && currRankType === RankTypeEnum.liveRoom"
               class="living-tag"
-              @click="
-                router.push({
-                  name: routerName.pull,
-                  params: { roomId: item.live.live_room_id },
-                  query: {
-                    liveType: item.live.flvurl
-                      ? liveTypeEnum.srsFlvPull
-                      : liveTypeEnum.webrtcPull,
-                  },
-                })
-              "
+              @click="handleJoin(item.live)"
             >
               直播中
             </div>
@@ -116,7 +96,13 @@ import { fetchLiveRoomList } from '@/api/liveRoom';
 import { fetchBlogUserList, fetchUserList } from '@/api/user';
 import { fetchWalletList } from '@/api/wallet';
 import { fullLoading } from '@/components/FullLoading';
-import { ILive, IUser, liveTypeEnum, RankTypeEnum } from '@/interface';
+import {
+  ILiveRoom,
+  IUser,
+  LiveRoomTypeEnum,
+  liveTypeEnum,
+  RankTypeEnum,
+} from '@/interface';
 import router, { routerName } from '@/router';
 
 export interface IRankType {
@@ -153,7 +139,7 @@ const mockRank: {
   level: number;
   score: number;
   balance: string;
-  live?: ILive;
+  live?: ILiveRoom;
 }[] = [
   {
     user: {
@@ -206,6 +192,23 @@ const mockRank: {
 ];
 const rankList = ref(mockRank);
 
+function handleJoin(item) {
+  let liveType: liveTypeEnum = liveTypeEnum.webrtcPull;
+  if (
+    item?.type === LiveRoomTypeEnum.system ||
+    item?.type === LiveRoomTypeEnum.user_obs
+  ) {
+    liveType = liveTypeEnum.srsFlvPull;
+  } else if (item?.type === LiveRoomTypeEnum.user_srs) {
+    liveType = liveTypeEnum.srsWebrtcPull;
+  }
+  router.push({
+    name: routerName.pull,
+    params: { roomId: item.live.live_room_id },
+    query: { liveType },
+  });
+}
+
 async function getWalletList() {
   try {
     fullLoading({ loading: true });
@@ -248,6 +251,7 @@ async function getLiveRoomList() {
             username: item.user_username!,
             avatar: item.user_avatar!,
           },
+          live: item,
           rank: index + 1,
           level: 1,
           score: 1,