Exemple #1
0
 /**
  * Subscribe to engine events (OKMOVED,FAILMOVED,MOVED)
  *
  * @return void
  */
 protected function _subscribeToEngineEvents()
 {
     $events = array(Streamwide_Engine_Events_Event::MOVED, Streamwide_Engine_Events_Event::OKMOVED, Streamwide_Engine_Events_Event::FAILMOVED, Streamwide_Engine_Events_Event::CHILD);
     $controller = $this->getController();
     foreach (new ArrayIterator($events) as $event) {
         $controller->addEventListener($event, array('callback' => array($this, 'onSignalReceived'), 'options' => array('notifyFilter' => Streamwide_Engine_NotifyFilter_Factory::factory(Streamwide_Engine_NotifyFilter_Factory::T_EVT_SIG_PARAM_REMOTE, Streamwide_Engine_NotifyFilter_Factory::FILTER_EQUAL_TO, $this->_callLeg->getName()))));
     }
 }
Exemple #2
0
 /**
  * Handle a CHILD signal received in the middle of the connection process
  *
  * @param Streamwide_Engine_Signal $signal
  * @param string $errorCode
  * @return void
  */
 protected function _handleChildSignal(Streamwide_Engine_Signal $signal, $errorCode)
 {
     $this->_unsubscribeFromEngineEvents();
     $remoteName = $signal->getRemote();
     $defunctCallLeg = $remoteName === $this->_leftCallLeg->getName() ? $this->_leftCallLeg : $this->_rightCallLeg;
     if ($defunctCallLeg->isAlive()) {
         $defunctCallLeg->setDead();
     }
     return $this->dispatchErrorEvent($errorCode, array('callLeg' => $defunctCallLeg));
 }
Exemple #3
0
 /**
  * Subscribe to be notified on OK, FAIL and CHILD signals from SW Engine
  *
  * @return void
  */
 protected function _subscribeToEngineEvents()
 {
     $controller = $this->getController();
     // Start listen to OK signal
     $okNotifyFilter = Streamwide_Engine_NotifyFilter_Factory::factory(Streamwide_Engine_NotifyFilter_Factory::T_EVT_SIG_PARAM_REMOTE, Streamwide_Engine_NotifyFilter_Factory::FILTER_EQUAL_TO, $this->_callLeg->getName());
     $controller->addEventListener(Streamwide_Engine_Events_Event::OK, array('callback' => array($this, 'onSignalReceived'), 'options' => array('autoRemove' => 'before', 'notifyFilter' => $okNotifyFilter)));
     // End listen to OK signal
     // Start listen to FAIL signal
     $failNotifyFilter = Streamwide_Engine_NotifyFilter_Factory::factory(Streamwide_Engine_NotifyFilter_Factory::T_EVT_SIG_PARAM_REMOTE, Streamwide_Engine_NotifyFilter_Factory::FILTER_EQUAL_TO, $this->_callLeg->getName());
     $controller->addEventListener(Streamwide_Engine_Events_Event::FAIL, array('callback' => array($this, 'onSignalReceived'), 'options' => array('autoRemove' => 'before', 'notifyFilter' => $failNotifyFilter)));
     // End listen to FAIL signal
     // Start listen to CHILD signal
     $childNotifyFilter = Streamwide_Engine_NotifyFilter_Factory::factory(Streamwide_Engine_NotifyFilter_Factory::T_EVT_SIG_PARAM_REMOTE, Streamwide_Engine_NotifyFilter_Factory::FILTER_EQUAL_TO, $this->_callLeg->getName());
     $controller->addEventListener(Streamwide_Engine_Events_Event::CHILD, array('callback' => array($this, 'onSignalReceived'), 'options' => array('notifyFilter' => $childNotifyFilter)));
     // Start listen to CHILD signal
 }
Exemple #4
0
 /**
  * Kills a call leg
  *
  * @param Streamwide_Engine_Call_Leg_Abstract $callLeg
  * @param boolean $force
  * @return boolean
  */
 public function kill(Streamwide_Engine_Call_Leg_Abstract $callLeg, $force = false)
 {
     if (false === $force && !$callLeg->isAlive()) {
         $this->dispatchErrorEvent(self::CALL_LEG_NOT_ALIVE_ERR_CODE);
         return false;
     }
     $callLegName = $callLeg->getName();
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::KILL, $callLegName);
     if (false === $signal->send()) {
         $this->dispatchErrorEvent(self::KILL_SIGNAL_SEND_FAILURE_ERR_CODE);
         return false;
     }
     $callLeg->setDead();
     $event = new Streamwide_Engine_Events_Event(Streamwide_Engine_Events_Event::SUCCESS);
     $event->setParam('callLeg', $callLeg);
     $this->dispatchEvent($event);
     return true;
 }
Exemple #5
0
 /**
  * Stop recording
  *
  * @return boolean
  */
 public function stop()
 {
     if (!$this->isRecording()) {
         $this->dispatchErrorEvent(self::NOT_RECORDING_ERR_CODE);
         return false;
     }
     if (null === $this->_mediaServerCallLeg) {
         throw new RuntimeException('Media server call leg has not been set');
     }
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::RECORDSTOP, $this->_mediaServerCallLeg->getName(), $this->_storage->toArray());
     if (false === $signal->send()) {
         $this->dispatchErrorEvent(self::RECORDSTOP_SIGNAL_SEND_FAILURE_ERR_CODE);
         return false;
     }
     $this->_recordingStopTime = time();
     $this->_stateManager->setState(self::STATE_READY);
     return $this->_delayRecorderStoppedEventDispatch();
 }
Exemple #6
0
 /**
  * Create the list of engine event listeners
  *
  * @param array $eventsList
  * @return array
  */
 protected function _createEngineEventListenersList(array $eventsList)
 {
     $list = array();
     for ($i = 0, $n = count($eventsList); $i < $n; $i++) {
         $event = $eventsList[$i];
         $eventName = $event['name'];
         $allowedSignalSource = $event['source'];
         $listenerPriority = $event['priority'];
         $notifyFilterFactoryName = Streamwide_Engine_NotifyFilter_Factory::T_EVT_SIG_PARAM_REMOTE;
         switch ($allowedSignalSource) {
             case self::SIG_SRC_LEFT:
                 $notifyFilterType = Streamwide_Engine_NotifyFilter_Factory::FILTER_EQUAL_TO;
                 $notifyFilterParams = $this->_leftCallLeg->getName();
                 break;
             case self::SIG_SRC_RIGHT:
                 $notifyFilterType = Streamwide_Engine_NotifyFilter_Factory::FILTER_EQUAL_TO;
                 $notifyFilterParams = $this->_rightCallLeg->getName();
                 break;
             default:
                 $notifyFilterType = Streamwide_Engine_NotifyFilter_Factory::FILTER_IN_ARRAY;
                 $notifyFilterParams = array(array($this->_leftCallLeg->getName(), $this->_rightCallLeg->getName()));
                 break;
         }
         $notifyFilter = Streamwide_Engine_NotifyFilter_Factory::factory($notifyFilterFactoryName, $notifyFilterType, $notifyFilterParams);
         $list[$eventName] = array('callback' => array($this, 'onSignalReceived'), 'options' => array('notifyFilter' => $notifyFilter, 'priority' => $listenerPriority));
     }
     return $list;
 }