Services
ChannelServiceInterface
v1.0.0Real-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.
Works Well With
Methods
public function subscribe(string $channel, callable $handler): callableSubscribes to a channel and returns an unsubscribe callable.
public function publish(string $channel, array $data): voidPublishes a server-side message to a channel.
public function isConnected(): boolReports 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(),
]);
}