| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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.Master = false
- active.CabNum = "8"
- } else {
- active.Master = true
- active.CabNum = "1"
- }
- }
|