index.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package app
  2. import (
  3. "pbx-api-gin/internal/app/ami/action"
  4. "pbx-api-gin/internal/app/stc"
  5. "pbx-api-gin/internal/app/stc/active"
  6. "pbx-api-gin/internal/app/stc/priority"
  7. "pbx-api-gin/internal/app/stc/socket"
  8. "pbx-api-gin/pkg/utils"
  9. "time"
  10. )
  11. func StartApp() {
  12. time.Sleep(2 * time.Second)
  13. //init asterisk
  14. if !utils.CheckAsterisk() {
  15. utils.LoggerDebug.Printf("Asterisk not running , run cmd /usr/sbin/asterisk !")
  16. utils.ExecCmdAsync("/usr/sbin/asterisk")
  17. time.Sleep(3 * time.Second)
  18. }
  19. if utils.CheckAsterisk() {
  20. utils.LoggerDebug.Printf("Check asterisk , Asterisk is running !")
  21. }
  22. //Get cab number acording to IP
  23. socket.SetMasterCabNum()
  24. utils.LoggerDebug.Printf("Get CabNumber:%s Master:%+v", active.CabNum, active.Master)
  25. //init the active status
  26. //active.ActivedCab = ""
  27. //get priority
  28. priority.GetPriority()
  29. //初始化列车信息map 列车号+车厢号
  30. active.InitTrainInfoMap()
  31. // 启动带有重连机制的连接管理协程MC1
  32. go stc.StartStcConnection(socket.Conn, "1")
  33. // 启动带有重连机制的连接管理协程MC8
  34. go stc.StartStcConnection(socket.Conn8, "8")
  35. //启动连接到Master服务器,检查Master是否在线
  36. //if active.CabNum == "1" {
  37. // go stc.StartConnectionToSipServer(socket.ConnToSlave)
  38. //} else {
  39. // go stc.RecvFromSipServer()
  40. //}
  41. // 启动其他服务...
  42. // 启动 AMI
  43. go func() {
  44. action.StartAMI(func() {
  45. utils.LoggerDebug.Printf("AMI callback Start .")
  46. }, []func(event map[string]string){})
  47. }()
  48. //refresh extension status
  49. time.Sleep(1 * time.Second)
  50. utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "reload")
  51. }