Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
Archivo: Filter.php Proyecto: cwcw/cms
 /**
  * Send the filter settings to the engine for activation, deactivation or update
  *
  * @param boolean $activate
  */
 protected function _applyFilterSettings($activate = true)
 {
     $name = Streamwide_Engine_Signal::SET;
     $remote = $this->_mediaServerCallLeg->getName();
     $params = array();
     $params['name'] = $this->_getFilterFullName();
     $params['activate'] = 'false';
     if (true === $activate) {
         $params['activate'] = 'true';
         $params = array_merge($params, $this->_params);
     }
     $set = Streamwide_Engine_Signal::factory($name, $remote, $params);
     return $set->send();
 }
Ejemplo n.º 3
0
 /**
  * Send a RING signal to the SIP call leg
  *
  * @return void
  */
 protected function _sendRing()
 {
     // retrieve the OK signal from the event object
     $okSignal = $this->_event->getParam('signal');
     // get a reference to the SIP call leg
     $sipCallLeg = $this->_widget->getLeftCallLeg();
     // send the RING signal
     $ringSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::RING, $sipCallLeg->getName(), $okSignal->getParams());
     $ringSignal->send();
 }
Ejemplo n.º 4
0
 /**
  * Start receiving the fax
  *
  * @return void
  */
 protected function _faxReceive()
 {
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAXRECEIVE, $this->_msCallLeg->getName(), array('filename' => $this->_savePath));
     if (false === $signal->send()) {
         return $this->dispatchErrorEvent(self::FAXRECEIVE_SIGNAL_SEND_ERR_CODE);
     }
     $this->_subscribeToEngineEvents();
     return $this->dispatchEvent(new Streamwide_Engine_Events_Event(Streamwide_Engine_Events_Event::FAX_RECEIVING_STARTED));
 }
Ejemplo n.º 5
0
 /**
  * Handle a MOVED received from the call leg AFTER OKMOVED has been received in response to
  * the MOVED we sent to start the suspension process.
  *
  * @param Streamwide_Engine_Signal $signal
  * @return void
  */
 protected function _handleMovedSignal(Streamwide_Engine_Signal $signal)
 {
     $params = $signal->getParams();
     $okMovedSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::OKMOVED, $this->_callLeg->getName(), array('sdp' => $params['sdp']));
     if (false === $okMovedSignal->send()) {
         return $this->dispatchErrorEvent(self::OKMOVED_SIGNAL_SEND_ERR_CODE);
     }
 }
Ejemplo n.º 6
0
 /**
  * Perform the transfer
  *
  * @return boolean
  * @throws RuntimeException
  */
 public function transfer()
 {
     if (!isset($this->_options[self::OPT_TRANSFER_DESTINATION])) {
         throw new RuntimeException('Transfer destination has not been provided');
     }
     if (!$this->_sipCallLeg->isAlive()) {
         $this->dispatchErrorEvent(self::DEAD_CALL_LEG_ERR_CODE);
         return false;
     }
     if ($this->isTransferring()) {
         $this->dispatchErrorEvent(self::ALREADY_TRANSFERRING_ERR_CODE);
         return false;
     }
     $params = array('number' => $this->_options[self::OPT_TRANSFER_DESTINATION]);
     $headers = $this->_options[self::OPT_TRANSFER_HEADERS];
     if (!empty($headers)) {
         foreach ($headers as $name => $value) {
             $params[$name] = $value;
         }
     }
     $transferSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::TRANSFER, $this->_sipCallLeg->getName(), $params);
     if (false === $transferSignal->send()) {
         $this->dispatchErrorEvent(self::TRANSFER_SIGNAL_SEND_ERR_CODE);
         return false;
     }
     $this->_subscribeToEngineEvents();
     $this->_stateManager->setState(self::STATE_TRANSFERRING);
     return true;
 }
