From 0b5208507fab01e7e95753a5ae03dd4bb0df4969 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Sun, 9 Feb 2014 00:44:05 +0400 Subject: [PATCH] Added subscribers filtering in topic broadcasting for taking into account exclude & eligible data --- src/Ratchet/Wamp/Topic.php | 15 +++++++++++++-- src/Ratchet/Wamp/WampConnection.php | 9 ++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Ratchet/Wamp/Topic.php b/src/Ratchet/Wamp/Topic.php index 688195a..c2f7217 100644 --- a/src/Ratchet/Wamp/Topic.php +++ b/src/Ratchet/Wamp/Topic.php @@ -32,10 +32,21 @@ class Topic implements \IteratorAggregate, \Countable { /** * Send a message to all the connections in this topic * @param string $msg + * @param array $exclude + * @param array $eligible * @return Topic */ - public function broadcast($msg) { + public function broadcast($msg, array $exclude, array $eligible) { + $useEligible = count($eligible); foreach ($this->subscribers as $client) { + if(in_array($client->getSessionId(), $exclude)) { + continue; + } + + if($useEligible && !in_array($client->getSessionId(), $eligible)) { + continue; + } + $client->event($this->id, $msg); } @@ -85,4 +96,4 @@ class Topic implements \IteratorAggregate, \Countable { public function count() { return $this->subscribers->count(); } -} \ No newline at end of file +} diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index de13844..4004843 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -99,4 +99,11 @@ class WampConnection extends AbstractConnectionDecorator { public function close($opt = null) { $this->getConnection()->close($opt); } -} \ No newline at end of file + + /** + * Get session ID + */ + public function getSessionId() { + return $this->WAMP->sessionId; + } +}