github.com/CyCoreSystems/ari@v4.8.4+incompatible/ext/play/play.go (about)

     1  package play
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/CyCoreSystems/ari"
     7  )
     8  
     9  // AllDTMF is a string which contains all possible
    10  // DTMF digits.
    11  const AllDTMF = "0123456789ABCD*#"
    12  
    13  // NewPlay creates a new audio Options suitable for general audio playback
    14  func NewPlay(ctx context.Context, p ari.Player, opts ...OptionFunc) (*Options, error) {
    15  	o := NewDefaultOptions()
    16  	err := o.ApplyOptions(opts...)
    17  
    18  	return o, err
    19  }
    20  
    21  // NewPrompt creates a new audio Options suitable for prompt-style playback-and-get-response situations
    22  func NewPrompt(ctx context.Context, p ari.Player, opts ...OptionFunc) (*Options, error) {
    23  	o := NewPromptOptions()
    24  	err := o.ApplyOptions(opts...)
    25  
    26  	return o, err
    27  }
    28  
    29  // Play plays a set of media URIs.  Pass these URIs in with the `URI` OptionFunc.
    30  func Play(ctx context.Context, p ari.Player, opts ...OptionFunc) Session {
    31  	o, err := NewPlay(ctx, p, opts...)
    32  	if err != nil {
    33  		return errorSession(err)
    34  	}
    35  
    36  	return o.Play(ctx, p)
    37  }
    38  
    39  // Prompt plays the given media URIs and waits for a DTMF response.  The
    40  // received DTMF is available as `DTMF` in the Result object.  Further
    41  // customize the behaviour with Match type OptionFuncs.
    42  func Prompt(ctx context.Context, p ari.Player, opts ...OptionFunc) Session {
    43  	o, err := NewPrompt(ctx, p, opts...)
    44  	if err != nil {
    45  		return errorSession(err)
    46  	}
    47  
    48  	return o.Play(ctx, p)
    49  }
    50  
    51  // Play starts a new Play Session from the existing Options
    52  func (o *Options) Play(ctx context.Context, p ari.Player) Session {
    53  
    54  	s := newPlaySession(o)
    55  
    56  	go s.play(ctx, p)
    57  
    58  	return s
    59  }