register() public method

Register
public register ( string $procedureName, callable $callback, array | mixed $options = null ) : Promise
$procedureName string
$callback callable
$options array | mixed
return React\Promise\Promise
Exemplo n.º 1
0
 /**
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     // TODO: now that the session has started, setup the stuff
     echo "--------------- Hello from InternalClient ------------\n";
     $session->register('com.example.getphpversion', [$this, 'getPhpVersion']);
     $session->register('com.example.getonline', [$this, 'getOnline']);
     $session->subscribe('wamp.metaevent.session.on_join', [$this, 'onSessionJoin']);
     $session->subscribe('wamp.metaevent.session.on_leave', [$this, 'onSessionLeave']);
 }
Exemplo n.º 2
0
 /**
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  * @throws \yii\base\InvalidConfigException
  */
 public function onSessionStart($session, $transport)
 {
     echo "--------------- Hello from InternalClient ------------" . PHP_EOL;
     try {
         $this->session = $session;
         $session->register('app.auth', [$this, 'onAuth']);
         $session->subscribe('wamp.metaevent.session.on_join', [$this, 'onSessionJoin']);
         $session->subscribe('wamp.metaevent.session.on_leave', [$this, 'onSessionLeave']);
         // todo регистрировать только после авторизации
         // инициализация методов
         foreach ($this->controllers as $controllerClass) {
             $controller = \Yii::createObject($controllerClass);
             if ($controller && $controller instanceof WampController) {
                 /** @var $controller WampController */
                 foreach ($controller->registers() as $callUri => $callOptions) {
                     if (is_array($callOptions) === false) {
                         $callOptions = [$callOptions];
                     }
                     if (is_numeric($callUri) || empty($callOptions[0])) {
                         // todo throw exception
                         continue;
                     }
                     $procedureName = $controller->getUri($callUri);
                     $callback = [$controller, '_call_' . $callOptions[0]];
                     unset($callOptions[0]);
                     $options = empty($callOptions) ? $callOptions : [];
                     //                        $this->getCallee()->register(
                     //                            $this->getSession(),
                     $session->register($procedureName, $callback, $options);
                 }
                 foreach ($controller->subscribes() as $subscribeUri => $subscribeOptions) {
                     if (is_array($subscribeOptions) === false) {
                         $subscribeOptions = [$subscribeOptions];
                     }
                     if (is_numeric($subscribeUri) || empty($subscribeOptions[0])) {
                         // todo throw exception
                         continue;
                     }
                     $topicName = $controller->getUri($subscribeUri);
                     $callback = [$controller, '_call_' . $subscribeOptions[0]];
                     unset($subscribeOptions[0]);
                     $options = empty($subscribeOptions) ? $subscribeOptions : [];
                     //                        $this->getSubscriber()->subscribe(
                     //                            $this->getSession(),
                     $session->subscribe($topicName, $callback, $options);
                 }
                 $this->_controllers[$controller->getId()] = $controller;
             }
         }
         foreach ($this->_controllers as $controller) {
             $controller->init();
         }
     } catch (\Exception $e) {
         echo Console::renderColoredString('%rError: %w' . (string) $e . '%n') . PHP_EOL;
     }
 }
Exemplo n.º 3
0
 /**
  * Handles session started
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportProviderInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $promises = [];
     $promises[] = $session->register('add_state_handler', [$this, "addStateHandler"]);
     $promises[] = $session->register('remove_state_handler', [$this, "removeStateHandler"]);
     $pAll = \React\Promise\all($promises);
     $pAll->then(function () {
         $this->setReady(true);
     }, function () {
         $this->setReady(false);
     });
 }
 /**
  * Handles session start
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportProviderInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register("thruway.auth.{$this->getMethodName()}.onhello", [$this, 'processHello'], ["replace_orphaned_session" => "yes"])->then(function () use($session) {
         $session->register("thruway.auth.{$this->getMethodName()}.onauthenticate", [$this, 'preProcessAuthenticate'], ["replace_orphaned_session" => "yes"])->then(function () use($session) {
             $registrations = new \stdClass();
             $registrations->onhello = "thruway.auth.{$this->getMethodName()}.onhello";
             $registrations->onauthenticate = "thruway.auth.{$this->getMethodName()}.onauthenticate";
             $session->call('thruway.auth.registermethod', [$this->getMethodName(), $registrations, $this->getAuthRealms()])->then(function ($args) {
                 Logger::debug($this, "Authentication Method Registration Successful: {$this->getMethodName()}");
             });
         });
     });
 }
Exemplo n.º 5
0
 /**
  * Handle on session start
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('com.example.add2', [$this, 'add2'])->then(function () use($session) {
         echo "Registered RPC\n";
         $session->call('com.example.add2', [2, 3])->then(function ($res) {
             echo "Got result: " . $res[0] . "\n";
             $this->setAttemptRetry(false);
             $this->session->shutdown();
         });
     });
 }
Exemplo n.º 6
0
 /**
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('add_command', [$this, 'addCommand']);
     $session->register('status', [$this, 'status']);
     $session->register('start_process', [$this, 'startProcess']);
     $session->register('stop_process', [$this, 'stopProcess']);
     $session->register('restart_process', [$this, 'restartProcess']);
     $session->register('add_instance', [$this, 'addInstance']);
     //Congestion Manager Client.  This needs to be a separate client because it needs to listen on the main realm and not `process_manager`.
     $config = $this->container->getParameter('voryx_thruway');
     $congestionManager = new Client($config['realm'], $session->getLoop());
     $congestionManager->addTransportProvider(new PawlTransportProvider($config['trusted_url']));
     $congestionManager->on('open', function (ClientSession $session) {
         $session->subscribe("thruway.metaevent.procedure.congestion", [$this, "onCongestion"]);
     });
     $congestionManager->start(false);
 }
Exemplo n.º 7
0
 /**
  * @param \Thruway\ClientSession $session ClientSession
  * @param \Thruway\Transport\TransportInterface $transport Transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->subscribe('wamp.metaevent.session.on_join', [$this, 'onJoin']);
     $session->subscribe('wamp.metaevent.session.on_leave', [$this, 'onLeave']);
     $session->register('server.get_user_sessions', [$this, 'getUserSession']);
 }
Exemplo n.º 8
0
 /**
  * Handle on session start
  * 
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('com.example.thefunction' . $this->number, [$this, 'theFunction'])->then(function () {
         $this->registeredDeferred->resolve();
     });
 }
Exemplo n.º 9
0
 /**
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('com.example.getfreespace', [$this, 'getFreeSpace']);
 }
Exemplo n.º 10
0
 /**
  * Handles session started
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportProviderInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('thruway.auth.registermethod', [$this, 'registerAuthMethod'], ['disclose_caller' => true])->then(function () {
         $this->setReady(true);
     }, function () {
         $this->setReady(false);
         Logger::error($this, "registration of registerAuthMethod failed.");
     });
 }
Exemplo n.º 11
0
 /**
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     // TODO: now that the session has started, setup the stuff
     echo "--------------- Hello from InternalClient ------------\n";
     $session->register('com.example.getphpversion', [$this, 'getPhpVersion']);
 }