zhoufan vor 1 Jahr
Ursprung
Commit
36bea03637

+ 9 - 0
midware-service/src/main/java/midware/service/eslclient/EslCommon.java

@@ -100,6 +100,15 @@ public class EslCommon {
100 100
         return chan;
101 101
     }
102 102
 
103
+    //根据会话id获取第一个通道
104
+    public static Channel getFirstChanBySessionId(String sessionId) {
105
+        List<Channel> cs = channels.stream().filter(p -> p.getSessionId().equals(sessionId) && p.getSessionSort() == 1).collect(Collectors.toList());
106
+        if (cs.size() > 0) {
107
+            return cs.get(0);
108
+        }
109
+        return null;
110
+    }
111
+
103 112
     //根据id获取会话
104 113
     public static Session getSessionById(String id){
105 114
         List<Session> cs=sessions.stream().filter(p -> p.getSessionId().equals(id)).collect(Collectors.toList());

+ 13 - 16
midware-service/src/main/java/midware/service/eslclient/EslEventListener.java

@@ -336,6 +336,19 @@ public class EslEventListener implements IEslEventListener {
336 336
                                     result.put("Number", calleeNum);
337 337
                                     webSocketService.sendMessage(callerAgent.getAgent(), JSON.toJSONString(result));
338 338
                                 }
339
+                                if(chanNames[2].equals(calleeNum)) {
340
+                                    if (calleeAgent1 != null) {
341
+                                        Map<String, Object> result = new HashMap<>();
342
+                                        result.put("Type", "Incoming");
343
+                                        result.put("Result", true);
344
+                                        result.put("CallID", chan.getRecordId());
345
+                                        //result.put("Number", callerNum);
346
+                                        Channel fc = EslCommon.getFirstChanBySessionId(session.getSessionId());
347
+                                        result.put("Number", fc != null ? fc.getNumber() : callerNum);
348
+                                        result.put("Action", chan.getOpType());
349
+                                        webSocketService.sendMessage(calleeAgent1.getAgent(), JSON.toJSONString(result));
350
+                                    }
351
+                                }
339 352
                             } else {
340 353
                                 chan.setRecordId(EslCommon.getChanByNumber(callerNum).getRecordId());
341 354
                                 if (calleeAgent1 != null) {
@@ -413,9 +426,7 @@ public class EslEventListener implements IEslEventListener {
413 426
                                     if (!opType.equals("MakeCall") || calleeNum.equals(chanNames[2])) {
414 427
                                         actionNotice(opType, callerAgent.getAgent(), callId, true);
415 428
                                         if (opType.equals("Meeting") && chan.getSessionSort() == 3) {
416
-                                            eslClientService.talkJoinMeeting(callId);
417 429
                                             eslClientService.setConferenceExitSound(callId, true);
418
-                                            if (session != null) session.setMeeting(true);
419 430
                                         }
420 431
                                     }
421 432
                                 }
@@ -539,20 +550,6 @@ public class EslEventListener implements IEslEventListener {
539 550
                             if (callerAgent != null && StringHelper.isNotEmpty(chan.getOpType())) {
540 551
                                 actionNotice(chan.getOpType(), callerAgent.getAgent(), sid, false);
541 552
                             }
542
-                            if (chan.getOpType().equals("Meeting")) {
543
-                                List<Channel> channels = EslCommon.channels.stream().filter(p ->
544
-                                        p.getSessionId().equals(sid) && !p.getChanId().equals(chanId)).collect(Collectors.toList());
545
-                                AsyncHelper.instance().execute(new TimerTask() {
546
-                                    @Override
547
-                                    public void run() {
548
-                                        for (Channel c : channels) {
549
-                                            eslClientService.playBreak(c.getChanId());
550
-                                            eslClientService.playBack("/home/website/midware/files/others/noanswer.mp3",c.getChanId());
551
-                                        }
552
-                                    }
553
-                                });
554
-                            }
555
-
556 553
                         }
557 554
 
558 555
                         boolean isupdate = true;

+ 20 - 23
midware-service/src/main/java/midware/service/init/EslClientService.java

@@ -289,9 +289,13 @@ public class EslClientService {
289 289
         try {
290 290
             String fix = action.substring(action.lastIndexOf("|") + 1);
291 291
             String command = EslCommandEnum.originate.name();
292
-            String arg = " {instant_ringback=true,origination_caller_id_number=" + callerNum
293
-                    + ",call_called=" + calleeNum.substring(fix.length()) + ",record_concat_video=true"
294
-                    + ",transfer_ringback=local_stream://moh,ignore_early_media=true"
292
+//            String arg = " {instant_ringback=true,origination_caller_id_number=" + callerNum
293
+//                    + ",call_called=" + calleeNum.substring(fix.length()) + ",record_concat_video=true"
294
+//                    + ",transfer_ringback=local_stream://moh,ignore_early_media=true"
295
+//                    + "}user/" + callerNum + " &bridge(" + getCallString(calleeNum) + ")"
296
+//                    + "\r\nJob-UUID: " + action + "|" + System.currentTimeMillis();
297
+            String arg = " {origination_caller_id_number=" + callerNum + ",call_called=" + calleeNum.substring(fix.length())
298
+                    + ",record_concat_video=true,transfer_ringback=local_stream://moh,ringback=${us-ring}"
295 299
                     + "}user/" + callerNum + " &bridge(" + getCallString(calleeNum) + ")"
296 300
                     + "\r\nJob-UUID: " + action + "|" + System.currentTimeMillis();
297 301
             result = client.sendAsyncApiCommand(command, arg);
@@ -487,19 +491,6 @@ public class EslClientService {
487 491
         return !result.equals("");
488 492
     }
489 493
 
490
-    //暂停播放语音
491
-    public boolean playBreak(String chanId) {
492
-        String result = "";
493
-        try {
494
-            String command = EslCommandEnum.uuid_break.name();
495
-            String arg = chanId ;
496
-            result = client.sendAsyncApiCommand(command, arg);
497
-        } catch (Exception e) {
498
-            log.error( chanId + " 暂停播放语音失败", e);
499
-        }
500
-        return !result.equals("");
501
-    }
502
-
503 494
     //会话加入会议
504 495
     public boolean talkJoinMeeting(String sessionId) {
505 496
         String result = "";
@@ -513,6 +504,7 @@ public class EslClientService {
513 504
             String arg = sessionId + " -both 'set:hangup_after_bridge=false,set:record_concat_video=true,"
514 505
                     + "conference:" + sessionId + "@" + at + "' inline";
515 506
             result = client.sendAsyncApiCommand(command, arg);
507
+            if (!result.equals("") && session != null) session.setMeeting(true);
516 508
         } catch (Exception e) {
517 509
             log.error(sessionId + " 会话加入会议失败", e);
518 510
         }
@@ -536,13 +528,13 @@ public class EslClientService {
536 528
             }
537 529
 
538 530
             String arg = " {origination_caller_id_number=" + callerNum + ",cc_member_session_uuid=" + meetingId
539
-                    + ",call_called=" + calleeNum.substring(fix.length()) + argstr + "}"
540
-                    //+ getCallString(calleeNum) + " " + meetingId + " xml ExtenMeeting";
541
-                    + getCallString(calleeNum) + " &conference(" + meetingId + "@" + at + ")"
531
+                    + ",call_called=" + calleeNum.substring(fix.length())
532
+                    + ",transfer_ringback=local_stream://moh,ringback=${us-ring}"
533
+                    + argstr + "}" + getCallString(calleeNum)
534
+                    // + " " + meetingId + " xml ExtenMeeting";
535
+                    + " &conference(" + meetingId + "@" + at + ")"
542 536
                     + "\r\nJob-UUID: " + action + "|" + System.currentTimeMillis();
543 537
             result = client.sendAsyncApiCommand(command, arg);
544
-            playBack("local_stream://moh",meetingId);
545
-
546 538
         } catch (Exception e) {
547 539
             log.error(callerNum + "|" + calleeNum + "|" + meetingId + " 呼叫加入会议失败", e);
548 540
         }
@@ -629,9 +621,14 @@ public class EslClientService {
629 621
             String fix = action.substring(action.lastIndexOf("|") + 1);
630 622
             String command = EslCommandEnum.uuid_transfer.name();
631 623
             //String arg = chanId + " " + calleeNum + " xml ForExten";
624
+//            String arg = chanId + " 'm:^:set:hangup_after_bridge=false^set:record_concat_video=true^"
625
+//                    + "set:instant_ringback=true^set:transfer_ringback=local_stream://moh^"
626
+//                    + "bridge:{ignore_early_media=true,origination_caller_id_number=" + callerNum + ",call_called="
627
+//                    + calleeNum.substring(fix.length()) + "}" + getCallString(calleeNum) + "' inline"
628
+//                    + "\r\nJob-UUID: " + action + "|" + System.currentTimeMillis();
632 629
             String arg = chanId + " 'm:^:set:hangup_after_bridge=false^set:record_concat_video=true^"
633
-                    + "set:instant_ringback=true^set:transfer_ringback=local_stream://moh^"
634
-                    + "bridge:{ignore_early_media=true,origination_caller_id_number=" + callerNum + ",call_called="
630
+                    + "set:transfer_ringback=local_stream://moh^set:ringback=${us-ring}^"
631
+                    + "bridge:{origination_caller_id_number=" + callerNum + ",call_called="
635 632
                     + calleeNum.substring(fix.length()) + "}" + getCallString(calleeNum) + "' inline"
636 633
                     + "\r\nJob-UUID: " + action + "|" + System.currentTimeMillis();
637 634
             result = client.sendAsyncApiCommand(command, arg);

+ 12 - 7
midware-service/src/main/java/midware/service/init/WebSocketService.java

@@ -283,7 +283,14 @@ public class WebSocketService {
283 283
                                     result.put("Result", "目标号码忙碌中");
284 284
                                 } else {
285 285
                                     agent.setOpType(type);
286
-                                    isExec = eslClientService.callJoinMeeting(agent.getExten(), DestinationNumber, chan.getSessionId(), type + "|" + agentId + "|" + DestinationNumber+ "|" + Fix);
286
+                                    if (eslClientService.talkJoinMeeting(chan.getSessionId())) {
287
+                                        try {
288
+                                            Thread.sleep(300);
289
+                                            isExec = eslClientService.callJoinMeeting(agent.getExten(), DestinationNumber, chan.getSessionId(), type + "|" + agentId + "|" + DestinationNumber + "|" + Fix);
290
+                                        } catch (InterruptedException e) {
291
+                                            throw new RuntimeException(e);
292
+                                        }
293
+                                    }
287 294
                                 }
288 295
                             }
289 296
                         }
@@ -384,9 +391,8 @@ public class WebSocketService {
384 391
                                     Channel tchan = EslCommon.getChanByExten(tAgent.getExten());
385 392
                                     if (tchan != null && StringHelper.isNotEmpty(tchan.getSessionId())) {
386 393
                                         agent.setOpType(type);
387
-                                        String sid = tchan.getSessionId(), cid = tchan.getChanId();
388
-                                        Channel channel = EslCommon.channels.stream().filter(p -> p.getSessionId().equals(sid)
389
-                                                && !p.getChanId().equals(cid)).findFirst().get();
394
+                                        String sid = tchan.getSessionId();
395
+                                        Channel channel = EslCommon.getFirstChanBySessionId(sid);
390 396
                                         isExec = eslClientService.intercept(agent.getExten(), tAgent.getExten(), channel.getChanId(), sid, type + "|" + agentId + "|" + agent.getExten());
391 397
                                     }
392 398
                                 } else {
@@ -439,9 +445,8 @@ public class WebSocketService {
439 445
                                             result.put("Result", "主叫不能代接");
440 446
                                         } else {
441 447
                                             agent.setOpType(type);
442
-                                            String sid = tchan.getSessionId(), cid = tchan.getChanId();
443
-                                            Channel channel = EslCommon.channels.stream().filter(p -> p.getSessionId().equals(sid)
444
-                                                    && !p.getChanId().equals(cid)).findFirst().get();
448
+                                            String sid = tchan.getSessionId();
449
+                                            Channel channel = EslCommon.getFirstChanBySessionId(sid);
445 450
                                             isExec = eslClientService.intercept(agent.getExten(), tAgent.getExten(), channel.getChanId(), sid, type + "|" + agentId + "|" + agent.getExten());
446 451
                                         }
447 452
                                     }