clientManipulator = $clientManipulator; $this->entityManager = $entityManager; } /** * This will receive any Subscription requests for this topic. * * @param ConnectionInterface $connection * @param Topic $topic * @param WampRequest $request * @return void */ public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request) { /** this will broadcast the message to ALL subscribers of this topic. */ $user = $this->clientManipulator->getClient($connection); $userName = is_string($user) ? $user : $user->getUsername(); $topic->broadcast([ 'userTopicId' => $connection->resourceId, 'channel' => $topic->getId(), 'user' => $userName, 'userCnt' => $topic->count() ]); } /** * This will receive any UnSubscription requests for this topic. * * @param ConnectionInterface $connection * @param Topic $topic * @param WampRequest $request * @return void */ 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()]); } /** * This will receive any Publish requests for this topic. * * @param ConnectionInterface $connection * @param Topic $topic * @param WampRequest $request * @param $event * @param array $exclude * @param array $eligible * @return mixed|void * @internal param Topic $Topic * @internal param array $eligibles */ public function onPublish(ConnectionInterface $connection, Topic $topic, WampRequest $request, $event, array $exclude, array $eligible) { $user = $this->clientManipulator->getClient($connection); $userName = is_string($user) ? $user : $user->getUsername(); $topic->broadcast([ 'userTopicId' => $connection->resourceId, 'channel' => $topic->getId(), 'user' => $userName, 'userCnt' => $topic->count(), 'data' => $event ]); } /** * Like RPC is will use to prefix the channel * @return string */ public function getName() { return 'acme.topic'; } }