/** * process unregister * * @param \Thruway\ClientSession $session * @param string $Uri * @throws \Exception * @return \React\Promise\Promise|false */ public function unregister(ClientSession $session, $Uri) { // TODO: maybe add an option to wait for pending calls to finish $registration = null; foreach ($this->registrations as $k => $r) { if (isset($r['procedure_name'])) { if ($r['procedure_name'] == $Uri) { $registration =& $this->registrations[$k]; break; } } } if ($registration === null) { Logger::warning($this, "registration not found: " . $Uri); return false; } // we remove the callback from the client here // because we don't want the client to respond to any more calls $registration['callback'] = null; $futureResult = new Deferred(); if (!isset($registration["registration_id"])) { // this would happen if the registration was never acknowledged by the router // we should remove the registration and resolve any pending deferreds Logger::error($this, "Registration ID is not set while attempting to unregister " . $Uri); // reject the pending registration $registration['futureResult']->reject(); // TODO: need to figure out what to do in this off chance // We should still probably return a promise here that just rejects // there is an issue with the pending registration too that // the router may have a "REGISTERED" in transit and may still think that is // good to go - so maybe still send the unregister? } $requestId = Session::getUniqueId(); // save the request id so we can find this in the registration // list to call the deferred and remove it from the list $registration['unregister_request_id'] = $requestId; $registration['unregister_deferred'] = $futureResult; $unregisterMsg = new UnregisterMessage($requestId, $registration['registration_id']); $session->sendMessage($unregisterMsg); return $futureResult->promise(); }
/** * Handle process goodbye message * * @param \Thruway\ClientSession $session * @param \Thruway\Message\GoodbyeMessage $msg */ public function processGoodbye(ClientSession $session, GoodbyeMessage $msg) { if (!$session->isGoodbyeSent()) { $goodbyeMsg = new GoodbyeMessage(new \stdClass(), "wamp.error.goodbye_and_out"); $session->sendMessage($goodbyeMsg); $session->setGoodbyeSent(true); } }
/** * process publish * * @param \Thruway\ClientSession $session * @param string $topicName * @param mixed $arguments * @param mixed $argumentsKw * @param mixed $options * @return \React\Promise\Promise */ public function publish(ClientSession $session, $topicName, $arguments, $argumentsKw, $options) { $options = (object) $options; $requestId = Utils::getUniqueId(); if (isset($options->acknowledge) && $options->acknowledge === true) { $futureResult = new Deferred(); $this->publishRequests[$requestId] = ['future_result' => $futureResult]; } $publishMsg = new PublishMessage($requestId, $options, $topicName, $arguments, $argumentsKw); $session->sendMessage($publishMsg); return isset($futureResult) ? $futureResult->promise() : false; }
/** * process subscribe * * @param \Thruway\ClientSession $session * @param string $topicName * @param callable $callback * @param $options * @return Promise */ public function subscribe(ClientSession $session, $topicName, $callback, $options = null) { $requestId = Utils::getUniqueId(); $options = $options ? (object) $options : (object) []; $deferred = new Deferred(); $subscription = ["topic_name" => $topicName, "callback" => $callback, "request_id" => $requestId, "options" => $options, "deferred" => $deferred]; array_push($this->subscriptions, $subscription); $subscribeMsg = new SubscribeMessage($requestId, $options, $topicName); $session->sendMessage($subscribeMsg); return $deferred->promise(); }
/** * process call * * @param \Thruway\ClientSession $session * @param string $procedureName * @param mixed $arguments * @param mixed $argumentsKw * @param mixed $options * @return \React\Promise\Promise */ public function call(ClientSession $session, $procedureName, $arguments = null, $argumentsKw = null, $options = null) { //This promise gets resolved in Caller::processResult $futureResult = new Deferred(); $requestId = Session::getUniqueId(); $this->callRequests[$requestId] = ["procedure_name" => $procedureName, "future_result" => $futureResult]; if (!(is_array($options) && Message::isAssoc($options))) { if ($options !== null) { Logger::warning($this, "Options don't appear to be the correct type."); } $options = new \stdClass(); } $callMsg = new CallMessage($requestId, $options, $procedureName, $arguments, $argumentsKw); $session->sendMessage($callMsg); return $futureResult->promise(); }
/** * @param $topicName * @param $callback */ public function subscribe(ClientSession $session, $topicName, $callback) { $requestId = Session::getUniqueId(); $options = new \stdClass(); $subscription = ["topic_name" => $topicName, "callback" => $callback, "request_id" => $requestId, "options" => $options]; array_push($this->subscriptions, $subscription); $subscribeMsg = new SubscribeMessage($requestId, $options, $topicName); $session->sendMessage($subscribeMsg); }
/** * @param $procedureName * @param $arguments * @return \React\Promise\Promise */ public function call(ClientSession $session, $procedureName, $arguments = null, $argumentsKw = null) { //This promise gets resolved in Caller::processResult $futureResult = new Deferred(); $requestId = Session::getUniqueId(); $this->callRequests[$requestId] = ["procedure_name" => $procedureName, "future_result" => $futureResult]; $options = new \stdClass(); $callMsg = new CallMessage($requestId, $options, $procedureName, $arguments, $argumentsKw); $session->sendMessage($callMsg); return $futureResult->promise(); }