-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
62 lines (47 loc) · 1.81 KB
/
client.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
// Copyright 2015 Nevio Vesic
// Please check out LICENSE file for more information about what you CAN and what you CANNOT do!
// Basically in short this is a free software for you to do whatever you want to do BUT copyright must be included!
// I didn't write all of this code so you could say it's yours.
// MIT License
package examples
import (
"flag"
"fmt"
. "github.com/0x19/goesl"
"runtime"
"strings"
)
var (
fshost = flag.String("fshost", "localhost", "Freeswitch hostname. Default: localhost")
fsport = flag.Uint("fsport", 8021, "Freeswitch port. Default: 8021")
password = flag.String("pass", "ClueCon", "Freeswitch password. Default: ClueCon")
timeout = flag.Int("timeout", 10, "Freeswitch conneciton timeout in seconds. Default: 10")
)
// Small client that will first make sure all events are returned as JSON and second, will originate
func main() {
// Boost it as much as it can go ...
runtime.GOMAXPROCS(runtime.NumCPU())
client, err := NewClient(*fshost, *fsport, *password, *timeout)
if err != nil {
Error("Error while creating new client: %s", err)
return
}
Debug("Yuhu! New client: %q", client)
// Apparently all is good... Let us now handle connection :)
// We don't want this to be inside of new connection as who knows where it my lead us.
// Remember that this is crutial part in handling incoming messages :)
go client.Handle()
client.Send("events json ALL")
client.BgApi(fmt.Sprintf("originate %s %s", "sofia/internal/1001@127.0.0.1", "&socket(192.168.1.2:8084 async full)"))
for {
msg, err := client.ReadMessage()
if err != nil {
// If it contains EOF, we really dont care...
if !strings.Contains(err.Error(), "EOF") && err.Error() != "unexpected end of JSON input" {
Error("Error while reading Freeswitch message: %s", err)
}
break
}
Debug("%s", msg)
}
}