create first working communication
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Mine\SeekerBundle\Topic;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface;
|
||||
use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
|
||||
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
|
||||
@@ -13,14 +14,23 @@ class AcmeTopic implements TopicInterface
|
||||
/** @var ClientManipulatorInterface */
|
||||
protected $clientManipulator;
|
||||
|
||||
/** @var EntityManager */
|
||||
protected $entityManager;
|
||||
|
||||
protected $red;
|
||||
|
||||
protected $blue;
|
||||
|
||||
/**
|
||||
* AcmeTopic constructor.
|
||||
*
|
||||
* @param $clientManipulator ClientManipulatorInterface
|
||||
* @param EntityManager $entityManager
|
||||
*/
|
||||
public function __construct(ClientManipulatorInterface $clientManipulator)
|
||||
public function __construct(ClientManipulatorInterface $clientManipulator, EntityManager $entityManager)
|
||||
{
|
||||
$this->clientManipulator = $clientManipulator;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,10 +45,24 @@ class AcmeTopic implements TopicInterface
|
||||
{
|
||||
/** this will broadcast the message to ALL subscribers of this topic. */
|
||||
$user = $this->clientManipulator->getClient($connection);
|
||||
dump($user);
|
||||
$userName = is_string($user) ? $user : $user->getUsername();
|
||||
|
||||
if ($topic->count() === 1) {
|
||||
$this->red = $userName;
|
||||
}
|
||||
|
||||
if ($topic->count() === 2) {
|
||||
$this->blue = $userName;
|
||||
}
|
||||
|
||||
$topic->broadcast([
|
||||
'msg' => $connection->resourceId . " has joined " . $topic->getId(),
|
||||
'user' => $this->getName()
|
||||
'userTopicId' => $connection->resourceId,
|
||||
'channel' => $topic->getId(),
|
||||
'user' => $userName,
|
||||
'color' => $userName === $this->red ? 'red' : 'blue',
|
||||
'red' => $this->red,
|
||||
'blue' => $this->blue,
|
||||
'userCnt' => $topic->count()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -53,8 +77,6 @@ class AcmeTopic implements TopicInterface
|
||||
public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||
{
|
||||
/** this will broadcast the message to ALL subscribers of this topic. */
|
||||
$user = $this->clientManipulator->getClient($connection);
|
||||
dump($user);
|
||||
$topic->broadcast(['msg' => $connection->resourceId . " has left " . $topic->getId()]);
|
||||
}
|
||||
|
||||
@@ -73,13 +95,18 @@ class AcmeTopic implements TopicInterface
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
$user = $this->clientManipulator->getClient($connection);
|
||||
$userName = is_string($user) ? $user : $user->getUsername();
|
||||
|
||||
$topic->broadcast([
|
||||
'msg' => $event
|
||||
'userTopicId' => $connection->resourceId,
|
||||
'channel' => $topic->getId(),
|
||||
'user' => $userName,
|
||||
'color' => $userName === $this->red ? 'red' : 'blue',
|
||||
'red' => $this->red,
|
||||
'blue' => $this->blue,
|
||||
'userCnt' => $topic->count(),
|
||||
'data' => $event
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user