index.go 54 KB

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