This commit is contained in:
freek 2018-12-03 23:52:39 +01:00
parent 5c93909f31
commit 6c96bb8edc
2 changed files with 11 additions and 9 deletions

View File

@ -57,7 +57,7 @@ class HttpStatisticsLogger implements StatisticsLogger
protected function findOrMakeStatisticForAppId($appId): Statistic
{
if (! isset($this->statistics[$appId])) {
if (!isset($this->statistics[$appId])) {
$this->statistics[$appId] = new Statistic($appId);
}
@ -68,23 +68,19 @@ class HttpStatisticsLogger implements StatisticsLogger
{
foreach ($this->statistics as $appId => $statistic) {
if (! $statistic->isEnabled()) {
if (!$statistic->isEnabled()) {
continue;
}
$this->browser
$this
->browser
->post(
action([WebSocketStatisticsEntriesController::class, 'store']),
['Content-Type' => 'application/json'],
stream_for(json_encode($statistic->toArray()))
);
// Reset connection and message count
$currentConnectionCount = collect($this->channelManager->getChannels($appId))
->sum(function ($channel) {
return count($channel->getSubscribedConnections());
});
$currentConnectionCount = $this->channelManager->getConnectionCount($appId);
$statistic->reset($currentConnectionCount);
}
}

View File

@ -46,6 +46,12 @@ class ChannelManager
return $this->channels[$appId] ?? [];
}
public function getConnectionCount(string $appId): int
{
return collect($this->getChannels($appId))
->sum->getSubscribedConnections();
}
public function removeFromAllChannels(ConnectionInterface $connection)
{
if (!isset($connection->app)) {