index.go 1.5 KB

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