Documentation ¶
Overview ¶
Package client provides an ari.Client implementation for a NATS-based ARI proxy cluster
Index ¶
- Constants
- Variables
- func ErrorToMap(err error, parent string) map[string]interface{}
- func Listen(ctx context.Context, ac ari.Client, ...) error
- func MapToError(i map[string]interface{}) error
- type Client
- func (c *Client) Application() ari.Application
- func (c *Client) ApplicationName() string
- func (c *Client) Asterisk() ari.Asterisk
- func (c *Client) Bridge() ari.Bridge
- func (c *Client) Bus() ari.Bus
- func (c *Client) Channel() ari.Channel
- func (c Client) ClientClosed()
- func (c *Client) Close()
- func (c *Client) DeviceState() ari.DeviceState
- func (c *Client) Endpoint() ari.Endpoint
- func (c *Client) LiveRecording() ari.LiveRecording
- func (c *Client) Mailbox() ari.Mailbox
- func (c *Client) New(ctx context.Context) *Client
- func (c *Client) Playback() ari.Playback
- func (c *Client) Sound() ari.Sound
- func (c Client) Start() error
- func (c *Client) StoredRecording() ari.StoredRecording
- func (c *Client) TextMessage() ari.TextMessage
- func (c *Client) TimeoutCount() int64
- type OptionFunc
- func FromClient(cl ari.Client) OptionFunc
- func WithApplication(name string) OptionFunc
- func WithLogHandler(h log15.Handler) OptionFunc
- func WithLogger(l log15.Logger) OptionFunc
- func WithNATS(nc *nats.EncodedConn) OptionFunc
- func WithPrefix(prefix string) OptionFunc
- func WithTimeoutRetries(count int) OptionFunc
- func WithURI(uri string) OptionFunc
Constants ¶
const DefaultInputBufferLength = 100
DefaultInputBufferLength is the default size of the event buffer for events coming in from NATS
const DefaultRequestTimeout = 500 * time.Millisecond
DefaultRequestTimeout is the default timeout for a NATS request. (Note: Answer() takes longer than 250ms on average)
Variables ¶
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.
var DefaultClusterMaxAge = 5 * time.Minute
DefaultClusterMaxAge is the default maximum age for cluster members to be considered by this client
var ErrNil = errors.New("Nil")
ErrNil indicates that the request returned an empty response
var ListenQueue = "ARIProxyStasisStartDistributorQueue"
ListenQueue is the queue group to use for distributing StasisStart events to Listeners.
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:
ari.Logger.SetHandler(log15.StderrHandler)
Functions ¶
func ErrorToMap ¶
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 ¶
MapToError converts a JSON parsed map to an error type
Types ¶
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 ¶
ApplicationName returns the ARI application's name
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) DeviceState ¶
func (c *Client) DeviceState() ari.DeviceState
DeviceState is the device state operation accessor
func (*Client) LiveRecording ¶
func (c *Client) LiveRecording() ari.LiveRecording
LiveRecording is the live recording accessor
func (*Client) New ¶
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) 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 ¶
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`.