Ejemplo n.º 7
0
 /**
  * @see Engine/Call/Leg/Streamwide_Engine_Call_Leg_Connexant#connect()
  */
 public function connect()
 {
     $params = array();
     $params['name'] = $this->_rightCallLeg->getName();
     $params['proto'] = 'SIP';
     if (isset($this->_connectionParams['outgoingProtocol'])) {
         $params['proto'] = $this->_connectionParams['outgoingProtocol'];
     }
     $params['sdp'] = $this->_connectionParams['sdp'];
     $params['srcnum'] = $this->_connectionParams['sourceNumber'];
     $params['destnum'] = $this->_connectionParams['destinationNumber'];
     $params['ip'] = $this->_connectionParams['ip'];
     if (isset($this->_connectionParams['uri'])) {
         $params['uri'] = $this->_connectionParams['uri'];
     }
     $canAddExtraParams = isset($this->_connectionParams['sipExtraParams']) && is_array($this->_connectionParams['sipExtraParams']) && !empty($this->_connectionParams['sipExtraParams']);
     if ($canAddExtraParams) {
         foreach ($this->_connectionParams['sipExtraParams'] as $parameterName => $parameterValue) {
             $params[$parameterName] = $parameterValue;
         }
     }
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::CREATE, $this->_rightCallLeg->getName(), $params);
     if (false === $signal->send()) {
         $this->dispatchErrorEvent(self::CREATE_SIGNAL_SEND_ERR_CODE);
         return false;
     }
     $this->_subscribeToEngineEvents();
     return true;
 }
Ejemplo n.º 8
0
 /**
  * We have received CHILD signal from the MS call leg, we need to send
  * FAIL to the SIP call leg and dispatch an error event
  *
  * @param Streamwide_Engine_Signal $signal
  * @return void
  */
 protected function _handleChildSignal(Streamwide_Engine_Signal $signal)
 {
     $this->_unsubscribeFromEngineEvents();
     $remote = $signal->getRemote();
     if ($remote === $this->_leftCallLeg->getName()) {
         if ($this->_leftCallLeg->isAlive()) {
             $this->_leftCallLeg->setDead();
         }
         return $this->dispatchErrorEvent(self::CALL_LEG_DIED_ERR_CODE, array('callLeg' => $this->_leftCallLeg));
     }
     if ($remote === $this->_rightCallLeg->getName()) {
         $failSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAIL, $this->_leftCallLeg->getName());
         if (false === $failSignal->send()) {
             return $this->dispatchErrorEvent(self::FAIL_SIGNAL_SEND_ERR_CODE);
         }
         if ($this->_rightCallLeg->isAlive()) {
             $this->_rightCallLeg->setDead();
         }
         return $this->dispatchErrorEvent(self::CALL_LEG_DIED_ERR_CODE, array('callLeg' => $this->_rightCallLeg));
     }
 }
Ejemplo n.º 9
0
 protected function _handleFailMovedSignal(Streamwide_Engine_Signal $signal)
 {
     $remote = $signal->getRemote();
     $params = $signal->getParams();
     $failureCode = isset($params['code']) ? $params['code'] : null;
     if ($remote === $this->_leftCallLeg->getName()) {
         $this->_sipCallLegUpdateFailed = true;
         $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAILSDP, $this->_rightCallLeg->getName(), null !== $failureCode ? array('code' => $failureCode) : $failureCode);
         if (false === $signal->send()) {
             $this->_unsubscribeFromEngineEvents();
             $this->dispatchErrorEvent(self::FAILSDP_SIGNAL_SEND_ERR_CODE);
         }
         return;
     }
     if ($remote === $this->_rightCallLeg->getName()) {
         $this->_unsubscribeFromEngineEvents();
         $errorCode = self::MS_NOT_UPDATED_ERR_CODE;
         if ($this->_sipCallLegUpdateFailed) {
             $errorCode = self::SIP_NOT_UPDATED_ERR_CODE;
         }
         return $this->dispatchErrorEvent($errorCode, array('failureCode' => $failureCode, 'signal' => $signal));
     }
 }
Ejemplo n.º 10
0
 /**
  * @return void
  */
 protected function _killLeftCallLeg()
 {
     $shouldKillLeftCallLeg = $this->_options[self::OPT_KILL_LEFT_CALL_LEG];
     if ($shouldKillLeftCallLeg) {
         $killSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::KILL, $this->_leftCallLeg->getName());
         if ($killSignal->send()) {
             $this->_leftCallLeg->setDead();
         }
     }
 }
Ejemplo n.º 11
0
 public function stopRecognition()
 {
     $stop = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::STOP, $this->_asrCallLeg->getName());
     if (false === $stop->send()) {
         $this->dispatchErrorEvent(self::STOP_SIGNAL_SEND_FAILURE_ERR_CODE);
         return false;
     }
     $this->_unsubscribeFromEngineEvents();
     return true;
 }
