forked from Marquis42/ari-proxy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (53 loc) · 1.41 KB
/
main.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
package main
import (
"context"
"github.com/inconshreveable/log15"
"github.com/CyCoreSystems/ari-proxy/v5/client"
"github.com/CyCoreSystems/ari/v5"
"github.com/CyCoreSystems/ari/v5/ext/record"
)
var ariApp = "test"
var log = log15.New()
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
record.Logger = log
// connect
log.Info("Connecting to ARI")
cl, err := client.New(ctx, client.WithApplication(ariApp), client.WithLogger(log))
if err != nil {
log.Error("Failed to build ARI client", "error", err)
return
}
// setup app
log.Info("Starting listener app")
err = client.Listen(ctx, cl, appStart(ctx))
if err != nil {
log.Error("failed to listen for new calls")
}
<-ctx.Done()
return
}
func appStart(ctx context.Context) func(*ari.ChannelHandle, *ari.StasisStart) {
return func(h *ari.ChannelHandle, startEvent *ari.StasisStart) {
defer h.Hangup()
log.Info("running app", "channel", h.Key().ID)
if err := h.Answer(); err != nil {
log.Error("failed to answer call", "error", err)
// return
}
res, err := record.Record(ctx, h,
record.TerminateOn("any"),
record.IfExists("overwrite"),
).Result()
if err != nil {
log.Error("failed to record", "error", err)
return
}
if err = res.Save("test-recording"); err != nil {
log.Error("failed to save recording", "error", err)
}
log.Info("completed recording")
h.Hangup()
}
}