|
@@ -5,6 +5,7 @@ import { AlertController, ToastController } from '@ionic/angular';
|
|
|
// import AgoraRTM from 'agora-rtmClient';
|
|
|
import { Subject } from 'rxjs';
|
|
|
import { Router } from '@angular/router';
|
|
|
+import { AiChatService } from './aichart.service';
|
|
|
declare const AgoraRTM: any;
|
|
|
@Injectable({
|
|
|
providedIn: 'root',
|
|
@@ -26,14 +27,18 @@ export class MessageService {
|
|
|
pageFun?: Function; //页面传入的方法
|
|
|
alert: any; // 弹窗
|
|
|
messageMapList: any = {};
|
|
|
- giftLog?: string = ''; //当前礼物弹窗
|
|
|
-
|
|
|
+ giftLogMap: any = [];
|
|
|
+ giftList: Array<any> = [];//礼物列表
|
|
|
+ timeg:any
|
|
|
constructor(
|
|
|
private alertController: AlertController,
|
|
|
private router: Router,
|
|
|
public toastController: ToastController,
|
|
|
- private http: HttpService
|
|
|
- ) {}
|
|
|
+ private http: HttpService,
|
|
|
+ private aiServ: AiChatService
|
|
|
+ ) {
|
|
|
+ this.aiServ.getGift().then((data) => (this.giftList = data));
|
|
|
+ }
|
|
|
|
|
|
/* 获取token */
|
|
|
async getToken() {
|
|
@@ -89,7 +94,7 @@ export class MessageService {
|
|
|
const message = JSON.parse(event.message);
|
|
|
let is_self = event.publisher == this.userId;
|
|
|
console.log('自己发出的消息:', is_self, message.text);
|
|
|
- if (states.includes(message.text)) {
|
|
|
+ if (states.includes(message.text) || message.text.indexOf('ONUSERSENDGIFT_') > -1) {
|
|
|
if (!is_self) {
|
|
|
this.callPresence(message.text, event.publisher, event.channelName);
|
|
|
}
|
|
@@ -121,11 +126,7 @@ export class MessageService {
|
|
|
Mode: mode,
|
|
|
};
|
|
|
try {
|
|
|
- await this.rtmClient?.presence.setState(
|
|
|
- channelName,
|
|
|
- channelType,
|
|
|
- states
|
|
|
- );
|
|
|
+ await this.rtmClient?.presence.setState(channelName, channelType, states);
|
|
|
console.log('频道状态发生更改:', mode);
|
|
|
} catch (err: any) {
|
|
|
console.log(err);
|
|
@@ -137,6 +138,17 @@ export class MessageService {
|
|
|
console.log(message);
|
|
|
let userData = await this.getUserMetadata(publisher);
|
|
|
let toast;
|
|
|
+ if(message.indexOf('ONUSERSENDGIFT_') > -1){
|
|
|
+ let arr = message.split('_')
|
|
|
+ let gift = this.giftList.find((item: any) => item.id == arr[1]);
|
|
|
+ this.giftLogMap.push({
|
|
|
+ gift,
|
|
|
+ count:arr?.[2],
|
|
|
+ user:userData
|
|
|
+ })
|
|
|
+ !this.timeg && this.showGiftDecrement()
|
|
|
+ return
|
|
|
+ }
|
|
|
switch (message) {
|
|
|
case 'USERCALLINVITATION':
|
|
|
await this.setConnectState(this.userId, 'CONNECTING');
|
|
@@ -198,7 +210,22 @@ export class MessageService {
|
|
|
this.eventSource.next(true);
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 礼物消息
|
|
|
+ showGiftDecrement(){
|
|
|
+ this.timeg = setTimeout(() => {
|
|
|
+ this.giftLogMap.shift();
|
|
|
+ if(this.giftLogMap.length > 0){
|
|
|
+ this.showGiftDecrement();
|
|
|
+ }else{
|
|
|
+ clearTimeout(this.timeg);
|
|
|
+ this.timeg = null
|
|
|
+ }
|
|
|
+ }, 500000);
|
|
|
}
|
|
|
+
|
|
|
async getRoom(uid: string): Promise<string | undefined> {
|
|
|
let query = new Parse.Query('Room');
|
|
|
query.equalTo('company', this.company);
|
|
@@ -424,9 +451,9 @@ export class MessageService {
|
|
|
publishMessage,
|
|
|
publishOptions
|
|
|
);
|
|
|
- console.log(result);
|
|
|
+ console.log('发出消息:', result);
|
|
|
} catch (status) {
|
|
|
- console.log(status);
|
|
|
+ console.log('发出消息失败:', status);
|
|
|
}
|
|
|
}
|
|
|
}
|