Ejemplo n.º 12
0
 /**
  * We have received OKMOVED from the callee SIP call leg. We need to send
  * OKSDP to caller SIP call leg.
  *
  * @param Streamwide_Engine_Signal $signal
  * @return void
  */
 protected function _handleOkMovedSignal(Streamwide_Engine_Signal $signal)
 {
     $this->_okMovedReceived = true;
     $params = $signal->getParams();
     $okSdpSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::OKSDP, $this->_rightCallLeg->getName(), array('sdp' => $params['sdp']));
     if (false === $okSdpSignal->send()) {
         $this->_unsubscribeFromEngineEvents();
         return $this->dispatchErrorEvent(self::OKSDP_SIGNAL_SEND_ERR_CODE);
     }
 }
Ejemplo n.º 13
0
Archivo: Creator.php Proyecto: cwcw/cms
 /**
  * Initialize the creation process
  *
  * @param string $errorCode
  * @return boolean
  */
 public function create($errorCode)
 {
     $create = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::CREATE, $this->_callLeg->getName(), $this->_normalizeCreationParams());
     if (false === $create->send()) {
         $this->dispatchErrorEvent($errorCode);
         return false;
     }
     $this->_subscribeToEngineEvents();
     return true;
 }
Ejemplo n.º 14
0
Archivo: Player.php Proyecto: cwcw/cms
 /**
  * Go forward or backward in the play of the currently played media
  *
  * @param integer $amount
  * @param integer $direction Defaults to 1 (go forward)
  * @return boolean
  * @throws RuntimeException
  */
 public function goto($amount, $direction = 1)
 {
     if (!$this->isPlaying() && !$this->isPaused()) {
         $this->dispatchErrorEvent(self::NOT_PLAYING_OR_PAUSED_ERR_CODE);
         return false;
     }
     if (is_float($amount) || is_string($amount) && preg_match('~^[1-9][0-9]*$~', $amount) === 1) {
         $amount = (int) $amount;
     }
     if (!is_int($amount) || $amount < 1) {
         return false;
     }
     if (!is_int($direction)) {
         $direction = 1;
     }
     if ($direction > 0) {
         $gotoAmount = sprintf('+%d', $amount);
     } elseif ($direction < 0) {
         $gotoAmount = sprintf('-%d', $amount);
     } else {
         $gotoAmount = sprintf('%d', $amount);
     }
     if (null === $this->_mediaServerCallLeg) {
         throw new RuntimeException('Media server call leg has not been set');
     }
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::GOTO, $this->_mediaServerCallLeg->getName(), array('time' => $gotoAmount));
     // send the GOTO signal
     // if the sending of the signal failed dispatch an ERROR event
     if (false === $signal->send()) {
         $this->dispatchErrorEvent(Streamwide_Engine_Media_Player::GOTO_SIGNAL_SEND_FAILURE_ERR_CODE);
         return false;
     }
     return true;
 }
Ejemplo n.º 15
0
 protected function _handleFailMovedSignal(Streamwide_Engine_Signal $signal)
 {
     $this->_unsubscribeFromEngineEvents();
     if ($this->_sipCallLegCreationFailed) {
         if (!$this->_triggerErrorEventOnRemoteSipFailure) {
             return;
         }
         $errorCode = self::SIP_NOT_CREATED_ERR_CODE;
         $failureCode = $this->_sipCallLegCreationFailureCode;
     } else {
         $errorCode = self::MS_NOT_UPDATED_ERR_CODE;
         $params = $signal->getParams();
         $failureCode = isset($params['code']) ? $params['code'] : null;
         $killSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::KILL, $this->_leftCallLeg->getName());
         $killSignal->send();
     }
     $this->dispatchErrorEvent($errorCode, array('failureCode' => $failureCode, 'signal' => $signal));
 }
Ejemplo n.º 16
0
 /**
  * Send PROGRESS to the SIP call leg
  *
  * @return void
  */
 protected function _sendProgress()
 {
     // extract the OK signal parameters
     $okSignal = $this->_event->getParam('signal');
     $params = $okSignal->getParams();
     // get a reference to the SIP call leg
     $sipCallLeg = $this->_widget->getLeftCallLeg();
     // send the PROGRESS signal to the SIP call leg
     $progressSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::PROGRESS, $sipCallLeg->getName(), array('proto' => 'SIP', 'sdp' => $params['sdp']));
     $progressSignal->send();
 }
