Merge branch 'master' of github.com:beyondcode/laravel-websockets
This commit is contained in:
commit
90b6998eaa
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace BeyondCode\LaravelWebSockets\Console;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
||||
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
|
||||
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
|
||||
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
|
||||
|
|
@ -17,9 +18,20 @@ class StartWebSocketServer extends Command
|
|||
|
||||
protected $description = 'Start the Laravel WebSocket Server';
|
||||
|
||||
/** @var \React\EventLoop\LoopInterface */
|
||||
protected $loop;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->loop = LoopFactory::create();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this
|
||||
->configureStatisticsLogger()
|
||||
->configureHttpLogger()
|
||||
->configureMessageLogger()
|
||||
->configureConnectionLogger()
|
||||
|
|
@ -60,6 +72,15 @@ class StartWebSocketServer extends Command
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function configureStatisticsLogger()
|
||||
{
|
||||
$this->loop->addPeriodicTimer(60, function() {
|
||||
StatisticsLogger::save();
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function registerEchoRoutes()
|
||||
{
|
||||
WebSocketsRouter::echo();
|
||||
|
|
@ -75,6 +96,7 @@ class StartWebSocketServer extends Command
|
|||
|
||||
/** 🛰 Start the server 🛰 */
|
||||
(new WebSocketServerFactory())
|
||||
->setLoop($this->loop)
|
||||
->useRoutes($routes)
|
||||
->setHost($this->option('host'))
|
||||
->setPort($this->option('port'))
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
|
||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TriggerEventController extends Controller
|
||||
|
|
@ -26,6 +27,8 @@ class TriggerEventController extends Controller
|
|||
$request->json()->get('name'),
|
||||
$request->json()->get('data')
|
||||
);
|
||||
|
||||
StatisticsLogger::apiMessage($request->appId);
|
||||
}
|
||||
|
||||
return $request->json()->all();
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ class Logger
|
|||
$this->statistics[$connection->app->id]->webSocketMessage();
|
||||
}
|
||||
|
||||
public function apiMessage(ConnectionInterface $connection)
|
||||
public function apiMessage($appId)
|
||||
{
|
||||
$this->initializeStatistics($connection->app->id);
|
||||
$this->initializeStatistics($appId);
|
||||
|
||||
$this->statistics[$connection->app->id]->apiMessage();
|
||||
$this->statistics[$appId]->apiMessage();
|
||||
}
|
||||
|
||||
public function connection(ConnectionInterface $connection)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ class WebSocketHandler implements MessageComponentInterface
|
|||
$message = PusherMessageFactory::createForMessage($message, $connection, $this->channelManager);
|
||||
|
||||
$message->respond();
|
||||
|
||||
StatisticsLogger::webSocketMessage($connection);
|
||||
}
|
||||
|
||||
public function onClose(ConnectionInterface $connection)
|
||||
|
|
@ -45,6 +47,8 @@ class WebSocketHandler implements MessageComponentInterface
|
|||
$this->channelManager->removeFromAllChannels($connection);
|
||||
|
||||
DashboardLogger::disconnection($connection);
|
||||
|
||||
StatisticsLogger::disconnection($connection);
|
||||
}
|
||||
|
||||
public function onError(ConnectionInterface $connection, Exception $exception)
|
||||
|
|
|
|||
Loading…
Reference in New Issue