forked from CyCoreSystems/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveRecording.go
150 lines (117 loc) · 4.24 KB
/
liveRecording.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package ari
import "sync"
// LiveRecording represents a communication path interacting with an Asterisk
// server for live recording resources
type LiveRecording interface {
// Get gets the Recording by type
Get(key *Key) *LiveRecordingHandle
// Data gets the data for the live recording
Data(key *Key) (*LiveRecordingData, error)
// Stop stops the live recording
Stop(key *Key) error
// Pause pauses the live recording
Pause(key *Key) error
// Resume resumes the live recording
Resume(key *Key) error
// Mute mutes the live recording
Mute(key *Key) error
// Unmute unmutes the live recording
Unmute(key *Key) error
// Scrap Stops and deletes the current LiveRecording
Scrap(key *Key) error
// Stored returns the StoredRecording handle for this LiveRecording
Stored(key *Key) *StoredRecordingHandle
// Subscribe subscribes to events
Subscribe(key *Key, n ...string) Subscription
}
// LiveRecordingData is the data for a live recording
type LiveRecordingData struct {
// Key is the cluster-unique identifier for this live recording
Key *Key `json:"key"`
Cause string `json:"cause,omitempty"` // If failed, the cause of the failure
Duration DurationSec `json:"duration,omitempty"` // Length of recording in seconds
Format string `json:"format"` // Format of recording (wav, gsm, etc)
Name string `json:"name"` // (base) name for the recording
Silence DurationSec `json:"silence_duration,omitempty"` // If silence was detected in the recording, the duration in seconds of that silence (requires that maxSilenceSeconds be non-zero)
State string `json:"state"` // Current state of the recording
Talking DurationSec `json:"talking_duration,omitempty"` // Duration of talking, in seconds, that has been detected in the recording (requires that maxSilenceSeconds be non-zero)
TargetURI string `json:"target_uri"` // URI for the channel or bridge which is being recorded (TODO: figure out format for this)
}
// ID returns the identifier of the live recording
func (s *LiveRecordingData) ID() string {
return s.Name
}
// NewLiveRecordingHandle creates a new live recording handle
func NewLiveRecordingHandle(key *Key, r LiveRecording, exec func(*LiveRecordingHandle) (err error)) *LiveRecordingHandle {
return &LiveRecordingHandle{
key: key,
r: r,
exec: exec,
}
}
// A LiveRecordingHandle is a reference to a live recording that can be operated on
type LiveRecordingHandle struct {
key *Key
r LiveRecording
exec func(*LiveRecordingHandle) (err error)
executed bool
mu sync.Mutex
}
// ID returns the identifier of the live recording
func (h *LiveRecordingHandle) ID() string {
return h.key.ID
}
// Key returns the key of the live recording
func (h *LiveRecordingHandle) Key() *Key {
return h.key
}
// Data gets the data for the live recording
func (h *LiveRecordingHandle) Data() (*LiveRecordingData, error) {
return h.r.Data(h.key)
}
// Stop stops and saves the recording
func (h *LiveRecordingHandle) Stop() error {
return h.r.Stop(h.key)
}
// Scrap stops and deletes the recording
func (h *LiveRecordingHandle) Scrap() error {
return h.r.Scrap(h.key)
}
// Resume resumes the recording
func (h *LiveRecordingHandle) Resume() error {
return h.r.Resume(h.key)
}
// Pause pauses the recording
func (h *LiveRecordingHandle) Pause() error {
return h.r.Pause(h.key)
}
// Mute mutes the recording
func (h *LiveRecordingHandle) Mute() error {
return h.r.Mute(h.key)
}
// Unmute mutes the recording
func (h *LiveRecordingHandle) Unmute() error {
return h.r.Unmute(h.key)
}
// Stored returns the StoredRecordingHandle for this LiveRecordingHandle
func (h *LiveRecordingHandle) Stored() *StoredRecordingHandle {
return h.r.Stored(h.key)
}
// Exec executes any staged operations attached to the `LiveRecordingHandle`
func (h *LiveRecordingHandle) Exec() (err error) {
h.mu.Lock()
if !h.executed {
h.executed = true
if h.exec != nil {
err = h.exec(h)
h.exec = nil
}
}
h.mu.Unlock()
return
}
// Subscribe subscribes the recording handle's underlying recorder to
// the provided event types.
func (h *LiveRecordingHandle) Subscribe(n ...string) Subscription {
return h.r.Subscribe(h.key, n...)
}