-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
44 lines (35 loc) · 828 Bytes
/
example_test.go
File metadata and controls
44 lines (35 loc) · 828 Bytes
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
package esl_test
import (
"fmt"
"github.com/mdigger/esl"
)
//nolint:testableexamples
func Example() {
// initialize buffered events channel
events := make(chan esl.Event, 1)
// connect to FreeSWITCH & init events channel with auto-close flag
client, err := esl.Connect("10.10.61.76", "ClueCon",
esl.WithEvents(events, true))
if err != nil {
panic(err)
}
defer client.Close()
// send a command
msg, err := client.API("show calls count")
if err != nil {
panic(err)
}
fmt.Println(msg)
// subscribe to BACKGROUND_JOB events
if err = client.Subscribe("BACKGROUND_JOB"); err != nil {
panic(err)
}
// send a background command
if err = client.JobWithID("uptime s", "test-xxx"); err != nil {
panic(err)
}
// read events
for ev := range events {
fmt.Println(ev.Name(), ev.Get("Job-UUID"))
}
}