瀏覽代碼

fix: 优化

shuisheng 2 年之前
父節點
當前提交
ed01134d93
共有 5 個文件被更改,包括 51 次插入11 次删除
  1. 5 3
      src/hooks/use-pull.ts
  2. 7 1
      src/hooks/use-push.ts
  3. 33 6
      src/hooks/use-ws.ts
  4. 1 0
      src/views/h5/room/index.vue
  5. 5 1
      src/views/pull/index.vue

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

@@ -111,12 +111,13 @@ export function usePull({
   watch(
     () => roomLiveing.value,
     (val) => {
+      console.log(val, roomLiveType.value, '-------');
       if (val) {
         flvurl.value = val.live?.live_room?.flv_url!;
         hlsurl.value = val.live?.live_room?.hls_url!;
-        if (val && roomLiveType.value === liveTypeEnum.webrtcPull) {
-          handlePlay();
-        }
+        // if (val && roomLiveType.value === liveTypeEnum.webrtcPull) {
+        handlePlay();
+        // }
       }
     }
   );
@@ -212,6 +213,7 @@ export function usePull({
       isSRS,
       isAnchor: false,
       isPull: true,
+      roomLiveType: roomLiveType.value,
     });
   }
 

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

@@ -6,7 +6,12 @@ import {
   fetchCreateUserLiveRoom,
   fetchUserHasLiveRoom,
 } from '@/api/userLiveRoom';
-import { DanmuMsgTypeEnum, IMessage, MediaTypeEnum } from '@/interface';
+import {
+  DanmuMsgTypeEnum,
+  IMessage,
+  MediaTypeEnum,
+  liveTypeEnum,
+} from '@/interface';
 import { WsMsgTypeEnum } from '@/network/webSocket';
 import { useAppStore } from '@/store/app';
 import { useNetworkStore } from '@/store/network';
@@ -215,6 +220,7 @@ export function usePush({
       currentMaxBitrate: currentMaxBitrate.value,
       currentMaxFramerate: currentMaxFramerate.value,
       currentResolutionRatio: currentResolutionRatio.value,
+      roomLiveType: isSRS ? liveTypeEnum.srsPush : liveTypeEnum.webrtcPush,
     });
     return;
   }

+ 33 - 6
src/hooks/use-ws.ts

@@ -17,6 +17,7 @@ import {
   IOtherJoin,
   IUpdateJoinInfo,
   LiveRoomTypeEnum,
+  liveTypeEnum,
 } from '@/interface';
 import { WebRTCClass } from '@/network/webRTC';
 import {
@@ -41,6 +42,7 @@ export const useWs = () => {
   const roomLiveing = ref<IJoin['data']>();
   const liveRoomInfo = ref<ILive>();
   const isAnchor = ref(false);
+  const roomLiveType = ref(liveTypeEnum.srsFlvPull);
   const joined = ref(false);
   const isSRS = ref(false);
   const isPull = ref(false);
@@ -359,12 +361,21 @@ export const useWs = () => {
       const sdp = await rtc.createOffer();
       await rtc.setLocalDescription(sdp!);
       let res;
+
       if (isPull.value) {
+        console.log(
+          roomLiveing.value,
+          2222222222,
+          roomLiveing.value!.live!.live_room!.rtmp_url!.replace(
+            'rtmp',
+            'webrtc'
+          )
+        );
         res = await fetchRtcV1Play({
           api: `/rtc/v1/play/`,
           clientip: null,
           sdp: sdp!.sdp!,
-          streamurl: userStore.userInfo!.live_rooms![0]!.rtmp_url!.replace(
+          streamurl: roomLiveing.value!.live!.live_room!.rtmp_url!.replace(
             'rtmp',
             'webrtc'
           ),
@@ -653,8 +664,20 @@ export const useWs = () => {
     // 管理员正在直播
     ws.socketIo.on(WsMsgTypeEnum.roomLiveing, (data: IJoin) => {
       prettierReceiveWebsocket(WsMsgTypeEnum.roomLiveing, data);
-      console.log(data.data, 333323);
       roomLiveing.value = data.data;
+      console.log(isSRS.value, isPull.value, data, 111);
+      // 如果是srs开播,则不需要等有人进来了才new webrtc,只要Websocket连上了就开始new webrtc
+      if (isSRS.value) {
+        if (isPull.value) {
+          console.log('llllll');
+          if (roomLiveType.value === liveTypeEnum.srsWebrtcPull) {
+            startNewWebRtc({
+              receiver: 'srs',
+              videoEl: localVideo.value,
+            });
+          }
+        }
+      }
     });
 
     // 管理员不在直播
@@ -696,10 +719,12 @@ export const useWs = () => {
       }
       // 如果是srs开播,则不需要等有人进来了才new webrtc,只要Websocket连上了就开始new webrtc
       if (isSRS.value) {
-        startNewWebRtc({
-          receiver: 'srs',
-          videoEl: localVideo.value,
-        });
+        if (!isPull.value) {
+          startNewWebRtc({
+            receiver: 'srs',
+            videoEl: localVideo.value,
+          });
+        }
       }
     });
 
@@ -764,9 +789,11 @@ export const useWs = () => {
     currentResolutionRatio?: number;
     currentMaxFramerate?: number;
     currentMaxBitrate?: number;
+    roomLiveType: liveTypeEnum;
   }) {
     roomId.value = data.roomId;
     isAnchor.value = data.isAnchor;
+    roomLiveType.value = data.roomLiveType;
     if (data.currentMaxBitrate) {
       currentMaxBitrate.value = data.currentMaxBitrate;
     }

+ 1 - 0
src/views/h5/room/index.vue

@@ -247,6 +247,7 @@ onMounted(() => {
     .media-list {
       height: 230px;
       overflow-y: scroll;
+      position: absolute;
       :deep(video) {
         width: 100%;
         height: 100%;

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

@@ -271,7 +271,11 @@ const {
   localVideoRef,
   canvasRef,
   liveType: route.query.liveType as liveTypeEnum,
-  isSRS: route.query.liveType === liveTypeEnum.srsWebrtcPull,
+  isSRS: [
+    liveTypeEnum.srsWebrtcPull,
+    liveTypeEnum.srsFlvPull,
+    liveTypeEnum.srsHlsPull,
+  ].includes(route.query.liveType as liveTypeEnum),
 });
 
 async function getGoodsList() {