Skip to content

Commit

Permalink
Updating README with new example
Browse files Browse the repository at this point in the history
  • Loading branch information
0x19 committed Feb 8, 2015
1 parent fde810f commit ed29597
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
. "github.com/0x19/goesl"
"os"
"runtime"
"strings"
)

var (
Expand All @@ -35,6 +36,12 @@ var (

func main() {

defer func() {
if r := recover(); r != nil {
Error("Recovered in f", r)
}
}()

// Boost it as much as it can go ...
runtime.GOMAXPROCS(runtime.NumCPU())

Expand All @@ -58,15 +65,15 @@ func main() {

// handle - Running under goroutine here to explain how to send message, receive message and in general dump stuff out
func handle(s *OutboundServer) {
select {
case conn := <-s.Conn:

for {

conn := <-s.Conns

Notice("New incomming connection: %v", conn)

conn.Send("connect")

// Uncomment if you wish to see more informational dump from freeswitch
// conn.Send("myevents")

aMsg, err := conn.Execute("answer", "", false)

if err != nil {
Expand All @@ -75,6 +82,9 @@ func handle(s *OutboundServer) {
}

Debug("Answer Message: %s", aMsg)
Debug("Caller UUID: %s", aMsg.GetHeader("Caller-Unique-Id"))

cUUID := aMsg.GetHeader("Caller-Unique-Id")

pMsg, err := conn.Execute("playback", welcomeFile, true)

Expand All @@ -85,7 +95,7 @@ func handle(s *OutboundServer) {

Debug("Playback Message: %s", pMsg)

hMsg, err := conn.Execute("hangup", "", false)
hMsg, err := conn.ExecuteUUID(cUUID, "hangup", "", false)

if err != nil {
Error("Got error while executing hangup against call: %s", err)
Expand All @@ -94,22 +104,29 @@ func handle(s *OutboundServer) {

Debug("Hangup Message: %s", hMsg)

for {
msg, err := conn.ReadMessage()
done := make(chan bool)

go func() {
for {
msg, err := conn.ReadMessage()

if err != nil {

if err != nil {
// If it contains EOF, we really dont care...
if !strings.Contains(err.Error(), "EOF") {
Error("Error while reading Freeswitch message: %s", err)
}

// Just please, don't show EOF
if err.Error() != "EOF" {
Debug("Got error while reading Freeswitch message: %s", err)
done <- true
break
}

continue
Info("%s", msg.Dump())
}
}()

Info("%s", msg.Dump())
}

<-done
}

}
```

0 comments on commit ed29597

Please sign in to comment.