# `Sippy.Registrar`
[🔗](https://pushin.eu/hermanverschooten/sippy/blob/v0.1.0/lib/sippy/registrar.ex#L1)

Keeps an extension registered with the PBX and reports its incoming calls.

Start it under a supervisor:

    children = [
      {Sippy.Registrar, config: Sippy.config(...), notify: MyApp.Phone}
    ]

or with `Sippy.register/2`. Options:

  * `:config` - `Sippy.Config` (required)
  * `:notify` - pid or registered name that receives the call messages
    (required)
  * `:name` - registers the registrar under this name

The `:notify` process receives:

  * `{:incoming_call, %Sippy.IncomingCall{}}` for a new call, after the
    registrar sent `100 Trying`
  * `{:incoming_call_cancelled, call_id}` when an unanswered call is
    cancelled by the caller, or rings for longer than the config's
    `:pending_call_timeout` and is ended with `480 Temporarily Unavailable`

An incoming call that is not answered can be rung with `Sippy.ring/1` or
turned down with `Sippy.reject/2`. A CANCEL for it is answered with
`200 OK` and ends the INVITE with `487 Request Terminated`. An offer
without PCMU or PCMA is rejected with `488 Not Acceptable Here`, and calls
beyond the config's `:max_pending_calls` with `486 Busy Here`; neither is
reported.

Retransmitted INVITEs and CANCELs are answered again but reported only
once, also for 32 seconds after the call was turned down, so a lost final
response does not show up as a new call. OPTIONS keepalives are answered
with `200 OK`.

The registrar keeps retrying a failed registration with a growing delay,
see the config's `:register_retry_interval`.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `registered?`

```elixir
@spec registered?(GenServer.server()) :: boolean()
```

Whether the PBX accepted the last REGISTER.

# `start_link`

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

Starts a registrar, see the module documentation for the options.

# `unregister`

```elixir
@spec unregister(GenServer.server()) :: :ok
```

Unregisters from the PBX and stops the registrar.

---

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