/**
  * Process the incoming command, default commands have a system of twist
  * @param $resUserSocket
  * @param $strMessageData
  */
 protected function process($resUserSocket, $strMessageData)
 {
     $arrData = $this->parseString($strMessageData);
     //Check that we have a valid response
     if (is_array($arrData) && count($arrData)) {
         //Check that a valid system call has been passed in
         if (array_key_exists('instance', $arrData) && array_key_exists('system', $arrData) && array_key_exists('action', $arrData) && array_key_exists('data', $arrData)) {
             switch ($arrData['system']) {
                 case 'twist':
                     switch ($arrData['action']) {
                         case 'login':
                             Users::login($arrData, $resUserSocket);
                             break;
                         case 'logout':
                             Users::logout($arrData, $resUserSocket);
                             break;
                         case 'debug':
                             //Toggle the admin log for this connection, only allowing toggle of connections that belong to admins
                             $blCurrentStatus = Sockets::getData($resUserSocket, 'system_admin_log');
                             Sockets::setData($resUserSocket, 'system_admin_log', $blCurrentStatus ? false : true);
                             System::stats();
                             break;
                         case 'restart':
                             //Shutdown the server and it will restart in 1 minute
                             $this->shutdownServer();
                             break;
                         case 'active':
                         case 'inactive':
                             //Set the connections current Active status (clicked in the last 30 seconds or not)
                             Sockets::setData($resUserSocket, 'activeStatus', array('status' => $arrData['action'], 'updated' => time()));
                             break;
                         case 'blur':
                         case 'focus':
                             //Set the connections current View status (focused on browser tab or not)
                             Sockets::setData($resUserSocket, 'viewStatus', array('status' => $arrData['action'], 'updated' => time()));
                             break;
                         case 'uri':
                             //Set the connections current URI (The page of the website that the connection is coming from)
                             Sockets::setData($resUserSocket, 'currentURI', $arrData['data']);
                             break;
                         case 'users':
                             Users::sendUserList($resUserSocket, $arrData);
                             break;
                     }
                     break;
                     //This is where the magic happens, any module can be called here using the correct command
                 //This is where the magic happens, any module can be called here using the correct command
                 default:
                     AppHandler::process($arrData['system'], $resUserSocket, $arrData);
                     break;
             }
         } else {
             //Error invalid params
             System::sendErrorResponse($resUserSocket, $arrData, 'Invalid request parameters');
         }
     }
 }
Example #2
0
 /**
  * Get all the connections that belong to a particular user
  * @param $intUserID
  * @return array
  */
 public static function getSockets($intUserID)
 {
     $arrOut = array();
     foreach (Sockets::getAllConnected() as $arrEachSocket) {
         //Check User ID for matches
         if ($arrEachSocket['data']['user_id'] == $intUserID) {
             $arrOut[] = $arrEachSocket['socket'];
         }
     }
     return $arrOut;
 }