Skip to content

Commit

Permalink
Added new events
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnabil230 committed Mar 12, 2024
1 parent b2cc479 commit e21536a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Events/WebSocketConnected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Laravel\Reverb\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Laravel\Reverb\Contracts\Connection;

class WebSocketConnected
{
use Dispatchable;

/**
* Create a new event instance.
*/
public function __construct(public Connection $connection)
{
//
}
}
19 changes: 19 additions & 0 deletions src/Events/WebSocketDisconnect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Laravel\Reverb\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Laravel\Reverb\Contracts\Connection;

class WebSocketDisconnect
{
use Dispatchable;

/**
* Create a new event instance.
*/
public function __construct(public Connection $connection)
{
//
}
}
6 changes: 6 additions & 0 deletions src/Protocols/Pusher/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Support\Str;
use Laravel\Reverb\Contracts\Connection;
use Laravel\Reverb\Events\MessageReceived;
use Laravel\Reverb\Events\WebSocketConnected;
use Laravel\Reverb\Events\WebSocketDisconnect;
use Laravel\Reverb\Loggers\Log;
use Laravel\Reverb\Protocols\Pusher\Contracts\ChannelManager;
use Laravel\Reverb\Protocols\Pusher\Exceptions\InvalidOrigin;
Expand Down Expand Up @@ -34,6 +36,8 @@ public function open(Connection $connection): void
$this->handler->handle($connection, 'pusher:connection_established');

Log::info('Connection Established', $connection->id());

WebSocketConnected::dispatch($connection);
} catch (Exception $e) {
$this->error($connection, $e);
}
Expand Down Expand Up @@ -81,6 +85,8 @@ public function close(Connection $connection): void

$connection->disconnect();

WebSocketDisconnect::dispatch($connection);

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

Expand Down

0 comments on commit e21536a

Please sign in to comment.