call.go 20 KB

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