forked from CyCoreSystems/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storedRecording.go
98 lines (80 loc) · 2.74 KB
/
storedRecording.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
96
97
98
package ari
// StoredRecording represents a communication path interacting with an Asterisk
// server for stored recording resources
type StoredRecording interface {
// List lists the recordings
List(filter *Key) ([]*Key, error)
// Get gets the Recording by type
Get(key *Key) *StoredRecordingHandle
// data gets the data for the stored recording
Data(key *Key) (*StoredRecordingData, error)
// Copy copies the recording to the destination name
//
// NOTE: because ARI offers no forced-copy, Copy should always return the
// StoredRecordingHandle of the destination, even if the Copy fails. Doing so
// allows the user to Delete the existing StoredRecording before retrying.
Copy(key *Key, dest string) (*StoredRecordingHandle, error)
// Delete deletes the recording
Delete(key *Key) error
}
// StoredRecordingData is the data for a stored recording
type StoredRecordingData struct {
// Key is the cluster-unique identifier for this stored recording
Key *Key `json:"key"`
Format string `json:"format"`
Name string `json:"name"`
}
// ID returns the identifier for the stored recording.
func (d StoredRecordingData) ID() string {
return d.Name // TODO: does the identifier include the Format and Name?
}
// A StoredRecordingHandle is a reference to a stored recording that can be operated on
type StoredRecordingHandle struct {
key *Key
s StoredRecording
exec func(a *StoredRecordingHandle) error
executed bool
}
// NewStoredRecordingHandle creates a new stored recording handle
func NewStoredRecordingHandle(key *Key, s StoredRecording, exec func(a *StoredRecordingHandle) error) *StoredRecordingHandle {
return &StoredRecordingHandle{
key: key,
s: s,
exec: exec,
}
}
// ID returns the identifier for the stored recording
func (s *StoredRecordingHandle) ID() string {
return s.key.ID
}
// Key returns the Key for the stored recording
func (s *StoredRecordingHandle) Key() *Key {
return s.key
}
// Exec executes any staged operations
func (s *StoredRecordingHandle) Exec() (err error) {
if !s.executed {
s.executed = true
if s.exec != nil {
err = s.exec(s)
s.exec = nil
}
}
return
}
// Data gets the data for the stored recording
func (s *StoredRecordingHandle) Data() (*StoredRecordingData, error) {
return s.s.Data(s.key)
}
// Copy copies the stored recording.
//
// NOTE: because ARI offers no forced-copy, this should always return the
// StoredRecordingHandle of the destination, even if the Copy fails. Doing so
// allows the user to Delete the existing StoredRecording before retrying.
func (s *StoredRecordingHandle) Copy(dest string) (*StoredRecordingHandle, error) {
return s.s.Copy(s.key, dest)
}
// Delete deletes the recording
func (s *StoredRecordingHandle) Delete() error {
return s.s.Delete(s.key)
}