Implemented writeAll and closeAll for groups
This commit is contained in:
parent
b0aede55b9
commit
ca84671f33
@ -61,8 +61,20 @@ class ConnectionGroup implements EventEmitterInterface, IteratorAggregate, Count
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(string $payload)
|
public function writeAll(string $payload)
|
||||||
{
|
{
|
||||||
|
foreach ($this->connections as $connection) {
|
||||||
|
if ($connection->isWritable()) {
|
||||||
|
$connection->write($payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function closeAll(string $reason, int $code=1001)
|
||||||
|
{
|
||||||
|
foreach ($this->connections as $connection) {
|
||||||
|
$connection->closeWithReason($reason, $code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -44,5 +44,11 @@ class GroupManager implements EventEmitterInterface
|
|||||||
return $group;
|
return $group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function closeAll(string $reason, int $code=1001)
|
||||||
|
{
|
||||||
|
foreach ($this->groups as $group) {
|
||||||
|
$group->closeAll($reason, $code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -252,8 +252,17 @@ class WebSocketConnection implements WebSocketInterface
|
|||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
|
// TODO send close
|
||||||
$this->outStream->close();
|
$this->outStream->close();
|
||||||
$this->inStream->close();
|
$this->inStream->close();
|
||||||
|
// TODO emit close event
|
||||||
|
}
|
||||||
|
|
||||||
|
public function closeWithReason(string $reason, int $code=1000)
|
||||||
|
{
|
||||||
|
// TODO send close
|
||||||
|
$payload = chr(($code >> 8) & 0xFF) . chr($code & 0xFF) . $reason;
|
||||||
|
$this->send(self::OP_CLOSE, $payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,4 +23,6 @@ interface WebSocketInterface extends ConnectionInterface
|
|||||||
|
|
||||||
public function getGroup(): ?ConnectionGroup;
|
public function getGroup(): ?ConnectionGroup;
|
||||||
|
|
||||||
|
public function closeWithReason(string $reason, int $code=1000);
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user