warrior 4 kuukautta sitten
vanhempi
commit
8327726d7a

+ 5 - 5
projects/live-app/src/moduls/live/link-page/link-page.component.html

@@ -31,15 +31,15 @@
   >
     <div class="row">
       <div class="row-li" (click)="onChangeLiveStatus($event, 'audio')">
-        <div [ngClass]="{ 'action-icon': audio, 'icon-box': true }">
+        <div [ngClass]="{ 'action-icon': liveService.tools['audio'], 'icon-box': true }">
           <ion-icon class="icon" name="mic-off"></ion-icon>
         </div>
-        <div class="label">麦克风{{ audio ? "已关" : "已开" }}</div>
+        <div class="label">麦克风{{ liveService.tools['audio'] ? "已关" : "已开" }}</div>
       </div>
     </div>
     <div class="row">
       <div class="row-li" (click)="onChangeLiveStatus($event, 'camera')">
-        <div [ngClass]="{ 'action-icon': camera, 'icon-box': true }">
+        <div [ngClass]="{ 'action-icon': liveService.tools['camera'], 'icon-box': true }">
           <ion-icon name="camera-reverse"></ion-icon>
         </div>
         <div class="label">旋转摄像头</div>
@@ -47,11 +47,11 @@
       <div class="row-li" (click)="onChangeLiveStatus($event, 'mute')">
         <div
           class="icon-box"
-          [ngClass]="{ 'action-icon': mute, 'icon-box': true }"
+          [ngClass]="{ 'action-icon': liveService.tools['mute'], 'icon-box': true }"
         >
           <ion-icon class="icon" name="notifications-off"></ion-icon>
         </div>
-        <div class="label">{{ mute ? "已静音" : "静音" }}</div>
+        <div class="label">{{ liveService.tools['mute'] ? "已静音" : "静音" }}</div>
       </div>
     </div>
     <div class="row">

+ 16 - 8
projects/live-app/src/moduls/live/link-page/link-page.component.ts

@@ -26,15 +26,14 @@ export class LinkPageComponent implements OnInit {
   room?: Parse.Object;
   isFollow: boolean = false;
   showTool: boolean = true; // 是否显示工具栏
-  audio: boolean = false; //是否关闭音频
-  camera: boolean = false; //是否切换摄像头
-  mute: boolean = false; //是否静音
+  // camera: boolean = false; //是否切换摄像头
+  // mute: boolean = false; //是否静音
   constructor(
     public toastController: ToastController,
     private loadingCtrl: LoadingController,
     private alertController: AlertController,
     private activateRoute: ActivatedRoute,
-    private liveService: LiveService
+    public liveService: LiveService
   ) {}
 
   ngOnInit() {
@@ -105,12 +104,21 @@ export class LinkPageComponent implements OnInit {
   /* 直播状态 */
   onChangeLiveStatus(e: any, type: string) {
     e.cancelBubble = true;
-    if (type == 'audio' || type == 'camera' || type == 'mute') {
-      this[type] = !this[type];
+    switch (type) {
+      case 'audio':
+        this.liveService.updatePublishedAudioTrack();
+        break;
+      case 'camera':
+        break;
+      case 'mute':
+        break;
     }
+    // if (type == 'audio' || type == 'camera' || type == 'mute') {
+    //   this.liveService.tools[type] = !this.liveService.tools[type];
+    // }
   }
   /* 结束直播 */
-  async endCall(e: any){
+  async endCall(e: any) {
     e.cancelBubble = true;
     const alert = await this.alertController.create({
       cssClass: 'my-custom-class',
@@ -123,7 +131,7 @@ export class LinkPageComponent implements OnInit {
           cssClass: 'secondary',
           handler: (blah) => {
             console.log('Confirm Cancel: blah');
-            this.onExit()
+            this.onExit();
           },
         },
         {

+ 25 - 1
projects/live-app/src/services/live.service.ts

@@ -26,6 +26,11 @@ export class LiveService {
   client: any; //客户端
   company: string = '';
   UID:any
+  tools: any = {
+    audio:false, //是否关闭音频
+    camera: false, //是否切换摄像头
+    mute: false, //是否静音
+  };
   constructor(private http: HttpService, private aiServ: AiChatService) {
     this.client?.leave();
     this.company = this.aiServ.company;
@@ -131,7 +136,12 @@ export class LiveService {
       remoteEle.textContent = '';
     }
     this.localTracks.videoTrack.play('vice-video'); //播放自己视频渲染
-    let publish = await this.client.publish(Object.values(this.localTracks));
+    if(this.tools['audio']){
+      this.localTracks.audioTrack.setEnabled(false);
+    }else{
+      this.localTracks.audioTrack.setEnabled(true);
+    }
+    await this.client.publish(Object.values(this.localTracks));
     this.joinReady();
   }
   /* 订阅远程视频 */
@@ -172,4 +182,18 @@ export class LiveService {
       // }
     });
   }
+  /* 停止音频推流 */
+  async updatePublishedAudioTrack(){
+    this.tools['audio'] = !this.tools['audio'];
+    if(this.tools['audio'] && this.localTracks.audioTrack){
+      await this.localTracks.audioTrack.setEnabled(false);
+      console.log('停止推送音频');
+    }else{
+      await this.localTracks.audioTrack.setEnabled(true)
+      console.log('恢复推送音频');
+    }
+    // await this.client.unpublish(this.localTracks.audioTrack);
+    return true
+  }
+
 }