wip
This commit is contained in:
parent
54e2287646
commit
9a2183f642
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?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 FetchUsers extends EchoController
|
||||||
|
{
|
||||||
|
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */
|
||||||
|
protected $channelManager;
|
||||||
|
|
||||||
|
public function __construct(ChannelManager $channelManager)
|
||||||
|
{
|
||||||
|
$this->channelManager = $channelManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(Request $request)
|
||||||
|
{
|
||||||
|
$channel = $this->channelManager->find($request->appId, $request->channelName);
|
||||||
|
|
||||||
|
if (is_null($channel)) {
|
||||||
|
throw new HttpException(404, 'Unknown channel "'.$request->channelName.'"');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $channel instanceof PresenceChannel) {
|
||||||
|
throw new HttpException(400, 'Invalid presence channel "'.$request->channelName.'"');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'users' => Collection::make($channel->getUsers())->map(function ($user) {
|
||||||
|
return ['id' => $user->user_id];
|
||||||
|
})->values()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,11 @@ class PresenceChannel extends Channel
|
||||||
{
|
{
|
||||||
protected $users = [];
|
protected $users = [];
|
||||||
|
|
||||||
|
public function getUsers(): array
|
||||||
|
{
|
||||||
|
return $this->users;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @link https://pusher.com/docs/pusher_protocol#presence-channel-events
|
* @link https://pusher.com/docs/pusher_protocol#presence-channel-events
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class Router
|
||||||
$this->get('/apps/{appId}/status', LaravelEcho\Http\Controllers\StatusController::class);
|
$this->get('/apps/{appId}/status', LaravelEcho\Http\Controllers\StatusController::class);
|
||||||
$this->get('/apps/{appId}/channels', LaravelEcho\Http\Controllers\StatusController::class);
|
$this->get('/apps/{appId}/channels', LaravelEcho\Http\Controllers\StatusController::class);
|
||||||
$this->get('/apps/{appId}/channels/{channelName}', LaravelEcho\Http\Controllers\FetchChannel::class);
|
$this->get('/apps/{appId}/channels/{channelName}', LaravelEcho\Http\Controllers\FetchChannel::class);
|
||||||
$this->get('/apps/{appId}/channels/{channelName}/users', LaravelEcho\Http\Controllers\StatusController::class);
|
$this->get('/apps/{appId}/channels/{channelName}/users', LaravelEcho\Http\Controllers\FetchUsers::class);
|
||||||
|
|
||||||
$this->post('/apps/{appId}/events', LaravelEcho\Http\Controllers\TriggerEvent::class);
|
$this->post('/apps/{appId}/events', LaravelEcho\Http\Controllers\TriggerEvent::class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue