Эх сурвалжийг харах

修复麦克风、静音问题

warrior 2 долоо хоног өмнө
parent
commit
990c9270fd

+ 1 - 1
projects/live-app/src/modules/user/browse/browse.component.html

@@ -26,7 +26,7 @@
           <div class="user-name">
             {{
               item.get("toUser")?.get("nickname") ||
-                item.get("toUser")?.get("name")
+                item.get("toUser")?.id
             }}
           </div>
           <div class="time">

+ 20 - 20
projects/live-app/src/services/live.service.ts

@@ -36,7 +36,7 @@ export class LiveService {
     glorify: false, //是否开启美颜
     mute: false, //是否静音
   };
-  user_published_list: Array<any> = []; //已发布列表
+  user_published_list: Array<any> = []; //已订阅频道用户列表
   timer: any; //轮询获取频道token的定时
   alert: any; //提示框
   media_devices: {
@@ -129,10 +129,6 @@ export class LiveService {
           audioDevice: this.media_devices.audioDevices[0].deviceId,
           videoDevice: this.media_devices.videoDevices[0].deviceId,
         };
-        // return Promise.all([
-        //   AgoraRTC.createCameraVideoTrack(),
-        //   AgoraRTC.createMicrophoneAudioTrack(),
-        // ]);
       })
       .then((tracks: any) => {
         console.log(tracks);
@@ -240,11 +236,11 @@ export class LiveService {
         remoteEle.style.display = 'block';
       }
       this.localTracks.videoTrack.play('vice-video'); //播放自己视频渲染
-      if (this.tools['audio']) {
-        this.localTracks.audioTrack.setEnabled(false);
-      } else {
-        this.localTracks.audioTrack.setEnabled(true);
-      }
+      // if (this.tools['audio']) {
+      //   this.localTracks.audioTrack.setEnabled(false);
+      // } else {
+      //   this.localTracks.audioTrack.setEnabled(true);
+      // }
 
       if (this.processor && this.localTracks.videoTrack) {
         // 将插件注入 SDK 内的视频处理管道
@@ -279,7 +275,6 @@ export class LiveService {
     this.client.remoteUsers.forEach((user: any) => {
       // console.log('remoteUsers', user.uid);
       this.client.subscribe(user, 'audio').then((audioTrack: any) => {
-        // this.user_published_list.add(user);
         if (!this.user_published_list.find((item) => item.uid === user.uid)) {
           this.user_published_list.push(user);
         }
@@ -310,7 +305,6 @@ export class LiveService {
       }
       if (mediaType === 'audio') {
         user.audioTrack.play();
-        // this.user_published_list.add(user);
         if (!this.user_published_list.find((item) => item.uid === user.uid)) {
           this.user_published_list.push(user);
         }
@@ -319,7 +313,6 @@ export class LiveService {
     this.client.on('user-unpublished', async (user: any, mediaType: string) => {
       if (mediaType === 'audio') {
         console.log('对方已静音');
-        // this.user_published_list.delete(user);
         let idx = this.user_published_list.findIndex(
           (item) => item.uid === user.uid
         );
@@ -341,8 +334,10 @@ export class LiveService {
     this.client.on('user-left', (user: any) => {
       console.log(`用户 ${user.uid} 离开了频道`);
       //主播离开,停止计时计费
-      if (user.uid !== 100001) this.client.leave();
-      this.alertTips('对方已离开直播间');
+      if (user.uid !== 100001) {
+        this.client.leave();
+        this.alertTips('对方已离开直播间');
+      }
     });
     this.client.on(
       'connection-state-change',
@@ -491,7 +486,7 @@ export class LiveService {
     //每10秒保存一次数据
     this.timer && clearTimeout(this.timer);
     let p = JSON.parse(this.profile);
-    console.log(p);
+    // console.log(p);
     let url = 'https://server.fmode.cn/api/ailiao/count/duration';
     let params = {
       company: this.company,
@@ -502,7 +497,7 @@ export class LiveService {
       logid: this.liveLog?.id,
     };
     let data = await this.http.httpRequst(url, params, 'POST');
-    console.log(data);
+    // console.log(data);
     this.timer = setTimeout(() => {
       this.computeDuration();
     }, num ?? 10000);
@@ -559,10 +554,12 @@ export class LiveService {
   async updatePublishedAudioTrack() {
     this.tools['audio'] = !this.tools['audio'];
     if (this.tools['audio'] && this.localTracks.audioTrack) {
-      await this.localTracks.audioTrack.setEnabled(false);
+      // await this.localTracks.audioTrack.setEnabled(false);
+      this.localTracks.audioTrack.setVolume(0);
       console.log('停止推送音频');
     } else {
-      await this.localTracks.audioTrack.setEnabled(true);
+      // await this.localTracks.audioTrack.setEnabled(true);
+      this.localTracks.audioTrack.setVolume(100);
       console.log('恢复推送音频');
     }
     // await this.client.unpublish(this.localTracks.audioTrack);
@@ -578,7 +575,10 @@ export class LiveService {
         console.log('静音');
         await this.client.unsubscribe(user, 'audio');
       } else {
-        await this.client.subscribe(user, 'audio');
+        await this.client.subscribe(user, 'audio').then((audioTrack: any) => {
+          audioTrack.setVolume(100);
+          audioTrack.play();
+        });
         console.log('恢复声音');
       }
     }