This commit is contained in:
Marcel Pociot 2018-12-03 21:06:49 +01:00
parent 08035dd5d3
commit 86651938ee
2 changed files with 20 additions and 18 deletions

View File

@ -7,18 +7,15 @@ use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger; use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger; use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger; use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebsocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use GuzzleHttp\Client; use Clue\React\Buzz\Browser;
use GuzzleHttp\HandlerStack;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory; use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
use React\EventLoop\Factory as LoopFactory; use React\EventLoop\Factory as LoopFactory;
use WyriHaximus\React\GuzzlePsr7\HttpClientAdapter;
class StartWebSocketServer extends Command class StartWebSocketServer extends Command
{ {
@ -49,14 +46,15 @@ class StartWebSocketServer extends Command
protected function configureStatisticsLogger() protected function configureStatisticsLogger()
{ {
$handler = new HttpClientAdapter($this->loop); $connector = new \React\Socket\Connector($this->loop, array(
'dns' => '127.0.0.1'
));
$client = new Client([ $browser = new Browser($this->loop, $connector);
'handler' => HandlerStack::create($handler),
]);
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() { $this->loop->addPeriodicTimer(5, function() {

View File

@ -5,6 +5,7 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Logger;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebsocketStatisticsEntriesController; use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebsocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Statistic; use BeyondCode\LaravelWebSockets\Statistics\Statistic;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Clue\React\Buzz\Browser;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
@ -16,11 +17,14 @@ class HttpStatisticsLogger implements StatisticsLogger
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */ /** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
protected $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->channelManager = $channelManager;
$this->client = $client; $this->browser = $browser;
} }
public function webSocketMessage(ConnectionInterface $connection) public function webSocketMessage(ConnectionInterface $connection)
@ -69,17 +73,17 @@ class HttpStatisticsLogger implements StatisticsLogger
} }
echo 'posted'; echo 'posted';
$this->client $this->browser
->postAsync( ->post(
action([WebsocketStatisticsEntriesController::class, 'store']), action([WebsocketStatisticsEntriesController::class, 'store']),
[],
$statistic->toArray() $statistic->toArray()
) )
->then(function() { ->then(function() {
echo 'fulfilled'; echo 'fulfilled';
}) }, function($e) {
->otherwise(function() { echo 'fulfilled';
echo 'rejected!'; dd($);
var_dump(func_get_args());
}); });
// Reset connection and message count // Reset connection and message count