/
playback.go
61 lines (49 loc) · 1.53 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
package native
import (
"errors"
"github.com/CyCoreSystems/ari/v6"
)
// Playback provides the ARI Playback accessors for the native client
type Playback struct {
client *Client
}
// Get gets a lazy handle for the given playback identifier
func (a *Playback) Get(key *ari.Key) *ari.PlaybackHandle {
return ari.NewPlaybackHandle(a.client.stamp(key), a, nil)
}
// Data returns a playback's details.
// (Equivalent to GET /playbacks/{playbackID})
func (a *Playback) Data(key *ari.Key) (*ari.PlaybackData, error) {
if key == nil || key.ID == "" {
return nil, errors.New("playback key not supplied")
}
data := new(ari.PlaybackData)
if err := a.client.get("/playbacks/"+key.ID, data); err != nil {
return nil, dataGetError(err, "playback", "%v", key.ID)
}
data.Key = a.client.stamp(key)
return data, nil
}
// Control performs the given operation on the current playback. Available operations are:
// - restart
// - pause
// - unpause
// - reverse
// - forward
func (a *Playback) Control(key *ari.Key, op string) error {
req := struct {
Operation string `json:"operation"`
}{
Operation: op,
}
return a.client.post("/playbacks/"+key.ID+"/control", nil, &req)
}
// Stop stops a playback session.
// (Equivalent to DELETE /playbacks/{playbackID})
func (a *Playback) Stop(key *ari.Key) error {
return a.client.del("/playbacks/"+key.ID, nil, "")
}
// Subscribe listens for ARI events for the given playback entity
func (a *Playback) Subscribe(key *ari.Key, n ...string) ari.Subscription {
return a.client.Bus().Subscribe(key, n...)
}