Explorar el Código

房间调整优化

lizhen_gitee hace 1 año
padre
commit
f4364d7ef8
Se han modificado 2 ficheros con 23 adiciones y 10 borrados
  1. 3 1
      application/api/controller/Easemob.php
  2. 20 9
      application/api/controller/Party.php

+ 3 - 1
application/api/controller/Easemob.php

@@ -65,6 +65,8 @@ class Easemob extends Api
      * 用户登出(被其他设备踢掉)
      * {"callId":"1101231101159883#demo_b2cdc4d9-a499-4e46-8aff-4503fb83a5c5","reason":"replaced","security":"1f4bb2ebb99c2f5da20048c7ca87f352","os":"android","ip":"182.37.138.94:41044","host":"msync@ebs-ali-beijing-msync62","appkey":"1101231101159883#demo","user":"1101231101159883#demo_9@easemob.com/android_fb260fdf-3935-4499-a09d-b270fdd88a0e","version":"4.1.2","timestamp":1700473675582,"status":"offline"}
      */
+
+    //登入,登出,进入房间其实都不需要处理。登入不影响房间。只登出只要不影响房间,在退出房间时间会重复回调。登入房间有接口,这里没必要重复处理。就只有退出房间有用也简单
     public function callback() {
         $this->notify_log_start();
 
@@ -222,7 +224,7 @@ class Easemob extends Api
                 $userId = $uid;
 
                 $this->redis->hSet("online_" . $roomId, $userId, $userId);
-                $this->redis->zAdd("party_user_".$roomId,$userId,0); //新加的
+                $this->redis->zAdd("party_user_".$roomId,$userId,$userId); //新加的
                 // 记录在线用户在房间情况
                 $this->redis->hSet("livingUser",$userId,$roomId);
 

+ 20 - 9
application/api/controller/Party.php

@@ -67,16 +67,16 @@ class Party extends Common
         //party_jewel_to_1:20231120w,live_jewel_to_1:20231120w      本周第一天
         //party_jewel_to_1:20231101m,live_jewel_to_1:20231101m      本月第一天
 
-        //在线人列表
+        //在线人列表。hSet增加,HDel减少, hGetAll来使用。大多用来计算数量 count(hGetAll),少数获取用户列表
         //online_1
 
+        //房间列表页的用户头像 。zAdd增加,zRem减少,zRange来使用。 party_user_1 总是 与 online_1 共同出现,加的时候一起加,减的时候一起减。多处维护,只有 RoomService/getPartyUserList 这个方法有使用到
+        //party_user_1
+
         //用户进房
         //joinParty_days
 
-        //首页用户头像
-        //party_user_1
-
-        //在线用户在房间情况
+        //在线用户在房间情况。当前用户在哪个房间
         //livingUser
 
         //派对管理 1=房管,2=禁言,3=拉黑,4=踢出
@@ -753,7 +753,7 @@ class Party extends Common
         }
         $user_id = $this->auth->id;
 
-        $this->redis->zAdd("party_user_".$party_id,$this->auth->u_id,$user_id);
+        $this->redis->zAdd("party_user_".$party_id,$user_id,$user_id);
         $this->redis->hSet("online_".$party_id,$user_id,$user_id); //新增的
 
         // 判断当前用户是否存在在直播间通过切换过来的
@@ -877,12 +877,16 @@ class Party extends Common
         //声网三个token
         $lsetList['shengwang_token'] = $this->shengwang_token($partyInfo['easemob_room_id'],1);
 
-        //更新聊天室自定义属性 用户列表
+        //[环信] 更新聊天室自定义属性 在线用户人数
+        $easemob = new Easemob();
+        $matedata = [
+            'online_user_num'  => count($this->redis->hGetAll("online_".$party_id)),
+        ];
+        $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
 
         return $this->success("加入成功!",$lsetList);
     }
 
-
     /**
      * 判断是否被禁言
      */
@@ -927,7 +931,6 @@ class Party extends Common
         $this->redis->zRem("party_user_".$party_id,$userId);
 
         // 处理online_party_id
-        //$this->redis->connect($redisconfig["host"], $redisconfig["port"]);
         $this->redis->HDel("online_" . $party_id, $this->auth->id);
 
         // 扣除在线用户在房间情况
@@ -955,6 +958,14 @@ class Party extends Common
                 \app\common\model\Party::update(["is_online" => 0], ["id" => $party_id]);
             }
         }
+
+        //[环信] 更新聊天室自定义属性 在线用户人数
+        $easemob = new Easemob();
+        $matedata = [
+            'online_user_num'  => count($this->redis->hGetAll("online_".$party_id)),
+        ];
+        $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
+
         return $this->success("退出成功!",[]);
     }