Supabase.Realtime.Message
(supabase_realtime v0.5.0)
Copy Markdown
Message encoding and decoding for Supabase Realtime.
This module handles serialization and deserialization of the WebSocket messages exchanged with the Supabase Realtime service.
Summary
Functions
Constructs an access token update message.
Constructs a broadcast message.
Constructs a broadcast message with acknowledgment support.
Decodes a message received from the Supabase Realtime server.
Encodes a message for sending to the Supabase Realtime server.
Constructs a heartbeat message.
Constructs a presence tracking message.
Constructs a presence untrack message.
Constructs a subscription message for a channel.
Constructs an unsubscribe message for a channel.
Functions
@spec access_token_message(Supabase.Realtime.Channel.t(), String.t()) :: map()
Constructs an access token update message.
Parameters
channel- The channel structtoken- The new access token
Returns
map- Access token message payload
@spec broadcast_message(Supabase.Realtime.Channel.t(), String.t(), map()) :: map()
Constructs a broadcast message.
Parameters
channel- The channel structevent- The event namepayload- The message payload
Returns
map- Broadcast message payload
@spec broadcast_message_with_ack( Supabase.Realtime.Channel.t(), String.t(), map(), String.t() ) :: map()
Constructs a broadcast message with acknowledgment support.
Parameters
channel- The channel structevent- The event namepayload- The message payloadack_ref- The acknowledgment reference
Returns
map- Broadcast message payload with acknowledgment reference
Decodes a message received from the Supabase Realtime server.
Parameters
data- The raw message data
Returns
{:ok, map}- Decoded message{:error, term}- Error information
Examples
iex> Message.decode("{"topic":"realtime:public","event":"INSERT","payload":{},"ref":"1"}")
{:ok, %{"topic" => "realtime:public", "event" => "INSERT", "payload" => %{}, "ref" => "1"}}
@spec encode(Supabase.Realtime.realtime_message() | map()) :: {:ok, binary()} | {:error, term()}
Encodes a message for sending to the Supabase Realtime server.
Parameters
message- The message to encode
Returns
binary- JSON-encoded message
Examples
iex> Message.encode(%{topic: "realtime:public", event: "INSERT", payload: %{}, ref: "1"})
"{"topic":"realtime:public","event":"INSERT","payload":{},"ref":"1"}"
@spec heartbeat_message() :: map()
Constructs a heartbeat message.
Returns
map- Heartbeat message payload
@spec presence_track_message(Supabase.Realtime.Channel.t(), map()) :: map()
Constructs a presence tracking message.
Parameters
channel- The channel structpresence_state- The presence state to track
Returns
map- Presence track message payload
@spec presence_untrack_message(Supabase.Realtime.Channel.t()) :: map()
Constructs a presence untrack message.
Parameters
channel- The channel struct
Returns
map- Presence untrack message payload
@spec subscription_message(Supabase.Realtime.Channel.t()) :: map()
Constructs a subscription message for a channel.
Parameters
channel- The channel struct
Returns
map- Subscription message payload
@spec unsubscribe_message(Supabase.Realtime.Channel.t()) :: map()
Constructs an unsubscribe message for a channel.
Parameters
channel- The channel struct
Returns
map- Unsubscribe message payload