go-eventsocket
go-eventsocket copied to clipboard
outbound can't get event in real-time
when ReadEvent in outbound, it can't get the events in real-time, all events will send on just disconnect when use linger.
if not use linger, it can't get any event at all.
// Copyright 2013 Alexandre Fiori
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Server that accepts connections from FreeSWITCH and controls incoming calls.
package main
import (
"fmt"
"log"
"github.com/fiorix/go-eventsocket/eventsocket"
)
// const audioFile = "/opt/freeswitch/sounds/en/us/callie/misc/8000/sorry.wav"
const audioFile = "/usr/share/freeswitch/sounds/music/8000/partita-no-3-in-e-major-bwv-1006-1-preludio.wav"
func main() {
eventsocket.ListenAndServe(":9090", handler)
}
func handler(c *eventsocket.Connection) {
fmt.Println("new client:", c.RemoteAddr())
c.Send("connect")
c.Send("myevents")
c.Send("event plain ALL")
c.Send("start_dtmf")
c.Send("linger")
c.Execute("answer", "", false)
c.Execute("playback", audioFile, true)
for {
ev, err := c.ReadEvent()
if err != nil {
log.Fatal(err)
}
fmt.Println("\nNew event")
ev.PrettyPrint()
if ev.Get("Application") == "playback" {
if ev.Get("Application-Response") == "FILE PLAYED" {
c.Send("exit")
}
}
}
}