Can not get session params in RPC

73 views Asked by At

I use https://github.com/JDare/ClankBundle for sockets. I try to get logged in user from session in RPC service:

namespace Example\Bundle\FrontendBundle\RPC;

use Ratchet\ConnectionInterface as Conn;
use Symfony\Component\HttpFoundation\Session\Session;

class Chat
{
    private $user;

    /**
     * @param Session $session
     */
    public function __construct(Session $session)
    {
        //...
    }

    public function someMethod(Conn $conn, $params)
    {
        //...
    }
}

Service config is:

example_frontend.chat_rpc:
    class: Example\Bundle\FrontendBundle\RPC\Chat
    arguments: ['@session']

Session is shared with memcached. (All required configurations are done) But when I connect to socket server and try to get something it seems like session is not started (also $_SESSION does not exist).

How can I fix it? Is RPC class right place to find something from session?

1

There are 1 answers

0
Sergei Gorjunov On

User's session is added to connection object (Ratchet\ConnectionInterface)

There is no special method for it. Just:

/** @var \Symfony\Component\HttpFoundation\Session\Session $session */
$session = $conn->Session;