call.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. //lfshook.NewLogger().Infof("InterruptRunningTask RunningTask:%+v ", task)
  130. //same type return
  131. if toRunTask == taskName {
  132. if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" || toRunTask == "PAD-OCC" {
  133. //Auto Answer PAD-OCC one by one, clean the old confbridge and channels before answer a new PAD .
  134. if toRunTask == "PAD-OCC" {
  135. Hangup(task.RunChannel) //pad
  136. ConfbridgeKick(task.ConfbridgeID, "all")
  137. HangupIO() //io
  138. //lfshook.NewLogger().Infof("===InterruptRunningTask=ret==== ")
  139. }
  140. return
  141. }
  142. }
  143. //pad all reset
  144. if toRunTask == "AlarmHoldResetAll" {
  145. HangupAllLocalChan()
  146. return
  147. }
  148. switch task.RunType {
  149. case "CPA":
  150. //kick CPA members
  151. CPAConfbridgeKick(task.ConfbridgeID)
  152. case "EMG":
  153. //kick EMG members
  154. EMGConfbridgeKick(task.ConfbridgeID)
  155. case "C2C": // Interrupt C2C task running,
  156. if toRunTask == "PA" || toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
  157. HangupICP()
  158. return
  159. }
  160. case "PAD-ICP", "PAD-TMS": // Interrupt PAD task running,
  161. if toRunTask == "PAD-ICP" || toRunTask == "PAD-TMS" {
  162. break
  163. }
  164. priority.InterruptedPad = "PAD-ICP"
  165. lfshook.NewLogger().Infof("InterruptRunningTask interrupt PAD-ICP/PAD-TMS ,Running type :%s !", task.RunType)
  166. chans, err := CoreShowChannels()
  167. if err != nil {
  168. lfshook.NewLogger().Infof("InterruptRunningTask CoreShowChannels err:%+v", err)
  169. return
  170. }
  171. //1. Redirect the connected PAD to 0300,hangup the other pad channel
  172. for _, ret := range chans {
  173. // Redirect the connected PAD to 0300
  174. if utils.IsPAIU(ret.CallerIDNum) {
  175. if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
  176. err := Redirect(ret.Channel, "0300", "queues-icp-redirect", "", "PAD")
  177. if err != nil {
  178. lfshook.NewLogger().Infof("InterruptRunningTask Redirect err:%+v", err)
  179. return
  180. }
  181. number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
  182. active.NotifyPaiu(number, "hold")
  183. //HangupAllLocalChan()
  184. }
  185. }
  186. }
  187. for _, ret := range chans {
  188. //hangup pad call ICP channel
  189. if utils.IsPAIU(ret.CallerIDNum) {
  190. if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
  191. lfshook.NewLogger().Infof("Hangup PAD Channel :%+v", ret.Channel)
  192. Hangup(ret.Channel)
  193. }
  194. }
  195. }
  196. priority.RegistryTask.StopAndUnregister("PAD-ICP")
  197. priority.RegistryTask.StopAndUnregister("PAD-TMS")
  198. //2. hangup task channel (ICP + PACU)
  199. //lfshook.NewLogger().Infof("===InterruptRunningTask=2. hangup task channel === ")
  200. HangupAllLocalChan()
  201. HangupICP()
  202. //pad end
  203. if priority.PADStart == 1 {
  204. alstatus.PaStatus("", "PAD", "end")
  205. priority.PADStart = 0
  206. }
  207. case "PAD-OCC": // Interrupt PAD-OCC task running,
  208. if toRunTask == "C2C" {
  209. HangupICP()
  210. break
  211. } else {
  212. priority.InterruptedPad = "PAD-OCC"
  213. priority.OCCAnswer = 0
  214. resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
  215. if err != nil {
  216. lfshook.NewLogger().Infof("QueueStatus err:%+v", err)
  217. return
  218. }
  219. if resCaller == nil {
  220. return
  221. }
  222. for _, caller := range resCaller.Entrys {
  223. //lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
  224. time.Sleep(time.Millisecond * 50)
  225. RedirectInQueue(caller.CallerIDNum, "0300", "queues-icp-redirect", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
  226. }
  227. priority.RegistryTask.StopAndUnregister("PAD-OCC")
  228. //2. Hangup connected PAD
  229. //lfshook.NewLogger().Infof("===InterruptRunningTask=Hangup connected PAD=== ")
  230. Hangup(task.RunChannel)
  231. //3. Hangup OI & ICP
  232. HangupIO()
  233. HangupAllLocalChan()
  234. ConfbridgeKick(task.ConfbridgeID, "all")
  235. //occ pad end
  236. if priority.PADOccStart == 1 {
  237. alstatus.OccPad("end")
  238. priority.PADOccStart = 0
  239. }
  240. }
  241. default:
  242. lfshook.NewLogger().Infof("InterruptRunningTask goto default !")
  243. //if !strings.Contains(priority.RunningPATaskChan, "0502@default") {
  244. // Hangup(priority.RunningPATaskChan)
  245. //}
  246. Hangup(task.RunChannel)
  247. ConfbridgeKick(task.ConfbridgeID, "all")
  248. }
  249. }
  250. // Hangup all ICP
  251. func HangupICP() {
  252. Hangup("2311") //ICP1
  253. Hangup("2381") //ICP8
  254. }
  255. // Hangup all IO
  256. func HangupIO() {
  257. Hangup("1411") //IO1
  258. Hangup("1481") //IO8
  259. }
  260. // Hangup all PACU
  261. func HangupAllPACU() {
  262. //all PACU
  263. for _, ret := range Pacus {
  264. Hangup(ret)
  265. }
  266. }
  267. func HangupAllLocalChan() {
  268. chans, err := CoreShowChannels()
  269. if err != nil {
  270. lfshook.NewLogger().Infof("CoreShowChannels %+v", err)
  271. return
  272. }
  273. for _, ret := range chans {
  274. if strings.Contains(ret.Channel, "Local") && !strings.Contains(ret.Channel, "0502@default") {
  275. //lfshook.NewLogger().Infof("HangupAllLocalChan=====hangup========= %+v", ret)
  276. Hangup(ret.Channel)
  277. }
  278. }
  279. }
  280. // Hangup all PACU
  281. func HangupAllPAD() {
  282. //all PAD
  283. for _, ret := range Pads {
  284. Hangup(ret)
  285. }
  286. }
  287. // Hangup all calls
  288. func HangupAll() {
  289. utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "hangup request all")
  290. }
  291. // Dial 拨打号码
  292. func Dial(src, dst, dialrule, callerID, callerName string, callType string) {
  293. chanel := fmt.Sprintf("%s/%s@default", "Local", src)
  294. action := map[string]string{
  295. "Action": "Originate",
  296. "Channel": chanel,
  297. "Exten": dst,
  298. "Context": dialrule,
  299. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  300. "Priority": "1",
  301. "Variable": fmt.Sprintf("CAB=%s", callType),
  302. "async": "true",
  303. }
  304. //lfshook.NewLogger().Infof("dial action %+v", action)
  305. res, _, err := AminInstance.Send(action)
  306. if err != nil {
  307. lfshook.NewLogger().Errorf("%+v", err)
  308. }
  309. lfshook.NewLogger().Info(res)
  310. }
  311. // Dial 拨打号码
  312. func DialICP(src, dst, dialrule, callerID, callerName string) {
  313. chanel := fmt.Sprintf("%s/%s@call-icp", "Local", src)
  314. action := map[string]string{
  315. "Action": "Originate",
  316. "Channel": chanel,
  317. "Exten": dst,
  318. "Context": dialrule,
  319. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  320. "Priority": "1",
  321. "Variable": fmt.Sprintf("CBID=%s", callerID),
  322. "async": "true",
  323. }
  324. lfshook.NewLogger().Infof("dial action %+v", action)
  325. res, _, err := AminInstance.Send(action)
  326. if err != nil {
  327. lfshook.NewLogger().Errorf("%+v", err)
  328. }
  329. lfshook.NewLogger().Info(res)
  330. }
  331. // 获取分机状态
  332. func ExtenStatus(exten string) (Status string) {
  333. action := map[string]string{
  334. "Action": "ExtensionState",
  335. "Exten": exten,
  336. "Context": "default",
  337. }
  338. res, _, err := AminInstance.Send(action)
  339. if err != nil {
  340. lfshook.NewLogger().Errorf("%+v", err)
  341. return ""
  342. }
  343. //lfshook.NewLogger().Infof("================ExtensionState:res %+v", res)
  344. return res["StatusText"]
  345. }
  346. // PACU ChanSpy
  347. func ChanSpy(src, dst string, whisper, bargein bool) {
  348. lfshook.NewLogger().Infof("chan spy src:%s dst:%s", src, dst)
  349. //channel := fmt.Sprintf("%s/%s", utils.DialPrefix, dst)
  350. channel := fmt.Sprintf("Local/%s@aio-rule", dst)
  351. data := fmt.Sprintf("%s/%s,qBE", utils.DialPrefix, src)
  352. /*
  353. if whisper {
  354. data = fmt.Sprintf("%s,w", data)
  355. }
  356. if bargein {
  357. data = fmt.Sprintf("%s,B", data)
  358. }
  359. */
  360. action := map[string]string{
  361. "Action": "Originate",
  362. "Channel": channel, // 不存在的通话
  363. "Application": "ChanSpy",
  364. "Data": data, // 存在的通话
  365. "CallerID": dst,
  366. "Async": "true",
  367. }
  368. lfshook.NewLogger().Infof("PACU ChanSpy action %+v", action)
  369. _, _, err := AminInstance.Send(action)
  370. if err != nil {
  371. lfshook.NewLogger().Errorf("%+v", err)
  372. }
  373. }
  374. // Redirect 转接
  375. func RedirectInQueue(channel, dst, dialrule, callerID string) (err error) {
  376. //callerID := "redirect"
  377. //lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
  378. if !utils.IsChannel(channel) {
  379. //callerID = channel
  380. if channel, err = GetChannelByExtenNotBridged(channel); err != nil {
  381. return err
  382. }
  383. }
  384. action := map[string]string{
  385. "Action": "Redirect",
  386. "Channel": channel,
  387. "Exten": dst,
  388. "Context": dialrule,
  389. "CallerID": callerID,
  390. "Priority": "1",
  391. "async": "true",
  392. }
  393. lfshook.NewLogger().Infof("RedirectInQueue: %+v", action)
  394. res, _, err := AminInstance.Send(action)
  395. if err != nil {
  396. lfshook.NewLogger().Error(err)
  397. }
  398. lfshook.NewLogger().Info(res)
  399. return err
  400. }
  401. // Redirect 转接
  402. func Redirect(channel, dst, dialrule, callerID, callerName string) (err error) {
  403. //callerID := "redirect"
  404. //lfshook.NewLogger().Infof("redirect src %s to dst %s", channel, dst)
  405. if !utils.IsChannel(channel) {
  406. callerID = channel
  407. if channel, err = GetChannelByExten(channel); err != nil {
  408. return err
  409. }
  410. }
  411. action := map[string]string{
  412. "Action": "Redirect",
  413. "Channel": channel,
  414. "Exten": dst,
  415. "Context": dialrule,
  416. "CallerID": fmt.Sprintf("%s<%s>", callerName, callerID),
  417. "Priority": "1",
  418. "async": "true",
  419. }
  420. lfshook.NewLogger().Infof("Redirect: %+v", action)
  421. res, _, err := AminInstance.Send(action)
  422. if err != nil {
  423. lfshook.NewLogger().Error(err)
  424. }
  425. lfshook.NewLogger().Info(res)
  426. return err
  427. }
  428. func SetPadTimer() {
  429. toRunPadpriority := priority.GetPriorityByKey(priority.InterruptedPad) //Get PAD priori 获取之前打断的报警优先级
  430. //toRunpriority := priority.GetPriorityByKey("PAD-ICP")
  431. _, taskTmp, ok := priority.RegistryTask.HighestPriorityRunningTask()
  432. if ok {
  433. lfshook.NewLogger().Infof("PAD SetPadTimer runing priority:%d toRun priority:%d", taskTmp.Priority, toRunPadpriority)
  434. if taskTmp.Priority < toRunPadpriority { //higher priority task running ,do not set timer
  435. return
  436. }
  437. }
  438. res, err := QueueStatus("0300", "") // check OCC queue , if empty OCC-PAD start
  439. if err != nil {
  440. lfshook.NewLogger().Infof("QueueStatus err%+v", err)
  441. return
  442. }
  443. if res == nil {
  444. return
  445. }
  446. if res.Calls != "0" {
  447. lfshook.NewLogger().Infof("PAD SetPadTimer Set QueueTimer timeout 30s !")
  448. //active.SetTimer = true
  449. //lfshook.NewLogger().Logger.Infof("=========Start PAD timer !=============")
  450. if active.QueueTimer != nil {
  451. if active.QueueTimer.Stop() {
  452. lfshook.NewLogger().Logger.Infof("=========Release PAD timer true !============")
  453. } else {
  454. lfshook.NewLogger().Logger.Infof("=========Release PAD timer false ! ============")
  455. }
  456. }
  457. lfshook.NewLogger().Logger.Infof("=========Start PAD timer !======%d=======", active.PADTimeout)
  458. active.QueueTimer = time.AfterFunc(time.Duration(active.PADTimeout)*time.Second, func() { // check the PAD 30s timeout
  459. //active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
  460. //if both not active , return
  461. if active.ActivedCab == "" {
  462. return
  463. }
  464. res, err := QueueStatus("0301", "") // check OCC queue , if empty OCC-PAD start
  465. if err != nil {
  466. lfshook.NewLogger().Infof("OCC QueueStatus err:%+v", err)
  467. return
  468. }
  469. if res == nil {
  470. return
  471. }
  472. if res.Calls == "0" { // OCC queue empty
  473. resCaller, 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. sort.Slice(resCaller.Entrys, func(i, j int) bool {
  479. return resCaller.Entrys[i].Position < resCaller.Entrys[j].Position
  480. })
  481. for _, caller := range resCaller.Entrys {
  482. priority.ICPAnswer = 0
  483. //lfshook.NewLogger().Infof("====SetPadTimer==QueueTimer==2=")
  484. //lfshook.NewLogger().Infof("==SetPadTimer==Redirect to 0301 entry:%s=Pos:%s==", caller.CallerIDNum, caller.Position)
  485. //order by pos
  486. RedirectInQueue(caller.CallerIDNum, "0301", "queues-occ", caller.CallerIDNum) // redirect All ICP-PAD redirect to OCC queue
  487. time.Sleep(time.Millisecond * 100) //200 ms delay
  488. }
  489. }
  490. })
  491. }
  492. }
  493. func ConfbridgeKick(confnum, channel string) (res map[string]string, err error) {
  494. action := map[string]string{
  495. "Action": "ConfbridgeKick",
  496. "Conference": confnum,
  497. "Channel": channel,
  498. }
  499. res, _, err = AminInstance.Send(action)
  500. if err != nil {
  501. return nil, err
  502. }
  503. lfshook.NewLogger().Infof("ConfbridgeKick res:%+v", res)
  504. if res["Response"] != "Success" {
  505. return nil, errors.New(res["Message"])
  506. }
  507. return res, nil
  508. }
  509. func CPAConfbridgeKick(confnum string) (res map[string]string, err error) {
  510. chans, err := ConfbridgeList(confnum)
  511. if err != nil {
  512. return nil, errors.New(res["Message"])
  513. }
  514. for _, confChan := range chans {
  515. if !strings.Contains(confChan, "PJSIP/1481") {
  516. ConfbridgeKick(confnum, confChan)
  517. }
  518. }
  519. return res, nil
  520. }
  521. func CPAConfbridgeReinvite(confID string) {
  522. time.Sleep(time.Millisecond * 500)
  523. for _, ext := range Speakers {
  524. ConfbridgeReinvite(ext, "call-speakers-cpa", confID)
  525. }
  526. }
  527. func EMGConfbridgeKick(confnum string) (res map[string]string, err error) {
  528. chans, err := ConfbridgeList(confnum)
  529. if err != nil {
  530. return nil, errors.New(res["Message"])
  531. }
  532. for _, confChan := range chans {
  533. if !strings.Contains(confChan, "0502@default") {
  534. ConfbridgeKick(confnum, confChan)
  535. }
  536. }
  537. return res, nil
  538. }
  539. func EMGConfbridgeReinvite(confID string) {
  540. time.Sleep(time.Millisecond * 500)
  541. for _, ext := range Speakers {
  542. ConfbridgeReinvite(ext, "call-speakers-emg", confID)
  543. }
  544. }
  545. func ConfbridgeList(confnum string) (chans []string, err error) {
  546. action := map[string]string{
  547. "Action": "ConfbridgeList",
  548. "Conference": confnum,
  549. }
  550. res, events, err := AminInstance.Send(action)
  551. if err != nil {
  552. return nil, err
  553. }
  554. lfshook.NewLogger().Infof("ConfbridgeList res:%+v", res)
  555. if res["Response"] == "Success" {
  556. for _, event := range events {
  557. if event.Data["Event"] == "ConfbridgeList" {
  558. chans = append(chans, event.Data["Channel"])
  559. }
  560. }
  561. return chans, nil
  562. } else {
  563. return nil, errors.New(res["Message"])
  564. }
  565. }
  566. func ConfbridgeReinvite(src, context, confID string) {
  567. if ExtenStatus(src) != "Idle" {
  568. lfshook.NewLogger().Infof(" ConfbridgeReinvite ext:%s Not Idle !", src)
  569. return
  570. }
  571. chanel := fmt.Sprintf("Local/%s@%s", src, context)
  572. action := map[string]string{
  573. "Action": "Originate",
  574. "Channel": chanel,
  575. "Exten": "000",
  576. "Context": "confbridge-join",
  577. "CallerID": fmt.Sprintf("%s<%s>", "", ""),
  578. "Priority": "1",
  579. "Variable": fmt.Sprintf("CBID=%s", confID),
  580. "async": "true",
  581. }
  582. lfshook.NewLogger().Infof("dial action %+v", action)
  583. res, _, err := AminInstance.Send(action)
  584. if err != nil {
  585. lfshook.NewLogger().Errorf("%+v", err)
  586. }
  587. lfshook.NewLogger().Info(res)
  588. }
  589. func ICPConfbridgeReinvite(confID, paType string) {
  590. switch paType {
  591. case "PAD-OCC":
  592. go DialICP("8", "2311", "confbridge-join", confID, "1") //ICP1---call
  593. go DialICP("8", "2381", "confbridge-join", confID, "8") //ICP8---call
  594. case "CPA":
  595. go DialICP("2", "2311", "confbridge-join", confID, "1") //ICP1---call
  596. go DialICP("2", "2381", "confbridge-join", confID, "8") //ICP8---call
  597. case "EMG":
  598. go DialICP("3", "2311", "confbridge-join", confID, "1") //ICP1---call
  599. go DialICP("3", "2381", "confbridge-join", confID, "8") //ICP8---call
  600. case "SPC":
  601. go DialICP("6", "2311", "confbridge-join", confID, "1") //ICP1---call
  602. go DialICP("6", "2381", "confbridge-join", confID, "8") //ICP8---call
  603. case "STN":
  604. go DialICP("4", "2311", "confbridge-join", confID, "1") //ICP1---call
  605. go DialICP("4", "2381", "confbridge-join", confID, "8") //ICP8---call
  606. case "DCS":
  607. go DialICP("5", "2311", "confbridge-join", confID, "1") //ICP1---call
  608. go DialICP("5", "2381", "confbridge-join", confID, "8") //ICP8---call
  609. case "CHK":
  610. go DialICP("10", "2311", "confbridge-join", confID, "1") //ICP1---call
  611. go DialICP("10", "2381", "confbridge-join", confID, "8") //ICP8---call
  612. case "VOL":
  613. go DialICP("11", "2311", "confbridge-join", confID, "1") //ICP1---call
  614. go DialICP("11", "2381", "confbridge-join", confID, "8") //ICP8---call
  615. }
  616. }