Ejemplo n.º 17
0
 /**
  * Send the SET signal to SW Engine to deactivate detection
  *
  * @param array|null $params
  * @return void
  */
 protected function _deactivateDetection(array $params = null)
 {
     $invariantParams = array('name' => $this->_detectorName, 'activate' => 'false');
     if (is_array($params) && !empty($params)) {
         $params = array_merge($invariantParams, $params);
     } else {
         $params = $invariantParams;
     }
     $setSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::SET, $this->_msCallLeg->getName(), $params);
     $setSignal->send();
 }
Ejemplo n.º 18
0
 /**
  * We have received FAILMOVED. If it came from SIP call leg we need to send a
  * FAILSDP to the MS call leg and dispatch an error event. If it came from MS call
  * leg the fax environment could not be created
  *
  * @param Streamwide_Engine_Signal $signal
  * @return void
  */
 protected function _handleFailMovedSignal(Streamwide_Engine_Signal $signal)
 {
     $this->_unsubscribeFromEngineEvents();
     $remote = $signal->getRemote();
     if ($remote === $this->_leftCallLeg->getName()) {
         $failSdpSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAILSDP, $this->_rightCallLeg->getName(), $signal->getParams());
         if (false === $failSdpSignal->send()) {
             $this->dispatchErrorEvent(self::FAILSDP_SIGNAL_SEND_ERR_CODE);
         }
         return null;
     }
     if ($remote === $this->_rightCallLeg->getName()) {
         return $this->dispatchErrorEvent(self::FAX_ENV_NOT_CREATED_ERR_CODE);
     }
 }
Ejemplo n.º 19
0
Archivo: Handler.php Proyecto: cwcw/cms
 /**
  * Callback. Called when the transfer has failed. Will notify the call leg that
  * emitted the TRANSFER and will attempt to reconnect the call legs.
  *
  * @param Streamwide_Engine_Events_Event $event
  * @return void
  */
 public function onTransferFailure(Streamwide_Engine_Events_Event $event)
 {
     $this->_connector->reset();
     $failTransfer = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAILTRANSFER, $this->_transferSource->getName());
     if (false === $failTransfer->send()) {
         $this->dispatchErrorEvent(self::FAILTRANSFER_SIGNAL_SEND_ERR_CODE);
         return;
     }
     $this->_revertTransfer();
 }
Ejemplo n.º 20
0
 /**
  * Update the RTPROXY call leg with the new sdp
  *
  * @param string $sdp
  * @param string $source The source of the sdp (one of the two values: left or right)
  * @return void
  */
 protected function _updateRtpProxyCallLeg($sdp, $source)
 {
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::RTPPROXY, $this->_rtpProxyCallLeg->getName(), array($source . 'sdp' => $sdp));
     $signal->send();
 }
Ejemplo n.º 21
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();
 }
Ejemplo n.º 22
0
 /**
  * During the reconnect process we can receive a MOVED from the right SIP call leg. If this occurs
  * before we received OKMOVED from the right SIP call leg we need to reply with a FAILMOVED.
  *
  * @param Streamwide_Engine_Signal $signal
  * @return void
  */
 protected function _handleMovedSignal(Streamwide_Engine_Signal $signal)
 {
     if ($this->_rightOkMovedReceived) {
         $this->_movedSignal = $signal;
     } else {
         $failMovedSignal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAILMOVED, $this->_rightCallLeg->getName(), array('code' => '491'));
         if (false === $failMovedSignal->send()) {
             $this->_unsubscribeFromEngineEvents();
             return $this->dispatchErrorEvent(self::FAILMOVED_SIGNAL_SEND_ERR_CODE);
         }
     }
 }
Ejemplo n.º 23
0
Archivo: Sender.php Proyecto: cwcw/cms
 /**
  * Send the FAXSEND signal
  *
  * @return void
  */
 protected function _faxSend()
 {
     $params = $this->_preparePages();
     if (empty($params)) {
         return $this->dispatchErrorEvent(self::FAX_PAGES_NOT_PROVIDED_ERR_CODE);
     }
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::FAXSEND, $this->_msCallLeg->getName(), $params);
     if (false === $signal->send()) {
         return $this->dispatchErrorEvent(self::FAXSEND_SIGNAL_SEND_ERR_CODE);
     }
     $this->dispatchEvent(new Streamwide_Engine_Events_Event(Streamwide_Engine_Events_Event::FAX_SENDING_STARTED));
     $this->_subscribeToEngineEvents();
 }
