liming 4 ngày trước cách đây
mục cha
commit
57c46512c2

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

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

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

@@ -111,8 +111,8 @@ function hangupCall() {
 watch(
 watch(
   () => rtcStore.remoteStream,
   () => rtcStore.remoteStream,
   (val) => {
   (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;
       // let preview = null;
 
 
-      if (!rtcStore.peerConnection) {
-        rtcStore.initConnection(false); // false表示是Answer方
-      }
+     
 
 
       let video = false;
       let video = false;
       if (message.contentType === Constant.VIDEO_ONLINE) {
       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) {
       if (message.contentType === Constant.AUDIO_ONLINE) {
         // preview = document.getElementById("audioPhone");
         // preview = document.getElementById("audioPhone");
         // 音频电话
         // 音频电话
@@ -205,7 +207,7 @@ const messageCallback = (contentType, state)=>{
 const startAudioOnline = (video, state) => { 
 const startAudioOnline = (video, state) => { 
   const rtcStore = useWebRTCStore();
   const rtcStore = useWebRTCStore();
   // 初始化webrtc连接
   // 初始化webrtc连接
-  rtcStore.initConnection(true);
+  rtcStore.initConnection(true, video);
 
 
   navigator.mediaDevices
   navigator.mediaDevices
     .getUserMedia({ audio: true, video: video })
     .getUserMedia({ audio: true, video: video })