Skip to content

Commit

Permalink
Flash client fix (#15)
Browse files Browse the repository at this point in the history
* Fixing flash socket configuration

* Make flash socket configurable externaly
  • Loading branch information
akadlec authored Apr 19, 2023
1 parent 1db1a3c commit 0bdcf4d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public function __construct(
* Run IO server
*
* @param React\Socket\SocketServer|null $socket
* @param React\Socket\SocketServer|null $flashSocket
*
* @return void
*/
public function create($socket = null): void
public function create($socket = null, $flashSocket = null): void
{
$client = $this->configuration->getAddress() . ':' . $this->configuration->getPort();

Expand All @@ -87,13 +88,6 @@ public function create($socket = null): void
if ($this->configuration->isSslEnabled()) {
$socket = new React\Socket\SecureServer($socket, $this->loop, $this->configuration->getSslConfiguration());
}

if ($this->configuration->getPort() === 80) {
$client = '0.0.0.0:843';

} else {
$client = $this->configuration->getAddress() . ':8843';
}
}

$socket->on('connection', function (React\Socket\ConnectionInterface $connection): void {
Expand All @@ -104,14 +98,24 @@ public function create($socket = null): void
$this->logger->error('Could not establish connection: ' . $ex->getMessage());
});

$flashSocket = new React\Socket\SocketServer($client, [], $this->loop);
if ($flashSocket === null) {
if ($this->configuration->getPort() === 80) {
$flashClient = '0.0.0.0:843';

} else {
$flashClient = $this->configuration->getAddress() . ':8843';
}

$flashSocket = new React\Socket\SocketServer($flashClient, [], $this->loop);
}

$flashSocket->on('connection', function (React\Socket\ConnectionInterface $connection): void {
$this->handlers->handleFlashConnect($connection);
});

$this->logger->debug('Starting IPub\WebSockets');
$this->logger->debug(sprintf('Launching WebSockets WS Server on: %s:%s', $this->configuration->getAddress(), $this->configuration->getPort()));
$flashSocket->on('error', function (Throwable $ex): void {
$this->logger->error('Could not establish connection: ' . $ex->getMessage());
});

$this->onCreate($this);
}
Expand All @@ -120,6 +124,9 @@ public function run(): void
{
$this->onStart($this->loop, $this);

$this->logger->debug('Starting IPub\WebSockets');
$this->logger->debug(sprintf('Launching WebSockets WS Server on: %s:%s', $this->configuration->getAddress(), $this->configuration->getPort()));

$this->loop->run();
}

Expand Down

0 comments on commit 0bdcf4d

Please sign in to comment.