2018-11-22 21:09:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-11-27 15:42:19 +00:00
|
|
|
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
|
2018-11-22 21:09:32 +00:00
|
|
|
|
2020-03-04 09:58:39 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel;
|
2018-11-22 21:09:32 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
|
|
|
2018-11-27 20:15:29 +00:00
|
|
|
class FetchUsersController extends Controller
|
2018-11-22 21:09:32 +00:00
|
|
|
{
|
|
|
|
|
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.'"');
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 21:33:27 +00:00
|
|
|
return $channel
|
|
|
|
|
->getUsers($request->appId)
|
|
|
|
|
->then(function (array $users) {
|
|
|
|
|
return [
|
|
|
|
|
'users' => Collection::make($users)->map(function ($user) {
|
|
|
|
|
return ['id' => $user->user_id];
|
|
|
|
|
})->values(),
|
|
|
|
|
];
|
2019-03-29 19:33:46 +00:00
|
|
|
});
|
2018-11-22 21:09:32 +00:00
|
|
|
}
|
2018-12-04 21:22:33 +00:00
|
|
|
}
|