wip
This commit is contained in:
parent
ef0d45fb6f
commit
b698b95147
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Http\Controllers;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager;
|
||||
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\PresenceChannel;
|
||||
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\InvalidSignatureException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class FetchChannels extends EchoController
|
||||
{
|
||||
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */
|
||||
protected $channelManager;
|
||||
|
||||
public function __construct(ChannelManager $channelManager)
|
||||
{
|
||||
$this->channelManager = $channelManager;
|
||||
}
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$channels = Collection::make($this->channelManager->getChannels($request->appId))->filter(function ($channel) {
|
||||
return $channel instanceof PresenceChannel;
|
||||
});
|
||||
|
||||
if ($request->has('filter_by_prefix')) {
|
||||
$channels = $channels->filter(function ($channel, $channelName) use ($request) {
|
||||
return starts_with($channelName, $request->filter_by_prefix);
|
||||
});
|
||||
}
|
||||
|
||||
return [
|
||||
'channels' => $channels->map(function ($channel) {
|
||||
return [
|
||||
'user_count' => count($channel->getUsers()),
|
||||
];
|
||||
})->toArray()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,11 @@ class ChannelManager
|
|||
return Channel::class;
|
||||
}
|
||||
|
||||
public function getChannels(string $appId): array
|
||||
{
|
||||
return $this->channels[$appId] ?? [];
|
||||
}
|
||||
|
||||
public function removeFromAllChannels(ConnectionInterface $connection)
|
||||
{
|
||||
collect($this->channels[$connection->appId])->each->unsubscribe($connection);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class Router
|
|||
//TODO: add origin checker middleware
|
||||
$this->get('/app/{appKey}', LaravelEcho\WebSocket\PusherServer::class);
|
||||
|
||||
$this->get('/apps/{appId}/channels', LaravelEcho\Http\Controllers\StatusController::class);
|
||||
$this->get('/apps/{appId}/channels', LaravelEcho\Http\Controllers\FetchChannels::class);
|
||||
$this->get('/apps/{appId}/channels/{channelName}', LaravelEcho\Http\Controllers\FetchChannel::class);
|
||||
$this->get('/apps/{appId}/channels/{channelName}/users', LaravelEcho\Http\Controllers\FetchUsers::class);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue