| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package app
- import (
- "pbx-api-gin/internal/app/ami/action"
- "pbx-api-gin/internal/app/stc"
- "pbx-api-gin/internal/app/stc/active"
- "pbx-api-gin/internal/app/stc/priority"
- "pbx-api-gin/internal/app/stc/socket"
- "pbx-api-gin/pkg/lfshook"
- "pbx-api-gin/pkg/utils"
- "time"
- )
- func StartApp() {
- //init mysql
- //mysql.CreateDBInstance()
- //Get cab number acording to IP
- SetMasterCabNum()
- //lfshook.NewLogger().Infof("=================cab number:%s========Master:%+v===", active.CabNum, active.Master)
- //init the active status
- //active.ActivedCab = ""
- //get priority
- priority.GetPriority()
- // 启动带有重连机制的连接管理协程MC1
- go stc.StartStcConnection(socket.Conn, "1")
- // 启动带有重连机制的连接管理协程MC8
- go stc.StartStcConnection(socket.Conn8, "8")
- //启动连接到Master服务器,检查Master是否在线
- //if active.CabNum == "8" {
- // socket.ConnectedMaster = false
- // go stc.StartConnectionToSipServer(socket.ConnToMaster)
- //}
- // 启动其他服务...
- // 启动 AMI
- go func() {
- action.StartAMI(func() {
- lfshook.NewLogger().Info("ami callback")
- }, []func(event map[string]string){})
- }()
- //refresh extension status
- time.Sleep(3 * time.Second)
- utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "reload")
- }
- // Get eth0 IP
- func SetMasterCabNum() {
- ext, err := socket.IsIPExists("10.0.11.11")
- if err != nil {
- lfshook.NewLogger().Infof("Check IP :%+v", err)
- }
- // Init cab number and master role
- if !ext {
- active.CabNum = "8"
- active.Master = false
- } else {
- active.CabNum = "1"
- active.Master = true
- }
- }
|