Merge pull request #634 from beyondcode/fix/prevent-collecting-if-stats-disable
[fix] Prevent collecting stats if disabled
This commit is contained in:
commit
01e3b67280
|
|
@ -51,6 +51,13 @@ abstract class Controller implements HttpServerInterface
|
|||
*/
|
||||
protected $channelManager;
|
||||
|
||||
/**
|
||||
* The app attached with this request.
|
||||
*
|
||||
* @var \BeyondCode\LaravelWebSockets\Apps\App|null
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Initialize the request.
|
||||
*
|
||||
|
|
@ -176,8 +183,7 @@ abstract class Controller implements HttpServerInterface
|
|||
|
||||
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
|
||||
|
||||
$this
|
||||
->ensureValidAppId($laravelRequest->appId)
|
||||
$this->ensureValidAppId($laravelRequest->get('appId'))
|
||||
->ensureValidSignature($laravelRequest);
|
||||
|
||||
// Invoke the controller action
|
||||
|
|
@ -220,7 +226,7 @@ abstract class Controller implements HttpServerInterface
|
|||
*/
|
||||
public function ensureValidAppId($appId)
|
||||
{
|
||||
if (! App::findById($appId)) {
|
||||
if (! $appId || ! $this->app = App::findById($appId)) {
|
||||
throw new HttpException(401, "Unknown app id `{$appId}` provided.");
|
||||
}
|
||||
|
||||
|
|
@ -252,9 +258,7 @@ abstract class Controller implements HttpServerInterface
|
|||
|
||||
$signature = "{$request->getMethod()}\n/{$request->path()}\n".Pusher::array_implode('=', '&', $params);
|
||||
|
||||
$app = App::findById($request->get('appId'));
|
||||
|
||||
$authSignature = hash_hmac('sha256', $signature, $app->secret);
|
||||
$authSignature = hash_hmac('sha256', $signature, $this->app->secret);
|
||||
|
||||
if ($authSignature !== $request->get('auth_signature')) {
|
||||
throw new HttpException(401, 'Invalid auth signature provided.');
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ class TriggerEvent extends Controller
|
|||
$request->appId, $request->socket_id, $channelName, (object) $payload
|
||||
);
|
||||
|
||||
if ($this->app->statisticsEnabled) {
|
||||
StatisticsCollector::apiMessage($request->appId);
|
||||
}
|
||||
|
||||
DashboardLogger::log($request->appId, DashboardLogger::TYPE_API_MESSAGE, [
|
||||
'event' => $request->name,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,9 @@ class WebSocketHandler implements MessageComponentInterface
|
|||
/** @var \GuzzleHttp\Psr7\Request $request */
|
||||
$request = $connection->httpRequest;
|
||||
|
||||
if ($connection->app->statisticsEnabled) {
|
||||
StatisticsCollector::connection($connection->app->id);
|
||||
}
|
||||
|
||||
$this->channelManager->subscribeToApp($connection->app->id);
|
||||
|
||||
|
|
@ -88,7 +90,9 @@ class WebSocketHandler implements MessageComponentInterface
|
|||
$message, $connection, $this->channelManager
|
||||
)->respond();
|
||||
|
||||
if ($connection->app->statisticsEnabled) {
|
||||
StatisticsCollector::webSocketMessage($connection->app->id);
|
||||
}
|
||||
|
||||
WebSocketMessageReceived::dispatch(
|
||||
$connection->app->id,
|
||||
|
|
@ -109,7 +113,9 @@ class WebSocketHandler implements MessageComponentInterface
|
|||
->unsubscribeFromAllChannels($connection)
|
||||
->then(function (bool $unsubscribed) use ($connection) {
|
||||
if (isset($connection->app)) {
|
||||
if ($connection->app->statisticsEnabled) {
|
||||
StatisticsCollector::disconnection($connection->app->id);
|
||||
}
|
||||
|
||||
$this->channelManager->unsubscribeFromApp($connection->app->id);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue