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