Added subscribers filtering in topic broadcasting for taking into account exclude & eligible data
This commit is contained in:
parent
3dc69de9d3
commit
0b5208507f
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,4 +99,11 @@ class WampConnection extends AbstractConnectionDecorator {
|
||||
public function close($opt = null) {
|
||||
$this->getConnection()->close($opt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session ID
|
||||
*/
|
||||
public function getSessionId() {
|
||||
return $this->WAMP->sessionId;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user