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\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() {

View File

@ -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