Skip to content

Commit

Permalink
Dispatch an event when channel created or removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirills-morozovs committed Aug 16, 2024
1 parent c57dc96 commit 6e16aa1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Events/ChannelCreated.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\Protocols\Pusher\Channels\Channel;

class ChannelCreated
{
use Dispatchable;

/**
* Create a new event instance.
*/
public function __construct(public Channel $channel)
{
//
}
}
19 changes: 19 additions & 0 deletions src/Events/ChannelRemoved.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\Protocols\Pusher\Channels\Channel;

class ChannelRemoved
{
use Dispatchable;

/**
* Create a new event instance.
*/
public function __construct(public Channel $channel)
{
//
}
}
6 changes: 6 additions & 0 deletions src/Protocols/Pusher/Managers/ArrayChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Laravel\Reverb\Concerns\InteractsWithApplications;
use Laravel\Reverb\Contracts\ApplicationProvider;
use Laravel\Reverb\Contracts\Connection;
use Laravel\Reverb\Events\ChannelCreated;
use Laravel\Reverb\Events\ChannelRemoved;
use Laravel\Reverb\Protocols\Pusher\Channels\Channel;
use Laravel\Reverb\Protocols\Pusher\Channels\ChannelBroker;
use Laravel\Reverb\Protocols\Pusher\Contracts\ChannelManager as ChannelManagerInterface;
Expand Down Expand Up @@ -76,6 +78,8 @@ public function findOrCreate(string $channelName): Channel

$this->applications[$this->application->id()][$channel->name()] = $channel;

ChannelCreated::dispatch($channel);

return $channel;
}

Expand Down Expand Up @@ -109,6 +113,8 @@ public function unsubscribeFromAll(Connection $connection): void
public function remove(Channel $channel): void
{
unset($this->applications[$this->application->id()][$channel->name()]);

ChannelRemoved::dispatch($channel);
}

/**
Expand Down

0 comments on commit 6e16aa1

Please sign in to comment.