liming 4 روز پیش
والد
کامیت
57c46512c2
3فایلهای تغییر یافته به همراه10 افزوده شده و 8 حذف شده
  1. 2 2
      src/stores/modules/webrtcStore.js
  2. 2 2
      src/views/im/components/CallController/index.vue
  3. 6 4
      src/views/im/hook/messagesHook.js

+ 2 - 2
src/stores/modules/webrtcStore.js

@@ -78,10 +78,10 @@ export const useWebRTCStore = defineStore("webrtc", {
     },
 
     // 初始化 WebRTC 连接
-    initConnection(isCaller) {
+    initConnection(isCaller, video) {
       this.cleanup();
       this.isCaller = isCaller;
-
+      this.streamType = video ? "video" : "audio";
       const wsStore = useWebSocketStore();
       try {
         this.peerConnection = new RTCPeerConnection();

+ 2 - 2
src/views/im/components/CallController/index.vue

@@ -111,8 +111,8 @@ function hangupCall() {
 watch(
   () => rtcStore.remoteStream,
   (val) => {
-    if (val && rtcStore.streamType == "audio") {
-  
+    if (val && rtcStore.streamType == "video") {
+      console.log("remoteStream===", rtcStore.streamType)
     }
   }
 );

+ 6 - 4
src/views/im/hook/messagesHook.js

@@ -156,9 +156,7 @@ export const handleMessageHook = (message, state) => {
       // 检查媒体权限是否开启
       // let preview = null;
 
-      if (!rtcStore.peerConnection) {
-        rtcStore.initConnection(false); // false表示是Answer方
-      }
+     
 
       let video = false;
       if (message.contentType === Constant.VIDEO_ONLINE) {
@@ -167,6 +165,10 @@ export const handleMessageHook = (message, state) => {
         // // 屏幕共享
       }
 
+       if (!rtcStore.peerConnection) {
+        rtcStore.initConnection(false, video); // false表示是Answer方
+      }
+
       if (message.contentType === Constant.AUDIO_ONLINE) {
         // preview = document.getElementById("audioPhone");
         // 音频电话
@@ -205,7 +207,7 @@ const messageCallback = (contentType, state)=>{
 const startAudioOnline = (video, state) => { 
   const rtcStore = useWebRTCStore();
   // 初始化webrtc连接
-  rtcStore.initConnection(true);
+  rtcStore.initConnection(true, video);
 
   navigator.mediaDevices
     .getUserMedia({ audio: true, video: video })