Skip to content

Broadcast Channel

The BroadcastChannel component is used to listen to a channel on the Supabase Realtime service. It uses a svelte store to store and forward the data received from the channel to wrapped components.

This component must be a child of the SupabaseApp component to work.

Props

Prop nameTypeDefault valueDescription
channelNamestring'any'The name of the channel to listen to.
eventNamestring'sync'The name of the event to listen to.

Slots

PropertyTypeDescription
payloadRecord<string, any> | nullThe data payload received from the channel.
errorError | nullThe error object if there was an error receiving the payload.
realtimeRealtimeClientThe Supabase RealtimeClient instance.
channelRealtimeChannel | nullThe RealtimeChannel instance for the channel being listened to. This will be null if the channel has not been successfully subscribed to yet.

Usage

<script lang="ts">
import { BroadcastChannel } from 'supasveltekit';
</script>
<BroadcastChannel channelName="any" eventName="sync" let:payload let:error let:realtime let:channel>
{#if error !== null}
<div>{error.message}</div>
{/if}
{#if payload !== null}
<div>{JSON.stringify(payload)}</div>
{/if}
</BroadcastChannel>