0

我正在研究内部客户端 + 身份验证模型的示例,如下所示。现在我需要检索已连接会话的列表并从内部客户端拦截会话的关闭事件。我想问是否有任何方法可以存档该任务?我正在考虑将该列表保存在 redis 中,但这意味着我必须重新编写Thruway\Peer\Router类,因为所需的变量现在是私有的,我们无法访问它们来扩展。

文件 server.php

    <?php
    /**
     * server.php
     */

    require "../bootstrap.php";
    require 'InternalClient.php';
    require 'SimpleAuthProviderClient.php';

    use Thruway\Peer\Router;
    use Thruway\Transport\RatchetTransportProvider;
    use React\EventLoop\Factory;
    use Thruway\Manager\ManagerClient;
    use Thruway\Transport\InternalClientTransportProvider;

    $manager = new ManagerClient();
    $loop = Factory::create();

    $router = new Router($loop, $manager);
    $router->addTransportProvider(new InternalClientTransportProvider($manager));

    $internalTransportProvider = new InternalClientTransportProvider(new \InternalClient());
    $router->addTransportProvider($internalTransportProvider);

    $authMgr = new \Thruway\Authentication\AuthenticationManager();

    $router->setAuthenticationManager($authMgr);
    $router->addTransportProvider(new InternalClientTransportProvider($authMgr));

    //Provide authentication for the realm: 'somerealm'
    $authProvClient = new SimpleAuthProviderClient(["somerealm"]);
    $router->addTransportProvider(new InternalClientTransportProvider($authProvClient));

    $transportProvider = new RatchetTransportProvider("127.0.0.1", 9090);
    $router->addTransportProvider($transportProvider);

    $router->start();

文件 SimpleAuthProviderClient.php

    <?php
    /**
     * SimpleAuthProviderClient.php
     */
    require "../bootstrap.php";

    /**
     * Class SimpleAuthProviderClient
     */
    class SimpleAuthProviderClient extends \Thruway\Authentication\AbstractAuthProviderClient
    {

        /**
         * @return string
         */
        public function getMethodName()
        {
            return 'simplysimple';
        }

        /**
         * @param mixed $signature
         * @param null $extra
         * @return array
         */
        public function processAuthenticate($signature, $extra = null)
        {
            if ($signature == "letMeIn") {
                return ["SUCCESS"];
            } else {
                return ["FAILURE"];
            }

        }

    }

文件 InternalClient.php

    <?php
    /**
     * InternalClient.php
     */
    require "../bootstrap.php";

    /**
     * Class InternalClient
     */
    class InternalClient extends Thruway\Peer\Client
    {

        function __construct()
        {
            parent::__construct("realm1");
        }

        /**
         * @param \Thruway\AbstractSession $session
         * @param \Thruway\Transport\TransportInterface $transport
         */
        public function onSessionStart($session, $transport)
        {
            echo "--------------- Hello from InternalClient ------------";
            $this->getCallee()->register($this->session, 'com.example.getphpversion', [$this, 'getPhpVersion']);
        }


        function start()
        {
        }

        /**
         * @return array
         */
        function getPhpVersion()
        {
            return [phpversion()];
        }
    }
4

1 回答 1

2

出于参考目的,这个问题在Github上得到了回答。

如果您订阅事件wamp.metaevent.session.on_joinwamp.metaevent.session.on_leave您将收到通知。该事件返回 1 个与此类似的参数:

{ "realm":"realm1", "authprovider":null, "authid":"username", "authrole":"none", "authmethod":"simplysimple", "session":6016528494456948 }

于 2014-10-07T14:18:00.420 回答