|
@@ -7,8 +7,7 @@ import { Subject } from 'rxjs';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { AiChatService } from './aichart.service';
|
|
|
declare const AgoraRTM: any;
|
|
|
-import { VapInit } from '../lib/vap-player/index'
|
|
|
-
|
|
|
+import { VapInit } from '../lib/vap-player/index';
|
|
|
|
|
|
@Injectable({
|
|
|
providedIn: 'root',
|
|
@@ -37,9 +36,9 @@ export class MessageService {
|
|
|
giftList: Array<any> = []; //礼物列表
|
|
|
timeg: any;
|
|
|
isPlayer: boolean = false;
|
|
|
-
|
|
|
+ newNoticeMap = new Set(); //新消息提示
|
|
|
private audioPlayer: HTMLAudioElement | null = null;
|
|
|
- private loopPlayAudio(audioUrl: string, rep?:boolean) {
|
|
|
+ private loopPlayAudio(audioUrl: string, rep?: boolean) {
|
|
|
if (this.audioPlayer) {
|
|
|
this.audioPlayer.pause();
|
|
|
this.audioPlayer.currentTime = 0;
|
|
@@ -47,7 +46,7 @@ export class MessageService {
|
|
|
|
|
|
this.audioPlayer = new Audio(audioUrl);
|
|
|
this.audioPlayer.loop = rep; // 设置循环播放
|
|
|
- this.audioPlayer.play().catch(error => {
|
|
|
+ this.audioPlayer.play().catch((error) => {
|
|
|
console.error('播放音频失败:', error);
|
|
|
});
|
|
|
}
|
|
@@ -56,6 +55,7 @@ export class MessageService {
|
|
|
this.rtmClient = null;
|
|
|
this.channelNameList = {};
|
|
|
this.messageMapList = {};
|
|
|
+ this.newNoticeMap = new Set();
|
|
|
}
|
|
|
constructor(
|
|
|
private alertController: AlertController,
|
|
@@ -132,7 +132,7 @@ export class MessageService {
|
|
|
}
|
|
|
//呼出播放声音
|
|
|
if (message.text == 'USERCALLINVITATION') {
|
|
|
- this.loopPlayAudio('mp3/call.mp3',true);
|
|
|
+ this.loopPlayAudio('mp3/call.mp3', true);
|
|
|
} else if (message.text == 'CLOASEINVITATION') {
|
|
|
if (this.audioPlayer) {
|
|
|
this.audioPlayer.pause();
|
|
@@ -189,18 +189,19 @@ export class MessageService {
|
|
|
count: arr?.[2],
|
|
|
user: userData,
|
|
|
});
|
|
|
- !this.isPlayer && setTimeout(() => {
|
|
|
- // this.playGift(this.giftLogMap.slice(-1)[0]);
|
|
|
- let obj = this.giftLogMap.slice(-1)[0]
|
|
|
- this.eventplay.next({
|
|
|
- video: obj.gift.video,
|
|
|
- config: obj.gift.config,
|
|
|
- });
|
|
|
- }, 0);
|
|
|
+ !this.isPlayer &&
|
|
|
+ setTimeout(() => {
|
|
|
+ // this.playGift(this.giftLogMap.slice(-1)[0]);
|
|
|
+ let obj = this.giftLogMap.slice(-1)[0];
|
|
|
+ this.eventplay.next({
|
|
|
+ video: obj.gift.video,
|
|
|
+ config: obj.gift.config,
|
|
|
+ });
|
|
|
+ }, 0);
|
|
|
return;
|
|
|
}
|
|
|
if (message.indexOf('USERGREETING_') > -1) {
|
|
|
- this.loopPlayAudio('mp3/message.mp3')
|
|
|
+ this.loopPlayAudio('mp3/message.mp3');
|
|
|
let arr = message.split('_');
|
|
|
this.alert = await this.alertController.create({
|
|
|
cssClass: 'my-custom-class',
|
|
@@ -211,8 +212,7 @@ export class MessageService {
|
|
|
{
|
|
|
text: '关闭',
|
|
|
role: 'cancel',
|
|
|
- handler: async (blah) => {
|
|
|
- },
|
|
|
+ handler: async (blah) => {},
|
|
|
},
|
|
|
{
|
|
|
text: '查看主页',
|
|
@@ -228,7 +228,7 @@ export class MessageService {
|
|
|
}
|
|
|
switch (message) {
|
|
|
case 'USERCALLINVITATION':
|
|
|
- this.loopPlayAudio('mp3/call.mp3',true);
|
|
|
+ this.loopPlayAudio('mp3/call.mp3', true);
|
|
|
await this.setConnectState(this.userId, 'CONNECTING');
|
|
|
// console.log(`收到${userData?.nickname?.value ?? '未知用户'}通话邀请`);
|
|
|
this.alert = await this.alertController.create({
|
|
@@ -328,7 +328,7 @@ export class MessageService {
|
|
|
|
|
|
playGift(giftModule: any) {
|
|
|
console.log(giftModule);
|
|
|
- this.isPlayer = true
|
|
|
+ this.isPlayer = true;
|
|
|
let dom = document.getElementById('vap-gift');
|
|
|
console.log(dom);
|
|
|
let vapPlayer = VapInit({
|
|
@@ -355,10 +355,12 @@ export class MessageService {
|
|
|
if (this.giftLogMap.length > 0) {
|
|
|
this.playGift(this.giftLogMap.slice(-1)[0]);
|
|
|
} else {
|
|
|
- this.isPlayer = false
|
|
|
+ this.isPlayer = false;
|
|
|
}
|
|
|
});
|
|
|
- vapPlayer.on('playering', function () { console.log('playering'); })
|
|
|
+ vapPlayer.on('playering', function () {
|
|
|
+ console.log('playering');
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
async getRoom(uid: string): Promise<string | undefined> {
|
|
@@ -432,7 +434,9 @@ export class MessageService {
|
|
|
}
|
|
|
/* 订阅消息 */
|
|
|
subscribeMessage(channelName: string, param?: any, deadline?: number): any {
|
|
|
- if (this.channelNameList[channelName]) { return };
|
|
|
+ if (this.channelNameList[channelName]) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const options = {
|
|
@@ -451,6 +455,10 @@ export class MessageService {
|
|
|
if (!this.messageMapList[channelName]) {
|
|
|
this.messageMapList[channelName] = [];
|
|
|
if (channelName.indexOf('-') > -1 || channelName == 'global_room') {
|
|
|
+ let noticeMap = localStorage.getItem('noticeMap') || '{}';
|
|
|
+ noticeMap = JSON.parse(noticeMap);
|
|
|
+ noticeMap[channelName] = 0;
|
|
|
+ localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
|
|
|
this.getHistoryMessage(channelName, deadline);
|
|
|
}
|
|
|
}
|
|
@@ -478,10 +486,22 @@ export class MessageService {
|
|
|
let is_self = item?.get('from_id') == this.userId;
|
|
|
let data: any = item?.get('content');
|
|
|
data['is_self'] = is_self;
|
|
|
- data['istoday'] = true;
|
|
|
data['timestamp'] = new Date(data.timestamp);
|
|
|
this.messageMapList[channelName].unshift(data);
|
|
|
});
|
|
|
+ //处理未读信息红点
|
|
|
+ let noticeMap = localStorage.getItem('noticeMap') || '{}';
|
|
|
+ noticeMap = JSON.parse(noticeMap);
|
|
|
+ if (this.router.url.indexOf('/live/chat/' + channelName) == 0) {
|
|
|
+ noticeMap[channelName] = new Date().getTime();
|
|
|
+ localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
|
|
|
+ this.newNoticeMap.delete(channelName);
|
|
|
+ } else if (msgList.length > 0 && !this.newNoticeMap.has(channelName)) {
|
|
|
+ let lastMsg = this.messageMapList[channelName]?.at(-1);
|
|
|
+ if (!lastMsg.is_self && lastMsg.timestamp > noticeMap[channelName]) {
|
|
|
+ this.newNoticeMap.add(channelName);
|
|
|
+ }
|
|
|
+ }
|
|
|
// this.messageMapList[channelName].unshift(...msgList);
|
|
|
}
|
|
|
/* 取消订阅 */
|
|
@@ -523,6 +543,18 @@ export class MessageService {
|
|
|
timestamp: param.timestamp,
|
|
|
},
|
|
|
});
|
|
|
+ } else if (param.channelName.indexOf('-') > -1) {
|
|
|
+ let noticeMap: any = localStorage.getItem('noticeMap') || '{}';
|
|
|
+ noticeMap = JSON.parse(noticeMap);
|
|
|
+ if (
|
|
|
+ this.router.url.indexOf('/live/chat/' + param.channelName) == 0
|
|
|
+ ) {
|
|
|
+ noticeMap[param.channelName] = new Date().getTime();
|
|
|
+ localStorage.setItem('noticeMap', JSON.stringify(noticeMap));
|
|
|
+ this.newNoticeMap.delete(param.channelName);
|
|
|
+ } else if (param.timestamp > noticeMap[param.channelName]) {
|
|
|
+ this.newNoticeMap.add(param.channelName);
|
|
|
+ }
|
|
|
}
|
|
|
let data: any = {
|
|
|
is_self: is_self,
|
|
@@ -534,7 +566,6 @@ export class MessageService {
|
|
|
content: message?.text ?? '',
|
|
|
publisher: param.publisher,
|
|
|
timestamp: new Date(param.timestamp),
|
|
|
- istoday: true,
|
|
|
};
|
|
|
this.messageMapList[param.channelName].push(data);
|
|
|
this.pageFun?.();
|