Skip to content

Commit

Permalink
Merge pull request #266 from d47081/ratchet-ws
Browse files Browse the repository at this point in the history
draft ratchet/ws server #261
  • Loading branch information
programarivm authored Feb 29, 2024
2 parents 12cf576 + 79db3fe commit cd9b02a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ JWT_SECRET=password
UID=1000
GID=1000

# wss.php
WSS_ADDRESS=0.0.0.0
WSS_PORT=8443

WSS_ALLOWED_SCHEME=https
WSS_ALLOWED_HOST=ui.chesslablab.org

# ws.php
WS_ADDRESS=0.0.0.0
WS_PORT=8085
37 changes: 37 additions & 0 deletions cli/ratchet/ws.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace ChessServer\Cli\Ratchet;

use ChessServer\Socket\RatchetClientStorage;
use ChessServer\Socket\RatchetWebSocket;
use Dotenv\Dotenv;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Ratchet\Http\HttpServer;
use Ratchet\Http\OriginCheck;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;

require __DIR__ . '/../../vendor/autoload.php';

$dotenv = Dotenv::createImmutable(__DIR__.'/../../');
$dotenv->load();

$logger = new Logger('log');
$logger->pushHandler(new StreamHandler(__DIR__.'/../../storage' . '/pchess.log', Logger::INFO));

$clientStorage = new RatchetClientStorage($logger);

$webSocket = (new RatchetWebSocket())->init($clientStorage);

$ioServer = IoServer::factory(
new HttpServer(
new WsServer(
$webSocket
)
),
$_ENV['WS_PORT'],
$_ENV['WS_ADDRESS']
);

$ioServer->run();

0 comments on commit cd9b02a

Please sign in to comment.