Version: v2.5.3+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2019 License: Apache-2.0 Imports: 13 Imported by: 0



Package client provides an ari.Client implementation for a NATS-based ARI proxy cluster



View Source
const DefaultInputBufferLength = 100

DefaultInputBufferLength is the default size of the event buffer for events coming in from NATS

View Source
const DefaultRequestTimeout = 500 * time.Millisecond

DefaultRequestTimeout is the default timeout for a NATS request. (Note: Answer() takes longer than 250ms on average)


View Source
var ClosureGracePeriod = 10 * time.Second

ClosureGracePeriod is the amount of time to wait after the closure of the context to close the client. The delay here is important in order to allow wrap-up code to finish processing before losing connection to ARI. Depending on the characteristics of traffic and code, this value may need to be tweaked.

NOTE: It is always possible to call `Close()` on the client to close it immediately.

View Source
var DefaultClusterMaxAge = 5 * time.Minute

DefaultClusterMaxAge is the default maximum age for cluster members to be considered by this client

View Source
var ErrNil = errors.New("Nil")

ErrNil indicates that the request returned an empty response

View Source
var ListenQueue = "ARIProxyStasisStartDistributorQueue"

ListenQueue is the queue group to use for distributing StasisStart events to Listeners.

View Source
var Logger = log15.New()

Logger defaults to a discard handler (null output). If you wish to enable logging, you can set your own handler like so:



func ErrorToMap

func ErrorToMap(err error, parent string) map[string]interface{}

ErrorToMap converts an error type to a key-value map

func Listen

func Listen(ctx context.Context, ac ari.Client, h func(*ari.ChannelHandle, *ari.StasisStart)) error

Listen listens for StasisStart events, filtered by the given key. Any matching events will be sent down the returned StasisStart channel. The context which is passed to Listen can be used to stop the Listen execution.

Importantly, the StasisStart events are listened in a NATS Queue, which means that this may be used to deliver new calls to only a single handler out of a set of 1 or more handlers in a cluster.

func MapToError

func MapToError(i map[string]interface{}) error

MapToError converts a JSON parsed map to an error type


type Client

type Client struct {
	// contains filtered or unexported fields

Client provides an ari.Client for an ari-proxy server

func New

func New(ctx context.Context, opts ...OptionFunc) (*Client, error)

New creates a new Client to the Asterisk ARI NATS proxy.

func (*Client) Application

func (c *Client) Application() ari.Application

Application is the application operation accessor

func (*Client) ApplicationName

func (c *Client) ApplicationName() string

ApplicationName returns the ARI application's name

func (*Client) Asterisk

func (c *Client) Asterisk() ari.Asterisk

Asterisk is the asterisk operation accessor

func (*Client) Bridge

func (c *Client) Bridge() ari.Bridge

Bridge is the bridge operation accessor

func (*Client) Bus

func (c *Client) Bus() ari.Bus

Bus is the bus operation accessor

func (*Client) Channel

func (c *Client) Channel() ari.Channel

Channel is the channel operation accessor

func (Client) ClientClosed

func (c Client) ClientClosed()

clientClosed is called any time a derived ARI client is closed; if the reference counter is ever dropped to zero, the core is also shut down

func (*Client) Close

func (c *Client) Close()

Close shuts down the client

func (*Client) DeviceState

func (c *Client) DeviceState() ari.DeviceState

DeviceState is the device state operation accessor

func (*Client) Endpoint

func (c *Client) Endpoint() ari.Endpoint

Endpoint is the endpoint accessor

func (*Client) LiveRecording

func (c *Client) LiveRecording() ari.LiveRecording

LiveRecording is the live recording accessor

func (*Client) Mailbox

func (c *Client) Mailbox() ari.Mailbox

Mailbox is the mailbox accessor

func (*Client) New

func (c *Client) New(ctx context.Context) *Client

New returns a new client from the existing one. The new client will have a separate event bus and lifecycle, allowing the closure of all subscriptions and handles derived from the client by simply closing the client. The underlying NATS connection and cluster awareness (the common Core) will be preserved across derived Client lifecycles.

func (*Client) Playback

func (c *Client) Playback() ari.Playback

Playback is the media playback accessor

func (*Client) Sound

func (c *Client) Sound() ari.Sound

Sound is the sound accessor

func (Client) Start

func (c Client) Start() error

func (*Client) StoredRecording

func (c *Client) StoredRecording() ari.StoredRecording

StoredRecording is the stored recording accessor

func (*Client) TextMessage

func (c *Client) TextMessage() ari.TextMessage

TextMessage is the text message accessor

func (*Client) TimeoutCount

func (c *Client) TimeoutCount() int64

TimeoutCount is the amount of times the NATS communication times out

type OptionFunc

type OptionFunc func(*Client)

OptionFunc is a function which configures options on a Client

func FromClient

func FromClient(cl ari.Client) OptionFunc

FromClient configures the ARI Application to use the transport details from another ARI Client. Transport-related details are copied, such as the NATS Client, the NATS prefix, the timeout values.

Specifically NOT copied are dialog, application, and asterisk details.

NOTE: use of this function will cause NATS connection leakage if there is a mix of uses of FromClient and not over a period of time. If you intend to use FromClient, it is recommended that you always pass a NATS client in to the first ari.Client and maintain lifecycle control of it manually.

func WithApplication

func WithApplication(name string) OptionFunc

WithApplication configures the ARI Client to use the provided ARI Application

func WithLogHandler

func WithLogHandler(h log15.Handler) OptionFunc

WithLogHandler sets the logging handler on a Client logger

func WithLogger

func WithLogger(l log15.Logger) OptionFunc

WithLogger sets the logger on a Client.

func WithNATS

func WithNATS(nc *nats.EncodedConn) OptionFunc

WithNATS binds an existing NATS connection

func WithPrefix

func WithPrefix(prefix string) OptionFunc

WithPrefix configures the NATS Prefix to use on a Client

func WithTimeoutRetries

func WithTimeoutRetries(count int) OptionFunc

WithTimeoutRetries configures the amount of times to retry on request timeout for a Client

func WithURI

func WithURI(uri string) OptionFunc

WithURI sets the NATS URI to which the client will attempt to connect. The NATS URI may also be configured by the environment variable `NATS_URI`.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL