mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
moved event filters in constructor and increased the number of
reconnects to 10
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,4 +9,3 @@ a.out
|
||||
docs/_*
|
||||
bin
|
||||
.idea
|
||||
.gitignore
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user