mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
hangup if no creadit working
This commit is contained in:
@@ -35,6 +35,6 @@ func main() {
|
||||
sm := &sessionmanager.FSSessionManager{}
|
||||
sm.Connect(new(sessionmanager.DirectSessionDelegate), *freeswitchsrv, *freeswitchpass)
|
||||
waitChan := make(<-chan byte)
|
||||
log.Print("Session manager!")
|
||||
log.Print("CGRateS is listening!")
|
||||
<-waitChan
|
||||
}
|
||||
|
||||
@@ -88,8 +88,9 @@ func (sm *FSSessionManager) GetSession(uuid string) *Session {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disconnects a session by sending hangup command to freeswitch
|
||||
func (sm *FSSessionManager) DisconnectSession(s *Session) {
|
||||
fmt.Fprint(sm.conn, fmt.Sprintf("SendMsg %s\ncall-command: hangup\nhangup-cause: \n\n", s.uuid, "MANAGER_REQUEST"))
|
||||
fmt.Fprint(sm.conn, fmt.Sprintf("SendMsg %s\ncall-command: hangup\nhangup-cause: MANAGER_REQUEST\n\n", s.uuid))
|
||||
s.Close()
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
|
||||
// Called on freeswitch's events not processed by the session manger,
|
||||
// for logging purposes (maybe).
|
||||
func (sm *FSSessionManager) OnOther(ev Event) {
|
||||
//log.Printf("Other event: %s", ev.Fields["Event-Name"])
|
||||
//log.Printf("Other event: %s", ev.GetName())
|
||||
}
|
||||
|
||||
func (sm *FSSessionManager) GetSessionDelegate() SessionDelegate {
|
||||
|
||||
@@ -49,7 +49,7 @@ func NewSession(ev Event, sm SessionManager) (s *Session) {
|
||||
TimeStart: startTime}
|
||||
s = &Session{uuid: ev.GetUUID(),
|
||||
callDescriptor: cd,
|
||||
stopDebit: make(chan byte)}
|
||||
stopDebit: make(chan byte, 2)} //buffer it for multiple close signals
|
||||
s.sessionManager = sm
|
||||
go s.startDebitLoop()
|
||||
return
|
||||
@@ -95,6 +95,12 @@ func (s *Session) Close() {
|
||||
s.callDescriptor.TimeEnd = time.Now()
|
||||
}
|
||||
|
||||
// Disconects a session using session manager
|
||||
func (s *Session) Disconnect() {
|
||||
s.sessionManager.DisconnectSession(s)
|
||||
}
|
||||
|
||||
// Nice print for session
|
||||
func (s *Session) String() string {
|
||||
return fmt.Sprintf("%v: %s -> %s", s.callDescriptor.TimeStart, s.callDescriptor.Subject, s.callDescriptor.DestinationPrefix)
|
||||
}
|
||||
|
||||
@@ -55,23 +55,7 @@ func (dsd *DirectSessionDelegate) OnHeartBeat(ev Event) {
|
||||
}
|
||||
|
||||
func (dsd *DirectSessionDelegate) OnChannelAnswer(ev Event, s *Session) {
|
||||
s.callDescriptor.Amount = DEBIT_PERIOD.Seconds()
|
||||
s.callDescriptor.SetStorageGetter(storageGetter)
|
||||
remainingSeconds, err := s.callDescriptor.GetMaxSessionTime()
|
||||
if remainingSeconds == -1 || err == nil {
|
||||
log.Print("Postpaying client: happy talking!")
|
||||
return
|
||||
}
|
||||
if remainingSeconds == 0 || err != nil {
|
||||
log.Printf("No credit left: Disconnect %v", s)
|
||||
s.Disconnect()
|
||||
return
|
||||
}
|
||||
if remainingSeconds < DEBIT_PERIOD.Seconds() || err != nil {
|
||||
log.Printf("Not enough money for another debit period %v", s)
|
||||
s.Disconnect()
|
||||
return
|
||||
}
|
||||
log.Print("direct answer")
|
||||
}
|
||||
|
||||
func (dsd *DirectSessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
@@ -87,17 +71,19 @@ func (dsd *DirectSessionDelegate) LoopAction(s *Session, cd *timespans.CallDescr
|
||||
s.CallCosts = append(s.CallCosts, cc)
|
||||
cd.Amount = DEBIT_PERIOD.Seconds()
|
||||
remainingSeconds, err := cd.GetMaxSessionTime()
|
||||
if remainingSeconds == -1 || err == nil {
|
||||
if remainingSeconds == -1 && err == nil {
|
||||
log.Print("Postpaying client: happy talking!")
|
||||
return
|
||||
}
|
||||
if remainingSeconds == 0 || err != nil {
|
||||
log.Printf("No credit left: Disconnect %v", s)
|
||||
s.Disconnect()
|
||||
return
|
||||
}
|
||||
if remainingSeconds < DEBIT_PERIOD.Seconds() || err != nil {
|
||||
log.Printf("Not enough money for another debit period %v", s)
|
||||
s.Disconnect()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user