replace channel id with channel name
This commit is contained in:
parent
81bbf83aa5
commit
84dad775e5
|
|
@ -28,18 +28,18 @@ class DashboardLogger
|
|||
]);
|
||||
}
|
||||
|
||||
public static function occupied(ConnectionInterface $connection, string $channelId)
|
||||
public static function occupied(ConnectionInterface $connection, string $channelName)
|
||||
{
|
||||
static::log($connection->client->appId, static::TYPE_OCCUPIED, [
|
||||
'details' => "Channel: {$channelId}",
|
||||
'details' => "Channel: {$channelName}",
|
||||
]);
|
||||
}
|
||||
|
||||
public static function subscribed(ConnectionInterface $connection, string $channelId)
|
||||
public static function subscribed(ConnectionInterface $connection, string $channelName)
|
||||
{
|
||||
static::log($connection->client->appId, static::TYPE_SUBSCRIBED, [
|
||||
'socketId' => $connection->socketId,
|
||||
'details' => "Channel: {$channelId}",
|
||||
'details' => "Channel: {$channelName}",
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -59,10 +59,10 @@ class DashboardLogger
|
|||
]);
|
||||
}
|
||||
|
||||
public static function vacated(ConnectionInterface $connection, string $channelId)
|
||||
public static function vacated(ConnectionInterface $connection, string $channelName)
|
||||
{
|
||||
static::log($connection->client->appId, static::TYPE_VACATED, [
|
||||
'details' => "Channel: {$channelId}",
|
||||
'details' => "Channel: {$channelName}",
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -76,13 +76,13 @@ class DashboardLogger
|
|||
|
||||
public static function log($appId, string $type, array $attributes = [])
|
||||
{
|
||||
$channelId = static::LOG_CHANNEL_PREFIX . $type;
|
||||
$channelName = static::LOG_CHANNEL_PREFIX . $type;
|
||||
|
||||
$channel = app(ChannelManager::class)->find($appId, $channelId);
|
||||
$channel = app(ChannelManager::class)->find($appId, $channelName);
|
||||
|
||||
optional($channel)->broadcast([
|
||||
'event' => 'log-message',
|
||||
'channel' => $channelId,
|
||||
'channel' => $channelName,
|
||||
'data' => [
|
||||
'type' => $type,
|
||||
'time' => strftime("%H:%M:%S")
|
||||
|
|
|
|||
|
|
@ -11,18 +11,18 @@ class TriggerEventController extends Controller
|
|||
{
|
||||
$this->ensureValidSignature($request);
|
||||
|
||||
foreach ($request->json()->get('channels', []) as $channelId) {
|
||||
$channel = $this->channelManager->find($request->appId, $channelId);
|
||||
foreach ($request->json()->get('channels', []) as $channelName) {
|
||||
$channel = $this->channelManager->find($request->appId, $channelName);
|
||||
|
||||
optional($channel)->broadcastToEveryoneExcept([
|
||||
'channel' => $channelId,
|
||||
'channel' => $channelName,
|
||||
'event' => $request->json()->get('name'),
|
||||
'data' => $request->json()->get('data'),
|
||||
], $request->json()->get('socket_id'));
|
||||
|
||||
DashboardLogger::apiMessage(
|
||||
$request->appId,
|
||||
$channelId,
|
||||
$channelName,
|
||||
$request->json()->get('name'),
|
||||
$request->json()->get('data')
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ use stdClass;
|
|||
class Channel
|
||||
{
|
||||
/** @var string */
|
||||
protected $channelId;
|
||||
protected $channelName;
|
||||
|
||||
/** @var \Ratchet\ConnectionInterface[] */
|
||||
protected $subscriptions = [];
|
||||
|
||||
public function __construct(string $channelId)
|
||||
public function __construct(string $channelName)
|
||||
{
|
||||
$this->channelId = $channelId;
|
||||
$this->channelId = $channelName;
|
||||
}
|
||||
|
||||
public function hasConnections(): bool
|
||||
|
|
|
|||
|
|
@ -12,29 +12,29 @@ class ChannelManager
|
|||
/** @var array */
|
||||
protected $channels = [];
|
||||
|
||||
public function findOrCreate(string $appId, string $channelId): Channel
|
||||
{
|
||||
if (!isset($this->channels[$appId][$channelId])) {
|
||||
$channelClass = $this->determineChannelClass($channelId);
|
||||
|
||||
$this->channels[$appId][$channelId] = new $channelClass($channelId);
|
||||
}
|
||||
public function findOrCreate(string $appId, string $channelName): Channel
|
||||
{
|
||||
if (!isset($this->channels[$appId][$channelName])) {
|
||||
$channelClass = $this->determineChannelClass($channelName);
|
||||
|
||||
return $this->channels[$appId][$channelId];
|
||||
$this->channels[$appId][$channelName] = new $channelClass($channelName);
|
||||
}
|
||||
|
||||
public function find(string $appId, string $channelId): ?Channel
|
||||
return $this->channels[$appId][$channelName];
|
||||
}
|
||||
|
||||
public function find(string $appId, string $channelName): ?Channel
|
||||
{
|
||||
return $this->channels[$appId][$channelId] ?? null;
|
||||
return $this->channels[$appId][$channelName] ?? null;
|
||||
}
|
||||
|
||||
protected function determineChannelClass(string $channelId): string
|
||||
protected function determineChannelClass(string $channelName): string
|
||||
{
|
||||
if (starts_with($channelId, 'private-')) {
|
||||
if (starts_with($channelName, 'private-')) {
|
||||
return PrivateChannel::class;
|
||||
}
|
||||
|
||||
if (starts_with($channelId, 'presence-')) {
|
||||
if (starts_with($channelName, 'presence-')) {
|
||||
return PresenceChannel::class;
|
||||
}
|
||||
|
||||
|
|
@ -62,8 +62,8 @@ class ChannelManager
|
|||
*/
|
||||
collect(array_get($this->channels, $connection->client->appId, []))
|
||||
->reject->hasConnections()
|
||||
->each(function (Channel $channel, string $channelId) use ($connection) {
|
||||
unset($this->channels[$connection->client->appId][$channelId]);
|
||||
->each(function (Channel $channel, string $channelName) use ($connection) {
|
||||
unset($this->channels[$connection->client->appId][$channelName]);
|
||||
});
|
||||
|
||||
if (count(array_get($this->channels, $connection->client->appId, [])) === 0) {
|
||||
|
|
|
|||
|
|
@ -76,9 +76,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
return $connection;
|
||||
}
|
||||
|
||||
protected function getChannel(ConnectionInterface $connection, string $channelId)
|
||||
protected function getChannel(ConnectionInterface $connection, string $channelName)
|
||||
{
|
||||
return $this->channelManager->findOrCreate($connection->client->appId, $channelId);
|
||||
return $this->channelManager->findOrCreate($connection->client->appId, $channelName);
|
||||
}
|
||||
|
||||
protected function markTestAsPassed()
|
||||
|
|
|
|||
Loading…
Reference in New Issue