index.go 1.6 KB

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