shuisheng 3 rokov pred
rodič
commit
d0e81504da
3 zmenil súbory, kde vykonal 60 pridanie a 30 odobranie
  1. 21 0
      LICENSE
  2. 9 6
      src/hooks/use-srs-ws.ts
  3. 30 24
      src/views/push/rtc/index.vue

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023-PRESENT shuisheng<https://github.com/galaxy-s10>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 9 - 6
src/hooks/use-srs-ws.ts

@@ -151,7 +151,6 @@ export const useSrsWs = () => {
       startNewWebRtc({
         videoEl: createVideo({}),
         receiver,
-        type,
       });
     }
   }
@@ -175,13 +174,11 @@ export const useSrsWs = () => {
   function startNewWebRtc({
     receiver,
     videoEl,
-    type,
   }: {
     receiver: string;
     videoEl: HTMLVideoElement;
-    type: LiveRoomTypeEnum;
   }) {
-    console.warn('开始new WebRTCClass', `${roomId.value}___${receiver!}`);
+    console.warn('22开始new WebRTCClass', `${roomId.value}___${receiver!}`);
     new WebRTCClass({
       maxBitrate: currentMaxBitrate.value,
       maxFramerate: currentMaxFramerate.value,
@@ -221,7 +218,10 @@ export const useSrsWs = () => {
       console.log('收到offer', data);
       if (data.receiver === mySocketId.value) {
         console.warn('是发给我的offer');
-        console.warn('开始new WebRTCClass', `${roomId.value}___${data.sender}`);
+        console.warn(
+          '33开始new WebRTCClass',
+          `${roomId.value}___${data.sender}`
+        );
         const videoEl = createVideo({ appendChild: true });
         const rtc = new WebRTCClass({
           maxBitrate: currentMaxBitrate.value,
@@ -357,7 +357,10 @@ export const useSrsWs = () => {
             networkStore.getRtcMap(`${roomId.value}___${receiver!}`)
           )
             return;
-          console.warn('开始new WebRTCClass', `${roomId.value}___${receiver!}`);
+          console.warn(
+            '11开始new WebRTCClass',
+            `${roomId.value}___${receiver!}`
+          );
           const rtc = new WebRTCClass({
             maxBitrate: currentMaxBitrate.value,
             maxFramerate: currentMaxFramerate.value,

+ 30 - 24
src/views/push/rtc/index.vue

@@ -451,30 +451,31 @@ function initNullAudio() {
   // 将源连接到gain node,再连接到输出
   source.connect(gainNode);
   gainNode.connect(audioContext.destination);
-  const destination = audioContext.createMediaStreamDestination();
-
-  const webAudioTrack: AppRootState['allTrack'][0] = {
-    id: getRandomEnglishString(8),
-    audio: 1,
-    video: 2,
-    mediaName: 'webAudio占位',
-    type: MediaTypeEnum.webAudio,
-    track: destination.stream.getAudioTracks()[0],
-    trackid: destination.stream.getAudioTracks()[0].id,
-    stream: destination.stream,
-    streamid: destination.stream.id,
-    hidden: true,
-    muted: false,
-  };
-  const res = [...appStore.allTrack, webAudioTrack];
+  const res = [...appStore.allTrack];
   appStore.setAllTrack(res);
-  const videoEl = createVideo({ appendChild: true });
-  videoEl.srcObject = destination.stream;
-  bodyAppendChildElArr.value.push(videoEl);
+  // const destination = audioContext.createMediaStreamDestination();
+
+  // const webAudioTrack: AppRootState['allTrack'][0] = {
+  //   id: getRandomEnglishString(8),
+  //   audio: 1,
+  //   video: 2,
+  //   mediaName: 'webAudio占位',
+  //   type: MediaTypeEnum.webAudio,
+  //   track: destination.stream.getAudioTracks()[0],
+  //   trackid: destination.stream.getAudioTracks()[0].id,
+  //   stream: destination.stream,
+  //   streamid: destination.stream.id,
+  //   hidden: true,
+  //   muted: false,
+  // };
+
+  // const videoEl = createVideo({ appendChild: true });
+  // videoEl.srcObject = destination.stream;
+  // bodyAppendChildElArr.value.push(videoEl);
 }
 
 let streamTmp: MediaStream;
-let vel;
+const webaudioVideo = ref<HTMLVideoElement>();
 
 function handleMixedAudio() {
   console.log('handleMixedAudiohandleMixedAudio');
@@ -502,9 +503,13 @@ function handleMixedAudio() {
     // @ts-ignore
     canvasVideoStream.value?.addTrack(destination.stream.getAudioTracks()[0]);
     gainNode.connect(destination);
-    vel = createVideo({ appendChild: true });
-    vel.srcObject = destination.stream;
-    bodyAppendChildElArr.value.push(vel);
+    webaudioVideo.value = createVideo({ appendChild: true });
+    webaudioVideo.value.className = 'web-audio-video';
+    webaudioVideo.value.srcObject = destination.stream;
+    console.log('kkkk1', webaudioVideo.value);
+    bodyAppendChildElArr.value.push(webaudioVideo.value);
+  } else {
+    console.error('没有audioCtx');
   }
 }
 
@@ -553,7 +558,7 @@ function autoCreateVideo({
   rect?: { left: number; top: number };
   muted?: boolean;
 }) {
-  console.warn('autoCreateVideoautoCreateVideo', id);
+  console.warn('autoCreateVideo', id);
   const videoEl = createVideo({ appendChild: true });
   if (muted !== undefined) {
     videoEl.muted = muted;
@@ -1305,6 +1310,7 @@ async function addMediaOk(val: {
       const { canvasDom, scale } = await autoCreateVideo({
         stream,
         id: mediaVideoTrack.id,
+        video: videoEl,
       });
       mediaVideoTrack.scaleInfo = { scaleX: scale, scaleY: scale };
       mediaVideoTrack.videoEl = videoEl;