Skip to content

Commit

Permalink
resolve higher
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Nov 22, 2023
1 parent 27a59b2 commit 633161c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/Servers/Reverb/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class Controller
{
public function __construct(protected Server $server, protected ApplicationProvider $applications)
{
//
}

/**
* Invoke the Reverb WebSocket server.
*/
Expand All @@ -20,11 +25,10 @@ public function __invoke(RequestInterface $request, WsConnection $connection, st
return;
}

$server = app(Server::class);
$server->open($reverbConnection);
$this->server->open($reverbConnection);

$connection->on('message', fn (string $message) => $server->message($reverbConnection, $message));
$connection->on('close', fn () => $server->close($reverbConnection));
$connection->on('message', fn (string $message) => $this->server->message($reverbConnection, $message));
$connection->on('close', fn () => $this->server->close($reverbConnection));
}

/**
Expand All @@ -33,7 +37,7 @@ public function __invoke(RequestInterface $request, WsConnection $connection, st
protected function connection(RequestInterface $request, WsConnection $connection, string $key): ?ReverbConnection
{
try {
$application = app(ApplicationProvider::class)->findByKey($key);
$application = $this->applications->findByKey($key);
} catch (InvalidApplication $e) {
$connection->send('{"event":"pusher:error","data":"{\"code\":4001,\"message\":\"Application does not exist\"}"}');

Expand Down
4 changes: 3 additions & 1 deletion src/Servers/Reverb/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Reverb\Servers\Reverb;

use Laravel\Reverb\Contracts\ApplicationProvider;
use Laravel\Reverb\Http\Route;
use Laravel\Reverb\Http\Router;
use Laravel\Reverb\Http\Server as HttpServer;
Expand All @@ -11,6 +12,7 @@
use Laravel\Reverb\Pusher\Http\Controllers\EventsBatchController;
use Laravel\Reverb\Pusher\Http\Controllers\EventsController;
use Laravel\Reverb\Pusher\Http\Controllers\UsersTerminateController;
use Laravel\Reverb\Server;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\Socket\SocketServer;
Expand Down Expand Up @@ -39,7 +41,7 @@ protected static function routes(): RouteCollection
{
$routes = new RouteCollection;

$routes->add('sockets', Route::get('/app/{appKey}', new Controller));
$routes->add('sockets', Route::get('/app/{appKey}', new Controller(app(Server::class), app(ApplicationProvider::class))));
$routes->add('events', Route::post('/apps/{appId}/events', new EventsController));
$routes->add('events_batch', Route::post('/apps/{appId}/batch_events', new EventsBatchController));
$routes->add('channels', Route::get('/apps/{appId}/channels', new ChannelsController));
Expand Down

0 comments on commit 633161c

Please sign in to comment.