/** * @param CallMessage $msg * @param Registration $registration * @return static */ static function createMessageFrom(CallMessage $msg, Registration $registration) { $requestId = Session::getUniqueId(); $details = new \stdClass(); return new static($requestId, $registration->getId(), $details, $msg->getArguments(), $msg->getArgumentsKw()); }
/** * Process call * * @param \Thruway\Session $session * @param \Thruway\Message\CallMessage $msg * @return boolean */ private function processCall(Session $session, CallMessage $msg) { if (!Utils::uriIsValid($msg->getProcedureName())) { $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri')); return; } if (!isset($this->procedures[$msg->getProcedureName()])) { $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure')); return; } /* @var $procedure \Thruway\Procedure */ $procedure = $this->procedures[$msg->getProcedureName()]; $call = new Call($session, $msg, $procedure); $this->callInvocationIndex[$call->getInvocationRequestId()] = $call; $this->callRequestIndex[$msg->getRequestId()] = $call; $keepIndex = $procedure->processCall($session, $call); if (!$keepIndex) { $this->removeCall($call); } }
/** * @param Session $session * @param CallMessage $msg * @return bool */ private function processCall(Session $session, CallMessage $msg) { $registration = $this->getRegistrationByProcedureName($msg->getProcedureName()); if (!$registration) { $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg); $this->manager->error('No registration for call message: ' . $msg->getProcedureName()); $errorMsg->setErrorURI('wamp.error.no_such_registration'); $session->sendMessage($errorMsg); return false; } $invocationMessage = InvocationMessage::createMessageFrom($msg, $registration); if ($registration->getDiscloseCaller() === true && $session->getAuthenticationDetails()) { $details = ["caller" => $session->getSessionId(), "authid" => $session->getAuthenticationDetails()->getAuthId(), "authmethod" => $session->getAuthenticationDetails()->getAuthMethod()]; $invocationMessage->setDetails($details); } $call = new Call($msg, $session, $invocationMessage, $registration->getSession()); $this->calls->attach($call); $registration->getSession()->sendMessage($invocationMessage); }
public function testCallCancelCallInQueue() { $sessionMockBuilder = $this->getMockBuilder('\\Thruway\\Session')->setMethods(['sendMessage'])->disableOriginalConstructor(); $realm = new \Thruway\Realm('realm1'); /** @var Session $eeSession */ $eeSession = $sessionMockBuilder->getMock(); $eeSession->setRealm($realm); $eeSession->setHelloMessage($this->_helloMessage); $erSession = $sessionMockBuilder->getMock(); $erSession->setRealm($realm); $erSession->expects($this->exactly(1))->method('sendMessage')->withConsecutive([$this->callback(function (\Thruway\Message\ErrorMessage $msg) { $this->assertEquals("wamp.error.canceled", $msg->getErrorURI()); $this->assertObjectHasAttribute("_thruway_removed_from_queue", $msg->getDetails()); $this->assertTrue($msg->getDetails()->_thruway_removed_from_queue); return true; })]); $dealer = new \Thruway\Role\Dealer(); $registerMsg = new \Thruway\Message\RegisterMessage(1, (object) ["thruway_multiregister" => true], "cancel_queued_call_procedure"); $dealer->handleRegisterMessage(new \Thruway\Event\MessageEvent($eeSession, $registerMsg)); $callMessage = new \Thruway\Message\CallMessage(2, (object) [], 'cancel_queued_call_procedure'); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($erSession, $callMessage)); // this should get through to callee $callMessage->setRequestId(3); $dealer->handleCallMessage(new \Thruway\Event\MessageEvent($erSession, $callMessage)); // this should be in the queue now $cancelMessage = new \Thruway\Message\CancelMessage(3, (object) []); $dealer->handleCancelMessage(new \Thruway\Event\MessageEvent($erSession, $cancelMessage)); }