call.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. package action
  2. import (
  3. "errors"
  4. "fmt"
  5. "pbx-api-gin/internal/app/stc/active"
  6. "pbx-api-gin/internal/app/stc/priority"
  7. alstatus "pbx-api-gin/internal/app/stc/sendstatus"
  8. "pbx-api-gin/pkg/lfshook"
  9. "pbx-api-gin/pkg/utils"
  10. "sort"
  11. "strings"
  12. "time"
  13. )
  14. var Pads = []string{"2413", "2414", "2415", "2421", "2422", "2423", "2424", "2425", "2431", "2432", "2433", "2434", "2435", "2441", "2442", "2443", "2444",
  15. "2445", "2451", "2452", "2453", "2454", "2455", "2461", "2462", "2463", "2464", "2465", "2471", "2472", "2473", "2474", "2475", "2481", "2482", "2483",
  16. "2484", "2485", "2411", "2412"}
  17. var Pacus = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181"}
  18. var Speakers = []string{"2111", "2121", "2131", "2141", "2151", "2161", "2171", "2181", "2311", "2381"}
  19. // Function triggered before no cab occupied signal interrupt
  20. func InActiveHangup() {
  21. if active.ActivedCab == "" {
  22. HangupTask("PA")
  23. HangupTask("CPA")
  24. HangupTask("VOL")
  25. HangupTask("PAD-OCC")
  26. } else {
  27. HangupTask("PA")
  28. HangupTask("PAD-OCC")
  29. HangupTask("CPA")
  30. HangupTask("EMG")
  31. HangupTask("SPC")
  32. HangupTask("DCS")
  33. HangupTask("STN")
  34. HangupTask("CHK")
  35. HangupTask("VOL")
  36. Hangup("2311") //hangup cabcab
  37. }
  38. }
  39. // Hangup 挂断指定分机或通道
  40. func Hangup(channel string) {
  41. lfshook.NewLogger().Infof("Hangup extensions/channel :%s", channel)
  42. if !utils.IsChannel(channel) {
  43. channel = fmt.Sprintf(`/^(PJ)?SIP\/%s-.*$/`, channel)
  44. }
  45. action := map[string]string{
  46. "Action": "hangup",
  47. "Channel": channel,
  48. }
  49. //lfshook.NewLogger().Infof("hangup action :%+v", action)
  50. if _, _, err := AminInstance.Send(action); err != nil {
  51. lfshook.NewLogger().Errorf("Hangup %+v", err)
  52. }
  53. }
  54. // Hangup 挂断所有分机,除指定分机和PAD
  55. func HangupAllExcept(caller string) {
  56. //all PACU
  57. for _, ret := range Pacus {
  58. Hangup(ret)
  59. }
  60. switch caller {
  61. case "2311":
  62. Hangup("1411") //IO1
  63. Hangup("1481") //IO8
  64. //Hangup("2311") //ICP1
  65. Hangup("2381") //ICP8
  66. case "2381":
  67. Hangup("1411") //IO1
  68. Hangup("1481") //IO8
  69. Hangup("2311") //ICP1
  70. //Hangup("2381") //ICP8
  71. case "1411":
  72. //Hangup("1411") //IO1
  73. Hangup("1481") //IO8
  74. Hangup("2311") //ICP1
  75. Hangup("2381") //ICP8
  76. case "1481":
  77. Hangup("1411") //IO1
  78. //Hangup("1481") //IO8
  79. Hangup("2311") //ICP1
  80. Hangup("2381") //ICP8
  81. case "":
  82. Hangup("1411") //IO1
  83. Hangup("1481") //IO8
  84. Hangup("2311") //ICP1
  85. Hangup("2381") //ICP8
  86. }
  87. }
  88. // Hangup task
  89. func HangupTask(TaskName string) {
  90. lfshook.NewLogger().Infof("HangupTask Check TaskName:%s ", TaskName)
  91. if TaskName == "PAD-OCC" {
  92. resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
  93. if err != nil {
  94. lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
  95. return
  96. }
  97. if resCaller != nil {
  98. for _, caller := range resCaller.Entrys {
  99. //lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
  100. time.Sleep(time.Millisecond * 50)
  101. RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
  102. }
  103. }
  104. }
  105. taskInfo, ok := priority.RegistryTask.Get(TaskName)
  106. if ok {
  107. HangupAllLocalChan()
  108. ConfbridgeKick(taskInfo.ConfbridgeID, "all")
  109. Hangup(taskInfo.RunChannel)
  110. }
  111. }
  112. // interrupt the running task
  113. func InterruptRunningTask(toRunTask string) {
  114. var task priority.TaskInfo
  115. var taskName string
  116. var ok bool
  117. lfshook.NewLogger().Infof("InterruptRunningTask toRuntask:%s ", toRunTask)
  118. if toRunTask != "PA" && toRunTask != "PAD-ICP" && toRunTask != "PAD-TMS" { // ignore C2C
  119. taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask1()
  120. if !ok {
  121. return
  122. }
  123. } else { // have to check C2C
  124. taskName, task, ok = priority.RegistryTask.HighestPriorityRunningTask()
  125. if !ok {
  126. return
  127. }
  128. }
  129. //same type return
  130. if toRunTask == taskName {
  131. if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" || toRunTask == "PAD-OCC" {
  132. //Auto Answer PAD-OCC one by one, clean the old confbridge and channels before answer a new PAD .
  133. if toRunTask == "PAD-OCC" {
  134. Hangup(task.RunChannel) //pad
  135. ConfbridgeKick(task.ConfbridgeID, "all")
  136. HangupIO() //io
  137. //lfshook.NewLogger().Infof("===InterruptRunningTask=ret==== ")
  138. }
  139. return
  140. }
  141. }
  142. //pad all reset
  143. if toRunTask == "AlarmHoldResetAll" {
  144. HangupAllLocalChan()
  145. return
  146. }
  147. switch task.RunType {
  148. case "CPA":
  149. //kick CPA members
  150. CPAConfbridgeKick(task.ConfbridgeID)
  151. case "EMG":
  152. //kick EMG members
  153. EMGConfbridgeKick(task.ConfbridgeID)
  154. case "C2C": // Interrupt C2C task running,
  155. if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
  156. HangupICP()
  157. return
  158. }
  159. case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
  160. priority.InterruptedPad = "PAD-ICP"
  161. lfshook.NewLogger().Infof("InterruptRunningTask interrupt PAD-ICP/PAD-TMS ,Running type :%s !", task.RunType)
  162. chans, err := CoreShowChannels()
  163. if err != nil {
  164. lfshook.NewLogger().Infof("InterruptRunningTask CoreShowChannels err:%+v", err)
  165. return
  166. }
  167. //1. Redirect the connected PAD to 0300,hangup the other pad channel
  168. for _, ret := range chans {
  169. // Redirect the connected PAD to 0300
  170. if utils.IsPAIU(ret.CallerIDNum) {
  171. if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
  172. err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
  173. if err != nil {
  174. lfshook.NewLogger().Infof("InterruptRunningTask Redirect err:%+v", err)
  175. return
  176. }
  177. number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
  178. active.NotifyPaiu(number, "hold")
  179. //HangupAllLocalChan()
  180. }
  181. }
  182. }
  183. for _, ret := range chans {
  184. //hangup pad call ICP channel
  185. if utils.IsPAIU(ret.CallerIDNum) {
  186. if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
  187. lfshook.NewLogger().Infof("Hangup PAD Channel :%+v", ret.Channel)
  188. Hangup(ret.Channel)
  189. }
  190. }
  191. }
  192. priority.RegistryTask.StopAndUnregister("PAD-ICP")
  193. priority.RegistryTask.StopAndUnregister("PAD-TMS")
  194. //2. hangup task channel (ICP + PACU)
  195. //lfshook.NewLogger().Infof("===InterruptRunningTask=2. hangup task channel === ")
  196. HangupAllLocalChan()
  197. HangupICP()
  198. //pad end
  199. if priority.PADStart == 1 {
  200. alstatus.PaStatus("", "PAD", "end")
  201. priority.PADStart = 0
  202. }
  203. case "PAD-OCC": // Interrupt PAD-OCC task running,
  204. if toRunTask == "C2C" {
  205. HangupICP()
  206. break
  207. } else {
  208. priority.InterruptedPad = "PAD-OCC"
  209. priority.OCCAnswer = 0
  210. resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
  211. if err != nil {
  212. lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
  213. return
  214. }
  215. if resCaller == nil {
  216. return
  217. }
  218. for _, caller := range resCaller.Entrys {
  219. //lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
  220. time.Sleep(time.Millisecond * 50)
  221. RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
  222. }
  223. priority.RegistryTask.StopAndUnregister("PAD-OCC")
  224. //2. Hangup connected PAD
  225. //lfshook.NewLogger().Infof("===InterruptRunningTask=Hangup connected PAD=== ")
  226. Hangup(task.RunChannel)
  227. //3. Hangup OI & ICP
  228. HangupIO()
  229. HangupAllLocalChan()
  230. ConfbridgeKick(task.ConfbridgeID, "all")
  231. //occ pad end
  232. if priority.PADOccStart == 1 {
  233. alstatus.OccPad("end")
  234. priority.PADOccStart = 0
  235. }
  236. }
  237. default:
  238. lfshook.NewLogger().Infof("InterruptRunningTask goto default !")
  239. //if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
  240. // Hangup(priority.RunningPATaskChan)
  241. //}
  242. Hangup(task.RunChannel)
  243. ConfbridgeKick(task.ConfbridgeID, "all")
  244. }
  245. }
  246. // Hangup all ICP
  247. func HangupICP() {
  248. Hangup("2311") //ICP1
  249. Hangup("2381") //ICP8
  250. }
  251. // Hangup all IO
  252. func HangupIO() {
  253. Hangup("1411") //IO1
  254. Hangup("1481") //IO8
  255. }
  256. // Hangup all PACU
  257. func HangupAllPACU() {
  258. //all PACU
  259. for _, ret := range Pacus {
  260. Hangup(ret)
  261. }
  262. }
  263. func HangupAllLocalChan() {
  264. chans, err := CoreShowChannels()
  265. if err != nil {
  266. lfshook.NewLogger().Infof("CoreShowChannels %+v", err)
  267. return
  268. }
  269. for _, ret := range chans {
  270. if strings.Contains(ret.Channel, "Local") && !strings.Contains(ret.Channel, "0502@default") {
  271. //lfshook.NewLogger().Infof("HangupAllLocalChan=====hangup========= %+v", ret)
  272. Hangup(ret.Channel)
  273. }
  274. }
  275. }
  276. // Hangup all PACU
  277. func HangupAllPAD() {
  278. //all PAD
  279. for _, ret := range Pads {
  280. Hangup(ret)
  281. }
  282. }
  283. // Hangup all calls
  284. func HangupAll() {
  285. utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "hangup request all")
  286. }
  287. // Dial 拨打号码
  288. func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
  289. chanel := fmt.Sprintf("%s/%s@default", "Local", src)
  290. action := map[string]string{
  291. "Action": "Originate",
  292. "Channel": chanel,
  293. "Exten": dst,
  294. "Context": dialrule,
  295. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  296. "Priority": "1",
  297. "Variable": fmt.Sprintf("CAB=%s", callType),
  298. "async": "true",
  299. }
  300. //lfshook.NewLogger().Infof("dial action %+v", action)
  301. res, _, err := AminInstance.Send(action)
  302. if err != nil {
  303. lfshook.NewLogger().Errorf("%+v", err)
  304. }
  305. lfshook.NewLogger().Info(res)
  306. }
  307. // Dial 拨打号码
  308. func DialICP(src, dst, dialrule, callerID, callerName string) {
  309. chanel := fmt.Sprintf("%s/%s@call-icp", "Local", src)
  310. action := map[string]string{
  311. "Action": "Originate",
  312. "Channel": chanel,
  313. "Exten": dst,
  314. "Context": dialrule,
  315. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  316. "Priority": "1",
  317. "Variable": fmt.Sprintf("CBID=%s", callerID),
  318. "async": "true",
  319. }
  320. lfshook.NewLogger().Infof("dial action %+v", action)
  321. res, _, err := AminInstance.Send(action)
  322. if err != nil {
  323. lfshook.NewLogger().Errorf("%+v", err)
  324. }
  325. lfshook.NewLogger().Info(res)
  326. }
  327. // 获取分机状态
  328. func ExtenStatus(exten string) (Status string) {
  329. action := map[string]string{
  330. "Action": "ExtensionState",
  331. "Exten": exten,
  332. "Context": "default",
  333. }
  334. res, _, err := AminInstance.Send(action)
  335. if err != nil {
  336. lfshook.NewLogger().Errorf("%+v", err)
  337. return ""
  338. }
  339. //lfshook.NewLogger().Infof("================ExtensionState:res %+v", res)
  340. return res["StatusText"]
  341. }
  342. // PACU ChanSpy
  343. func ChanSpy(src, dst string, whisper, bargein bool) {
  344. lfshook.NewLogger().Infof("chan spy src:%s dst:%s", src, dst)
  345. //channel := fmt.Sprintf("%s/%s", utils.DialPrefix, dst)
  346. channel := fmt.Sprintf("Local/%s@aio-rule", dst)
  347. data := fmt.Sprintf("%s/%s,qBE", utils.DialPrefix, src)
  348. /*
  349. if whisper {
  350. data = fmt.Sprintf("%s,w", data)
  351. }
  352. if bargein {
  353. data = fmt.Sprintf("%s,B", data)
  354. }
  355. */
  356. action := map[string]string{
  357. "Action": "Originate",
  358. "Channel": channel, // 不存在的通话
  359. "Application": "ChanSpy",
  360. "Data": data, // 存在的通话
  361. "CallerID": dst,
  362. "Async": "true",
  363. }
  364. lfshook.NewLogger().Infof("PACU ChanSpy action %+v", action)
  365. _, _, err := AminInstance.Send(action)
  366. if err != nil {
  367. lfshook.NewLogger().Errorf("%+v", err)
  368. }
  369. }
  370. // Redirect 转接
  371. func RedirectInQueue(channel, dst, dialrule, callerID string) (err error) {
  372. //callerID := "redirect"
  373. //lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
  374. if !utils.IsChannel(channel) {
  375. //callerID = channel
  376. if channel, err = GetChannelByExtenNotBridged(channel); err != nil {
  377. return err
  378. }
  379. }
  380. action := map[string]string{
  381. "Action": "Redirect",
  382. "Channel": channel,
  383. "Exten": dst,
  384. "Context": dialrule,
  385. "CallerID": callerID,
  386. "Priority": "1",
  387. "async": "true",
  388. }
  389. lfshook.NewLogger().Infof("RedirectInQueue: %+v", action)
  390. res, _, err := AminInstance.Send(action)
  391. if err != nil {
  392. lfshook.NewLogger().Error(err)
  393. }
  394. lfshook.NewLogger().Info(res)
  395. return err
  396. }
  397. // Redirect 转接
  398. func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
  399. //callerID := "redirect"
  400. //lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
  401. if !utils.IsChannel(channel) {
  402. callerID = channel
  403. if channel, err = GetChannelByExten(channel); err != nil {
  404. return err
  405. }
  406. }
  407. action := map[string]string{
  408. "Action": "Redirect",
  409. "Channel": channel,
  410. "Exten": dst,
  411. "Context": dialrule,
  412. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  413. "Priority": "1",
  414. "async": "true",
  415. }
  416. lfshook.NewLogger().Infof("Redirect: %+v", action)
  417. res, _, err := AminInstance.Send(action)
  418. if err != nil {
  419. lfshook.NewLogger().Error(err)
  420. }
  421. lfshook.NewLogger().Info(res)
  422. return err
  423. }
  424. func SetPadTimer() {
  425. toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) //Get PAD priori 获取之前打断的报警优先级
  426. //toRunpriority := priority.GetPriorityByKey("PAD-ICP")
  427. _, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
  428. if ok {
  429. lfshook.NewLogger().Infof("PAD SetPadTimer runing priority:%d toRun priority:%d", taskTmp.Priority, toRunPadpriority)
  430. if taskTmp.Priority < toRunPadpriority { //higher priority task running ,do not set timer
  431. return
  432. }
  433. }
  434. res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
  435. if err != nil {
  436. lfshook.NewLogger().Infof("QueueStatus err%+v", err)
  437. return
  438. }
  439. if res == nil {
  440. return
  441. }
  442. if res.Calls != "0" {
  443. lfshook.NewLogger().Infof("PAD SetPadTimer Set QueueTimer timeout 30s !")
  444. //active.SetTimer = true
  445. //lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
  446. if active.QueueTimer != nil {
  447. if active.QueueTimer.Stop() {
  448. lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  449. } else {
  450. lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  451. }
  452. }
  453. lfshook.NewLogger().Logger.Infof("=========Start PAD timer !======%d=======", active.PADTimeout)
  454. //active.QueueTimer = time.AfterFunc(time.Duration(active.PADTimeout)*time.Second, func() { // check the PAD 30s timeout
  455. active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
  456. //if both not active , return
  457. if active.ActivedCab == "" {
  458. return
  459. }
  460. res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
  461. if err != nil {
  462. lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
  463. return
  464. }
  465. if res == nil {
  466. return
  467. }
  468. if res.Calls == "0" { // OCC queue empty
  469. resCaller, err := QueueStatus("0300", "") // check ICP queue, get entries
  470. if err != nil {
  471. lfshook.NewLogger().Infof("ICP QueueStatus err:%+v", err)
  472. return
  473. }
  474. sort.Slice(resCaller.Entrys, func(i, j int) bool {
  475. return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
  476. })
  477. for _, caller := range resCaller.Entrys {
  478. priority.ICPAnswer = 0
  479. //lfshook.NewLogger().Infof("====SetPadTimer==QueueTimer==2=")
  480. //lfshook.NewLogger().Infof("==SetPadTimer==Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
  481. //order by pos
  482. RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
  483. time.Sleep(time.Millisecond * 100) //200 ms delay
  484. }
  485. }
  486. })
  487. }
  488. }
  489. func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
  490. action := map[string]string{
  491. "Action": "ConfbridgeKick",
  492. "Conference": confnum,
  493. "Channel": channel,
  494. }
  495. res, _, err = AminInstance.Send(action)
  496. if err != nil {
  497. return nil, err
  498. }
  499. lfshook.NewLogger().Infof("ConfbridgeKick res:%+v", res)
  500. if res["Response"] != "Success" {
  501. return nil, errors.New(res["Message"])
  502. }
  503. return res, nil
  504. }
  505. func CPAConfbridgeKick(confnum string) (res map[string]string, err error) {
  506. chans, err := ConfbridgeList(confnum)
  507. if err != nil {
  508. return nil, errors.New(res["Message"])
  509. }
  510. for _, confChan := range chans {
  511. if !strings.Contains(confChan, "PJSIP/1481") {
  512. ConfbridgeKick(confnum, confChan)
  513. }
  514. }
  515. return res, nil
  516. }
  517. func CPAConfbridgeReinvite(confID string) {
  518. time.Sleep(time.Millisecond * 500)
  519. for _, ext := range Speakers {
  520. ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
  521. }
  522. }
  523. func EMGConfbridgeKick(confnum string) (res map[string]string, err error) {
  524. chans, err := ConfbridgeList(confnum)
  525. if err != nil {
  526. return nil, errors.New(res["Message"])
  527. }
  528. for _, confChan := range chans {
  529. if !strings.Contains(confChan, "0502@default") {
  530. ConfbridgeKick(confnum, confChan)
  531. }
  532. }
  533. return res, nil
  534. }
  535. func EMGConfbridgeReinvite(confID string) {
  536. time.Sleep(time.Millisecond * 500)
  537. for _, ext := range Speakers {
  538. ConfbridgeReinvite(ext, "call-speakers-emg", confID)
  539. }
  540. }
  541. func ConfbridgeList(confnum string) (chans []string, err error) {
  542. action := map[string]string{
  543. "Action": "ConfbridgeList",
  544. "Conference": confnum,
  545. }
  546. res, events, err := AminInstance.Send(action)
  547. if err != nil {
  548. return nil, err
  549. }
  550. lfshook.NewLogger().Infof("ConfbridgeList res:%+v", res)
  551. if res["Response"] == "Success" {
  552. for _, event := range events {
  553. if event.Data["Event"] == "ConfbridgeList" {
  554. chans = append(chans, event.Data["Channel"])
  555. }
  556. }
  557. return chans, nil
  558. } else {
  559. return nil, errors.New(res["Message"])
  560. }
  561. }
  562. func ConfbridgeReinvite(src, context, confID string) {
  563. if ExtenStatus(src) != "Idle" {
  564. lfshook.NewLogger().Infof(" ConfbridgeReinvite ext:%s Not Idle !", src)
  565. return
  566. }
  567. chanel := fmt.Sprintf("Local/%s@%s", src, context)
  568. action := map[string]string{
  569. "Action": "Originate",
  570. "Channel": chanel,
  571. "Exten": "000",
  572. "Context": "confbridge-join",
  573. "CallerID": fmt.Sprintf("%s<%s>", "", ""),
  574. "Priority": "1",
  575. "Variable": fmt.Sprintf("CBID=%s", confID),
  576. "async": "true",
  577. }
  578. lfshook.NewLogger().Infof("dial action %+v", action)
  579. res, _, err := AminInstance.Send(action)
  580. if err != nil {
  581. lfshook.NewLogger().Errorf("%+v", err)
  582. }
  583. lfshook.NewLogger().Info(res)
  584. }
  585. func ICPConfbridgeReinvite(confID, paType string) {
  586. switch paType {
  587. case "PAD-OCC":
  588. go DialICP("8", "2311", "confbridge-join", confID, "1") //ICP1---call
  589. go DialICP("8", "2381", "confbridge-join", confID, "8") //ICP8---call
  590. case "CPA":
  591. go DialICP("2", "2311", "confbridge-join", confID, "1") //ICP1---call
  592. go DialICP("2", "2381", "confbridge-join", confID, "8") //ICP8---call
  593. case "EMG":
  594. go DialICP("3", "2311", "confbridge-join", confID, "1") //ICP1---call
  595. go DialICP("3", "2381", "confbridge-join", confID, "8") //ICP8---call
  596. case "SPC":
  597. go DialICP("6", "2311", "confbridge-join", confID, "1") //ICP1---call
  598. go DialICP("6", "2381", "confbridge-join", confID, "8") //ICP8---call
  599. case "STN":
  600. go DialICP("4", "2311", "confbridge-join", confID, "1") //ICP1---call
  601. go DialICP("4", "2381", "confbridge-join", confID, "8") //ICP8---call
  602. case "DCS":
  603. go DialICP("5", "2311", "confbridge-join", confID, "1") //ICP1---call
  604. go DialICP("5", "2381", "confbridge-join", confID, "8") //ICP8---call
  605. case "CHK":
  606. go DialICP("10", "2311", "confbridge-join", confID, "1") //ICP1---call
  607. go DialICP("10", "2381", "confbridge-join", confID, "8") //ICP8---call
  608. case "VOL":
  609. go DialICP("11", "2311", "confbridge-join", confID, "1") //ICP1---call
  610. go DialICP("11", "2381", "confbridge-join", confID, "8") //ICP8---call
  611. }
  612. }