Browse Source

fix: 和你走过

shuisheng 1 year ago
parent
commit
b0ceb41ef1
3 changed files with 10 additions and 85 deletions
  1. 0 10
      src/hooks/use-push.ts
  2. 3 75
      src/utils/network/webRTC.ts
  3. 7 0
      src/views/push/index.vue

+ 0 - 10
src/hooks/use-push.ts

@@ -349,16 +349,6 @@ export function usePush() {
         user_agent: navigator.userAgent,
       },
     });
-    // damuList.value.push({
-    //   user_agent: navigator.userAgent,
-    //   live_room_id: Number(roomId.value),
-    //   socket_id: mySocketId.value,
-    //   msgType: DanmuMsgTypeEnum.danmu,
-    //   msg: danmuStr.value,
-    //   userInfo: userStore.userInfo!,
-    //   msgIsFile: msgIsFile.value,
-    //   send_msg_time: +new Date(),
-    // });
     danmuStr.value = '';
   }
 

+ 3 - 75
src/utils/network/webRTC.ts

@@ -1,8 +1,8 @@
 import { getRandomString } from 'billd-utils';
 
-import { LiveLineEnum, MediaTypeEnum } from '@/interface';
+import { LiveLineEnum } from '@/interface';
 import { prodDomain } from '@/spec-config';
-import { AppRootState, useAppStore } from '@/store/app';
+import { useAppStore } from '@/store/app';
 import { useNetworkStore } from '@/store/network';
 import { WsCandidateType, WsMsgTypeEnum } from '@/types/websocket';
 
@@ -281,82 +281,10 @@ export class WebRTCClass {
       console.log('track事件的视频轨', event.streams[0].getVideoTracks());
       console.log('track事件的音频轨', event.streams[0].getAudioTracks());
       const stream = event.streams[0];
-      this.localStream = stream;
-      const appStore = useAppStore();
       stream.onremovetrack = () => {
         this.prettierLog({ msg: 'onremovetrack事件', type: 'warn' });
       };
-
-      const addTrack: AppRootState['allTrack'] = [];
-
-      this.localStream?.getVideoTracks().forEach((track) => {
-        if (!appStore.allTrack.find((info) => info.track?.id === track.id)) {
-          addTrack.push({
-            openEye: true,
-            id: getRandomString(8),
-            track,
-            stream,
-            audio: 2,
-            video: 1,
-            type: MediaTypeEnum.screen,
-            mediaName: '',
-            streamid: stream.id,
-            trackid: track.id,
-            scaleInfo: {},
-          });
-        }
-      });
-      this.localStream?.getAudioTracks().forEach((track) => {
-        if (!appStore.allTrack.find((info) => info.track?.id === track.id)) {
-          addTrack.push({
-            openEye: true,
-            id: getRandomString(8),
-            track,
-            stream,
-            audio: 1,
-            video: 2,
-            type: MediaTypeEnum.microphone,
-            mediaName: '',
-            streamid: stream.id,
-            trackid: track.id,
-            scaleInfo: {},
-          });
-        }
-      });
-      stream.getVideoTracks().forEach((track) => {
-        if (!appStore.allTrack.find((info) => info.track?.id === track.id)) {
-          addTrack.push({
-            openEye: true,
-            id: getRandomString(8),
-            track,
-            stream,
-            audio: 2,
-            video: 1,
-            type: MediaTypeEnum.screen,
-            mediaName: '',
-            streamid: stream.id,
-            trackid: track.id,
-            scaleInfo: {},
-          });
-        }
-      });
-      stream.getAudioTracks().forEach((track) => {
-        if (!appStore.allTrack.find((info) => info.track?.id === track.id)) {
-          addTrack.push({
-            openEye: true,
-            id: getRandomString(8),
-            track,
-            stream,
-            audio: 1,
-            video: 2,
-            type: MediaTypeEnum.microphone,
-            mediaName: '',
-            streamid: stream.id,
-            trackid: track.id,
-            scaleInfo: {},
-          });
-        }
-      });
+      this.localStream = stream;
       this.videoEl.srcObject = event.streams[0];
     });
   };

+ 7 - 0
src/views/push/index.vue

@@ -547,6 +547,7 @@ const {
   liveUserList,
 } = usePush();
 
+const addMediaOkMap = ref(new Map());
 const currentMediaType = ref(MediaTypeEnum.camera);
 const currentMediaData = ref<AppRootState['allTrack'][0]>();
 const recording = ref(false);
@@ -686,6 +687,10 @@ watch(
       if (appStore.allTrack.find((v) => v.mediaName === item.receiver)) {
         return;
       }
+      const streamid = item.localStream?.id;
+      if (!streamid) return;
+      if (addMediaOkMap.value.get(streamid)) return;
+      addMediaOkMap.value.set(streamid, item);
       addMediaOk({
         id: getRandomEnglishString(6),
         openEye: true,
@@ -1848,6 +1853,7 @@ function setScaleInfo({ track, canvasDom, scale = 1 }) {
 }
 
 async function addMediaOk(val: AppRootState['allTrack'][0]) {
+  console.log('addMediaOk');
   showMediaModalCpt.value = false;
   if (val.type === MediaTypeEnum.screen) {
     const event = await handleDisplayMedia({
@@ -2327,6 +2333,7 @@ async function addMediaOk(val: AppRootState['allTrack'][0]) {
 }
 
 function editMediaOk(val: AppRootState['allTrack'][0]) {
+  console.log('editMediaOk');
   showMediaModalCpt.value = false;
   const res = appStore.allTrack.map((item) => {
     if (item.id === val.id) {