Skip to content

Commit

Permalink
Dispatch event when connection is terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirRezaM75 committed Apr 13, 2024
1 parent 0b337be commit 786e180
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Laravel\Reverb\Concerns\GeneratesIdentifiers;
use Laravel\Reverb\Contracts\Connection as ConnectionContract;
use Laravel\Reverb\Events\ConnectionTerminated;
use Laravel\Reverb\Events\MessageSent;

class Connection extends ConnectionContract
Expand Down Expand Up @@ -56,5 +57,7 @@ public function send(string $message): void
public function terminate(): void
{
$this->connection->close();

ConnectionTerminated::dispatch($this);
}
}
19 changes: 19 additions & 0 deletions src/Events/ConnectionTerminated.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 ConnectionTerminated
{
use Dispatchable;

/**
* Create a new event instance.
*/
public function __construct(public Connection $connection)
{
//
}
}

0 comments on commit 786e180

Please sign in to comment.