瀏覽代碼

用户在线状态

warrior 4 月之前
父節點
當前提交
71171ebf13
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      projects/live-app/src/services/message.service.ts

+ 5 - 4
projects/live-app/src/services/message.service.ts

@@ -118,7 +118,8 @@ export class MessageService {
     // };
     this.joinReady();
     await this.loginRTM();
-    this.subscribeMessage(channelName);
+    // this.subscribeMessage(channelName);
+    this.publishMessage('user-online',channelName,'USER')//用户上线通知
   }
   /* 监听频道消息 */
   joinReady(channelName?: string) {
@@ -160,7 +161,7 @@ export class MessageService {
       });
       this.options.connectState = true; // 登录成功
       let userMateData = await this.getUserMetadata(this.userId);
-      if(!userMateData){
+      if (!userMateData) {
         let user = Parse.User.current();
         const metadata = [
           {
@@ -192,7 +193,7 @@ export class MessageService {
   logOutRTM() {
     this.rtmClient.logout().then(() => {
       console.log('logout success');
-      this.options.connectState = false
+      this.options.connectState = false;
     });
   }
   /* 订阅消息 */
@@ -267,7 +268,7 @@ export class MessageService {
     }
   }
 
-  async publishMessage(message: string, channelName: string) {
+  async publishMessage(message: string, channelName: string, channelType?:string) {
     const payload = { type: 'text', message: message };
     const publishMessage = JSON.stringify(payload);
     const publishOptions = { channelType: 'MESSAGE' };