Ejemplo n.º 24
0
Archivo: Timeout.php Proyecto: cwcw/cms
 /**
  * Disarm the timer
  *
  * @return boolean
  */
 public function disarm()
 {
     if (!$this->isArmed()) {
         $this->dispatchErrorEvent(self::NOT_ARMED_ERR_CODE);
         return false;
     }
     $signal = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::DISARM, self::REMOTE_NAME, array('reference' => $this->_name));
     // send the DISARM signal
     $ret = $signal->send();
     // dispatch an ERROR event and exit if the signal could not be sent
     if (false === $ret) {
         $this->dispatchErrorEvent(self::DISARM_SIGNAL_SEND_FAILURE_ERR_CODE);
         return $ret;
     }
     // unsubscribe from the SIGNAL_IN_TIMEOUT event
     $this->_unsubscribeFromEngineEvents();
     // mark the timer as READY
     $this->_stateManager->setState(self::STATE_READY);
     // lower the flag so, that the next call to arm() will
     // generate a new name
     $this->_nameGenerated = false;
     // dispatch an TIMEOUT_TIMER_DISARMED event
     $this->dispatchEvent(new Streamwide_Engine_Events_Event(Streamwide_Engine_Events_Event::DISARMED));
     return $ret;
 }
Ejemplo n.º 25
0
 /**
  * Because we are sending 2 CREATE signals, we can receive two OK signals as response (if
  * everything is well). On OK received from the SIP call leg we send an OKSDP signal
  * to the MS call leg. On OK received from the MS call leg we dispatch the CONNECTED event
  *
  * @param Streamwide_Engine_Signal $signal
  * @return void
  */
 protected function _handleOkSignal(Streamwide_Engine_Signal $signal)
 {
     $remoteName = $signal->getRemote();
     $params = $signal->getParams();
     if ($remoteName === $this->_rightCallLeg->getName()) {
         // The OK came from the media server call leg
         $this->_rightCallLeg->setAlive();
         $this->_rightCallLeg->okSent();
         $this->_rightCallLeg->setParams($params);
         if ($this->_msNegotiationActive) {
             if ($this->_leftCallLeg->hasSentOrReceivedOk()) {
                 $params = $this->_leftCallLeg->getParams();
                 $moved = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::MOVED, $this->_rightCallLeg->getName(), array('sdp' => $params['sdp']));
                 if (false === $moved->send()) {
                     $this->_unsubscribeFromEngineEvents();
                     return $this->dispatchErrorEvent(self::MOVED_SIGNAL_SEND_ERR_CODE);
                 }
             }
             $event = new Streamwide_Engine_Events_Event(Streamwide_Engine_Events_Event::EARLY_MEDIA_NEGOTIATED);
             return $this->dispatchEvent($event);
         } else {
             $this->_unsubscribeFromEngineEvents();
             $event = new Streamwide_Engine_Events_Event(Streamwide_Engine_Events_Event::CONNECTED);
             $event->setParam('signal', $signal);
             if (null !== $this->_movedSignal) {
                 $event->setParam('moved', $this->_movedSignal);
             }
             return $this->dispatchEvent($event);
         }
     }
     if ($remoteName === $this->_leftCallLeg->getName()) {
         // The OK came from the sip call leg
         $this->_leftCallLeg->setAlive();
         $this->_leftCallLeg->okSent();
         $this->_leftCallLeg->setParams($params);
         if ($this->_msNegotiationActive) {
             if ($this->_rightCallLeg->hasSentOrReceivedOk()) {
                 $moved = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::MOVED, $this->_rightCallLeg->getName(), array('sdp' => $params['sdp']));
                 if (false === $moved->send()) {
                     $this->_unsubscribeFromEngineEvents();
                     return $this->dispatchErrorEvent(self::MOVED_SIGNAL_SEND_ERR_CODE);
                 }
             }
             return;
         } else {
             $okSdp = Streamwide_Engine_Signal::factory(Streamwide_Engine_Signal::OKSDP, $this->_rightCallLeg->getName(), array('sdp' => $params['sdp']));
             if (false === $okSdp->send()) {
                 $this->_unsubscribeFromEngineEvents();
                 return $this->dispatchErrorEvent(self::OKSDP_SIGNAL_SEND_ERR_CODE);
             }
         }
     }
 }