示例#1
0
 public function dispatchReceivePacket(Packet $packet, Session $session)
 {
     if (!$session->isAuth()) {
         return;
     }
     /* @var \jegarn\session\SwooleSession $session
      * @var GroupChatPacket $pkt
      */
     if ($pkt = ChatroomPacket::getPacketFromPacket($packet)) {
         // check send user is a member of this group
         $cm = ChatroomManager::getInstance();
         if ($packet->isFromSystemUser() || $cm->isGroupUser($pkt->getGroupId(), $pkt->getFrom())) {
             $fromUid = $pkt->getFrom();
             if ($uidList = $cm->getGroupUsers($pkt->getGroupId())) {
                 $sm = ServerManager::getInstance();
                 foreach ($uidList as $uid) {
                     if ($uid != $fromUid) {
                         $pktCopy = clone $pkt;
                         $pktCopy->setTo($uid);
                         if ($toSession = SessionManager::getInstance()->getSessionByUserId($uid)) {
                             Logger::addInfo('user online,chatroom(uid:' . $uid . ')');
                             $sm->send($toSession, $pktCopy);
                         } else {
                             Logger::addInfo('user not online,chatroom,abandon message(uid:' . $uid . ')');
                         }
                     }
                 }
             } else {
                 Logger::addInfo('chatroom ' . $pkt->getGroupId() . ' users lost, from uid ' . $pkt->getFrom());
             }
         } else {
             Logger::addInfo('chatroom ' . $pkt->getGroupId() . ' has no user ' . $pkt->getFrom() . ' and it is not a system user');
         }
     }
 }
示例#2
0
 public function testClear()
 {
     /**
      * @var array $users
      * @var integer $groupId
      * @var integer $chatroomId
      */
     require __DIR__ . '/initData.php';
     $userList = [];
     foreach ($users as $user) {
         UserManager::getInstance()->removeUser($user['account']);
         $userList[] = $user['uid'];
     }
     // create group, and user to group
     GroupManager::getInstance()->removeGroupUsers($groupId, $userList);
     // create chatroom, add user to chatroom
     ChatroomManager::getInstance()->removeChatroomUsers($chatroomId, $userList);
 }
示例#3
0
 public static function quitChatroom($groupId, $requestUid)
 {
     ChatroomManager::getInstance()->removeChatroomUser(intval($groupId), intval($requestUid));
 }
示例#4
0
 public function quitGroup(User $user, Group $group)
 {
     $resp = $this->request('/api/group/quit', ['uid' => $user->id, 'token' => $user->token, 'group_id' => $group->id], true);
     $this->assertRequestSuccess($resp);
     $result = $this->getResponseBody($resp);
     // check cache
     if ($group->type == Group::TYPE_GROUP) {
         self::assertTrue(\jegarn\manager\GroupManager::getInstance()->isGroupUser($group->id, $user->id) == false);
         $this->assertNotificationPacket($group->uid, new GroupQuitNotification());
     } else {
         self::assertTrue(\jegarn\manager\ChatroomManager::getInstance()->isGroupUser($group->id, $user->id) == false);
     }
     return ConvertUtil::arrayToObject($result, new GroupUser(), ['id', 'gid', 'uid', 'status', 'permission', 'create_time', 'remark']);
 }
示例#5
0
 public static function getUser()
 {
     $user = ['uid' => self::$uidIndex, 'account' => 'tester_' . self::$uidIndex, 'password' => rand(100000, 999999), 'groupId' => self::getGroup(), 'chatroomId' => self::getChatroom()];
     self::$uidList[] = self::$uidIndex;
     ++self::$uidIndex;
     UserManager::getInstance()->addUser($user['uid'], $user['account'], $user['password']);
     GroupManager::getInstance()->addGroupUser($user['groupId'], $user['uid']);
     ChatroomManager::getInstance()->addChatroomUser($user['chatroomId'], $user['uid']);
     return $user;
 }