PhoenixKit.Modules.Sync.ChannelClient (phoenix_kit v1.7.62)

Copy Markdown View Source

Client for communicating with the Sync channel from the Receiver's LiveView.

This module provides a simple interface for the Receiver to request data from the connected Sender through the channel.

Usage

# In Receiver LiveView, after sender connects:
# You receive {:sync, {:sender_joined, channel_pid}}

# Then request tables:
ref = ChannelClient.request_tables(channel_pid, self())
# Wait for {:sync_response, ref, {:ok, tables}} message

# Or use synchronous API:
{:ok, tables} = ChannelClient.fetch_tables(channel_pid)

Summary

Functions

Synchronously requests count and waits for response.

Synchronously requests records and waits for response.

Synchronously requests schema and waits for response.

Synchronously requests tables and waits for response.

Requests the record count for a specific table from the sender.

Requests paginated records from a specific table from the sender.

Requests the schema for a specific table from the sender.

Requests the list of available tables from the sender.

Functions

fetch_count(channel_pid, table)

@spec fetch_count(pid(), String.t()) :: {:ok, integer()} | {:error, any()}

Synchronously requests count and waits for response.

fetch_records(channel_pid, table, opts \\ [])

@spec fetch_records(pid(), String.t(), keyword()) :: {:ok, map()} | {:error, any()}

Synchronously requests records and waits for response.

fetch_schema(channel_pid, table)

@spec fetch_schema(pid(), String.t()) :: {:ok, map()} | {:error, any()}

Synchronously requests schema and waits for response.

fetch_tables(channel_pid)

@spec fetch_tables(pid()) :: {:ok, [map()]} | {:error, any()}

Synchronously requests tables and waits for response.

request_count(channel_pid, table, reply_to)

@spec request_count(pid(), String.t(), pid()) :: String.t()

Requests the record count for a specific table from the sender.

request_records(channel_pid, table, opts \\ [], reply_to)

@spec request_records(pid(), String.t(), keyword(), pid()) :: String.t()

Requests paginated records from a specific table from the sender.

Options

  • :offset - Starting offset (default: 0)
  • :limit - Maximum records to fetch (default: 100)

request_schema(channel_pid, table, reply_to)

@spec request_schema(pid(), String.t(), pid()) :: String.t()

Requests the schema for a specific table from the sender.

request_tables(channel_pid, reply_to)

@spec request_tables(pid(), pid()) :: String.t()

Requests the list of available tables from the sender.

Returns the request ref. Response will be sent as: {:sync_response, ref, {:ok, tables} | {:error, reason}}