From 17b81245f31d032d5eed69c190e42edb1949f46b Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 12 四月 2022 16:37:39 +0800
Subject: [PATCH] 修复接听后闪退的问题

---
 HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java |   45 +++++++++++++++++++++++++++------------------
 1 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
index 85c48bb..0016adc 100644
--- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
+++ b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
@@ -68,7 +68,7 @@
     /**
      * instance
      */
-    private volatile static HDLAuthSocket instance;
+    private  static final HDLAuthSocket instance=new HDLAuthSocket();
 
     private HDLAuthSocket() {
         initListenerGatewayEvent();
@@ -84,14 +84,14 @@
      *
      * @return HDLAuthSocket
      */
-    public static synchronized HDLAuthSocket getInstance() {
-        if (instance == null) {
-            synchronized (HDLLinkConfig.class) {
-                if (instance == null) {
-                    instance = new HDLAuthSocket();
-                }
-            }
-        }
+    public  static HDLAuthSocket getInstance() {
+//        if (instance == null) {
+//            synchronized (HDLAuthSocket.class) {
+//        if (instance == null) {
+//            instance = new HDLAuthSocket();
+//        }
+//            }
+//        }
         return instance;
     }
 
@@ -110,14 +110,14 @@
      *
      * @return 杩斿洖褰撳墠瀵硅薄
      */
-    private UdpSocketBoot getUdpBoot() {
+    private synchronized UdpSocketBoot getUdpBoot() {
         try {
             if (udpSocketBoot == null) {
                 udpSocketBoot = UdpClient.init(UDP_PORT, getUdpOptions());
                 udpSocketBoot.bind();
             }
         } catch (Exception e) {
-//            return null;
+              LogUtils.e("鍒濆鍖朣ocket udp寮傚父"+e.getMessage());
         }
 
         return udpSocketBoot;
@@ -136,9 +136,11 @@
         //2.鏋勫缓鐩戝惉Listener
 //        authEvent =
         //3.鐩戝惉缃戝叧骞挎挱鐨勫叆缃戞寚浠�
+        EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST);
         EventDispatcher.getInstance().register(TopicConstant.GATEWAY_AUTH_BROADCAST, new EventListener() {
             @Override
             public void onMessage(Object msg) {
+                LogUtils.i("鏀跺埌缃戝叧璁よ瘉淇℃伅: ");
                 NetworkAccessBroadcastResponse bean = getNetworkAccessBroadcastResponse(msg);
                 if (bean != null) {
                     //绉婚櫎鐩戝惉
@@ -408,11 +410,11 @@
      */
     public void udpSendMsg(String topic, String bodyStr,boolean broadcast) {
         if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) {
-            LogUtils.e("udpSendMsg", "鍙傛暟涓嶈兘涓虹┖");
+            LogUtils.e( "鍙傛暟涓嶈兘涓虹┖锛屼笉鑳藉彂閫乁DP鏁版嵁");
             return;
         }
         if (!HDLLinkConfig.getInstance().checkIfCertified()) {
-            LogUtils.e("udpSendMsg", "鏈璇侊紝璇峰厛璁よ瘉");
+            LogUtils.e("鏈璇侊紝璇峰厛璁よ瘉鍐嶈皟鐢║DP鍙戦�佹柟娉�");
             return;
         }
         LinkRequest message = new LinkRequest(topic, bodyStr);
@@ -492,7 +494,8 @@
                             }.getType());
                             GatewaySearchBean searchBean = response.getObjects();
                             if (searchBean != null && !TextUtils.isEmpty(searchBean.getGatewayId())) {
-                                if (searchBean.getGatewayId().contains(searchGatewayId)) {
+                                searchBean.setIp_address(linkResponse.getSource_ipAddress());
+                                if (searchBean.getGatewayId().contains(searchGatewayId)&&!TextUtils.isEmpty(searchGatewayId)) {
                                     removeSearchGatewayEvent();//绉婚櫎鎼滅储缃戝叧鐩戝惉
                                     isSearchGatewaySuccess.set(true);//鎼滅储鎴愬姛鏍囪
                                     searchGatewayCount.set(11);//娆℃暟鏍囪
@@ -526,10 +529,14 @@
                             }.getType());
                             GatewaySearchBean gateway = response.getObjects();
                             if (gateway != null && !TextUtils.isEmpty(gateway.getGatewayId())) {
+                                //鍙兘缃戝叧甯﹁繃鏉ョ殑ip涓嶅
+                                gateway.setIp_address(linkResponse.getSource_ipAddress());
                                 //涓荤綉鍏冲苟涓旀槸褰撳墠缁戝畾鐨勭綉鍏�
                                 if ("true".equals(gateway.getMaster().toLowerCase()) && gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId())) {
                                     HDLLinkConfig.getInstance().setCurrentGateway(gateway);//璁剧疆褰撳墠缃戝叧
-                                    HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address());
+                                    if(!TextUtils.isEmpty( gateway.getIp_address())) {
+                                        HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address());
+                                    }
                                     //鏇存柊褰撳墠缃戝叧鐨勪俊鎭�
                                     HDLLinkConfig.getInstance().reSaveConfig();
                                 }
@@ -582,9 +589,11 @@
                 }
 
                 if (!isSearchGatewaySuccess.get()) {
-                    //鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�
-                    callBackSearchGatewayTimeout();
-                    LogUtils.e("鎼滅储缃戝叧", "鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�");
+                    try {
+                        LogUtils.e("鎼滅储缃戝叧", "鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�");
+                        //鎼滅储10娆★紝鎸囧畾缃戝叧閮芥病鍥炲锛屽洖璋冭秴鏃�
+                        callBackSearchGatewayTimeout();
+                    }catch (Exception e){}
                 }
             }
         }).start();

--
Gitblit v1.8.0