esdee/discoverer

Provides an actor-based DNS-SD discovery mechanism.

Types

A type for building the options for starting a discovery actor.

pub opaque type Builder

A handle to a service discovery actor.

pub opaque type Discoverer

The internal actor message type (required to be visible for naming the process).

pub opaque type Msg

A handle that can be used to unsubscribe from updates.

pub opaque type Subscription

Values

pub fn build(options: esdee.Options) -> Builder

Starts building a discoverer from the base options.

pub fn named(
  builder: Builder,
  name: process.Name(Msg),
) -> #(Builder, Discoverer)

Configures the builder to use a named process with the actor, and returns a discoverer instance that can be used across potential restarts.

pub fn poll_service_details(
  discoverer: Discoverer,
  service_type: String,
) -> Result(Nil, toss.Error)

Sends a DNS-SD question querying the given service type in the local network. If there are errors with the socket(s), returns the first error.

pub fn poll_service_types(
  discoverer: Discoverer,
) -> Result(Nil, toss.Error)

Sends a DNS-SD question querying all the available service types in the local network. If there are errors with the socket(s), returns the first error.

pub fn poll_timeout(builder: Builder, timeout: Int) -> Builder

Sets a timeout for the actor to respond to poll requests. Should be very fast, as no incoming data is waited for.

pub fn start(
  builder: Builder,
) -> Result(actor.Started(Discoverer), actor.StartError)

Starts a DNS-SD service discovery actor

pub fn start_timeout(builder: Builder, timeout: Int) -> Builder

Sets a timeout for the actor to start. Should be very fast, as no incoming data is waited for.

pub fn stop(discoverer: Discoverer) -> Nil

Stops the service discovery actor.

pub fn subscribe_to_service_details(
  discoverer: Discoverer,
  service_type: String,
  subject: process.Subject(esdee.ServiceDescription),
) -> Subscription

Subscribes the given subject to all discovered service details. You will also need to call poll_service_details to discover services quickly.

pub fn subscribe_to_service_details_mapping(
  discoverer: Discoverer,
  service_type: String,
  subject: process.Subject(a),
  mapper: fn(esdee.ServiceDescription) -> a,
) -> Subscription

Subscribes the given subject to all discovered service details, using the given function to map to another message type. You will also need to call poll_service_details to discover services quickly.

pub fn subscribe_to_service_types(
  discoverer: Discoverer,
  subject: process.Subject(String),
) -> Subscription

Subscribes the given subject to all discovered service types. Note that the same service type might be reported by multiple peers. You will also need to call poll_service_types to discover services quickly.

pub fn subscribe_to_service_types_mapping(
  discoverer: Discoverer,
  subject: process.Subject(a),
  mapper: fn(String) -> a,
) -> Subscription

Subscribes the given subject to all discovered service types, using the given function to map to another message type. Note that the same service type might be reported by multiple peers. You will also need to call poll_service_types to discover services quickly.

pub fn supervised(
  builder: Builder,
  on_start: option.Option(fn(Discoverer) -> Nil),
) -> supervision.ChildSpecification(Discoverer)

Returns a child specification for running the actor with supervision. If specified, the on_start function will be called after the actor starts or restarts.

pub fn unsubscribe(
  discoverer: Discoverer,
  subscription: Subscription,
) -> Nil

Terminates the given subscription.

Search Document