Added subscribers filtering in topic broadcasting for taking into account exclude & eligible data

This commit is contained in:
Konstantin Burkalev 2014-02-09 00:44:05 +04:00
parent 3dc69de9d3
commit 0b5208507f
2 changed files with 21 additions and 3 deletions

View File

@ -32,10 +32,21 @@ class Topic implements \IteratorAggregate, \Countable {
/** /**
* Send a message to all the connections in this topic * Send a message to all the connections in this topic
* @param string $msg * @param string $msg
* @param array $exclude
* @param array $eligible
* @return Topic * @return Topic
*/ */
public function broadcast($msg) { public function broadcast($msg, array $exclude, array $eligible) {
$useEligible = count($eligible);
foreach ($this->subscribers as $client) { 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); $client->event($this->id, $msg);
} }
@ -85,4 +96,4 @@ class Topic implements \IteratorAggregate, \Countable {
public function count() { public function count() {
return $this->subscribers->count(); return $this->subscribers->count();
} }
} }

View File

@ -99,4 +99,11 @@ class WampConnection extends AbstractConnectionDecorator {
public function close($opt = null) { public function close($opt = null) {
$this->getConnection()->close($opt); $this->getConnection()->close($opt);
} }
}
/**
* Get session ID
*/
public function getSessionId() {
return $this->WAMP->sessionId;
}
}