subscribe() public method

Subscribe
public subscribe ( string $topicName, callable $callback, $options = null ) : Promise
$topicName string
$callback callable
$options array
return React\Promise\Promise
Beispiel #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']);
 }
 /**
  * @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;
     }
 }
 /**
  *
  * @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);
 }
 /**
  * @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']);
 }