Browse Source

feat: connect rtmClient not init in home page

ryanemax 3 months ago
parent
commit
0df8d37047
2 changed files with 50 additions and 8 deletions
  1. 33 0
      package-lock.json
  2. 17 8
      projects/live-app/src/services/connectTask.service.ts

+ 33 - 0
package-lock.json

@@ -16,6 +16,8 @@
         "@angular/platform-browser": "^18.0.0",
         "@angular/platform-browser-dynamic": "^18.0.0",
         "@angular/router": "^18.0.0",
+        "@ionic-native/core": "^5.36.0",
+        "@ionic-native/wechat": "^5.36.0",
         "@ionic/angular": "^8.4.0",
         "@ionic/angular-server": "^8.4.0",
         "@ionic/angular-toolkit": "^11.0.1",
@@ -3029,6 +3031,31 @@
         "node": ">=18"
       }
     },
+    "node_modules/@ionic-native/core": {
+      "version": "5.36.0",
+      "resolved": "https://registry.npmmirror.com/@ionic-native/core/-/core-5.36.0.tgz",
+      "integrity": "sha512-lOrkktadlKYbYf1LrDyAtsu1JnQ0oCCdkOU7iHQ8oXnNOkMwobFfD2m62F1CoOr0u9LIkpYnZSPjng8lZbmbNw==",
+      "license": "MIT",
+      "dependencies": {
+        "@types/cordova": "latest"
+      },
+      "peerDependencies": {
+        "rxjs": "^5.5.0 || ^6.5.0"
+      }
+    },
+    "node_modules/@ionic-native/wechat": {
+      "version": "5.36.0",
+      "resolved": "https://registry.npmmirror.com/@ionic-native/wechat/-/wechat-5.36.0.tgz",
+      "integrity": "sha512-e8yZairpw2+RSN25d+fL2Do6rMCwPUSqQ7Y5stwRxGpnWCkoYnTO31fjrK163tnuYc9No/IXR8otJijJ57JQhg==",
+      "license": "MIT",
+      "dependencies": {
+        "@types/cordova": "latest"
+      },
+      "peerDependencies": {
+        "@ionic-native/core": "^5.1.0",
+        "rxjs": "^5.5.0 || ^6.5.0"
+      }
+    },
     "node_modules/@ionic/angular": {
       "version": "8.4.0",
       "resolved": "https://registry.npmmirror.com/@ionic/angular/-/angular-8.4.0.tgz",
@@ -4323,6 +4350,12 @@
       "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==",
       "dev": true
     },
+    "node_modules/@types/cordova": {
+      "version": "11.0.3",
+      "resolved": "https://registry.npmmirror.com/@types/cordova/-/cordova-11.0.3.tgz",
+      "integrity": "sha512-kyuRQ40/NWQVhqGIHq78Ehu2Bf9Mlg0LhmSmis6ZFJK7z933FRfYi8tHe/k/0fB+PGfCf95rJC6TO7dopaFvAg==",
+      "license": "MIT"
+    },
     "node_modules/@types/cors": {
       "version": "2.8.17",
       "resolved": "https://registry.npmmirror.com/@types/cors/-/cors-2.8.17.tgz",

+ 17 - 8
projects/live-app/src/services/connectTask.service.ts

@@ -23,7 +23,12 @@ export class ConnectTaskService {
   }
   /* 主播上线 */
   async anchorOnline() {
-    let profile = JSON.parse(localStorage.getItem('profile') || '');
+    let profile
+    try{
+      profile = JSON.parse(localStorage.getItem('profile') || '');
+    }catch(err){
+      console.log("profile err",err)
+    }
     const uid = Parse.User.current()?.id!;
     if (profile?.identyType == 'anchor' && !this.isSubscribe) {
       let nowChannes = await this.getWhereNow(uid);
@@ -100,25 +105,29 @@ export class ConnectTaskService {
     };
     if (page) options.page = page;
     try {
-      const result = await this.msgSer.rtmClient.presence.whoNow(
+      const result = await this.msgSer?.rtmClient?.presence?.whoNow(
         channelName,
         channelType ?? 'MESSAGE',
         options
       );
       // console.log(result);
       // 如果 nextPage 存在,下一次调用 whoNow 时,需将 nextPage 的值填入 whoNowOptions 的 page 字段
-      const { totalOccupancy, occupants, nextPage } = result;
-      occupants.forEach((userInfo: any) => {
+      
+      let totalOccupancy = result?.totalOccupancy
+      let occupants = result?.occupants
+      let nextPage = result?.nextPage
+      occupants?.forEach((userInfo: any) => {
         const { states, userId, statesCount } = userInfo;
         this.onlineUserList.add(userId);
       });
       console.log('获取在线用户列表:',this.onlineUserList);
       if (nextPage) this.getOnlieUserList(channelName, nextPage, channelType);
     } catch (status: any) {
-      const { operation, reason, errorCode } = status;
-      console.error(
-        `${operation} failed, ErrorCode: ${errorCode}, due to: ${reason}.`
-      );
+      // const { operation, reason, errorCode } = status;
+      console.error("getOnlieUserList err",status)
+      // console.error(
+      //   `${operation} failed, ErrorCode: ${errorCode}, due to: ${reason}.`
+      // );
     }
   }
 }