index.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // 启动带有重连机制的连接管理协程MC1
  27. go stc.StartStcConnection(socket.Conn, "1")
  28. // 启动带有重连机制的连接管理协程MC8
  29. go stc.StartStcConnection(socket.Conn8, "8")
  30. //启动连接到Master服务器,检查Master是否在线
  31. if active.CabNum == "1" {
  32. go stc.StartConnectionToSipServer(socket.ConnToSlave)
  33. } else {
  34. go stc.RecvFromSipServer()
  35. }
  36. // 启动其他服务...
  37. // 启动 AMI
  38. go func() {
  39. action.StartAMI(func() {
  40. lfshook.NewLogger().Info("ami callback")
  41. }, []func(event map[string]string){})
  42. }()
  43. //refresh extension status
  44. time.Sleep(3 * time.Second)
  45. utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "reload")
  46. }