Merge branch 'master' of github.com:beyondcode/laravel-websockets
This commit is contained in:
commit
224845d6fd
|
|
@ -33,8 +33,6 @@ class ConfigClientProvider implements ClientProvider
|
||||||
return $this->instanciate($clientAttributes);
|
return $this->instanciate($clientAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected function allClients(): Collection
|
protected function allClients(): Collection
|
||||||
{
|
{
|
||||||
return collect(config('websockets.clients'));
|
return collect(config('websockets.clients'));
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ class StartWebSocketServer extends Command
|
||||||
app()->singleton(MessageLogger::class, function() {
|
app()->singleton(MessageLogger::class, function() {
|
||||||
return (new MessageLogger($this->output))
|
return (new MessageLogger($this->output))
|
||||||
->enable(config('app.debug'))
|
->enable(config('app.debug'))
|
||||||
//TODO: use real option
|
->verbose($this->output->isVerbose());
|
||||||
->verbose($this->hasOption('vvv'));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -42,8 +41,7 @@ class StartWebSocketServer extends Command
|
||||||
app()->bind(ConnectionLogger::class, function() {
|
app()->bind(ConnectionLogger::class, function() {
|
||||||
return (new ConnectionLogger($this->output))
|
return (new ConnectionLogger($this->output))
|
||||||
->enable(config('app.debug'))
|
->enable(config('app.debug'))
|
||||||
//TODO: use real option
|
->verbose($this->output->isVerbose());
|
||||||
->verbose($this->hasOption('vvv'));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Exceptions;
|
namespace BeyondCode\LaravelWebSockets\Exceptions;
|
||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class InvalidClient extends Exception
|
class InvalidClient extends Exception
|
||||||
|
|
@ -19,6 +18,6 @@ class InvalidClient extends Exception
|
||||||
|
|
||||||
public static function valueIsRequired($name, int $appId)
|
public static function valueIsRequired($name, int $appId)
|
||||||
{
|
{
|
||||||
return new static("{$name} is required but was empty for app id {$appId}");
|
return new static("{$name} is required but was empty for app id `{$appId}`.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,6 +18,10 @@ class SendMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
return (new PusherBroadcaster($pusher))
|
return (new PusherBroadcaster($pusher))
|
||||||
->broadcast([$request->channel], $request->event, json_decode($request->data, true));
|
->broadcast(
|
||||||
|
[$request->channel],
|
||||||
|
$request->event,
|
||||||
|
json_decode($request->data, true)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ class ShowDashboard
|
||||||
public function __invoke(Request $request, ClientProvider $clients)
|
public function __invoke(Request $request, ClientProvider $clients)
|
||||||
{
|
{
|
||||||
return view('websockets::dashboard', [
|
return view('websockets::dashboard', [
|
||||||
'clients' => $clients->all()
|
'clients' => $clients->all(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -40,8 +40,9 @@ abstract class EchoController implements HttpServerInterface
|
||||||
|
|
||||||
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
|
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
|
||||||
|
|
||||||
$this->verifyAppId($laravelRequest->appId);
|
$this
|
||||||
$this->verifySignature($laravelRequest);
|
->ensureValidAppId($laravelRequest->appId)
|
||||||
|
->ensureValidSignature($laravelRequest);
|
||||||
|
|
||||||
$response = $this($laravelRequest);
|
$response = $this($laravelRequest);
|
||||||
|
|
||||||
|
|
@ -66,21 +67,21 @@ abstract class EchoController implements HttpServerInterface
|
||||||
'error' => $exception->getMessage()
|
'error' => $exception->getMessage()
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$connection->send(gPsr\str($response));
|
$connection->send(Psr\str($response));
|
||||||
$connection->close();
|
$connection->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verifyAppId(string $appId)
|
public function ensureValidAppId(string $appId)
|
||||||
{
|
{
|
||||||
if ($client = Client::findByAppId($appId)) {
|
if (! $client = Client::findByAppId($appId)) {
|
||||||
return;
|
throw new HttpException(401, "Unknown app id `{$appId}` provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new HttpException(401, "Unknown app id `{$appId}` provided.");
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function verifySignature(Request $request)
|
protected function ensureValidSignature(Request $request)
|
||||||
{
|
{
|
||||||
$bodyMd5 = md5($request->getContent());
|
$bodyMd5 = md5($request->getContent());
|
||||||
|
|
||||||
|
|
@ -96,6 +97,8 @@ abstract class EchoController implements HttpServerInterface
|
||||||
if ($authSignature !== $request->get('auth_signature')) {
|
if ($authSignature !== $request->get('auth_signature')) {
|
||||||
throw new HttpException(401, 'Invalid auth signature provided.');
|
throw new HttpException(401, 'Invalid auth signature provided.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function __invoke(Request $request);
|
abstract public function __invoke(Request $request);
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,15 @@ class TriggerEvent extends EchoController
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$this->verifySignature($request);
|
$this->ensureValidSignature($request);
|
||||||
|
|
||||||
foreach ($request->json()->get('channels', []) as $channelId) {
|
foreach ($request->json()->get('channels', []) as $channelId) {
|
||||||
Dashboard::apiMessage($request->appId, $channelId, $request->json()->get('name'), $request->json()->get('data'));
|
Dashboard::apiMessage(
|
||||||
|
$request->appId,
|
||||||
|
$channelId,
|
||||||
|
$request->json()->get('name'),
|
||||||
|
$request->json()->get('data')
|
||||||
|
);
|
||||||
|
|
||||||
$channel = $this->channelManager->find($request->appId, $channelId);
|
$channel = $this->channelManager->find($request->appId, $channelId);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue