rename channel id to channel name

This commit is contained in:
freek 2018-12-01 12:41:58 +01:00
parent acaa7aa205
commit 8648a182b3
3 changed files with 17 additions and 17 deletions

View File

@ -18,7 +18,7 @@ class Channel
public function __construct(string $channelName)
{
$this->channelId = $channelName;
$this->channelName = $channelName;
}
public function hasConnections(): bool
@ -33,7 +33,7 @@ class Channel
protected function verifySignature(ConnectionInterface $connection, stdClass $payload)
{
$signature = "{$connection->socketId}:{$this->channelId}";
$signature = "{$connection->socketId}:{$this->channelName}";
if (isset($payload->channel_data)) {
$signature .= ":{$payload->channel_data}";
@ -53,7 +53,7 @@ class Channel
$connection->send(json_encode([
'event' => 'pusher_internal:subscription_succeeded',
'channel' => $this->channelId
'channel' => $this->channelName
]));
}
@ -62,7 +62,7 @@ class Channel
unset($this->subscriptions[$connection->socketId]);
if (! $this->hasConnections()) {
DashboardLogger::vacated($connection, $this->channelId);
DashboardLogger::vacated($connection, $this->channelName);
}
}
@ -73,10 +73,10 @@ class Channel
$this->subscriptions[$connection->socketId] = $connection;
if (! $hadConnectionsPreviously) {
DashboardLogger::occupied($connection, $this->channelId);
DashboardLogger::occupied($connection, $this->channelName);
}
DashboardLogger::subscribed($connection, $this->channelId);
DashboardLogger::subscribed($connection, $this->channelName);
}
public function broadcast($payload)

View File

@ -12,17 +12,17 @@ class ChannelManager
/** @var array */
protected $channels = [];
public function findOrCreate(string $appId, string $channelName): Channel
{
if (!isset($this->channels[$appId][$channelName])) {
$channelClass = $this->determineChannelClass($channelName);
public function findOrCreate(string $appId, string $channelName): Channel
{
if (!isset($this->channels[$appId][$channelName])) {
$channelClass = $this->determineChannelClass($channelName);
$this->channels[$appId][$channelName] = new $channelClass($channelName);
}
return $this->channels[$appId][$channelName];
$this->channels[$appId][$channelName] = new $channelClass($channelName);
}
return $this->channels[$appId][$channelName];
}
public function find(string $appId, string $channelName): ?Channel
{
return $this->channels[$appId][$channelName] ?? null;

View File

@ -29,13 +29,13 @@ class PresenceChannel extends Channel
// Send the success event
$connection->send(json_encode([
'event' => 'pusher_internal:subscription_succeeded',
'channel' => $this->channelId,
'channel' => $this->channelName,
'data' => json_encode($this->getChannelData())
]));
$this->broadcastToOthers($connection, [
'event' => 'pusher_internal:member_added',
'channel' => $this->channelId,
'channel' => $this->channelName,
'data' => json_encode($channelData)
]);
}
@ -46,7 +46,7 @@ class PresenceChannel extends Channel
$this->broadcastToOthers($connection, [
'event' => 'pusher_internal:member_removed',
'channel' => $this->channelId,
'channel' => $this->channelName,
'data' => json_encode([
'user_id' => $this->users[$connection->socketId]->user_id
])