Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Nov 24, 2023
1 parent c2824c1 commit f213c38
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 69 deletions.
28 changes: 12 additions & 16 deletions src/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Support\Arr;
use Laravel\Reverb\Contracts\ChannelConnectionManager;
use Laravel\Reverb\Contracts\Connection;
use React\Promise\Promise;

class Channel
{
Expand Down Expand Up @@ -90,24 +89,21 @@ public function broadcast(array $payload, Connection $except = null): void
$chunks = array_chunk($this->connections(), 100);

foreach ($chunks as $connections) {
new Promise(function ($resolve, $reject) use ($connections, $message, $except) {
foreach ($connections as $connection) {
if ($except && $except->id() === $connection->connection()->id()) {
break;
}

if (isset($payload['except']) && $payload['except'] === $connection->connection()->id()) {
break;
}

try {
foreach ($connections as $connection) {
if ($except && $except->id() === $connection->connection()->id()) {
break;
}

if (isset($payload['except']) && $payload['except'] === $connection->connection()->id()) {
break;
}

$connection->send($message);
$resolve();
}
$connection->send($message);
} catch (Exception $e) {
$reject($e);
//
}
});
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/Contracts/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Laravel\Reverb\Contracts;

use Laravel\Reverb\Application;
use Laravel\Reverb\Output;
use Laravel\Reverb\Pusher\Event as PusherEvent;

abstract class Connection
{
Expand All @@ -27,7 +25,6 @@ public function __construct(
protected ?string $origin
) {
$this->lastSeenAt = time();
// $this->pusher = new PusherEvent;
}

/**
Expand Down Expand Up @@ -74,8 +71,6 @@ public function ping(): void
$this->hasBeenPinged = true;

// $this->pusher->ping($this);

// Output::info('Connection Pinged', $this->id());
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Jobs/PruneStaleConnections.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Laravel\Reverb\Contracts\ApplicationProvider;
use Laravel\Reverb\Contracts\ChannelManager;
use Laravel\Reverb\Output;

class PruneStaleConnections
{
Expand Down Expand Up @@ -33,7 +32,6 @@ public function handle(ChannelManager $channels): void
]));

$connection->disconnect();
// Output::info('Connection Pruned', $connection->id());
}
});
}
Expand Down
19 changes: 0 additions & 19 deletions src/Output.php

This file was deleted.

18 changes: 2 additions & 16 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function open(Connection $connection): void
$connection->touch();

$this->pusher->handle($connection, 'pusher:connection_established');

// Output::info('Connection Established', $connection->id());
} catch (Exception $e) {
$this->error($connection, $e);
}
Expand All @@ -40,11 +38,6 @@ public function open(Connection $connection): void
*/
public function message(Connection $from, string $message): void
{
// Output::info('Message Received', $from->id());
// Output::message($message);

$from->touch();

$event = json_decode($message, true);

try {
Expand All @@ -58,10 +51,11 @@ public function message(Connection $from, string $message): void
default => ClientEvent::handle($from, $event)
};

// Output::info('Message Handled', $from->id());
} catch (Exception $e) {
$this->error($from, $e);
}

$from->touch();
}

/**
Expand All @@ -74,8 +68,6 @@ public function close(Connection $connection): void
->unsubscribeFromAll($connection);

$connection->disconnect();

// Output::info('Connection Closed', $connection->id());
}

/**
Expand All @@ -86,9 +78,6 @@ public function error(Connection $connection, Exception $exception): void
if ($exception instanceof PusherException) {
$connection->send(json_encode($exception->payload()));

// Output::error('Message from '.$connection->id().' resulted in a pusher error');
// Output::info($exception->getMessage());

return;
}

Expand All @@ -99,9 +88,6 @@ public function error(Connection $connection, Exception $exception): void
'message' => 'Invalid message format',
]),
]));

// Output::error('Message from '.$connection->id().' resulted in an unknown error');
// Output::info($exception->getMessage());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Servers/ApiGateway/Jobs/SendToConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Config;
use Laravel\Reverb\Output;
use Throwable;

class SendToConnection implements ShouldQueue
Expand Down Expand Up @@ -37,8 +36,7 @@ public function handle(): void
'Data' => $this->message,
]);
} catch (Throwable $e) {
// Output::error('Unable to send message.');
// Output::info($e->getMessage());
//
}
}
}
5 changes: 1 addition & 4 deletions src/Servers/Reverb/Console/Commands/StartServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Laravel\Reverb\Concerns\InteractsWithAsyncRedis;
use Laravel\Reverb\Jobs\PingInactiveConnections;
use Laravel\Reverb\Jobs\PruneStaleConnections;
use Laravel\Reverb\Output;
use Laravel\Reverb\Servers\Reverb\Factory as ServerFactory;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
Expand Down Expand Up @@ -58,11 +57,9 @@ public function handle(): void
*/
protected function scheduleCleanup(LoopInterface $loop): void
{
$loop->addPeriodicTimer(60, function () {
// Output::info('Pruning Stale Connections');
$loop->addPeriodicTimer(300, function () {
PruneStaleConnections::dispatch();

// Output::info('Pinging Inactive Connections');
PingInactiveConnections::dispatch();
});
}
Expand Down
4 changes: 0 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Laravel\Reverb\Contracts\ChannelConnectionManager;
use Laravel\Reverb\Contracts\ChannelManager;
use Laravel\Reverb\Contracts\Logger;
use Laravel\Reverb\Contracts\ServerProvider;
use Laravel\Reverb\Loggers\NullLogger;

class ServiceProvider extends BaseServiceProvider
{
Expand Down Expand Up @@ -56,7 +54,5 @@ public function registerServer()
ChannelConnectionManager::class,
fn () => $server->buildChannelConnectionManager()
);

$this->app->instance(Logger::class, new NullLogger);
}
}

0 comments on commit f213c38

Please sign in to comment.