Caracola.InfoPackages (Caracola v0.1.0-rc.1)

Copy Markdown View Source

INFO packages (RFC 6086): the INFO requests of a dialog carry the package they belong to (Info-Package), and each side says in the Recv-Info header of its INVITEs and their responses which packages it accepts.

defmodule MyUA do
  use Malla.Service,
    plugins: [Caracola.InfoPackages],
    sip: [listen: "sip:all:5060"],
    info_packages: ["dtmf"]

  defcb sip_info_package("dtmf", req, _call) do
    MyApp.dtmf(req.body)
    {:reply, :ok}
  end
end

Caracola.InfoPackages.send(dialog, "dtmf", "Signal=5\r\nDuration=160\r\n",
  content_type: "application/dtmf-relay")

The packages of :info_packages (the configuration of the plugin) are added to the :info_packages of the sip configuration, so the INVITEs of the service and the 1xx and 2xx responses to them carry a Recv-Info with them.

INFO requests with an Info-Package among them go to sip_info_package(package, req, call), which returns a reply as sip_info/2 (by default, it calls sip_info/2). INFOs for other packages are answered with 469 (Bad Info Package) and our Recv-Info. INFOs without Info-Package (legacy INFO, as most DTMF relays) go to sip_info/2 as usual.

send/4 sends an INFO of a package, if the remote side accepts it (it was in the Recv-Info of its last INVITE or response to ours), and remote_packages/1 returns the packages the remote side accepts.

Summary

Functions

The packages of the Recv-Info (or Info-Package) header of a message.

The packages the remote side of a dialog accepts: the Recv-Info of its last INVITE, or of its response to our last INVITE.

Sends an INFO of a package in a dialog, with a body and the Caracola.UAC options (as :content_type). Returns {:error, :bad_info_package} if the remote side does not accept it.

Functions

packages(msg, header \\ "recv-info")

@spec packages(Caracola.Message.t(), String.t()) :: [String.t()]

The packages of the Recv-Info (or Info-Package) header of a message.

iex> {:ok, req, ""} = Caracola.Parser.parse("INFO sip:a@h SIP/2.0\r\nVia: SIP/2.0/UDP h;branch=z9hG4bKa\r\nFrom: <sip:a@h>;tag=1\r\nTo: <sip:b@h>;tag=2\r\nCall-ID: c\r\nCSeq: 1 INFO\r\nRecv-Info: dtmf, Foo;x=1\r\n\r\n")
iex> Caracola.InfoPackages.packages(req)
["dtmf", "foo"]

remote_packages(dialog)

@spec remote_packages(Caracola.Dialog.handle()) :: [String.t()]

The packages the remote side of a dialog accepts: the Recv-Info of its last INVITE, or of its response to our last INVITE.

send(dialog, package, body, opts \\ [])

Sends an INFO of a package in a dialog, with a body and the Caracola.UAC options (as :content_type). Returns {:error, :bad_info_package} if the remote side does not accept it.