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

Copy Markdown View Source

Event state compositor for PUBLISH (RFC 3903). Equivalent to NkSIP's nksip_event_compositor.

defmodule MyCompositor do
  use Malla.Service,
    plugins: [Caracola.EventCompositor],
    sip: [listen: "sip:all:5060", events: "presence"],
    event_compositor: [default_expires: 60]
end

It answers PUBLISH requests (sip_publish/2, see request/1) for the events of the service (:events of the sip config), and adds PUBLISH to the Allow header. Each publication is stored for the AOR of the Request-URI with a new entity tag, returned in the SIP-ETag header (and the :sip_etag meta of Caracola.UAC.publish/3). PUBLISH requests with {:sip_if_match, etag} refresh (without body), modify (with body) or remove (with expires: 0) it; unknown tags get a 412.

Publications are found with find/3, and all the current ones of an AOR and event with list/3 (as Caracola.Presence does to compose the presence state).

Configuration

Under the :event_compositor key:

  • :default_expires - expiration without Expires (secs, default 60).

Storage

Publications are stored in memory. Services can use their own storage implementing sip_event_compositor_store(op, service), where op is {:get, aor, tag} (returns a Caracola.EventCompositor.Publication or :not_found), {:list, aor} (returns [{tag, publication}], without the expired ones), {:put, aor, tag, publication, ttl}, {:del, aor, tag} or :del_all (these return :ok).

Summary

Types

An address of record: scheme, user and domain.

Functions

Removes all the publications of a service.

Finds a publication by its AOR and entity tag.

The current publications of an AOR for an event (as "presence"), as {tag, publication}, the oldest first.

Processes a PUBLISH request, returning the reply. Called by the default sip_publish/2.

Types

aor()

@type aor() :: {Caracola.URI.scheme(), String.t() | nil, String.t()}

An address of record: scheme, user and domain.

Functions

clear(service)

@spec clear(module()) :: :ok

Removes all the publications of a service.

find(service, aor, tag)

@spec find(module(), aor(), String.t()) ::
  {:ok, Caracola.EventCompositor.Publication.t()} | :not_found

Finds a publication by its AOR and entity tag.

list(service, aor, event)

The current publications of an AOR for an event (as "presence"), as {tag, publication}, the oldest first.

request(req)

Processes a PUBLISH request, returning the reply. Called by the default sip_publish/2.