index.go 55 KB

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