A2UI.Server (A2UI v0.3.0)

Copy Markdown View Source

Starts an A2UI WebSocket server, embeddable in any OTP supervision tree.

Example

# In your application supervisor:
children = [
  {A2UI.Server,
   provider: MyApp.DashboardProvider,
   port: 4000}
]

Supervisor.start_link(children, strategy: :one_for_one)

Options

  • :provider (required) — module implementing A2UI.SurfaceProvider
  • :provider_opts — map passed to provider.init/1 (default: %{})
  • :port — HTTP port (default: 4000)
  • :ip — bind address (default: {127, 0, 0, 1})

All other options are forwarded to Bandit.

Push Updates

Use push_data/3 and push_surface/2 to broadcast updates to all connected clients from external processes (timers, PubSub, GenServer casts):

A2UI.Server.push_data("dashboard", %{"/uptime" => 42},
  provider: MyApp.DashboardProvider)

A2UI.Server.push_surface(updated_surface,
  provider: MyApp.DashboardProvider)

You can also pass registry: directly if you've already resolved it.

Summary

Functions

Sends an arbitrary message to all connected socket processes for the given surface.

Sends an arbitrary message to all connected socket processes for the provider, regardless of surface ID.

Returns a child specification for starting the A2UI server under a supervisor.

Broadcasts a data model update to all connected clients for the given surface.

Broadcasts a full surface update to all connected clients.

Starts the A2UI server linked to the current process.

Functions

broadcast(surface_id, message, opts)

@spec broadcast(String.t(), term(), keyword()) :: :ok

Sends an arbitrary message to all connected socket processes for the given surface.

Options

  • :provider — the provider module (resolves registry automatically)
  • :registry — the Registry name directly (use one or the other)

broadcast_all(message, opts)

@spec broadcast_all(
  term(),
  keyword()
) :: :ok

Sends an arbitrary message to all connected socket processes for the provider, regardless of surface ID.

Options

  • :provider — the provider module (resolves registry automatically)
  • :registry — the Registry name directly (use one or the other)

Examples

A2UI.Server.broadcast_all(:tick, provider: MyApp.Provider)

child_spec(opts)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child specification for starting the A2UI server under a supervisor.

push_data(surface_id, data, opts)

@spec push_data(String.t(), map(), keyword()) :: :ok

Broadcasts a data model update to all connected clients for the given surface.

Options

  • :provider — the provider module (resolves registry automatically)
  • :registry — the Registry name directly (use one or the other)

Examples

A2UI.Server.push_data("dashboard", %{"/uptime" => 42}, provider: MyApp.Provider)

push_surface(surface, opts)

@spec push_surface(
  A2UI.Surface.t(),
  keyword()
) :: :ok

Broadcasts a full surface update to all connected clients.

Options

  • :provider — the provider module (resolves registry automatically)
  • :registry — the Registry name directly (use one or the other)

Examples

A2UI.Server.push_surface(updated_surface, provider: MyApp.Provider)

start_link(opts)

@spec start_link(keyword()) :: {:ok, pid()} | {:error, term()}

Starts the A2UI server linked to the current process.

See child_spec/1 for available options.