index.go 55 KB

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