call.go 19 KB

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