Hello I'm trying to integrate the bundle in my project to use the real time notification. I need to get logged user to get information related to this user. I followed step by step the all configuration in the bundle but when I try to get the user using $user = $this->clientManipulator->getClient($connection) every time the function get me the anonymous user.
Here is my configuration.
GOS Configuration:
gos_web_socket:
server:
port: "%clank_port%" #The port the socket server will listen on
host: "%clank_host%" #The host ip to bind to
router:
resources:
- @SomeBundle/Resources/config/pubsub/routing.yml
shared_config: false
topics:
- @some.topic_test_service
client:
firewall: backend_secure_area
session_handler: @session.handler.pdo
storage:
driver: @gos_web_socket.client_storage.driver.redis
decorator: @gos_web_socket.client_storage.doctrine.decorator
SNC Redis configuration
snc_redis:
clients:
ws_client:
type: predis
alias: client_storage.driver #snc_redis.client_storage.driver
dsn: redis://127.0.0.1/2
logging: %kernel.debug%
options:
profile: 2.2
connection_timeout: 10
read_write_timeout: 30
Doctrine Cache Configuration
doctrine_cache:
providers:
redis_cache:
redis:
host: 127.0.0.1
port: 6379
database: 3
websocket_cache_client:
type: redis
alias: gos_web_socket.client_storage.driver.redis
Session Handler configuration
pdo:
class: PDO
arguments:
dsn: mysql:host=%database_host2%;dbname=%database_name2%
user: %database_user2%
password: %database_password2%
calls:
- [ setAttribute, [3, 2] ] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: [@pdo, {lock_mode: 0}]
GOS client Store driver configuration
gos_web_scocket.client_storage.driver.predis:
class: Gos\Bundle\WebSocketBundle\Client\Driver\PredisDriver
arguments:
- @snc_redis.client_storage.driver_client
My service
some.topic_test_service:
class: Backend\SomeBundle\Topic\SomTopic
arguments: [ @gos_web_socket.websocket.client_manipulator, @some.service]
Routing Channel configuration
some_topic:
channel: some/channel
handler:
callback: 'backend.some'
Topic class with periodic call
class SomeTopic implements TopicInterface, TopicPeriodicTimerInterface
{
/**
* @var TopicPeriodicTimer
*/
protected $periodicTimer;
/**
* @var ClientManipulatorInterface
*/
protected $clientManipulator;
/**
* @var SomeService
*/
protected $SomeService;
private $i;
/**
*
* param [ mixed $args [, $... ]]
* @param ClientManipulatorInterface $clientManipulatorInterface
* @param SomeService $transactionService
* @param ContainerInterface $container
* @internal param TokenStorageInterface $token
* @link http://php.net/manual/en/language.oop5.decon.php
*/
function __construct(ClientManipulatorInterface $clientManipulatorInterface,
SomeService $someService)
{
$this->clientManipulator = $clientManipulatorInterface;
$this->someService = $someService;
$this->i = 0;
}
/**
* @param ConnectionInterface $connection
* @param Topic $topic
* @param WampRequest $request
*/
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
{
$user = $this->clientManipulator->getClient($connection);
$topic->broadcast("Hello World ".$user);
}
/**
* @param ConnectionInterface $connection
* @param Topic $topic
* @param WampRequest $request
*/
public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
{
//this will broadcast the message to ALL subscribers of this topic.
$topic->broadcast(['msg' => $connection->resourceId . " has left " . $topic->getId()]);
}
/**
* @param ConnectionInterface $connection
* @param Topic $topic
* @param WampRequest $request
* @param $event
* @param array $exclude
* @param array $eligible
*/
public function onPublish(ConnectionInterface $connection, Topic $topic, WampRequest $request, $event, array $exclude, array $eligible)
{
/*
$topic->getId() will contain the FULL requested uri, so you can proceed based on that
if ($topic->getId() == "acme/channel/shout")
//shout something to all subs.
*/
$topic->broadcast([
'msg' => $event
]);
}
/**
* @return string
*/
public function getName()
{
return "backend.some";
}
/**
* @param Topic $topic
*
* @return mixed
*/
public function registerPeriodicTimer(Topic $topic)
{
$this->periodicTimer->addPeriodicTimer($this, 'some', 10, function() use ($topic){
$topic->broadcast("Hello World ".$this->i++);
});
//exist
$this->periodicTimer->isPeriodicTimerActive($this, 'some'); // true or false
//remove
$this->periodicTimer->cancelPeriodicTimer($this, 'some');
}
/**
* @param TopicPeriodicTimer $periodicTimer
*/
public function setPeriodicTimer(TopicPeriodicTimer $periodicTimer)
{
$this->periodicTimer = $periodicTimer;
}
}
When the websocket send the information about the user all time the user is anon-210954636255afb7a3535fe598094366 and I'm logged with other user.
Any idea??