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