-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* increase payload size * validate events * wip * format cache channels * corrrectly get channel users * terminate with user id * formatting
- Loading branch information
Showing
15 changed files
with
253 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Pusher\Concerns; | ||
|
||
use Laravel\Reverb\Channels\CacheChannel; | ||
use Laravel\Reverb\Channels\Channel; | ||
use Laravel\Reverb\Channels\Concerns\InteractsWithPresenceChannels; | ||
use Laravel\Reverb\Contracts\ChannelManager; | ||
|
||
trait InteractsWithChannelInformation | ||
{ | ||
/** | ||
* Get the info for the given channels. | ||
*/ | ||
protected function infoForChannels(array $channels, string $info): array | ||
{ | ||
return collect($channels)->mapWithKeys(function ($channel) use ($info) { | ||
$name = $channel instanceof Channel ? $channel->name() : $channel; | ||
|
||
return [$name => $this->info($name, $info)]; | ||
})->all(); | ||
} | ||
|
||
/** | ||
* Get the info for the given channels. | ||
* | ||
* @param array<int, string> $channels | ||
* @return array<string, array<string, int>> | ||
*/ | ||
protected function info(string $channel, string $info): array | ||
{ | ||
$info = explode(',', $info); | ||
|
||
if (! $channel = app(ChannelManager::class)->find($channel)) { | ||
return []; | ||
} | ||
|
||
$count = count($channel->connections()); | ||
|
||
$info = [ | ||
'occupied' => in_array('occupied', $info) ? $count > 0 : null, | ||
'user_count' => in_array('user_count', $info) && $this->isPresenceChannel($channel) ? $count : null, | ||
'subscription_count' => in_array('subscription_count', $info) && ! $this->isPresenceChannel($channel) ? $count : null, | ||
'cache' => in_array('cache', $info) && $this->isCacheChannel($channel) ? $channel->cachedPayload() : null, | ||
]; | ||
|
||
return array_filter($info, fn ($item) => $item !== null); | ||
} | ||
|
||
/** | ||
* Determine if the channel is a presence channel. | ||
*/ | ||
protected function isPresenceChannel(Channel $channel): bool | ||
{ | ||
return in_array(InteractsWithPresenceChannels::class, class_uses($channel)); | ||
} | ||
|
||
/** | ||
* Determine if the channel is a cache channel. | ||
*/ | ||
protected function isCacheChannel(Channel $channel): bool | ||
{ | ||
return $channel instanceof CacheChannel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.