소스 검색

## [1.1.52] version 70 - 2020-08-21
### Changed
- 改善TCP重连
- TTS在界面初始化
- 增加APP重启功能
- 连接开始6秒后判断是否连接完成,否则断开

allen 3 년 전
부모
커밋
cadea1599b

BIN
.gradle/4.10.1/fileHashes/fileHashes.bin


BIN
.gradle/4.10.1/fileHashes/fileHashes.lock


BIN
.gradle/4.10.1/fileHashes/resourceHashesCache.bin


BIN
.gradle/4.10.1/javaCompile/classAnalysis.bin


BIN
.gradle/4.10.1/javaCompile/javaCompile.lock


BIN
.gradle/4.10.1/javaCompile/taskHistory.bin


BIN
.gradle/4.10.1/taskHistory/taskHistory.bin


BIN
.gradle/4.10.1/taskHistory/taskHistory.lock


+ 2 - 2
build.gradle

@@ -47,12 +47,12 @@ buildscript {
     /**
      * APP版本码
      */
-    ext.app_version_code = 69
+    ext.app_version_code = 70
 
     /**
      * APP版本号
      */
-    ext.app_version = "1.1.51"
+    ext.app_version = "1.1.52"
 
     /**
      * 项目依赖库

+ 41 - 9
home/src/main/code/com/wdkl/ncs/android/component/home/activity/NewEventListActivity.kt

@@ -8,7 +8,6 @@ import android.view.View
 import com.alibaba.android.vlayout.DelegateAdapter
 import com.alibaba.android.vlayout.VirtualLayoutManager
 import com.enation.javashop.android.jrouter.external.annotation.Autowired
-import com.enation.javashop.android.jrouter.external.annotation.Router
 import com.enation.javashop.net.engine.model.NetState
 import com.google.common.base.Strings
 import com.google.gson.Gson
@@ -20,8 +19,8 @@ import com.wdkl.ncs.android.component.home.service.WdKeepAliveService
 import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
 import com.wdkl.ncs.android.component.home.util.SpeechUtil
 import com.wdkl.ncs.android.component.home.util.Util
+import com.wdkl.ncs.android.component.nursehome.common.Constants.Companion.ttsState
 import com.wdkl.ncs.android.lib.base.BaseActivity
-import com.wdkl.ncs.android.lib.base.BaseApplication
 import com.wdkl.ncs.android.lib.utils.AppTool
 import com.wdkl.ncs.android.lib.utils.showMessage
 import com.wdkl.ncs.android.middleware.logic.contract.home.NewEventListContract
@@ -64,8 +63,8 @@ class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventLis
 
     override fun init() {
         //TTS初始化
-//        SpeechUtil.getInstance().init(BaseApplication.appContext)
-//        SpeechUtil.getInstance().startSpeechThread()
+        SpeechUtil.getInstance().init(this)
+        SpeechUtil.getInstance().startSpeechThread()
 
         WdKeepAliveService.mNewEventListActive = true
         //震动
@@ -81,11 +80,27 @@ class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventLis
             if (tcpModel.type == TcpType.EVENT && tcpModel.action == TcpAction.EventAction.KEY_CLICK) {
                 val eventStr = Util.appendSpace(interactionVO.fromFrameFullName.replace("-", ",")) + ", " + interactionVO.data
                 SpeechUtil.getInstance().stopSpeak()
-                SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
+                AppTool.Time.delay(200) {
+                    var count = 1;
+                    while (ttsState == 0 && count<6){
+                        count++
+                        Thread.sleep(500)
+                    }
+                    SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
+                }
+
 
             } else if (tcpModel.type == TcpType.IM && tcpModel.action == TcpAction.IMAction.MSG) {
                 SpeechUtil.getInstance().stopSpeak()
-                SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
+                AppTool.Time.delay(200) {
+                    var count = 1;
+                    while (ttsState == 0 && count<6){
+                        count++
+                        Thread.sleep(500)
+                    }
+                    SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
+                }
+
             } else if (tcpModel.type == TcpType.SOS && tcpModel.action == TcpAction.SOSAction.CALL) {
                 SpeechUtil.getInstance().stopSpeak()
                 MediaPlayHelper.getInstance().stopMusic()
@@ -113,7 +128,8 @@ class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventLis
     override fun destory() {
         MediaPlayHelper.getInstance().stopMusic()
         mVibrator.cancel()
-        SpeechUtil.getInstance().stopSpeak()
+//        SpeechUtil.getInstance().stopSpeak()
+        SpeechUtil.getInstance().release()
         WdKeepAliveService.mNewEventListActive = false
     }
 
@@ -232,14 +248,30 @@ class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventLis
                     listData.add(responseInteractionVO)
                     renderData(listData)
                     val eventStr = Util.appendSpace(responseInteractionVO.fromFrameFullName.replace("-", ",")) + ", " + responseInteractionVO.data
-                    SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
+                    AppTool.Time.delay(200) {
+                        var count = 1;
+                        while (ttsState == 0 && count<6){
+                            count++
+                            Thread.sleep(500)
+                        }
+                        SpeechUtil.getInstance().newSpeech("您有新的事件待处理, " + eventStr, false)
+                    }
+
                 }
             } else if (tcpModel.type == TcpType.IM){
                 if (tcpModel.action == TcpAction.IMAction.MSG) {
                     handleVibrator()
                     listData.add(responseInteractionVO)
                     renderData(listData)
-                    SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
+                    AppTool.Time.delay(200) {
+                        var count = 1;
+                        while (ttsState == 0 && count<6){
+                            count++
+                            Thread.sleep(500)
+                        }
+                        SpeechUtil.getInstance().newSpeech("您有新的语音留言待处理", false)
+                    }
+
                 }
             }
         } else if (messageEvent.tag == 999){ //SOS

+ 29 - 37
home/src/main/code/com/wdkl/ncs/android/component/home/activity/WatchHome2Activity.kt

@@ -102,11 +102,10 @@ class WatchHome2Activity : BaseActivity<WatchHomeActivityPresenter, WatchActivit
         tv_register_version.text = "v" + BuildConfig.VERSION_NAME
 
         //TTS初始化
-        SpeechUtil.getInstance().init(BaseApplication.appContext)
-        SpeechUtil.getInstance().startSpeechThread()
+//        SpeechUtil.getInstance().init(BaseApplication.appContext)
+//        SpeechUtil.getInstance().startSpeechThread()
         DaemonEnv.initContext(this);
 
-
         initCountDownTimer()
 
         //网络强度监听
@@ -270,35 +269,32 @@ class WatchHome2Activity : BaseActivity<WatchHomeActivityPresenter, WatchActivit
             return
         }
 
-//        if (Strings.isNullOrEmpty(data.ethIp)){
-//            Thread(Runnable {
-//                //连接TCP
-//                if (TcpClient.getInstance().channel==null || !TcpClient.getInstance().channel.isActive) {
-//                    TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat,iTcpCallBack)
-//                }
-//                while (!(TcpClient.getInstance().channel==null || !TcpClient.getInstance().channel.isActive)) {
-//                    presenter.getDeviceVO(Constants.imei)
-//                    Thread.sleep(1000)
-//                }
-//            }).start()
-//            showMessage("获取设备数据中,请稍候")
-//            return
-//        } else {
-//            Thread(Runnable {
-//                //连接TCP
-//                if (TcpClient.getInstance().channel==null || !TcpClient.getInstance().channel.isActive) {
-//                    TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat,iTcpCallBack)
-//                }
-//            }).start()
-//        }
+        Constants.partId = data.partId
+        Constants.deviceId = data.id
+        Constants.sipId = data.sipId
 
-        if(!Strings.isNullOrEmpty(data.ethIp)&&!Strings.isNullOrEmpty(Constants.tcpServer)){
-            Thread(Runnable { //连接TCP
+        if (Strings.isNullOrEmpty(data.ethIp)){
+            Thread(Runnable {
+                //连接TCP
+                if (TcpClient.getInstance().channel==null || !TcpClient.getInstance().channel.isActive) {
                     TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat,iTcpCallBack)
+                }
+                while (!(TcpClient.getInstance().channel==null || !TcpClient.getInstance().channel.isActive)) {
+                    presenter.getDeviceVO(Constants.imei)
+                    Thread.sleep(1000)
+                }
+            }).start()
+            showMessage("获取设备数据中,请稍候")
+            return
+        } else {
+            Thread(Runnable {
+                //连接TCP
+                if (TcpClient.getInstance().channel==null || !TcpClient.getInstance().channel.isActive) {
+                    TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat,iTcpCallBack)
+                }
             }).start()
         }
 
-
         loadingDialog.dismiss()
         watch_activity_register_layout.visibility = View.GONE
         watch_activity_home_linyout.visibility = View.VISIBLE
@@ -311,22 +307,18 @@ class WatchHome2Activity : BaseActivity<WatchHomeActivityPresenter, WatchActivit
         isUnRegister = false
 
         Log.i(TAG, "收到返回的设备信息 ")
-        Constants.partId = data.partId
-        Constants.deviceId = data.id
-        Constants.sipId = data.sipId
         Constants.ethIp = data.ethIp
-        Constants.sipIp = data.sipIp
         Constants.sipPassword = data.sipPassword
         Constants.memberId = data.memberId
         Constants.userName = data.memberName
         Constants.userRoleName = data.roleName
 
-        if(!Strings.isNullOrEmpty(Constants.sipId)){ //拿到SIP账号后登陆webrtc
-            SocketManager.getInstance().unConnect()
-            AppTool.Time.delay(300, {
-                SocketManager.getInstance().connect(Urls.WS, Constants.sipId, 0)
-            })
-        }
+//        if(!Strings.isNullOrEmpty(Constants.sipId)&&SocketManager.getInstance().userState!=1){ //拿到SIP账号后登陆webrtc
+//            SocketManager.getInstance().unConnect()
+//            AppTool.Time.delay(300, {
+//                SocketManager.getInstance().connect(Urls.WS, Constants.sipId, 0)
+//            })
+//        }
 
         presenter.getAppVersion(Constants.partId, 7)
 

+ 18 - 9
home/src/main/code/com/wdkl/ncs/android/component/home/activity/WatchUserSettingActivity.java

@@ -22,8 +22,10 @@ import com.wdkl.ncs.android.component.home.BuildConfig;
 import com.wdkl.ncs.android.component.home.R;
 import com.wdkl.ncs.android.component.home.service.WdKeepAliveService;
 import com.wdkl.ncs.android.component.home.settingconfig.SettingConfig;
+import com.wdkl.ncs.android.component.home.util.AppUtils;
 import com.wdkl.ncs.android.component.home.util.NetHelper;
 import com.wdkl.ncs.android.component.nursehome.common.Constants;
+import com.wdkl.ncs.android.lib.utils.AppTool;
 import com.wdkl.ncs.android.lib.utils.ExtendMethodsKt;
 import com.wdkl.ncs.android.middleware.tcp.TcpClient;
 import com.wdkl.ncs.android.middleware.tcp.channel.DeviceUtil;
@@ -38,7 +40,7 @@ public class WatchUserSettingActivity extends Activity {
 
     private TextView tvAppVersion,tvDeviceId,tvDeviceImei,tvDeviceIp,tvServerIp;
 
-    private Button btnChange,btnCheckUpdate,btnSystemSetting;
+    private Button btnChange,btnAppRestart,btnCheckUpdate,btnSystemSetting;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -52,6 +54,7 @@ public class WatchUserSettingActivity extends Activity {
         tvServerIp = findViewById(R.id.tv_server_ip);
 
         btnChange = findViewById(R.id.btn_user_change);
+        btnAppRestart = findViewById(R.id.btn_app_restart);
         btnCheckUpdate = findViewById(R.id.btn_check_update);
         btnSystemSetting = findViewById(R.id.btn_system_setting);
 
@@ -72,17 +75,23 @@ public class WatchUserSettingActivity extends Activity {
         });
 
         final Context _this = this;
+        btnAppRestart.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                AppUtils.restartApp();
+            }
+        });
         btnCheckUpdate.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-            if ((System.currentTimeMillis() / 1000) - WdKeepAliveService.instance.getUpdateLastTime() > 10) {
-                WdKeepAliveService.instance.setUpdateLastTime(System.currentTimeMillis() / 1000);
-                Intent intent = new Intent();
-                intent.setClass(_this, AppUpdateActivity.class);
-                startActivity(intent);
-            } else {
-                Toast.makeText(_this, "请10秒后再尝试", Toast.LENGTH_SHORT).show();
-            }
+                if ((System.currentTimeMillis() / 1000) - WdKeepAliveService.instance.getUpdateLastTime() > 10) {
+                    WdKeepAliveService.instance.setUpdateLastTime(System.currentTimeMillis() / 1000);
+                    Intent intent = new Intent();
+                    intent.setClass(_this, AppUpdateActivity.class);
+                    startActivity(intent);
+                } else {
+                    Toast.makeText(_this, "请10秒后再尝试", Toast.LENGTH_SHORT).show();
+                }
             }
         });
         btnSystemSetting.setOnClickListener(new View.OnClickListener() {

+ 15 - 10
home/src/main/code/com/wdkl/ncs/android/component/home/activity/WebRTCVoipAudioActivity.kt

@@ -11,6 +11,7 @@ import android.util.Log
 import android.view.KeyEvent
 import android.view.View
 import com.google.gson.Gson
+import com.wdkl.core.socket.SocketManager
 import com.wdkl.core.voip.VoipEvent
 import com.wdkl.ncs.android.component.home.R
 import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
@@ -130,20 +131,24 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
 
     fun createCallout(){
         Handler().postDelayed({
-//            Log.i(TAG,"session state:"+gEngineKit?.currentSession?.state+",userState:"+SocketManager.getInstance().userState)
-//            if (gEngineKit?.currentSession?.state != EnumType.CallState.Connected){
-//                //showMessage("连接失败")
-//
-//                gEngineKit?.endCall()
-//                val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
-//                val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, tcpModel.toId, interactionVO.id)
-//                TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-//                finish()
-//            }
             call_duration_tv.base = SystemClock.elapsedRealtime()
             call_duration_tv.start()
         }, 2900)
 
+        //6秒后仍然未连接,则断开
+        Handler().postDelayed({
+            Log.i(TAG,"session state:"+gEngineKit?.currentSession?.state+",userState:"+ SocketManager.getInstance().userState)
+            if (gEngineKit?.currentSession?.state != EnumType.CallState.Connected){
+                showMessage("连接失败,请重试")
+
+                gEngineKit?.endCall()
+                val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
+                val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Constants.deviceId, tcpModel.toId, interactionVO.id)
+                TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
+                finish()
+            }
+        },6000)
+
         val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
         if ((interactionVO.fromClerkId!=null && interactionVO.fromClerkId>=0) && interactionVO.fromDeviceId!=Constants.deviceId){
 //            Handler().postDelayed({

+ 7 - 2
home/src/main/code/com/wdkl/ncs/android/component/home/service/WdKeepAliveService.kt

@@ -299,7 +299,6 @@ class WdKeepAliveService : AbsWorkService() {
                 }
             }
             checkNetStateTimer!!.schedule(checkNetStateTimerTask, 8000, Constants.heartBeat * 1000L)
-//            checkNetStateTimer!!.schedule(checkNetStateTimerTask, 8000, 5000)
         }
     }
 
@@ -314,7 +313,8 @@ class WdKeepAliveService : AbsWorkService() {
 //                val wakeLock = Util.wakeUpAndUnlock(this@WdKeepAliveService)
                 if (TcpClient.getInstance().retryTimes < 30) {
                     if (TcpClient.getInstance().channel == null || TcpClient.getInstance().bootstrap == null) {
-                        TcpClient.getInstance().doConnect(iTcpCallBack)//   TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat, iTcpCallBack)
+//                        TcpClient.getInstance().doConnect(iTcpCallBack)
+                       TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat, iTcpCallBack)
                     }
                 } else {
                     AppUtils.restartApp()
@@ -327,6 +327,11 @@ class WdKeepAliveService : AbsWorkService() {
                     iTcpCallBack.connected()
                 }
             }
+        } else {
+            Thread(Runnable {
+                Thread.sleep(5000)
+                reConnect()
+            }).start()
         }
     }
 }

+ 1 - 0
home/src/main/code/com/wdkl/ncs/android/component/home/util/SpeechUtil.java

@@ -166,6 +166,7 @@ public class SpeechUtil {
         speechTextList.clear();
         isStop = true;
         speakIndex = 0;
+        Constants.Companion.setTtsState(0);
         if (textToSpeech != null) {
             textToSpeech.stop();
             textToSpeech.shutdown();

+ 10 - 0
home/src/main/res/layout/user_setting_layout.xml

@@ -167,6 +167,16 @@
                     android:textSize="14dp" />
 
                 <Button
+                    android:id="@+id/btn_app_restart"
+                    android:layout_marginTop="10dp"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_horizontal"
+                    android:background="@drawable/javashop_btn_balck_line_bg"
+                    android:text="APP重启"
+                    android:textSize="14dp" />
+
+                <Button
                     android:id="@+id/btn_check_update"
                     android:layout_marginTop="10dp"
                     android:layout_width="wrap_content"

+ 25 - 6
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/TcpClient.java

@@ -30,7 +30,7 @@ public class TcpClient {
     //数据处理
     TcpClientHandler tcpClientHandler = new TcpClientHandler();
     //重试间隔
-    private Integer retrySeconds = 5;
+    private Integer retrySeconds = 3;
     //重试计数
     public Integer retryTimes = 1;
 
@@ -46,8 +46,20 @@ public class TcpClient {
 
     //初始化Netty Tcp Client 并连接
     public synchronized void init(String serverIP, Integer serverPort, Integer heartBeatSeconds, ITcpCallBack iTcpCallBack) {
+        if (TcpClientHandler.getConnected()){
+            return;
+        }
+
+        if (channel!=null){
+            if (channel.isActive()||channel.isOpen()) {
+                return;
+            }
+        }
+
         if (bootstrap!=null){
             bootstrap = null;
+            channel = null;
+            workGroup = null;
         }
 
         final Integer hbSeconds = heartBeatSeconds;
@@ -83,6 +95,12 @@ public class TcpClient {
             System.out.println("TcpClient connecting");
             return;
         }
+
+        if (TcpClientHandler.getConnected()){
+            System.out.println("TcpClient is connected");
+            return;
+        }
+
         System.out.println("TcpClient connect start");
         ChannelFuture future = bootstrap.connect().addListener(new ChannelFutureListener() {
             @Override
@@ -103,19 +121,20 @@ public class TcpClient {
                         public void run() {
                             if (retryTimes > 30) {
                                 System.out.println("TcpClient 重试" + (retryTimes - 1) + "次,结束");
-                                retryTimes = 1;
+
                                 channelFuture.channel().eventLoop().schedule(new Runnable() {
                                     @Override
                                     public void run() {
+                                        retryTimes = 1;
                                         System.out.println("TcpClient 10分钟后 重试连接");
-//                                        init(Constants.Companion.getTcpServer(),Constants.Companion.getTcpPort(),Constants.Companion.getHeartBeat(),iTcpCallBack);
-                                        doConnect(iTcpCallBack);
+                                        init(Constants.Companion.getTcpServer(),Constants.Companion.getTcpPort(),Constants.Companion.getHeartBeat(),iTcpCallBack);
+//                                        doConnect(iTcpCallBack);
                                     }
                                 },60*10, TimeUnit.SECONDS);
                             } else {
                                 retryTimes++;
-                                doConnect(iTcpCallBack);
-//                                init(Constants.Companion.getTcpServer(),Constants.Companion.getTcpPort(),Constants.Companion.getHeartBeat(),iTcpCallBack);
+//                                doConnect(iTcpCallBack);
+                                init(Constants.Companion.getTcpServer(),Constants.Companion.getTcpPort(),Constants.Companion.getHeartBeat(),iTcpCallBack);
                             }
                         }
                     }, retrySeconds, TimeUnit.SECONDS);

+ 4 - 2
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/TcpClientHandler.java

@@ -67,7 +67,7 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
         this.ctx = null;
         Log.i(TAG, "TcpClientHandler 失去连接");
         EventBus.getDefault().post(new MessageEvent("net off",Constants.EVENT_TCP_BREAK));
-        TcpClient.getInstance().doConnect(null);
+//        TcpClient.getInstance().doConnect(null);
 //        reConnect(ctx);
     }
 
@@ -127,9 +127,11 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
                     Thread.sleep(1000);
                 }catch (Exception ex){}
 
-                if (retrySendMsg < Constants.Companion.getHeartBeat()*2){
+                if (retrySendMsg < 3){
                     retrySendMsg++;
                     sendMsg(msg);
+                } else {
+                    ctx.close();    //主动断线
                 }
             }
         }).start();

+ 9 - 0
readme.md

@@ -26,6 +26,15 @@
 
 ---
 
+## [1.1.52] version 70 - 2020-08-21
+### Changed
+- 改善TCP重连
+- TTS在界面初始化
+- 增加APP重启功能
+- 连接开始6秒后判断是否连接完成,否则断开
+
+---
+
 ## [1.1.50] version 68 - 2020-08-17
 ### Changed
 - 常量值心跳29秒