# `NervesHubLink.Extensions`
[🔗](https://github.com/nerves-hub/nerves_hub_link/blob/v2.12.0/lib/nerves_hub_link/extensions/extensions.ex#L6)

Extensions are a mechanism for transmitting messages for non-critical
functionality over the existing NervesHub Socket. An extension will only
attach if the server-side requests it from the device to ensure it will not
disrupt regular operation.

This module provides a behaviour with a macro to use for implementing an
Extension.

Extensions are started as separate GenServers under a DynamicSupervisor and
any messages namespaced for a specific extension will be forwarded to that
extension's GenServer.

# `handle_event`

```elixir
@callback handle_event(String.t(), map(), state :: term()) ::
  {:noreply, new_state}
  | {:noreply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:stop, reason :: term(), new_state}
when new_state: term()
```

Invoked when routing an Extension event

Behaves the same as `c:GenServer.handle_info/2`

# `attach`

```elixir
@spec attach(String.t() | [String.t()] | :all) :: :ok
```

Attach specified extensions

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `detach`

```elixir
@spec detach(String.t() | [String.t()] | :all) :: :ok
```

Detach specified extensions

Also supports `:all` as an argument for cases NervesHubLink
may want to detach all of them at once

# `handle_event`

```elixir
@spec handle_event(String.t(), map()) :: :ok
```

# `list`

```elixir
@spec list() :: [
  %{
    required(String.t()) =&gt; %{
      attached?: boolean(),
      attach_ref: String.t(),
      module: module(),
      version: boolean()
    }
  }
]
```

List extensions currently available

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
