index.go 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489
  1. package action
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "pbx-api-gin/internal/app/stc/active"
  7. "pbx-api-gin/internal/app/stc/priority"
  8. alstatus "pbx-api-gin/internal/app/stc/sendstatus"
  9. "pbx-api-gin/internal/pkg/configs"
  10. "pbx-api-gin/pkg/lfshook"
  11. "pbx-api-gin/pkg/utils"
  12. "sort"
  13. "strings"
  14. "time"
  15. "github.com/sirupsen/logrus"
  16. "github.com/tqcenglish/amigo-go"
  17. "github.com/tqcenglish/amigo-go/pkg"
  18. )
  19. var AminInstance *amigo.Amigo
  20. var trainInfo = ""
  21. func HandleAMI(event map[string]string) {
  22. switch event["Event"] {
  23. case "DTMFBegin": //ICP interrupt PAD
  24. lfshook.NewLogger().Infof("=========%s====caller:%s=====digit:%s==", event["Event"], event["CallerIDNum"], event["Digit"])
  25. if utils.IsICP(event["CallerIDNum"]) && event["Exten"] != "" {
  26. //PA interrupt PAD
  27. switch event["Digit"] {
  28. case "#":
  29. //lfshook.NewLogger().Infof("===PA interrupt PAD====== ")
  30. utils.LoggerDebug.Printf("Get DTMF '#', PA interrupt other !")
  31. priority.PAInterrupt = 1
  32. runningTaskName := InterruptRunningTask("PA")
  33. if runningTaskName != "" {
  34. time.Sleep(time.Millisecond * 200) //wait endpoint release
  35. }
  36. case "*": //Cab cab interrupt PAD
  37. //lfshook.NewLogger().Infof("===Cab cab interrupt PAD and====== ")
  38. utils.LoggerDebug.Printf("Get DTMF '*', CabCab interrupt other !")
  39. priority.CABInterrupt = 1
  40. runningTaskName := InterruptRunningTask("C2C")
  41. //Hangup("2311")
  42. //Hangup("2381")
  43. if runningTaskName != "" {
  44. time.Sleep(time.Millisecond * 100) //wait endpoint release
  45. }
  46. }
  47. }
  48. case "UserEvent": // RCD filename; PA;CPA; CabCab
  49. lfshook.NewLogger().Infof("========event:%s File:%s", event["Event"], event["FILENAME"])
  50. if event["UserEvent"] == "CONTINUE" && event["Type"] != "" {
  51. utils.LoggerDebug.Printf("Get UserEvent Type=CONTINUE , Send %s continue status !", event["Type"])
  52. alstatus.PaStatus("", event["Type"], "continue")
  53. return
  54. }
  55. if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
  56. //PA & CPA interrupt others
  57. if utils.IsICP(event["CallerIDNum"]) { //PA
  58. utils.LoggerDebug.Printf("Get UserEvent , %s calling !", event["Type"])
  59. if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
  60. Hangup(event["CallerIDNum"])
  61. }
  62. WaitTaskCreate("PA", event["CallerIDNum"])
  63. if priority.CheckPriority("ManuPa") {
  64. //hangup others if priority is higher
  65. //lfshook.NewLogger().Infof("UserEvent event :PA start")
  66. utils.LoggerDebug.Printf("PA calling, check priority return true !")
  67. runningTaskName := InterruptRunningTask("PA") //PA interrupt other
  68. if runningTaskName != "" {
  69. time.Sleep(time.Millisecond * 100) //wait endpoint release
  70. }
  71. } else {
  72. if priority.TaskCreating == "PA" {
  73. utils.LoggerDebug.Printf("PA : Clean priority.TaskCreating = '' !")
  74. priority.TaskCreating = ""
  75. }
  76. utils.LoggerDebug.Printf("PA calling failed , check priority return false !")
  77. Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
  78. }
  79. time.Sleep(1 * time.Second)
  80. if priority.TaskCreating == "PA" {
  81. utils.LoggerDebug.Printf("PA : Clean priority.TaskCreating = '' !")
  82. priority.TaskCreating = ""
  83. }
  84. } else if utils.IsIO(event["CallerIDNum"]) { // CPA
  85. utils.LoggerDebug.Printf("Get UserEvent , %s calling !", event["Type"])
  86. WaitTaskCreate("CPA", event["CallerIDNum"])
  87. if priority.CheckPriority("CPA") {
  88. //lfshook.NewLogger().Infof("========event:%s ========devide:%d", event["Event"], active.TrainDevide)
  89. utils.LoggerDebug.Printf("CPA calling, check priority return true !")
  90. if active.TrainDevide == 1 || active.RadioFault == 1 { // 列车没有断开的情况下限制如下;列车断开之后CPA无任何限制
  91. utils.LoggerDebug.Printf("TrainDevide = %d, RadioFault = %d , CPA calling unlimit !", active.TrainDevide, active.RadioFault)
  92. //lfshook.NewLogger().Infof("===active.TrainDevide == 1 || active.RadioFault == 1====")
  93. } else {
  94. utils.LoggerDebug.Printf("CPA calling , ActivedCab = %s !", active.ActivedCab)
  95. if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
  96. Hangup(event["CallerIDNum"])
  97. if priority.TaskCreating == "CPA" {
  98. utils.LoggerDebug.Printf("CPA : Clean priority.TaskCreating = '' !")
  99. priority.TaskCreating = ""
  100. }
  101. return
  102. } else if active.ActivedCab == "1" && event["CallerIDNum"] == "1411" {
  103. Hangup(event["CallerIDNum"])
  104. if priority.TaskCreating == "CPA" {
  105. utils.LoggerDebug.Printf("CPA : Clean priority.TaskCreating = '' !")
  106. priority.TaskCreating = ""
  107. }
  108. return
  109. } else if active.ActivedCab == "8" && event["CallerIDNum"] == "1481" {
  110. Hangup(event["CallerIDNum"])
  111. if priority.TaskCreating == "CPA" {
  112. utils.LoggerDebug.Printf("CPA : Clean priority.TaskCreating = '' !")
  113. priority.TaskCreating = ""
  114. }
  115. return
  116. }
  117. }
  118. //hangup others if priority is higher
  119. runningTaskName := InterruptRunningTask("CPA") //CPA interrupt other
  120. if runningTaskName != "" {
  121. time.Sleep(time.Millisecond * 100) //wait endpoint release
  122. }
  123. } else {
  124. if priority.TaskCreating == "CPA" {
  125. utils.LoggerDebug.Printf("CPA : Clean priority.TaskCreating = '' !")
  126. priority.TaskCreating = ""
  127. }
  128. utils.LoggerDebug.Printf("CPA calling failed , check priority return false !")
  129. Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
  130. }
  131. time.Sleep(1 * time.Second)
  132. if priority.TaskCreating == "CPA" {
  133. utils.LoggerDebug.Printf("CPA : Clean priority.TaskCreating = '' !")
  134. priority.TaskCreating = ""
  135. }
  136. }
  137. } else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab start; check cab cab priority
  138. utils.LoggerDebug.Printf("Get UserEvent , %s calling !", event["Type"])
  139. WaitTaskCreate("C2C", event["CallerIDNum"])
  140. if priority.CheckPriority("CabCab") { // interrupt OCC-PAD
  141. //C2C start PAD interrupt
  142. taskName, _, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  143. lfshook.NewLogger().Infof("HighestPriorityRunningTask get task :%+v", taskName)
  144. utils.LoggerDebug.Printf("C2C calling, check priority return true !")
  145. if ok {
  146. if taskName == "PAD-ICP" || taskName == "PAD-TMS" || taskName == "PA" {
  147. utils.LoggerDebug.Printf("%s Start CabCab ,interrupt other !", event["CallerIDNum"])
  148. runningTaskName := InterruptRunningTask("C2C")
  149. if runningTaskName != "" {
  150. time.Sleep(time.Millisecond * 100) //wait endpoint release
  151. }
  152. } //else {
  153. //lfshook.NewLogger().Infof("CabCab hangup other the one caller %s", event["CallerIDNum"])
  154. time.Sleep(time.Millisecond * 100) //wait endpoint release
  155. utils.LoggerDebug.Printf("%s Start CabCab ,check and hangup the other ICP first", event["CallerIDNum"])
  156. if event["CallerIDNum"] == "2311" {
  157. Hangup("2381")
  158. } else {
  159. Hangup("2311")
  160. }
  161. //}
  162. }
  163. } else { // hangup caller; C2C start failed
  164. //lfshook.NewLogger().Infof("CabCab hangup caller %s", event["CallerIDNum"])
  165. if priority.TaskCreating == "C2C" {
  166. utils.LoggerDebug.Printf("C2C : Clean priority.TaskCreating = '' !")
  167. priority.TaskCreating = ""
  168. }
  169. utils.LoggerDebug.Printf("C2C calling failed , check priority return false !")
  170. Hangup(event["CallerIDNum"])
  171. }
  172. break
  173. //Get record file name ,encode and upload
  174. } else if event["UserEvent"] == "SetRecordFile" {
  175. if len(event["FILENAME"]) > 0 {
  176. if configs.ConfigGlobal.ProcessRecord != "yes" {
  177. break
  178. }
  179. //检测录音文件是否存在;最多检测5次,每次间隔1秒
  180. var fileExists bool
  181. for i := 0; i < 5; i++ {
  182. time.Sleep(time.Second) // 等待1秒
  183. if _, err := os.Stat(event["FILENAME"]); err == nil {
  184. fileExists = true
  185. //lfshook.NewLogger().Infof("File found: %s", event["FILENAME"])
  186. break
  187. } else if os.IsNotExist(err) {
  188. //lfshook.NewLogger().Infof("File not found (attempt %d): %s", i+1, event["FILENAME"])
  189. } else {
  190. //lfshook.NewLogger().Infof("Error checking file: %v", err)
  191. }
  192. }
  193. if !fileExists { //5秒内没有生成录音文件
  194. //lfshook.NewLogger().Infof("File %s not found after 5 attempts", event["FILENAME"])
  195. utils.LoggerDebug.Printf("Record File %s not found after 5 attempts", event["FILENAME"])
  196. break
  197. }
  198. } else {
  199. return
  200. }
  201. //获取录音文件时长,检测录音文件是否超过3min;
  202. duration, err := utils.GetDuration(event["FILENAME"])
  203. if err != nil {
  204. utils.Logger.Printf("%s Get duration err: %+v", event["FILENAME"], err)
  205. break
  206. }
  207. //lfshook.NewLogger().Infof("==========duration===== %d", duration)
  208. //转wav文件的采样率到22kHz,并切割位180秒每段
  209. var FileNames []string
  210. if duration >= 2000 { //超过2000秒的超长文件,不处理
  211. //lfshook.NewLogger().Infof("Audio file time length over 2000 seconds, Ignored !")
  212. utils.LoggerDebug.Printf("Audio file time length over 2000 seconds, Ignored !")
  213. break
  214. } else if duration < 2000 { //小于2000秒文件进行转换和切割
  215. FileNames, err = utils.ConvertAndSegmentWAV(event["FILENAME"], strings.Replace(event["FILENAME"], ".wav", "", -1))
  216. if err != nil {
  217. // lfshook.NewLogger().Infof("%s Get duration err: %+v", event["FILENAME"], err)
  218. utils.LoggerDebug.Printf("Split and convert record file failed : %+v !", err)
  219. break
  220. }
  221. utils.LoggerDebug.Printf("Audio file split to file :%+v ", FileNames)
  222. }
  223. //执行加密操作,并将录音信息写入日志文件
  224. DstFile := ""
  225. if len(FileNames) > 0 { // 文件切割之后进入循环处理
  226. for _, filepathFull := range FileNames {
  227. file := strings.Replace(filepathFull, ".wav", "", -1)
  228. DstFile = fmt.Sprintf("%s-encrypted.wav", file)
  229. err = utils.AudioFileEncode(DstFile, filepathFull)
  230. if err != nil {
  231. //lfshook.NewLogger().Infof("Encode file: %s err: %+v", DstFile, err)
  232. utils.LoggerDebug.Printf("Encrypt file %s err: %+v", DstFile, err)
  233. continue
  234. }
  235. //切割&加密之后发送生成的文件名到STC;
  236. alstatus.SendRecordFile(DstFile, event["RecordType"])
  237. trainInfo = fmt.Sprintf("TrainNumber %s ", active.TrainNum)
  238. utils.LoggerDebug.Printf("Write record log !")
  239. if strings.Contains(event["FILENAME"], "PAD") {
  240. _, caller, callee := utils.GetPadInfo(event["FILENAME"])
  241. carNum := int(caller[2] - '0')
  242. trainInfo = fmt.Sprintf("TrainNumber %s CarNumber %s ", active.TrainNum, active.TrainInfoMap[active.TrainNum][carNum])
  243. if len(caller) == 4 && len(caller) > 0 {
  244. utils.Logger.Printf("Train Information: %s, MessageType: PAD , LocationCode: %c, Connected: %s, RecordFileName:%s", trainInfo, caller[3], callee, DstFile)
  245. } else {
  246. utils.Logger.Printf("Train Information: %s, MessageType: PAD , RecordFileName:%s . Can not get caller and callee !", trainInfo, DstFile)
  247. }
  248. } else if strings.Contains(event["FILENAME"], "C2C") {
  249. _, caller, _ := utils.GetPadInfo(event["FILENAME"])
  250. utils.Logger.Printf("Train Information: %s , MessageType: CabCab, Caller: %s, RecordFileName: %s", trainInfo, caller, DstFile)
  251. } else if strings.Contains(event["FILENAME"], "CPA") {
  252. _, caller, _ := utils.GetPadInfo(event["FILENAME"])
  253. utils.Logger.Printf("Train Information: %s , MessageType: CPA, Caller: %s, RecordFileName: %s", trainInfo, caller, DstFile)
  254. } else if strings.Contains(event["FILENAME"], "EMG") {
  255. utils.Logger.Printf("Train Information: %s , MessageType: EMG, RecordFileName: %s", trainInfo, DstFile)
  256. } else if strings.Contains(event["FILENAME"], "STN") {
  257. utils.Logger.Printf("Train Information: %s , MessageType: STN, RecordFileName: %s", trainInfo, DstFile)
  258. } else if strings.Contains(event["FILENAME"], "DCS") {
  259. utils.Logger.Printf("Train Information: %s , MessageType: DCS, RecordFileName: %s", trainInfo, DstFile)
  260. } else if strings.Contains(event["FILENAME"], "SPC") {
  261. utils.Logger.Printf("Train Information: %s , MessageType: SPC, RecordFileName: %s", trainInfo, DstFile)
  262. } else if strings.Contains(event["FILENAME"], "CHK") {
  263. utils.Logger.Printf("Train Information: %s , MessageType: Self Check, RecordFileName: %s", trainInfo, DstFile)
  264. } else if strings.Contains(event["FILENAME"], "TONE") {
  265. utils.Logger.Printf("Train Information: %s , MessageType: TONE Test, RecordFileName: %s", trainInfo, DstFile)
  266. } else if strings.Contains(event["FILENAME"], "PA") {
  267. _, caller, _ := utils.GetPadInfo(event["FILENAME"])
  268. utils.Logger.Printf("Train Information: %s , MessageType: PA, Caller: %s, RecordFileName: %s", trainInfo, caller, DstFile)
  269. }
  270. }
  271. //Get path & generate recording XML file
  272. path := filepath.Dir(event["FILENAME"])
  273. rcdFileName := filepath.Base(event["FILENAME"])
  274. xmlFileName := strings.Replace(rcdFileName, "wav", "xml", 1)
  275. xmlFilePath := path + "/" + xmlFileName
  276. //lfshook.NewLogger().Infof("Train info= xml path============%s===============", xmlFilePath)
  277. utils.LoggerDebug.Printf("Write record info xml : %s !", xmlFilePath)
  278. err := active.GenerateXML(xmlFilePath)
  279. if err != nil {
  280. //lfshook.NewLogger().Infof("Generate recording XML err:%+v", err)
  281. utils.LoggerDebug.Printf("Write record info xml : %s ERR: %+v ", xmlFilePath, err)
  282. break
  283. }
  284. } else {
  285. //lfshook.NewLogger().Infof("No files to upload!!!")
  286. break
  287. }
  288. }
  289. case "Hangup":
  290. //lfshook.NewLogger().Infof("%s", event["Event"])
  291. //OCC answer PAD, hangup, redirect the next PAD to OCC
  292. if utils.IsIO(event["CallerIDNum"]) && (event["ConnectedLineNum"] == "ano1" || event["ConnectedLineNum"] == "ano8") && event["Context"] == "default" {
  293. utils.LoggerDebug.Printf("Check PAD-OCC queue if there are PADs need to be redirect to OCC !")
  294. res, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
  295. if res == nil {
  296. utils.LoggerDebug.Printf("Check PAD-OCC queue , return nill . exit !")
  297. return
  298. }
  299. if res.Calls == "0" { //OCC queue is empty
  300. utils.LoggerDebug.Printf("Check PAD-OCC queue no PAD now ! Send PAD-OCC end to STC .")
  301. alstatus.OccPad("end")
  302. priority.OCCAnswer = 0
  303. priority.PADOccStart = 0
  304. //clean confbridge
  305. taskTmp, _ := priority.RegistryTask.Get("PAD-OCC")
  306. priority.RegistryTask.StopAndUnregister("PAD-OCC")
  307. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  308. //check resume
  309. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  310. if ok {
  311. if taskName == "EMG" {
  312. EMGConfbridgeReinvite(task.ConfbridgeID)
  313. } else if taskName == "CPA" {
  314. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  315. alstatus.PaStatus("", "CPA", "start")
  316. }
  317. }
  318. }
  319. //break
  320. } else { //OCC queue is not empty
  321. utils.LoggerDebug.Printf("PAD goto OCC , interrupt other task !")
  322. // OCC hangup detected, hangup other running channels
  323. runningTaskName := InterruptRunningTask("PAD-OCC")
  324. if runningTaskName != "" {
  325. time.Sleep(time.Millisecond * 100) //wait endpoint release
  326. }
  327. //time.Sleep(time.Millisecond * 100) //wait io idle
  328. //lfshook.NewLogger().Infof("====Start OCC-PAD===next==%+v", res)
  329. if active.TrainDevide == 0 { //列车没有断开
  330. if (active.ActivedCab == "1" && ExtenStatus("1411") == "Idle") || (active.ActivedCab == "" && active.ActivedCabDelay == "1" && ExtenStatus("1411") == "Idle") { //check active and OCC status
  331. time.Sleep(time.Second)
  332. PADChan := ""
  333. if res.Entrys != nil {
  334. for _, chanEntry := range res.Entrys {
  335. lfshook.NewLogger().Infof("PAD answered by OCC1 pos:%s chan:%s", chanEntry.Position, chanEntry.Channel)
  336. if chanEntry.Position == "1" {
  337. PADChan = chanEntry.Channel
  338. utils.LoggerDebug.Printf("PAD-OCC , Get the first PAD(%s) in the queue !", PADChan)
  339. break
  340. }
  341. }
  342. if PADChan != "" {
  343. Ext := strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0]
  344. alstatus.AlarmStatus(Ext, "connect")
  345. utils.LoggerDebug.Printf("PAD goto OCC1 , redirect %s to OCC1 !", PADChan)
  346. go RedirectInQueue(PADChan, "1411", "pad-page-occ-icp", Ext) //PAD Page(OCC+ICPs)
  347. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
  348. } else {
  349. lfshook.NewLogger().Infof("OCC-QueueStatus PADCchan NULL")
  350. utils.LoggerDebug.Printf("PAD-OCC , OCC Queue Status PADCchan return NULL .")
  351. }
  352. }
  353. break
  354. } else if (active.ActivedCab == "8" && ExtenStatus("1481") == "Idle") || (active.ActivedCab == "" && active.ActivedCabDelay == "8" && ExtenStatus("1481") == "Idle") {
  355. time.Sleep(time.Second)
  356. PADChan := ""
  357. if res.Entrys != nil {
  358. for _, chanEntry := range res.Entrys {
  359. lfshook.NewLogger().Infof("PAD answered by OCC1 pos:%s chan:%s", chanEntry.Position, chanEntry.Channel)
  360. if chanEntry.Position == "1" {
  361. PADChan = chanEntry.Channel
  362. utils.LoggerDebug.Printf("PAD-OCC , Get the first PAD(%s) in the queue !", PADChan)
  363. break
  364. }
  365. }
  366. if PADChan != "" {
  367. Ext := strings.Split(strings.Split(res.Entrys[0].Channel, "/")[1], "-")[0]
  368. alstatus.AlarmStatus(Ext, "connect")
  369. utils.LoggerDebug.Printf("PAD goto OCC8 , redirect %s to OCC8 !", PADChan)
  370. go RedirectInQueue(PADChan, "1481", "pad-page-occ-icp", Ext) //PAD Page(OCC+ICPs)
  371. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC1
  372. } else {
  373. lfshook.NewLogger().Infof("OCC QueueStatus PADCchan NULL")
  374. }
  375. }
  376. break
  377. }
  378. } else { //列车断开模式下
  379. if active.ActivedCab == "1" && ExtenStatus("1411") == "Idle" { //check active and OCC status
  380. alstatus.AlarmStatus(event["CallerIDNum"], "connect")
  381. go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
  382. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
  383. } else if active.ActivedCab == "8" && ExtenStatus("1481") == "Idle" {
  384. alstatus.AlarmStatus(event["CallerIDNum"], "connect")
  385. go RedirectInQueue(event["Channel"], "1481", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
  386. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC8
  387. }
  388. }
  389. }
  390. }
  391. if utils.IsPAIU(event["CallerIDNum"]) { // PAD hangup, check if PAD all end, send PAD end status
  392. number := strings.Split(strings.Split(event["Channel"], "-")[0], "/")[1]
  393. lfshook.NewLogger().Infof("===hangup PAD ===NUM:%s=================listAllTask:%+v===", number, priority.RegistryTask.ListAll())
  394. if utils.IsPAIU(number) { //pad and io hangup
  395. //clean confbridge & clean task info
  396. //PAD-ICP
  397. taskTmp, ok := priority.RegistryTask.Get("PAD-ICP")
  398. if ok {
  399. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  400. priority.RegistryTask.StopAndUnregister("PAD-ICP")
  401. }
  402. // PAD-TMS
  403. taskTmp, ok = priority.RegistryTask.Get("PAD-TMS")
  404. if ok {
  405. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  406. priority.RegistryTask.StopAndUnregister("PAD-TMS")
  407. }
  408. //PAD-OCC
  409. taskTmp, ok = priority.RegistryTask.Get("PAD-OCC")
  410. if ok {
  411. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  412. priority.RegistryTask.StopAndUnregister("PAD-OCC")
  413. }
  414. lfshook.NewLogger().Infof("===hangup PAD ===NUM:%s========2222=========listAllTask:%+v===", number, priority.RegistryTask.ListAll())
  415. //Check PAD END
  416. res, _ := QueueStatus("0300", "") // check ICP queue ,if empty PAD end
  417. res1, _ := QueueStatus("0301", "") // check OCC queue ,if empty PAD end
  418. if res == nil || res1 == nil {
  419. utils.LoggerDebug.Printf("PAD Hangup , check ICP|OCC queue return nil, exit.")
  420. return
  421. }
  422. lfshook.NewLogger().Infof("===Hangup PAD====== ICP Queue calls:%s OCC Queue calls:%s", res.Calls, res1.Calls)
  423. if res.Calls == "0" && res1.Calls == "0" {
  424. if priority.PADStart == 1 {
  425. //SetPadTimer()
  426. alstatus.PaStatus("", "PAD", "end")
  427. priority.PADStart = 0
  428. //priority.PADTMSStart = 0
  429. /*
  430. //clean confbridge
  431. //PAD-ICP
  432. taskTmp, ok := priority.RegistryTask.Get("PAD-ICP")
  433. if ok {
  434. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  435. }
  436. priority.RegistryTask.StopAndUnregister("PAD-ICP")
  437. // PAD-TMS
  438. taskTmp, ok = priority.RegistryTask.Get("PAD-TMS")
  439. if ok {
  440. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  441. }
  442. priority.RegistryTask.StopAndUnregister("PAD-TMS")
  443. //PAD-OCC
  444. taskTmp, ok = priority.RegistryTask.Get("PAD-OCC")
  445. if ok {
  446. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  447. }
  448. priority.RegistryTask.StopAndUnregister("PAD-OCC")
  449. */
  450. //check resume
  451. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  452. if ok {
  453. if taskName == "EMG" {
  454. EMGConfbridgeReinvite(task.ConfbridgeID)
  455. //alstatus.PaStatus("", "EMG", "start")
  456. } else if taskName == "CPA" {
  457. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  458. alstatus.PaStatus("", "CPA", "start")
  459. }
  460. }
  461. }
  462. }
  463. priority.ICPAnswer = 0
  464. priority.OCCAnswer = 0
  465. break
  466. }
  467. }
  468. }
  469. //ICP 按下CABCAB,之后按RST取消,CABCAB建立失败
  470. if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0400" && event["ChannelStateDesc"] == "Ringing" {
  471. utils.LoggerDebug.Printf("CABCAB Canceled !")
  472. //time.Sleep(2 * time.Second)
  473. if priority.TaskCreating == "C2C" {
  474. utils.LoggerDebug.Printf("C2C : Clean priority.TaskCreating = '' !")
  475. priority.TaskCreating = ""
  476. }
  477. //check resume
  478. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  479. if ok {
  480. if taskName == "EMG" {
  481. EMGConfbridgeReinvite(task.ConfbridgeID)
  482. //alstatus.PaStatus("", "EMG", "start")
  483. } else if taskName == "CPA" {
  484. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  485. alstatus.PaStatus("", "CPA", "start")
  486. }
  487. }
  488. }
  489. }
  490. case "QueueCallerJoin":
  491. lfshook.NewLogger().Infof("=========%s", event["Event"])
  492. if priority.OCCAnswer == 1 && event["Queue"] == "0300" { //New PAD Goto the OCC queue in the first time, if OCC answered
  493. utils.LoggerDebug.Printf("Redirect PAD %s to OCC queue .", event["CallerIDNum"])
  494. alstatus.AlarmStatus(event["CallerIDNum"], "queue") //send status to STC
  495. go RedirectInQueue(event["CallerIDNum"], "0301", "queues-occ", event["CallerIDNum"])
  496. break
  497. }
  498. if utils.IsPAIU(event["CallerIDNum"]) && utils.IsPAIU(event["CallerIDName"]) && event["Queue"] == "0300" { // Alarm join the queue, PAD in the queue
  499. alstatus.AlarmStatus(event["CallerIDNum"], "queue") //send status to STC
  500. ICPQueue, err := QueueStatus("0300", "") // check ICP queue, get entries
  501. if err != nil {
  502. lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
  503. return
  504. }
  505. if ICPQueue == nil {
  506. return
  507. }
  508. if priority.ICPAnswer == 0 && ICPQueue.Calls == "1" { //ICP did not answer any first call to the ICP queue ; Ready to Set Occ Queue Timer
  509. toRunpriority := priority.GetPriorityByKey("PAD-ICP")
  510. time.Sleep(time.Millisecond * 500) //wait high priority task start
  511. _, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
  512. if ok {
  513. //lfshook.NewLogger().Infof("=1==QueueCallerJoin===runing:%d=====toRun:=%d==Status:%s", taskTmp, toRunpriority, event["ChannelStateDesc"])
  514. if taskTmp.Priority < toRunpriority { //higher priority task running ,do not set timer
  515. utils.LoggerDebug.Printf("The First PAD %s enter ICP queue , %s running do not set PAD timeout.", taskTmp.RunType, event["CallerIDNum"])
  516. break
  517. }
  518. }
  519. //lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
  520. if active.QueueTimer != nil {
  521. if active.QueueTimer.Stop() {
  522. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  523. } else {
  524. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  525. }
  526. }
  527. //lfshook.NewLogger().Logger.Infof("=========Start PAD timer !======%d=======", active.PADTimeout)
  528. utils.LoggerDebug.Printf("The first PAD %s enter ICP queue , set PAD timeout %d sec .", event["CallerIDNum"], active.PADTimeout)
  529. active.QueueTimer = time.AfterFunc(time.Duration(active.PADTimeout)*time.Second, func() { // check the PAD 30s timeout
  530. //active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
  531. //if both not active , return
  532. //if active.ActivedCab == "" {
  533. // return
  534. //}
  535. res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
  536. if err != nil {
  537. lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
  538. return
  539. }
  540. if res == nil {
  541. return
  542. }
  543. if res.Calls == "0" { // OCC queue empty
  544. resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
  545. if err != nil {
  546. lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
  547. return
  548. }
  549. if resCaller.Entrys != nil {
  550. sort.Slice(resCaller.Entrys, func(i, j int) bool {
  551. return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
  552. })
  553. for _, caller := range resCaller.Entrys {
  554. priority.ICPAnswer = 0
  555. //lfshook.NewLogger().Infof("====QueueCallerJoin==QueueTimer===%s", event["Event"])
  556. //lfshook.NewLogger().Infof("Redirect to 0301 extension:%s Pos:%s", caller.CallerIDNum, caller.Position)
  557. //order by pos
  558. utils.LoggerDebug.Printf("Redirect %s to OCC queue Pos:%s", caller.CallerIDNum, caller.Position)
  559. RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
  560. time.Sleep(time.Millisecond * 100) //200 ms delay
  561. }
  562. }
  563. }
  564. })
  565. }
  566. break
  567. }
  568. //first PAD caller goto OCC
  569. //OCC dial PACUs;
  570. //PAD Page OCC+ICPs;
  571. if utils.IsPAIU(event["CallerIDNum"]) && event["Queue"] == "0301" && priority.OCCAnswer == 0 { // The first PAD to OCC ,caller is PAD
  572. utils.LoggerDebug.Printf("The first PAD to OCC queue .")
  573. WaitTaskCreate("PAD-OCC")
  574. if priority.CheckPriority("PAD-OCC") {
  575. runningTaskName := InterruptRunningTask("PAD-OCC") //PAD-OCC interrupt other
  576. if runningTaskName != "" {
  577. time.Sleep(time.Millisecond * 100) //wait endpoint release
  578. }
  579. priority.OCCAnswer = 1
  580. time.Sleep(time.Millisecond * 300)
  581. if active.TrainDevide == 0 { //列车没有断开
  582. if (active.ActivedCab == "1" && ExtenStatus("1411") == "Idle") || (active.ActivedCab == "" && active.ActivedCabDelay == "1" && ExtenStatus("1411") == "Idle") { //check active and OCC status
  583. utils.LoggerDebug.Printf("PAD %s goto OCC1 .", event["CallerIDNum"])
  584. alstatus.AlarmStatus(event["CallerIDNum"], "connect")
  585. go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
  586. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
  587. } else if (active.ActivedCab == "8" && ExtenStatus("1481") == "Idle") || (active.ActivedCab == "" && active.ActivedCabDelay == "8" && ExtenStatus("1481") == "Idle") {
  588. utils.LoggerDebug.Printf("PAD %s goto OCC8 .", event["CallerIDNum"])
  589. alstatus.AlarmStatus(event["CallerIDNum"], "connect")
  590. go RedirectInQueue(event["Channel"], "1481", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
  591. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC8
  592. }
  593. } else { //列车断开模式下
  594. if active.ActivedCab == "1" && ExtenStatus("1411") == "Idle" { //check active and OCC status
  595. alstatus.AlarmStatus(event["CallerIDNum"], "connect")
  596. go RedirectInQueue(event["Channel"], "1411", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
  597. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano1", "ano1", "1") // PACUs dial OCC1
  598. } else if active.ActivedCab == "8" && ExtenStatus("1481") == "Idle" {
  599. alstatus.AlarmStatus(event["CallerIDNum"], "connect")
  600. go RedirectInQueue(event["Channel"], "1481", "pad-page-occ-icp", event["CallerIDNum"]) //PAD Page(OCC+ICPs)
  601. go Dial("0401", "0512", "pad-rule-pacus-occ", "ano8", "ano8", "8") // PACUs dial OCC8
  602. }
  603. }
  604. } else {
  605. if priority.TaskCreating == "PAD-OCC" {
  606. utils.LoggerDebug.Printf("PAD-OCC : Clean priority.TaskCreating = '' !")
  607. priority.TaskCreating = ""
  608. }
  609. utils.LoggerDebug.Printf("PAD-OCC calling failed , check priority return false !")
  610. lfshook.NewLogger().Infof("====PAD-OCC Priority false===")
  611. }
  612. time.Sleep(1 * time.Second)
  613. if priority.TaskCreating == "PAD-OCC" {
  614. utils.LoggerDebug.Printf("PAD-OCC : Clean priority.TaskCreating = '' !")
  615. priority.TaskCreating = ""
  616. }
  617. }
  618. case "ConfbridgeJoin":
  619. lfshook.NewLogger().Infof("=========%+v", event["Event"])
  620. //lfshook.NewLogger().Infof("=========%+v", event)
  621. //set priority and send PA status msg
  622. switch event["CallerIDName"] {
  623. case "EMG":
  624. if event["Exten"] == "0502" {
  625. //================================
  626. task := priority.TaskInfo{
  627. RunChannel: event["Channel"],
  628. LocalChan: event["Channel"],
  629. RunType: "EMG",
  630. Priority: priority.AllTasks.EMG.Priority,
  631. ConfbridgeID: event["Conference"],
  632. Running: true,
  633. }
  634. utils.LoggerDebug.Printf("%s Runing , Set %s task info %+v .", event["CallerIDName"], event["CallerIDName"], task)
  635. priority.RegistryTask.Register("EMG", task)
  636. if priority.TaskCreating == "EMG" {
  637. utils.LoggerDebug.Printf("EMG Connected : Clean priority.TaskCreating = '' !")
  638. priority.TaskCreating = ""
  639. }
  640. alstatus.PaStatus("", "EMG", "start")
  641. //check PAD timer
  642. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.EMG.Priority {
  643. if active.QueueTimer != nil {
  644. if active.QueueTimer.Stop() {
  645. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  646. } else {
  647. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  648. }
  649. }
  650. }
  651. return
  652. }
  653. case "SPC":
  654. if event["Exten"] == "0505" {
  655. //================================
  656. task := priority.TaskInfo{
  657. RunChannel: event["Channel"],
  658. LocalChan: event["Channel"],
  659. RunType: "SPC",
  660. Priority: priority.AllTasks.SPC.Priority,
  661. ConfbridgeID: event["Conference"],
  662. Running: true,
  663. }
  664. utils.LoggerDebug.Printf("%s Runing , Set %s task info %+v .", event["CallerIDName"], event["CallerIDName"], task)
  665. priority.RegistryTask.Register("SPC", task)
  666. alstatus.PaStatus("", "SPC", "start")
  667. if priority.TaskCreating == "SPC" {
  668. utils.LoggerDebug.Printf("SPC Connected : Clean priority.TaskCreating = '' !")
  669. priority.TaskCreating = ""
  670. }
  671. //check PAD timer
  672. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.SPC.Priority {
  673. if active.QueueTimer != nil {
  674. if active.QueueTimer.Stop() {
  675. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  676. } else {
  677. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  678. }
  679. }
  680. }
  681. return
  682. }
  683. case "DCS":
  684. if event["Exten"] == "0504" {
  685. //================================
  686. task := priority.TaskInfo{
  687. RunChannel: event["Channel"],
  688. LocalChan: event["Channel"],
  689. RunType: "DCS",
  690. Priority: priority.AllTasks.DCS.Priority,
  691. ConfbridgeID: event["Conference"],
  692. Running: true,
  693. }
  694. utils.LoggerDebug.Printf("%s Runing , Set %s task info %+v .", event["CallerIDName"], event["CallerIDName"], task)
  695. priority.RegistryTask.Register("DCS", task)
  696. alstatus.PaStatus("", "DCS", "start")
  697. if priority.TaskCreating == "DCS" {
  698. utils.LoggerDebug.Printf("DCS Connected : Clean priority.TaskCreating = '' !")
  699. priority.TaskCreating = ""
  700. }
  701. //check PAD timer
  702. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.DCS.Priority {
  703. if active.QueueTimer != nil {
  704. if active.QueueTimer.Stop() {
  705. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  706. } else {
  707. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  708. }
  709. }
  710. }
  711. return
  712. }
  713. case "STN":
  714. if event["Exten"] == "0503" {
  715. //================================
  716. task := priority.TaskInfo{
  717. RunChannel: event["Channel"],
  718. LocalChan: event["Channel"],
  719. RunType: "STN",
  720. Priority: priority.AllTasks.STN.Priority,
  721. ConfbridgeID: event["Conference"],
  722. Running: true,
  723. }
  724. utils.LoggerDebug.Printf("%s Runing , Set %s task info %+v .", event["CallerIDName"], event["CallerIDName"], task)
  725. priority.RegistryTask.Register("STN", task)
  726. alstatus.PaStatus("", "STN", "start")
  727. if priority.TaskCreating == "STN" {
  728. utils.LoggerDebug.Printf("STN Connected : Clean priority.TaskCreating = '' !")
  729. priority.TaskCreating = ""
  730. }
  731. //check PAD timer
  732. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.STN.Priority {
  733. if active.QueueTimer != nil {
  734. if active.QueueTimer.Stop() {
  735. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  736. } else {
  737. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  738. }
  739. }
  740. }
  741. return
  742. }
  743. case "CHK":
  744. if event["Exten"] == "0510" {
  745. //================================
  746. task := priority.TaskInfo{
  747. RunChannel: event["Channel"],
  748. LocalChan: event["Channel"],
  749. RunType: "CHK",
  750. Priority: priority.AllTasks.CHK.Priority,
  751. ConfbridgeID: event["Conference"],
  752. Running: true,
  753. }
  754. utils.LoggerDebug.Printf("%s Runing , Set %s task info %+v .", event["CallerIDName"], event["CallerIDName"], task)
  755. priority.RegistryTask.Register("CHK", task)
  756. alstatus.PaStatus("", "CHK", "start")
  757. if priority.TaskCreating == "CHK" {
  758. utils.LoggerDebug.Printf("CHK Connected : Clean priority.TaskCreating = '' !")
  759. priority.TaskCreating = ""
  760. }
  761. //check PAD timer
  762. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.CHK.Priority {
  763. if active.QueueTimer != nil {
  764. if active.QueueTimer.Stop() {
  765. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  766. } else {
  767. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  768. }
  769. }
  770. }
  771. return
  772. }
  773. case "VOL": // tone-test
  774. if event["Exten"] == "0513" {
  775. //================================
  776. task := priority.TaskInfo{
  777. RunChannel: event["Channel"],
  778. LocalChan: event["Channel"],
  779. RunType: "VOL",
  780. Priority: priority.AllTasks.VOL.Priority,
  781. ConfbridgeID: event["Conference"],
  782. Running: true,
  783. }
  784. utils.LoggerDebug.Printf("%s Runing , Set %s task info %+v .", event["CallerIDName"], event["CallerIDName"], task)
  785. priority.RegistryTask.Register("VOL", task)
  786. alstatus.PaStatus("", "VOL", "start")
  787. if priority.TaskCreating == "VOL" {
  788. utils.LoggerDebug.Printf("VOL Connected : Clean priority.TaskCreating = '' !")
  789. priority.TaskCreating = ""
  790. }
  791. //check PAD timer
  792. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.VOL.Priority {
  793. if active.QueueTimer != nil {
  794. if active.QueueTimer.Stop() {
  795. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  796. } else {
  797. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  798. }
  799. }
  800. }
  801. return
  802. }
  803. }
  804. /*
  805. //get confbridge id for join back to confbridge
  806. if event["Context"] == "pad-page-occ-icp" && utils.IsPAIU(event["CallerIDNum"]) {
  807. //active.ICPCONBID = event["Conference"] //pad-occ
  808. priority.AllTasks.PADOCC.ConfbridgeID = event["Conference"]
  809. }
  810. */
  811. //Send PA start msg to STC
  812. if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start
  813. alstatus.PaStatus(event["CallerIDNum"], "PA", "start")
  814. //================================
  815. task := priority.TaskInfo{
  816. RunChannel: event["Channel"],
  817. LocalChan: event["Channel"],
  818. RunType: "PA",
  819. Priority: priority.AllTasks.PA.Priority,
  820. ConfbridgeID: event["Conference"],
  821. Running: true,
  822. }
  823. priority.PAInterrupt = 0
  824. utils.LoggerDebug.Printf("PA Runing , Set PA task info %+v .", task)
  825. priority.RegistryTask.Register("PA", task)
  826. if priority.TaskCreating == "PA" {
  827. utils.LoggerDebug.Printf("PA Connected : Clean priority.TaskCreating = '' !")
  828. priority.TaskCreating = ""
  829. }
  830. //check PAD timer
  831. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.PA.Priority {
  832. if active.QueueTimer != nil {
  833. if active.QueueTimer.Stop() {
  834. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  835. } else {
  836. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  837. }
  838. }
  839. }
  840. break
  841. } else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA start
  842. alstatus.PaStatus(event["CallerIDNum"], "CPA", "start")
  843. //================================
  844. task := priority.TaskInfo{
  845. RunChannel: event["Channel"],
  846. LocalChan: event["Channel"],
  847. RunType: "CPA",
  848. Priority: priority.AllTasks.CPA.Priority,
  849. ConfbridgeID: event["Conference"],
  850. Running: true,
  851. }
  852. utils.LoggerDebug.Printf("CPA Runing , Set CPA task info %+v .", task)
  853. priority.RegistryTask.Register("CPA", task)
  854. utils.LoggerDebug.Printf("CPA Runing , Set CPA task info %+v .", priority.RegistryTask.ListAll())
  855. if priority.TaskCreating == "CPA" {
  856. utils.LoggerDebug.Printf("CPA Connected : Clean priority.TaskCreating = '' !")
  857. priority.TaskCreating = ""
  858. }
  859. //check PAD timer
  860. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.CPA.Priority {
  861. if active.QueueTimer != nil {
  862. if active.QueueTimer.Stop() {
  863. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  864. } else {
  865. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  866. }
  867. }
  868. }
  869. return
  870. }
  871. //ICP answer PAD;PACUs connected ICP
  872. //PAD chanspy ICP1
  873. //ICP8 call PAD
  874. if event["ConnectedLineNum"] == "ani1" && event["Exten"] == "0511" { //PAD answered by ICP; PACUs connected ICP1
  875. //lfshook.NewLogger().Infof("====PAD answered by ICP1:%s=====", event["ConnectedLineName"])
  876. alstatus.AlarmStatus(event["ConnectedLineName"], "connect")
  877. //================================
  878. task := priority.TaskInfo{
  879. RunChannel: event["Channel"],
  880. LocalChan: event["Channel"],
  881. RunType: "PAD-ICP",
  882. Priority: priority.AllTasks.PADICP.Priority,
  883. ConfbridgeID: event["Conference"],
  884. Running: true,
  885. }
  886. priority.RegistryTask.Register("PAD-ICP", task)
  887. if priority.TaskCreating == "PAD-ICP" {
  888. utils.LoggerDebug.Printf("PAD-ICP Connected : Clean priority.TaskCreating = '' !")
  889. priority.TaskCreating = ""
  890. }
  891. utils.LoggerDebug.Printf("PAD %s answered by ICP1 , set task info :%+v .", event["ConnectedLineName"], task)
  892. //lfshook.NewLogger().Infof("=========PAD-ICP answer==ListAll===%+v", priority.RegistryTask.ListAll())
  893. go RedirectInQueue(event["ConnectedLineName"], "2311", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP1
  894. if ExtenStatus("2381") == "Idle" {
  895. go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "8") // PAD call ICP8
  896. }
  897. }
  898. if event["ConnectedLineNum"] == "ani8" && event["Exten"] == "0511" { //PAD ansered by ICP8; PACUs connected ICP8
  899. lfshook.NewLogger().Infof("====PAD answered by ICP8:%s=====", event["ConnectedLineName"])
  900. alstatus.AlarmStatus(event["ConnectedLineName"], "connect")
  901. //================================
  902. task := priority.TaskInfo{
  903. RunChannel: event["Channel"],
  904. LocalChan: event["Channel"],
  905. RunType: "PAD-ICP",
  906. Priority: priority.AllTasks.PADICP.Priority,
  907. ConfbridgeID: event["Conference"],
  908. Running: true,
  909. }
  910. priority.RegistryTask.Register("PAD-ICP", task)
  911. if priority.TaskCreating == "PAD-ICP" {
  912. utils.LoggerDebug.Printf("PAD-ICP Connected : Clean priority.TaskCreating = '' !")
  913. priority.TaskCreating = ""
  914. }
  915. utils.LoggerDebug.Printf("PAD %s answered by ICP8 , set task info :%+v .", event["ConnectedLineName"], task)
  916. //lfshook.NewLogger().Infof("=========PAD-ICP answer==ListAll===%+v", priority.RegistryTask.ListAll())
  917. go RedirectInQueue(event["ConnectedLineName"], "2381", "chanspy-rule-whisper", event["ConnectedLineName"]) //PAD chanspy(EqW) ICP8
  918. if ExtenStatus("2311") == "Idle" {
  919. go Dial("0402", event["ConnectedLineName"], "call-pad-rule", event["ConnectedLineName"], event["ConnectedLineName"], "1") // PAD call ICP1
  920. }
  921. break
  922. }
  923. //OCC answer PAD;Set the task channel
  924. if utils.IsPAIU(event["CallerIDNum"]) && utils.IsIO(event["Exten"]) && event["Context"] == "pad-page-occ-icp" { //PAD Page OCC1+ICPs connected
  925. lfshook.NewLogger().Infof("====PAD answered by OCC:====")
  926. //================================
  927. task := priority.TaskInfo{
  928. RunChannel: event["Channel"],
  929. LocalChan: event["Channel"],
  930. RunType: "PAD-OCC",
  931. Priority: priority.AllTasks.PADOCC.Priority,
  932. ConfbridgeID: event["Conference"],
  933. Running: true,
  934. }
  935. priority.RegistryTask.Register("PAD-OCC", task)
  936. if priority.TaskCreating == "PAD-OCC" {
  937. utils.LoggerDebug.Printf("PAD-OCC Connected : Clean priority.TaskCreating = '' !")
  938. priority.TaskCreating = ""
  939. }
  940. utils.LoggerDebug.Printf("PAD %s answered by OCC , set task info :%+v .", event["CallerIDNum"], task)
  941. break
  942. }
  943. case "ConfbridgeLeave":
  944. lfshook.NewLogger().Infof("=========%s", event["Event"])
  945. if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA end
  946. alstatus.PaStatus(event["CallerIDNum"], "PA", "end")
  947. priority.RegistryTask.StopAndUnregister("PA")
  948. SetPadTimer()
  949. // check resume
  950. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  951. if ok {
  952. if taskName == "EMG" {
  953. EMGConfbridgeReinvite(task.ConfbridgeID)
  954. //alstatus.PaStatus("", "EMG", "start")
  955. } else if taskName == "CPA" {
  956. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  957. alstatus.PaStatus("", "CPA", "start")
  958. }
  959. }
  960. }
  961. } else if utils.IsIO(event["CallerIDNum"]) && event["Exten"] == "0501" { //CPA end
  962. alstatus.PaStatus(event["CallerIDNum"], "CPA", "end")
  963. //CPA
  964. taskTmp, ok := priority.RegistryTask.Get("CPA")
  965. if ok {
  966. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  967. }
  968. priority.RegistryTask.StopAndUnregister("CPA")
  969. SetPadTimer()
  970. //check resume
  971. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  972. if ok {
  973. if taskName == "EMG" {
  974. EMGConfbridgeReinvite(task.ConfbridgeID)
  975. //alstatus.PaStatus("", "EMG", "start")
  976. }
  977. }
  978. //lfshook.NewLogger().Infof("=========%s", event["Event"])
  979. } else if event["CallerIDName"] == "EMG" && event["Exten"] == "0502" { // EMG broadcast hangup
  980. alstatus.PaStatus("", "EMG", "end")
  981. //EMG
  982. taskTmp, ok := priority.RegistryTask.Get("EMG")
  983. if ok {
  984. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  985. }
  986. priority.RegistryTask.StopAndUnregister("EMG")
  987. SetPadTimer()
  988. //check resume
  989. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  990. if ok {
  991. if taskName == "CPA" {
  992. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  993. alstatus.PaStatus("", "CPA", "start")
  994. }
  995. }
  996. }
  997. } else if event["CallerIDName"] == "STN" && event["Exten"] == "0503" {
  998. alstatus.PaStatus("", "STN", "end")
  999. //STN
  1000. taskTmp, ok := priority.RegistryTask.Get("STN")
  1001. if ok {
  1002. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  1003. }
  1004. priority.RegistryTask.StopAndUnregister("STN")
  1005. SetPadTimer()
  1006. //check resume
  1007. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1008. if ok {
  1009. if taskName == "CPA" {
  1010. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  1011. alstatus.PaStatus("", "CPA", "start")
  1012. }
  1013. } else if taskName == "EMG" {
  1014. EMGConfbridgeReinvite(task.ConfbridgeID)
  1015. //alstatus.PaStatus("", "EMG", "start")
  1016. }
  1017. }
  1018. } else if event["CallerIDName"] == "DCS" && event["Exten"] == "0504" {
  1019. alstatus.PaStatus("", "DCS", "end")
  1020. //DSC
  1021. taskTmp, ok := priority.RegistryTask.Get("DCS")
  1022. if ok {
  1023. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  1024. }
  1025. priority.RegistryTask.StopAndUnregister("DCS")
  1026. SetPadTimer()
  1027. //check resume
  1028. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1029. if ok {
  1030. if taskName == "CPA" {
  1031. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  1032. alstatus.PaStatus("", "CPA", "start")
  1033. }
  1034. } else if taskName == "EMG" {
  1035. EMGConfbridgeReinvite(task.ConfbridgeID)
  1036. //alstatus.PaStatus("", "EMG", "start")
  1037. }
  1038. }
  1039. } else if event["CallerIDName"] == "SPC" && event["Exten"] == "0505" {
  1040. alstatus.PaStatus("", "SPC", "end")
  1041. //SPC
  1042. taskTmp, ok := priority.RegistryTask.Get("SPC")
  1043. if ok {
  1044. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  1045. }
  1046. priority.RegistryTask.StopAndUnregister("SPC")
  1047. SetPadTimer()
  1048. //check resume
  1049. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1050. if ok {
  1051. if taskName == "CPA" {
  1052. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  1053. alstatus.PaStatus("", "CPA", "start")
  1054. }
  1055. } else if taskName == "EMG" {
  1056. EMGConfbridgeReinvite(task.ConfbridgeID)
  1057. //alstatus.PaStatus("", "EMG", "start")
  1058. }
  1059. }
  1060. } else if event["CallerIDName"] == "CHK" && event["Exten"] == "0510" {
  1061. alstatus.PaStatus("", "CHK", "end")
  1062. //CHK
  1063. taskTmp, ok := priority.RegistryTask.Get("CHK")
  1064. if ok {
  1065. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  1066. }
  1067. priority.RegistryTask.StopAndUnregister("CHK")
  1068. SetPadTimer()
  1069. //check resume
  1070. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1071. if ok {
  1072. if taskName == "CPA" {
  1073. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  1074. alstatus.PaStatus("", "CPA", "start")
  1075. }
  1076. } else if taskName == "EMG" {
  1077. EMGConfbridgeReinvite(task.ConfbridgeID)
  1078. //alstatus.PaStatus("", "EMG", "start")
  1079. }
  1080. }
  1081. } else if event["CallerIDName"] == "VOL" && event["Exten"] == "0513" {
  1082. alstatus.PaStatus("", "VOL", "end")
  1083. //VOL
  1084. taskTmp, ok := priority.RegistryTask.Get("VOL")
  1085. if ok {
  1086. ConfbridgeKick(taskTmp.ConfbridgeID, "all")
  1087. }
  1088. priority.RegistryTask.StopAndUnregister("VOL")
  1089. SetPadTimer()
  1090. //check resume
  1091. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1092. if ok {
  1093. if taskName == "CPA" {
  1094. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  1095. alstatus.PaStatus("", "CPA", "start")
  1096. }
  1097. } else if taskName == "EMG" {
  1098. EMGConfbridgeReinvite(task.ConfbridgeID)
  1099. //alstatus.PaStatus("", "EMG", "start")
  1100. }
  1101. }
  1102. }
  1103. case "DialEnd":
  1104. //lfshook.NewLogger().Infof("=========%s", event["Event"])
  1105. //Cab Cab start
  1106. if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0400" && event["DialStatus"] == "ANSWER" {
  1107. //================================
  1108. task := priority.TaskInfo{
  1109. RunChannel: event["Channel"],
  1110. LocalChan: event["Channel"],
  1111. RunType: "C2C",
  1112. Priority: priority.AllTasks.C2C.Priority,
  1113. ConfbridgeID: "",
  1114. Running: true,
  1115. }
  1116. priority.CABInterrupt = 0
  1117. priority.RegistryTask.Register("C2C", task)
  1118. alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
  1119. if priority.TaskCreating == "C2C" {
  1120. utils.LoggerDebug.Printf("C2C Connected : Clean priority.TaskCreating = '' !")
  1121. priority.TaskCreating = ""
  1122. }
  1123. //check PAD timer
  1124. if priority.AllTasks.PADOCC.Priority > priority.AllTasks.C2C.Priority {
  1125. if active.QueueTimer != nil {
  1126. if active.QueueTimer.Stop() {
  1127. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  1128. } else {
  1129. //lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  1130. }
  1131. }
  1132. }
  1133. } else if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "NOANSWER" {
  1134. //lfshook.NewLogger().Infof("===%s======%s", event["Event"], event["DialStatus"])
  1135. time.Sleep(time.Millisecond * 300)
  1136. //check resume
  1137. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1138. if ok {
  1139. ICPConfbridgeReinvite(task.ConfbridgeID, taskName)
  1140. }
  1141. }
  1142. //TMS Answer PAD (有时asterisk反馈的BridgeEnter事件有问题,根据dialend判断)
  1143. if utils.IsPAIU(event["CallerIDName"]) && utils.IsPACU(event["CallerIDNum"]) && event["DialStatus"] == "ANSWER" && event["Exten"] == "0403" {
  1144. lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
  1145. alstatus.AlarmStatus(event["CallerIDName"], "connect") // Alarm connected
  1146. //=============================
  1147. task := priority.TaskInfo{
  1148. RunChannel: event["Channel"],
  1149. LocalChan: event["Channel"],
  1150. RunType: "PAD-TMS",
  1151. Priority: priority.AllTasks.PADTMS.Priority,
  1152. ConfbridgeID: "",
  1153. Running: true,
  1154. }
  1155. priority.RegistryTask.Register("PAD-TMS", task)
  1156. if priority.TaskCreating == "PAD-TMS" {
  1157. utils.LoggerDebug.Printf("PAD-TMS Connected : Clean priority.TaskCreating = '' !")
  1158. priority.TaskCreating = ""
  1159. }
  1160. lfshook.NewLogger().Infof("=========PAD-TMS answer==ListAll===%+v", priority.RegistryTask.ListAll())
  1161. if active.ActivedCab == "1" {
  1162. go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
  1163. go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8") //ICP8---call----PAD
  1164. } else if active.ActivedCab == "8" {
  1165. go RedirectInQueue(event["CallerIDName"], "2381", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP8
  1166. go Dial("0403", event["CallerIDName"], "call-pad-rule", "2311", "2311", "1") //ICP1---call----PAD
  1167. } else if active.ActivedCab == "" {
  1168. go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
  1169. go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8") //ICP8---call----PAD
  1170. }
  1171. }
  1172. case "BridgeLeave":
  1173. //lfshook.NewLogger().Infof("=========%s", event["Event"])
  1174. //Cab Cab end
  1175. if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
  1176. alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
  1177. priority.RegistryTask.StopAndUnregister("C2C")
  1178. //time.Sleep(time.Millisecond * 100)
  1179. SetPadTimer()
  1180. //check resume
  1181. taskName, task, ok := priority.RegistryTask.HighestPriorityRunningTask1()
  1182. if ok {
  1183. if taskName == "EMG" {
  1184. EMGConfbridgeReinvite(task.ConfbridgeID)
  1185. } else if taskName == "CPA" {
  1186. if CPAConfbridgeReinvite(task.ConfbridgeID) {
  1187. alstatus.PaStatus("", "CPA", "start")
  1188. }
  1189. } else {
  1190. ICPConfbridgeReinvite(task.ConfbridgeID, taskName)
  1191. }
  1192. }
  1193. }
  1194. case "ExtensionStatus":
  1195. //lfshook.NewLogger().Infof("=========event:%s Ext:%s status:%s ", event["Event"], event["Exten"], event["StatusText"])
  1196. //update extension status
  1197. if event["StatusText"] == "Idle" || event["StatusText"] == "Unavailable" {
  1198. if len(event["Exten"]) > 3 && utils.IsPAIU(event["Exten"]) {
  1199. alstatus.AlarmStatus(event["Exten"], event["StatusText"]) // PAD idle + unavailable
  1200. }
  1201. }
  1202. case "BridgeEnter": // TMS-ICP answer PAD; PACU connect ICP
  1203. lfshook.NewLogger().Infof("=========event:%s callerid-num:%s callerid-name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
  1204. //PAD-OCC start
  1205. if utils.IsIO(event["CallerIDNum"]) && utils.IsPAIU(event["ConnectedLineNum"]) {
  1206. if priority.PADOccStart == 0 {
  1207. if priority.TaskCreating == "PAD-OCC" {
  1208. utils.LoggerDebug.Printf("PAD-OCC Connected : Clean priority.TaskCreating = '' !")
  1209. priority.TaskCreating = ""
  1210. }
  1211. alstatus.OccPad("start")
  1212. priority.PADOccStart = 1
  1213. }
  1214. if priority.PADStart == 0 {
  1215. alstatus.PaStatus("", "PAD", "start")
  1216. priority.PADStart = 1
  1217. }
  1218. }
  1219. /*if utils.IsPACU(event["CallerIDNum"]) && utils.IsPAIU(event["CallerIDName"]) { //ICP and PACU connected -----TMS Answer PAD
  1220. lfshook.NewLogger().Infof("====BridgeEnter==IN action===%s===ID:%s Name:%s", event["Event"], event["CallerIDNum"], event["CallerIDName"])
  1221. alstatus.AlarmStatus(event["CallerIDName"], "connect") // Alarm connected
  1222. //=============================
  1223. task := priority.TaskInfo{
  1224. RunChannel: event["Channel"],
  1225. LocalChan: event["Channel"],
  1226. RunType: "PAD-TMS",
  1227. Priority: priority.AllTasks.PADTMS.Priority,
  1228. ConfbridgeID: "",
  1229. Running: true,
  1230. }
  1231. priority.RegistryTask.Register("PAD-TMS", task)
  1232. lfshook.NewLogger().Infof("=========PAD-TMS answer==ListAll===%+v", priority.RegistryTask.ListAll())
  1233. if active.ActivedCab == "1" {
  1234. go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
  1235. go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8") //ICP8---call----PAD
  1236. } else if active.ActivedCab == "8" {
  1237. go RedirectInQueue(event["CallerIDName"], "2381", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP8
  1238. go Dial("0403", event["CallerIDName"], "call-pad-rule", "2311", "2311", "1") //ICP1---call----PAD
  1239. } else if active.ActivedCab == "" {
  1240. go RedirectInQueue(event["CallerIDName"], "2311", "chanspy-rule-whisper", "") //PAD chanspy(EqW) ICP1
  1241. go Dial("0403", event["CallerIDName"], "call-pad-rule", "2381", "2381", "8") //ICP8---call----PAD
  1242. }
  1243. } else*/if utils.IsPAIU(event["CallerIDNum"]) && event["Exten"] == "0405" { // PAD connect ICP-TMS;PACU not available
  1244. //=============================
  1245. task := priority.TaskInfo{
  1246. RunChannel: event["Channel"],
  1247. LocalChan: event["Channel"],
  1248. RunType: "PAD-TMS",
  1249. Priority: priority.AllTasks.PADTMS.Priority,
  1250. ConfbridgeID: "",
  1251. Running: true,
  1252. }
  1253. priority.RegistryTask.Register("PAD-TMS", task)
  1254. if priority.TaskCreating == "PAD-TMS" {
  1255. utils.LoggerDebug.Printf("PAD-TMS Connected : Clean priority.TaskCreating = '' !")
  1256. priority.TaskCreating = ""
  1257. }
  1258. lfshook.NewLogger().Infof("=========PAD-TMS answer==ListAll===%+v", priority.RegistryTask.ListAll())
  1259. alstatus.AlarmStatus(event["CallerIDNum"], "connect") // PAD connect ICP-TMS
  1260. }
  1261. }
  1262. }
  1263. func StartAMI(connectOKCallBack func(), handleEvents []func(event map[string]string)) {
  1264. lfshook.NewLogger().Info("Start AMI")
  1265. settings := &amigo.Settings{
  1266. Host: configs.ConfigGlobal.AsteriskAMIHost,
  1267. Port: configs.ConfigGlobal.AsteriskAMIPort,
  1268. Username: configs.ConfigGlobal.AsteriskAMIUser,
  1269. Password: configs.ConfigGlobal.AsteriskAMISecret,
  1270. LogLevel: logrus.ErrorLevel}
  1271. //lfshook.NewLogger().Infof("ami setting: %+v", settings)
  1272. AminInstance = amigo.New(settings, lfshook.NewLogger())
  1273. AminInstance.EventOn(func(payload ...interface{}) {
  1274. // lfshook.NewLogger().Infof("ami event on %+v", payload[0])
  1275. event := payload[0].(map[string]string)
  1276. go HandleAMI(event)
  1277. for _, handle := range handleEvents {
  1278. go handle(event)
  1279. }
  1280. })
  1281. AminInstance.ConnectOn(func(payload ...interface{}) {
  1282. //lfshook.NewLogger().Infof("ami connect on %+v", payload[0])
  1283. if payload[0] == pkg.Connect_OK {
  1284. connectOKCallBack()
  1285. } else {
  1286. lfshook.NewLogger().Errorf("ami connect failure %+v", payload)
  1287. //active.Master = false
  1288. }
  1289. })
  1290. AminInstance.Connect()
  1291. }
  1292. func Connected() bool {
  1293. if AminInstance != nil {
  1294. return AminInstance.Connected()
  1295. }
  1296. return false
  1297. }