index.go 55 KB

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