|
@@ -1,4 +1,5 @@
|
|
|
import { Injectable } from '@angular/core';
|
|
|
+import { Router } from '@angular/router';
|
|
|
import { AlertController } from '@ionic/angular';
|
|
|
import * as Parse from 'parse';
|
|
|
import { AiChatService } from './aichart.service';
|
|
@@ -56,11 +57,12 @@ export class LiveService {
|
|
|
countdown: number = 0; // 新增倒计时变量
|
|
|
timer_countdown: any;
|
|
|
liveLog?: Parse.Object; //直播记录
|
|
|
-
|
|
|
- isOpenEvaluate:boolean = false; //是否开启评价
|
|
|
+
|
|
|
+ isOpenEvaluate: boolean = false; //是否开启评价
|
|
|
|
|
|
constructor(
|
|
|
private http: HttpService,
|
|
|
+ private router: Router,
|
|
|
private aiServ: AiChatService,
|
|
|
private alertController: AlertController,
|
|
|
private msgSer: MessageService
|
|
@@ -227,8 +229,9 @@ export class LiveService {
|
|
|
await this.client.publish(Object.values(this.localTracks));
|
|
|
} catch (err) {
|
|
|
console.log('发布本地视频失败:', err);
|
|
|
- history.back()
|
|
|
- this.alertTips('发布本地视频失败', '提示');
|
|
|
+ // history.back()
|
|
|
+ this.alertTips('发布本地视频失败,请检查摄像头是否授权或正常', '提示');
|
|
|
+ this.client.leave();
|
|
|
}
|
|
|
}
|
|
|
/* 订阅远程视频 */
|
|
@@ -280,9 +283,9 @@ export class LiveService {
|
|
|
}
|
|
|
//主播离开,停止计时计费
|
|
|
// if (!this.isAnchor) {
|
|
|
- this.client.leave();
|
|
|
+ this.client.leave();
|
|
|
// }
|
|
|
- history.back()
|
|
|
+ // history.back()
|
|
|
this.alertTips('对方已离开直播间');
|
|
|
}
|
|
|
});
|
|
@@ -300,7 +303,11 @@ export class LiveService {
|
|
|
if (!this.isAnchor) {
|
|
|
//用户离开直播间,断开与主播状态连接频道
|
|
|
this.msgSer.unsubscribeMessage(this.room?.get('user')?.id);
|
|
|
+ this.isOpenEvaluate = true;
|
|
|
}
|
|
|
+ console.log(this.router.url);
|
|
|
+ if(this.router.url.indexOf('/live/link-room/') == 0)
|
|
|
+ curState == 'DISCONNECTED' && history.back();
|
|
|
}
|
|
|
console.log('live状态变更:', this.connection_state);
|
|
|
}
|
|
@@ -339,7 +346,9 @@ export class LiveService {
|
|
|
async afterJoin() {
|
|
|
this.timer && clearTimeout(this.timer);
|
|
|
this.timer_countdown && clearInterval(this.timer_countdown);
|
|
|
- const targetUser = this.client.remoteUsers?.find((user: any) => user.uid !== 100001) //排出超管
|
|
|
+ const targetUser = this.client.remoteUsers?.find(
|
|
|
+ (user: any) => user.uid !== 100001
|
|
|
+ ); //排出超管
|
|
|
console.log(targetUser);
|
|
|
if (this.client.remoteUsers.length > 0 && targetUser) {
|
|
|
if (this.isAnchor) {
|
|
@@ -368,7 +377,7 @@ export class LiveService {
|
|
|
}, 1000);
|
|
|
}
|
|
|
}
|
|
|
- async getLiveLog(tarUid:string) {
|
|
|
+ async getLiveLog(tarUid: string) {
|
|
|
// let uid = this.client.remoteUsers[0].uid;
|
|
|
this.timer && clearTimeout(this.timer);
|
|
|
let query = new Parse.Query('LiveLog');
|
|
@@ -382,7 +391,7 @@ export class LiveService {
|
|
|
this.liveLog?.set('isLive', true);
|
|
|
await this.liveLog?.save();
|
|
|
await this.get_duration();
|
|
|
- this.getCallDuration()
|
|
|
+ this.getCallDuration();
|
|
|
return;
|
|
|
}
|
|
|
this.timer = setTimeout(() => {
|
|
@@ -416,7 +425,7 @@ export class LiveService {
|
|
|
// console.log(this.countdown);
|
|
|
} else {
|
|
|
clearInterval(this.timer_countdown);
|
|
|
- history.back()
|
|
|
+ // history.back()
|
|
|
this.alertTips('通话时间结束');
|
|
|
this.client.leave(); // 结束通话
|
|
|
}
|
|
@@ -444,12 +453,15 @@ export class LiveService {
|
|
|
}, num ?? 10000);
|
|
|
}
|
|
|
/* 主播每10s获取一次对方可通话时长 */
|
|
|
- getCallDuration(){
|
|
|
+ getCallDuration() {
|
|
|
this.timer && clearTimeout(this.timer);
|
|
|
- this.timer = setTimeout(async() => {
|
|
|
+ this.timer = setTimeout(async () => {
|
|
|
await this.get_duration();
|
|
|
- this.getCallDuration();
|
|
|
- },10000);
|
|
|
+ let arr = ['CONNECTING', 'CONNECTED'];
|
|
|
+ if (arr.includes(this.connection_state as any)) {
|
|
|
+ this.getCallDuration();
|
|
|
+ }
|
|
|
+ }, 10000);
|
|
|
}
|
|
|
/* 监听音视频设备插拔 */
|
|
|
monitorDevices() {
|