|
@@ -8,14 +8,14 @@ import { AiChatService } from '../../../services/aichart.service';
|
|
|
import { ConnectTaskService } from '../../../services/connectTask.service';
|
|
|
import { MessageService } from '../../../services/message.service';
|
|
|
import * as Parse from 'parse';
|
|
|
-
|
|
|
+import { Subject } from 'rxjs';
|
|
|
+import { takeUntil } from 'rxjs/operators';
|
|
|
@Component({
|
|
|
selector: 'app-call-modal',
|
|
|
templateUrl: './call-modal.component.html',
|
|
|
styleUrls: ['./call-modal.component.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [
|
|
|
- ],
|
|
|
+ imports: [],
|
|
|
})
|
|
|
export class CallModalComponent implements OnInit {
|
|
|
@Input('profile') profile?: Parse.Object;
|
|
@@ -25,6 +25,7 @@ export class CallModalComponent implements OnInit {
|
|
|
currentUser?: Parse.Object = Parse.User.current(); //当前登录用户
|
|
|
iscall: boolean = false;
|
|
|
isLiveing: boolean = false; // 是否在直播通话中
|
|
|
+ private ngUnsubscribe = new Subject<void>(); // 用于取消订阅
|
|
|
constructor(
|
|
|
private router: Router,
|
|
|
private toastController: ToastController,
|
|
@@ -33,7 +34,9 @@ export class CallModalComponent implements OnInit {
|
|
|
private msgSer: MessageService,
|
|
|
private aiChatServ: AiChatService
|
|
|
) {
|
|
|
- this.msgSer.event$.subscribe((data) => {
|
|
|
+ this.msgSer.event$
|
|
|
+ .pipe(takeUntil(this.ngUnsubscribe)) // 使用 takeUntil 取消订阅
|
|
|
+ .subscribe((data) => {
|
|
|
this.inviteCallback(data);
|
|
|
});
|
|
|
}
|
|
@@ -43,8 +46,9 @@ export class CallModalComponent implements OnInit {
|
|
|
this.refresh();
|
|
|
}
|
|
|
ngOnDestroy(): void {
|
|
|
- //Called once, before the instance is destroyed.
|
|
|
- //Add 'implements OnDestroy' to the class.
|
|
|
+ this.ngUnsubscribe.next();
|
|
|
+ this.ngUnsubscribe.complete();
|
|
|
+
|
|
|
if (!this.isLiveing && this.uid !== this.currentUser?.id) {
|
|
|
console.log('断开连接');
|
|
|
this.msgSer?.unsubscribeMessage(this.uid!);
|
|
@@ -59,6 +63,7 @@ export class CallModalComponent implements OnInit {
|
|
|
query.equalTo('profile', this.profile?.id);
|
|
|
query.notEqualTo('isDeleted', true);
|
|
|
this.room = await query.first();
|
|
|
+ console.log(this.room);
|
|
|
if (!this.room?.id) return;
|
|
|
this.userStatus = await this.connectTask.getState(
|
|
|
this.profile?.get('user').id,
|
|
@@ -110,20 +115,27 @@ export class CallModalComponent implements OnInit {
|
|
|
});
|
|
|
await alert.present();
|
|
|
}
|
|
|
- async inviteCallback(event: boolean) {
|
|
|
+ timer: any; // 定时器
|
|
|
+ inviteCallback(event: boolean) {
|
|
|
console.log(event);
|
|
|
if (event == undefined) return;
|
|
|
- this.iscall = false;
|
|
|
- const toast = await this.toastController.create({
|
|
|
- message: `对方${event ? '已接受' : '拒绝'}通话邀请`,
|
|
|
- color: event ? 'success' : 'warning',
|
|
|
- duration: 1500,
|
|
|
- });
|
|
|
- toast.present();
|
|
|
- if (event) {
|
|
|
- this.isLiveing = true;
|
|
|
- this.router.navigate(['live/link-room/' + this.room?.id]);
|
|
|
- }
|
|
|
+ this.timer && clearTimeout(this.timer);
|
|
|
+ this.timer = setTimeout(async () => {
|
|
|
+ this.iscall = false;
|
|
|
+ const toast = await this.toastController.create({
|
|
|
+ message: `对方${event ? '已接受' : '拒绝'}通话邀请`,
|
|
|
+ color: event ? 'success' : 'warning',
|
|
|
+ duration: 1500,
|
|
|
+ });
|
|
|
+ toast.present();
|
|
|
+ if (event) {
|
|
|
+ this.isLiveing = true;
|
|
|
+ let path = location.pathname;
|
|
|
+ if (path.indexOf('/live/link-room/') != -1) return;
|
|
|
+ console.log(this.room);
|
|
|
+ this.router.navigate(['live/link-room/' + this.room?.id]);
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
}
|
|
|
async sendVideoCallInvite() {
|
|
|
let second = await this.aiChatServ.get_duration(
|
|
@@ -148,6 +160,7 @@ export class CallModalComponent implements OnInit {
|
|
|
this.msgSer.publishMessage('USERCALLINVITATION', this.uid!);
|
|
|
}
|
|
|
async onCloseCall() {
|
|
|
+ this.timer && clearTimeout(this.timer);
|
|
|
this.iscall = false;
|
|
|
const toast = await this.toastController.create({
|
|
|
message: '已取消视频通话邀请',
|