moved event filters in constructor and increased the number of

reconnects to 10
This commit is contained in:
Radu Ioan Fericean
2012-10-10 17:22:16 +03:00
parent e8f01301fd
commit 8a38550122
3 changed files with 6 additions and 8 deletions

1
.gitignore vendored
View File

@@ -9,4 +9,3 @@ a.out
docs/_*
bin
.idea
.gitignore

View File

@@ -31,8 +31,7 @@ type fSock struct {
}
// Connects to FS and starts buffering input
func New(fsaddr, fspaswd string, reconnects int, eventHandlers map[string]func(string)) error {
eventFilters := make(map[string]string)
func New(fsaddr, fspaswd string, reconnects int, eventHandlers map[string]func(string), eventFilters map[string]string) error {
fs = &fSock{fsaddress: fsaddr, fspaswd: fspaswd, eventHandlers: eventHandlers, eventFilters: eventFilters}
fs.apiChan = make(chan string) // Init apichan so we can use it to pass api replies
fs.reconnects = reconnects
@@ -196,7 +195,7 @@ func EventsPlain(events []string) error {
}
// Enable filters
func FilterEvents(filters map[string]string) error {
func filterEvents(filters map[string]string) error {
if len(filters) == 0 { //Nothing to filter
return nil
}
@@ -237,7 +236,7 @@ func Connect(reconnects int) error {
}
if subscribeErr := EventsPlain(handledEvs); subscribeErr != nil {
return subscribeErr
} else if filterErr := FilterEvents(fs.eventFilters); filterErr != nil {
} else if filterErr := filterEvents(fs.eventFilters); filterErr != nil {
return filterErr
}
return nil

View File

@@ -46,11 +46,11 @@ func NewFSSessionManager(storage rater.DataStorage, connector rater.Connector, d
// Connects to the freeswitch mod_event_socket server and starts
// listening for events in json format.
func (sm *FSSessionManager) Connect(address, pass string) (err error) {
if err = fsock.New(address, pass, 3, sm.createHandlers()); err != nil {
eventFilters := map[string]string{"Call-Direction": "inbound"}
if err = fsock.New(address, pass, 10, sm.createHandlers(), eventFilters); err != nil {
rater.Logger.Crit(fmt.Sprintf("FreeSWITCH error:", err))
return
} else if fsock.Connected() {
fsock.FilterEvents(map[string]string{"Call-Direction": "inbound"})
} else if fsock.Connected() {
rater.Logger.Info("Successfully connected to FreeSWITCH")
}
fsock.ReadEvents()