zhoufan 1 год назад
Родитель
Сommit
cb17f9603e

+ 24 - 8
midware-service/src/main/java/midware/service/init/EslClientService.java

48
         new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(() -> {
48
         new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(() -> {
49
             if (!client.canSend()) {
49
             if (!client.canSend()) {
50
                 try {
50
                 try {
51
+                    if (EslCommon.agents.size() > 0) {
52
+                        for (Agent a : EslCommon.agents) {
53
+                            logout(a.getAgent(), a.getGroup());
54
+                            a.setAgentState(EslAgentEnum.logout.ordinal());
55
+                        }
56
+                        EslCommon.agents=new ArrayList<>();
57
+                    }
58
+
51
                     client.connect(config.getHost(), config.getPort(), config.getPassword(), config.getTimeout());
59
                     client.connect(config.getHost(), config.getPort(), config.getPassword(), config.getTimeout());
52
                     //移除事件
60
                     //移除事件
53
                     client.cancelEventSubscriptions();
61
                     client.cancelEventSubscriptions();
70
                     } catch (Exception e1) {
78
                     } catch (Exception e1) {
71
                     }
79
                     }
72
                 }
80
                 }
73
-            }else {
74
-                if (EslCommon.agents.size() > 0) {
75
-                    for (Agent a : EslCommon.agents) {
76
-                        logout(a.getAgent(), a.getGroup());
77
-                        a.setAgentState(EslAgentEnum.logout.ordinal());
78
-                    }
79
-                    EslCommon.agents=new ArrayList<>();
80
-                }
81
             }
81
             }
82
         }, 1, 5000, TimeUnit.MILLISECONDS);
82
         }, 1, 5000, TimeUnit.MILLISECONDS);
83
 
83
 
379
         return result;
379
         return result;
380
     }
380
     }
381
 
381
 
382
+    //放音收号
383
+    public String playAndGetDigits(String path, String chanId) {
384
+        String result = "";
385
+        try {
386
+            String command = EslCommandEnum.uuid_broadcast.name();
387
+            path = "/home/wav/8001.wav";
388
+
389
+            String arg = chanId + " 'play_and_get_digits::1 1 2 2000 # " + path + " silence_stream://250 res \\d+'";
390
+            result = client.sendAsyncApiCommand(command, arg);
391
+
392
+        } catch (Exception e) {
393
+            log.error(chanId + " 放音收号失败", e);
394
+        }
395
+        return result;
396
+    }
397
+
382
     //会话加入会议
398
     //会话加入会议
383
     public String talkJoinMeeting(String sessionId) {
399
     public String talkJoinMeeting(String sessionId) {
384
         String result = "";
400
         String result = "";

+ 13 - 8
midware-util/src/main/java/midware/util/helper/IpHelper.java

27
         return hostIP;
27
         return hostIP;
28
     }
28
     }
29
 
29
 
30
-    public static String getMac(){
31
-        String mac="";
30
+    public static String getMac() {
31
+        String mac = "";
32
         try {
32
         try {
33
             Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
33
             Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
34
             while (networkInterfaces.hasMoreElements()) {
34
             while (networkInterfaces.hasMoreElements()) {
35
                 NetworkInterface ni = networkInterfaces.nextElement();
35
                 NetworkInterface ni = networkInterfaces.nextElement();
36
-                if (ni.isLoopback() || ni.isVirtual() || !ni.isUp()) {
37
-                    continue;
36
+                if (ni.isLoopback() || ni.isVirtual() || !ni.isUp()) continue;
37
+                boolean ip4 = false;
38
+                Enumeration<InetAddress> nias = ni.getInetAddresses();
39
+                while (nias.hasMoreElements()) {
40
+                    InetAddress ia = nias.nextElement();
41
+                    if (!ia.isLinkLocalAddress() && !ia.isLoopbackAddress() && ia instanceof Inet4Address) {
42
+                        ip4 = true;
43
+                    }
38
                 }
44
                 }
45
+                if (!ip4) continue;
39
                 byte[] macByte = ni.getHardwareAddress();
46
                 byte[] macByte = ni.getHardwareAddress();
40
-                if (macByte == null) {
41
-                    continue;
42
-                }
47
+                if (macByte == null) continue;
43
                 StringBuilder buf = new StringBuilder();
48
                 StringBuilder buf = new StringBuilder();
44
                 for (byte aMac : macByte) {
49
                 for (byte aMac : macByte) {
45
                     buf.append(String.format("%02X-", aMac));
50
                     buf.append(String.format("%02X-", aMac));
46
                 }
51
                 }
47
                 if (buf.length() > 0) {
52
                 if (buf.length() > 0) {
48
                     buf.deleteCharAt(buf.length() - 1);
53
                     buf.deleteCharAt(buf.length() - 1);
49
-                    mac=buf.toString();
54
+                    mac = buf.toString();
50
                     break;
55
                     break;
51
                 }
56
                 }
52
             }
57
             }