From 86651938ee780e1a48d8ff0cb30a641a97553f1e Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 3 Dec 2018 21:06:49 +0100 Subject: [PATCH] wip --- src/Console/StartWebSocketServer.php | 18 ++++++++--------- .../Logger/HttpStatisticsLogger.php | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 94624f6..9c454ad 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -7,18 +7,15 @@ use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter; use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger; use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger; use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger; -use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebsocketStatisticsEntriesController; use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use GuzzleHttp\Client; -use GuzzleHttp\HandlerStack; +use Clue\React\Buzz\Browser; use Illuminate\Console\Command; use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory; use React\EventLoop\Factory as LoopFactory; -use WyriHaximus\React\GuzzlePsr7\HttpClientAdapter; class StartWebSocketServer extends Command { @@ -49,14 +46,15 @@ class StartWebSocketServer extends Command protected function configureStatisticsLogger() { - $handler = new HttpClientAdapter($this->loop); + $connector = new \React\Socket\Connector($this->loop, array( + 'dns' => '127.0.0.1' + )); - $client = new Client([ - 'handler' => HandlerStack::create($handler), - ]); + $browser = new Browser($this->loop, $connector); - app()->singleton(StatisticsLoggerInterface::class, function() use ($client) { - return new HttpStatisticsLogger(app(ChannelManager::class), $client); + + app()->singleton(StatisticsLoggerInterface::class, function() use ($browser) { + return new HttpStatisticsLogger(app(ChannelManager::class), $browser); }); $this->loop->addPeriodicTimer(5, function() { diff --git a/src/Statistics/Logger/HttpStatisticsLogger.php b/src/Statistics/Logger/HttpStatisticsLogger.php index 731b733..8bc7261 100644 --- a/src/Statistics/Logger/HttpStatisticsLogger.php +++ b/src/Statistics/Logger/HttpStatisticsLogger.php @@ -5,6 +5,7 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Logger; use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebsocketStatisticsEntriesController; use BeyondCode\LaravelWebSockets\Statistics\Statistic; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; +use Clue\React\Buzz\Browser; use GuzzleHttp\Client; use Ratchet\ConnectionInterface; @@ -16,11 +17,14 @@ class HttpStatisticsLogger implements StatisticsLogger /** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */ protected $channelManager; - public function __construct(ChannelManager $channelManager, Client $client) + /** @var Browser */ + protected $browser; + + public function __construct(ChannelManager $channelManager, Browser $browser) { $this->channelManager = $channelManager; - $this->client = $client; + $this->browser = $browser; } public function webSocketMessage(ConnectionInterface $connection) @@ -69,17 +73,17 @@ class HttpStatisticsLogger implements StatisticsLogger } echo 'posted'; - $this->client - ->postAsync( + $this->browser + ->post( action([WebsocketStatisticsEntriesController::class, 'store']), + [], $statistic->toArray() ) ->then(function() { echo 'fulfilled'; - }) - ->otherwise(function() { - echo 'rejected!'; - var_dump(func_get_args()); + }, function($e) { + echo 'fulfilled'; + dd($); }); // Reset connection and message count