Example #1
0
 protected function _registerCallbacks()
 {
     $this->_registerClockworkCallbacks('10 seconds', array('CM_Model_User::offlineDelayed' => function () {
         CM_Model_User::offlineDelayed();
     }));
     $this->_registerClockworkCallbacks('1 minute', array('CM_Model_User::offlineOld' => function () {
         CM_Model_User::offlineOld();
     }, 'CM_ModelAsset_User_Roles::deleteOld' => function () {
         CM_ModelAsset_User_Roles::deleteOld();
     }, 'CM_Paging_Useragent_Abstract::deleteOlder' => function () {
         CM_Paging_Useragent_Abstract::deleteOlder(100 * 86400);
     }, 'CM_File_UserContent_Temp::deleteOlder' => function () {
         CM_File_UserContent_Temp::deleteOlder(86400);
     }, 'CM_SVM_Model::deleteOldTrainings' => function () {
         CM_SVM_Model::deleteOldTrainings(3000);
     }, 'CM_Paging_Ip_Blocked::deleteOlder' => function () {
         CM_Paging_Ip_Blocked::deleteOld();
     }, 'CM_Captcha::deleteOlder' => function () {
         CM_Captcha::deleteOlder(3600);
     }, 'CM_Session::deleteExpired' => function () {
         CM_Session::deleteExpired();
     }, 'CM_Stream_Video::synchronize' => function () {
         CM_Stream_Video::getInstance()->synchronize();
     }, 'CM_Stream_Video::checkStreams' => function () {
         CM_Stream_Video::getInstance()->checkStreams();
     }, 'CM_MessageStream_Service::synchronize' => function () {
         CM_Service_Manager::getInstance()->getStreamMessage()->synchronize();
     }));
     $this->_registerClockworkCallbacks('15 minutes', array('CM_Mail::processQueue' => function () {
         CM_Mail::processQueue(500);
     }, 'CM_Action_Abstract::aggregate' => function () {
         CM_Action_Abstract::aggregate();
     }, 'CM_Action_Abstract::deleteTransgressionsOlder' => function () {
         CM_Action_Abstract::deleteTransgressionsOlder(3 * 31 * 86400);
     }, 'CM_Paging_Log_Abstract::cleanup' => function () {
         foreach (CM_Paging_Log_Abstract::getClassChildren() as $logClass) {
             /** @var CM_Paging_Log_Abstract $log */
             $log = new $logClass();
             $log->cleanUp();
         }
     }));
     $this->_registerClockworkCallbacks('8 days', array('CMService_MaxMind::upgrade' => function () {
         try {
             $maxMind = new CMService_MaxMind();
             $maxMind->upgrade();
         } catch (Exception $exception) {
             if (!is_a($exception, 'CM_Exception')) {
                 $exception = new CM_Exception($exception->getMessage(), ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString()]);
             }
             $exception->setSeverity(CM_Exception::FATAL);
             throw $exception;
         }
     }));
 }
Example #2
0
 public function testGetServer()
 {
     $server = CM_Stream_Video::getInstance()->getServer(1);
     $this->assertSame('10.0.3.108', $server['privateIp']);
     try {
         CM_Stream_Video::getInstance()->getServer(800);
         $this->fail('Found server with id 800');
     } catch (CM_Exception_Invalid $ex) {
         $this->assertContains('No video server with id `800` found', $ex->getMessage());
     }
 }
Example #3
0
 public function synchronize()
 {
     $startStampLimit = time() - 3;
     $status = array();
     foreach (CM_Stream_Video::getInstance()->getServers() as $serverId => $wowzaServer) {
         $singleStatus = CM_Params::decode($this->_fetchStatus($wowzaServer['privateIp']), true);
         foreach ($singleStatus as $streamName => $publish) {
             $publish['serverId'] = $serverId;
             $publish['serverHost'] = $wowzaServer['privateIp'];
             $status[$streamName] = $publish;
         }
     }
     $streamChannels = $this->_getStreamChannels();
     foreach ($status as $streamName => $publish) {
         /** @var CM_Model_StreamChannel_Abstract $streamChannel */
         $streamChannel = CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamName, $this->getType());
         if (!$streamChannel || !$streamChannel->getStreamPublishs()->findKey($publish['clientId'])) {
             $this->_stopClient($publish['clientId'], $publish['serverHost']);
         }
         foreach ($publish['subscribers'] as $clientId => $subscribe) {
             if (!$streamChannel || !$streamChannel->getStreamSubscribes()->findKey($clientId)) {
                 $this->_stopClient($clientId, $publish['serverHost']);
             }
         }
     }
     /** @var CM_Model_StreamChannel_Abstract $streamChannel */
     foreach ($streamChannels as $streamChannel) {
         if (!$streamChannel->hasStreams()) {
             $streamChannel->delete();
             continue;
         }
         /** @var CM_Model_Stream_Publish $streamPublish */
         $streamPublish = $streamChannel->getStreamPublishs()->getItem(0);
         if ($streamPublish) {
             if ($streamPublish->getStart() > $startStampLimit) {
                 continue;
             }
             if (!isset($status[$streamChannel->getKey()])) {
                 $this->unpublish($streamChannel->getKey());
             }
         }
         /** @var CM_Model_Stream_Subscribe $streamSubscribe */
         foreach ($streamChannel->getStreamSubscribes() as $streamSubscribe) {
             if ($streamSubscribe->getStart() > $startStampLimit) {
                 continue;
             }
             if (!isset($status[$streamChannel->getKey()]['subscribers'][$streamSubscribe->getKey()])) {
                 $this->unsubscribe($streamChannel->getKey(), $streamSubscribe->getKey());
             }
         }
     }
 }
Example #4
0
 /**
  * @param string $key
  * @return CM_Model_StreamChannel_Video|null
  */
 public static function findByKey($key)
 {
     $adapterType = CM_Stream_Video::getInstance()->getAdapter()->getType();
     return self::findByKeyAndAdapter($key, $adapterType);
 }