play

package
v4.0.0-pre0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const AllDTMF = "0123456789ABCD*#"

AllDTMF is a string which contains all possible DTMF digits.

Variables

View Source
var (
	// DefaultPlaybackStartTimeout is the default amount of time to wait for a playback to start before declaring that the playback has failed.
	DefaultPlaybackStartTimeout = 2 * time.Second

	// DefaultMaxPlaybackTime is the default maximum amount of time any playback is allowed to run.  If this time is exeeded, the playback will be cancelled.
	DefaultMaxPlaybackTime = 10 * time.Minute

	// DefaultFirstDigitTimeout is the default amount of time to wait, after the playback for all audio completes, for the first digit to be received.
	DefaultFirstDigitTimeout = 4 * time.Second

	// DefaultInterDigitTimeout is the maximum time to wait for additional
	// digits after the first is received.
	DefaultInterDigitTimeout = 3 * time.Second

	// DefaultOverallDigitTimeout is the default maximum time to wait for a
	// response, after the playback for all audio is complete, regardless of the
	// number of received digits or pattern matching.
	DefaultOverallDigitTimeout = 3 * time.Minute

	// DigitBufferSize is the number of digits stored in the received-digit
	// event buffer before further digit events are ignored.  NOTE that digits
	// overflowing this buffer are still stored in the digits received buffer.
	// This only affects the digit _signaling_ buffer.
	DigitBufferSize = 20
)
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:

ari.Logger.SetHandler(log15.StderrHandler)

Functions

func MatchAny

func MatchAny() func(*Options) error

MatchAny indicates that the playback should be considered Matched and terminated if any DTMF digit is received during the playback or post-playback time.

func MatchFunc

func MatchFunc(f func(string) (string, MatchResult)) func(*Options) error

MatchFunc uses the provided match function to determine when the playback should be terminated based on DTMF input.

func MatchHash

func MatchHash() func(*Options) error

MatchHash indicates that the playback should be considered Matched and terminated if it contains a hash (#). The hash (and any subsequent digits) is removed from the final result.

func MatchLen

func MatchLen(length int) func(*Options) error

MatchLen indicates that the playback should be considered Matched and terminated if the given number of DTMF digits are receieved.

func MatchLenOrTerminator

func MatchLenOrTerminator(length int, terminator string) func(*Options) error

MatchLenOrTerminator indicates that the playback should be considered Matched and terminated if the given number of DTMF digits are receieved or if the given terminator is received. If the terminator is present, it and any subsequent digits will be removed from the final result.

func MatchTerminator

func MatchTerminator(terminator string) func(*Options) error

MatchTerminator indicates that the playback shoiuld be considered Matched and terminated if it contains the provided Terminator string. The terminator (and any subsequent digits) is removed from the final result.

func PlaybackStartTimeout

func PlaybackStartTimeout(timeout time.Duration) func(*Options) error

PlaybackStartTimeout overrides the default playback start timeout

func Replays

func Replays(count int) func(*Options) error

Replays sets the number of replays of the audio sequence before exiting

func URI

func URI(uri ...string) func(*Options) error

URI adds a set of audio URIs to a playback

Types

type MatchResult

type MatchResult int

MatchResult indicates the status of a match for the received DTMF of a playback

const (
	// Incomplete indicates that there are not enough digits to determine a match
	Incomplete MatchResult = iota

	// Complete indicates that a match was found and the current DTMF pattern is complete
	Complete

	// Invalid indicates that a match cannot befound from the current DTMF received set
	Invalid
)

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options represent the various playback options which can modify the operation of a Playback.

func NewDefaultOptions

func NewDefaultOptions() *Options

NewDefaultOptions returns a set of options which represent reasonable defaults for most simple playbacks.

func NewPlay

func NewPlay(ctx context.Context, p ari.Player, opts ...func(*Options) error) (*Options, error)

NewPlay creates a new audio Options suitable for general audio playback

func NewPromptOptions

func NewPromptOptions() *Options

NewPromptOptions returns a set of options which represent reasonable defaults for most prompt playbacks.

func (*Options) ApplyOptions

func (o *Options) ApplyOptions(opts ...func(*Options) error) (err error)

ApplyOptions applies a set of options to the Playback

func (*Options) Done

func (o *Options) Done() <-chan struct{}

Done returns a channel which is closed when the playback exits

func (*Options) Play

func (o *Options) Play(ctx context.Context, p ari.Player) error

Play executes a playback with the existing options.

func (*Options) PlayAsync

func (o *Options) PlayAsync(ctx context.Context, p ari.Player) <-chan error

PlayAsync executes a playback, returning a channel which will be closed when the playback is ended

func (*Options) Stop

func (o *Options) Stop()

Stop terminates the execution of a playback

type Result

type Result struct {

	// Duration indicates how long the playback execution took, from start to finish
	Duration time.Duration

	// DTMF records any DTMF which was received by the playback, as modified by any match functions
	DTMF string

	// Error indicates any error encountered which caused the termination of the playback
	Error error

	// MatchResult indicates the final result of any applied match function for DTMF digits which were received
	MatchResult MatchResult

	// Status indicates the resulting status of the playback, why it was stopped
	Status Status
	// contains filtered or unexported fields
}

Result describes the result of a playback operation

func Play

func Play(ctx context.Context, p ari.Player, opts ...func(*Options) error) *Result

Play plays the given media URI

func (*Result) Err

func (r *Result) Err() error

Err returns any error found in the result

func (*Result) Result

func (r *Result) Result() (*Result, error)

Result returns the Result and the Error in a more standard form for consistency with other tools.

type Status

type Status int

Status indicates the final status of a playback, be it individual of an entire sequence. This Status indicates the reason the playback stopped.

const (
	// InProgress indicates that the audio is currently playing or is staged to play
	InProgress Status = iota

	// Cancelled indicates that the audio was cancelled.  This cancellation could be due
	// to anything from the control context being closed or a DTMF Match being found
	Cancelled

	// Failed indicates that the audio playback failed.  This indicates that one
	// or more of the audio playbacks failed to be played.  This could be due to
	// a system, network, or Asterisk error, but it could also be due to an
	// invalid audio URI.  Check the returned error for more details.
	Failed

	// Finished indicates that the playback completed playing all bound audio
	// URIs in full.  Note that for a prompt-style execution, this also means
	// that no DTMF was matched to the match function.
	Finished

	// Hangup indicates that the audio playback was interrupted due to a hangup.
	Hangup

	// Timeout indicates that audio playback timed out.  It is not known whether this was due to a failure in the playback, a network loss, or some other problem.
	Timeout
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL