|
@@ -28,12 +28,12 @@ export class MessageService {
|
|
|
alert: any; // 弹窗
|
|
|
messageMapList: any = {};
|
|
|
giftLogMap: any = [];
|
|
|
- giftList: Array<any> = [];//礼物列表
|
|
|
- timeg:any
|
|
|
+ giftList: Array<any> = []; //礼物列表
|
|
|
+ timeg: any;
|
|
|
|
|
|
reset() {
|
|
|
- this.options = {connectState: false};
|
|
|
- this.rtmClient = null
|
|
|
+ this.options = { connectState: false };
|
|
|
+ this.rtmClient = null;
|
|
|
this.channelNameList = {};
|
|
|
this.messageMapList = {};
|
|
|
}
|
|
@@ -86,6 +86,7 @@ export class MessageService {
|
|
|
*@'CLOASEINVITATION': 取消通话邀请
|
|
|
*@'REFUSEINVITATION_' + uid: 拒绝通话邀请
|
|
|
*@'RESPONSEINVITOIN_' + uid: 接受邀请
|
|
|
+ *@'USERGREETING_' + '': 问候
|
|
|
*/
|
|
|
joinReady() {
|
|
|
this.rtmClient?.addEventListener('message', async (event: any) => {
|
|
@@ -101,7 +102,11 @@ 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) || message.text.indexOf('ONUSERSENDGIFT_') > -1) {
|
|
|
+ if (
|
|
|
+ states.includes(message.text) ||
|
|
|
+ message.text.indexOf('ONUSERSENDGIFT_') > -1 ||
|
|
|
+ message.text.indexOf('USERGREETING_') > -1
|
|
|
+ ) {
|
|
|
if (!is_self) {
|
|
|
this.callPresence(message.text, event.publisher, event.channelName);
|
|
|
}
|
|
@@ -143,18 +148,44 @@ export class MessageService {
|
|
|
/* 呼叫事件 */
|
|
|
async callPresence(message: string, publisher: string, channelName: string) {
|
|
|
let userData = await this.getUserMetadata(publisher);
|
|
|
- console.log('发出消息用户:',userData);
|
|
|
+ console.log('发出消息用户:', userData);
|
|
|
let toast;
|
|
|
- if(message.indexOf('ONUSERSENDGIFT_') > -1){
|
|
|
- let arr = message.split('_')
|
|
|
+ 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
|
|
|
+ count: arr?.[2],
|
|
|
+ user: userData,
|
|
|
+ });
|
|
|
+ !this.timeg && this.showGiftDecrement();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (message.indexOf('USERGREETING_') > -1) {
|
|
|
+ let arr = message.split('_');
|
|
|
+ this.alert = await this.alertController.create({
|
|
|
+ cssClass: 'my-custom-class',
|
|
|
+ header: '收到打招呼消息',
|
|
|
+ message: `${userData?.nickname?.value ?? '未知用户'}:${arr[1]}`,
|
|
|
+ backdropDismiss: false,
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '关闭',
|
|
|
+ role: 'cancel',
|
|
|
+ handler: async (blah) => {
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '查看主页',
|
|
|
+ cssClass: 'secondary',
|
|
|
+ handler: async () => {
|
|
|
+ this.router.navigate(['user/profile/' + publisher]);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ await this.alert.present();
|
|
|
+ return;
|
|
|
}
|
|
|
switch (message) {
|
|
|
case 'USERCALLINVITATION':
|
|
@@ -217,18 +248,17 @@ export class MessageService {
|
|
|
this.eventSource.next(true);
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 礼物消息
|
|
|
- showGiftDecrement(){
|
|
|
+ showGiftDecrement() {
|
|
|
this.timeg = setTimeout(() => {
|
|
|
this.giftLogMap.shift();
|
|
|
- if(this.giftLogMap.length > 0){
|
|
|
+ if (this.giftLogMap.length > 0) {
|
|
|
this.showGiftDecrement();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
clearTimeout(this.timeg);
|
|
|
- this.timeg = null
|
|
|
+ this.timeg = null;
|
|
|
}
|
|
|
}, 5000);
|
|
|
}
|
|
@@ -303,7 +333,7 @@ export class MessageService {
|
|
|
});
|
|
|
}
|
|
|
/* 订阅消息 */
|
|
|
- subscribeMessage(channelName: string, param?: any,deadline?: number) {
|
|
|
+ subscribeMessage(channelName: string, param?: any, deadline?: number) {
|
|
|
if (this.channelNameList[channelName]) return;
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const options = {
|
|
@@ -321,8 +351,8 @@ export class MessageService {
|
|
|
this.channelNameList[channelName] = true;
|
|
|
if (!this.messageMapList[channelName]) {
|
|
|
this.messageMapList[channelName] = [];
|
|
|
- if(channelName.indexOf('-') > -1 || channelName == 'global_room'){
|
|
|
- this.getHistoryMessage(channelName,deadline);
|
|
|
+ if (channelName.indexOf('-') > -1 || channelName == 'global_room') {
|
|
|
+ this.getHistoryMessage(channelName, deadline);
|
|
|
}
|
|
|
}
|
|
|
this.pageFun?.();
|
|
@@ -335,7 +365,7 @@ export class MessageService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async getHistoryMessage(channelName: string,deadline?:number) {
|
|
|
+ async getHistoryMessage(channelName: string, deadline?: number) {
|
|
|
let query = new Parse.Query('MessageLog');
|
|
|
query.equalTo('channel', channelName);
|
|
|
query.descending('createdAt');
|
|
@@ -467,8 +497,11 @@ export class MessageService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- delMsg(channelName: string, index?: number,limit?: number) {
|
|
|
- this.messageMapList[channelName].splice(index ?? 0, limit ?? this.messageMapList[channelName].length);
|
|
|
+ delMsg(channelName: string, index?: number, limit?: number) {
|
|
|
+ this.messageMapList[channelName].splice(
|
|
|
+ index ?? 0,
|
|
|
+ limit ?? this.messageMapList[channelName].length
|
|
|
+ );
|
|
|
console.log(this.messageMapList[channelName]);
|
|
|
}
|
|
|
}
|