forked from CyCoreSystems/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playback.go
95 lines (79 loc) · 2.33 KB
/
playback.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package ari
// Playback represents a communication path for interacting
// with an Asterisk server for playback resources
type Playback interface {
// Get gets the handle to the given playbacl ID
Get(id string) *PlaybackHandle
// Data gets the playback data
Data(id string) (PlaybackData, error)
// Control performs the given operation on the current playback
Control(id string, op string) error
// Stop stops the playback
Stop(id string) error
// Subscribe subscribes on the playback events
Subscribe(id string, n ...string) Subscription
}
// Playbacker contains a playback transport
type Playbacker interface {
Playback() Playback
}
// PlaybackData represents the state of a playback
type PlaybackData struct {
ID string `json:"id"` // Unique ID for this playback session
Language string `json:"language,omitempty"`
MediaURI string `json:"media_uri"` // URI for the media which is to be played
State string `json:"state"` // State of the playback operation
TargetURI string `json:"target_uri"` // URI of the channel or bridge on which the media should be played (follows format of 'type':'name')
}
// NewPlaybackHandle builds a handle to the playback id
func NewPlaybackHandle(id string, pb Playback) *PlaybackHandle {
return &PlaybackHandle{
id: id,
p: pb,
}
}
// PlaybackHandle is the handle for performing playback operations
type PlaybackHandle struct {
id string
p Playback
}
// ID returns the identifier for the playback
func (ph *PlaybackHandle) ID() string {
return ph.id
}
// Data gets the playback data
func (ph *PlaybackHandle) Data() (pd PlaybackData, err error) {
pd, err = ph.p.Data(ph.id)
return
}
// Control performs the given operation
func (ph *PlaybackHandle) Control(op string) (err error) {
err = ph.p.Control(ph.id, op)
return
}
// Stop stops the playback
func (ph *PlaybackHandle) Stop() (err error) {
err = ph.p.Stop(ph.id)
return
}
// Match returns true if the event matches the playback
func (ph *PlaybackHandle) Match(e Event) bool {
p, ok := e.(PlaybackEvent)
if !ok {
return false
}
ids := p.GetPlaybackIDs()
for _, i := range ids {
if i == ph.ID() {
return true
}
}
return false
}
// Subscribe subscribes the list of channel events
func (ph *PlaybackHandle) Subscribe(n ...string) Subscription {
if ph == nil {
return nil
}
return ph.p.Subscribe(ph.id, n...)
}