Services

ChannelServiceInterface

v1.0.0

Real-time channel interface for subscribing and publishing over the Meteorack WebSocket stack.

Access

$ctx->channel()?->subscribe('reports.updates', $handler);

How To Use It

  • Reach for this when a module needs live updates rather than request-time polling.
  • Check isConnected() before assuming the realtime transport is available, and keep unsubscribe callbacks so screens can clean up on teardown.

Methods

public function subscribe(string $channel, callable $handler): callable

Subscribes to a channel and returns an unsubscribe callable.

public function publish(string $channel, array $data): void

Publishes a server-side message to a channel.

public function isConnected(): bool

Reports whether the realtime transport is currently connected.

Example

bootstrap.php
public function announceRefresh(SdkContext $ctx): void
{
    if (! $ctx->channel()?->isConnected()) {
        return;
    }

    $ctx->channel()?->publish('reports.updates', [
        'event' => 'dashboard_refreshed',
        'module' => $this->getSlug(),
    ]);
}