Browse Source

## [1.0.1] version 2 - 2020-07-03
### Added
- 等待通话界面常亮
- 事件语音界面常亮
- 升级界面常亮
- SOS界面常亮
### Changed
- 优化AppService,监测TCP断线亮屏

allen 4 years ago
parent
commit
bdb7d5973e

+ 1 - 0
.idea/gradle.xml

@@ -28,5 +28,6 @@
         <option name="useQualifiedModuleNames" value="true" />
       </GradleProjectSettings>
     </option>
+    <option name="offlineMode" value="true" />
   </component>
 </project>

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

@@ -160,7 +160,7 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener {
                 Log.i(TAG, "tcpModel" + interactionVO!!.id!!)
                 Log.i(TAG, "tcpModel" + tcpModel.toJson())
 
-                if(!TcpClientHandler.connecteds){
+                if(!TcpClientHandler.getConnected()){
                     EventBus.getDefault().post(MessageEvent(tcpModel, Constants.EVENT_TCP_BREAK))
                 }
 

+ 51 - 162
home/src/main/code/com/wdkl/ncs/android/component/home/service/APPService.kt

@@ -1,16 +1,15 @@
 package com.wdkl.ncs.android.component.home.service
 
-import android.app.Notification
 import android.app.Service
 import android.content.Intent
 import android.os.Binder
 import android.os.CountDownTimer
 import android.os.IBinder
 import android.text.TextUtils
-import android.util.Log
 import com.google.gson.Gson
 import com.wdkl.core.consts.Urls
 import com.wdkl.core.socket.SocketManager
+import com.wdkl.ncs.android.component.home.util.Util
 import com.wdkl.ncs.android.component.nursehome.common.Constants
 import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
 import com.wdkl.ncs.android.middleware.tcp.TcpClient
@@ -20,17 +19,14 @@ import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel
 import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction
 import com.wdkl.ncs.android.middleware.tcp.enums.TcpType
 import com.wdkl.ncs.android.middleware.utils.MessageEvent
-import com.wdkl.skywebrtc.SkyEngineKit
 import org.greenrobot.eventbus.EventBus
-import org.greenrobot.eventbus.Subscribe
-import org.greenrobot.eventbus.ThreadMode
 import java.util.*
 
 class APPService : Service() {
     private val TAG = APPService::class.java.simpleName
     internal var myBinder = ServiceBinder()
 
-    private var CALL_TIMEOUT = 12 //多久可以再次点击
+    private var CALL_TIMEOUT = 12 //拨出超时秒数
     //呼叫倒计时
     lateinit var countDownTimer: CountDownTimer
 
@@ -38,15 +34,11 @@ class APPService : Service() {
         var tcpModel: TcpModel? = null
     }
 
-    var isThread: Boolean = true
-
     override fun onCreate() {
         super.onCreate()
-        EventBus.getDefault().register(this)
-//        checkStatus()
-        connectWebsocket()
-        connectWebsocket2()
         initCountDownTimer()
+        connectRTC()
+        resendVoiceCallAndSuccess()
     }
 
     override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
@@ -58,85 +50,69 @@ class APPService : Service() {
         return myBinder
     }
 
-    var timer: Timer? = null
-    var timerTask: TimerTask? = null
-
-    private fun checkStatus() {
-        if (timer != null) timer!!.purge()
-        if (timerTask != null) timerTask!!.cancel()
-        timer = Timer()
-        timerTask = object : TimerTask() {
+    var rtcTimer: Timer? = null
+    var rtcTimerTask: TimerTask? = null
+
+    /**
+     * 重连wdklRTC
+     */
+    private fun connectRTC() {
+        if (rtcTimer != null) rtcTimer!!.purge()
+        if (rtcTimerTask != null) rtcTimerTask!!.cancel()
+        rtcTimer = Timer()
+        rtcTimerTask = object : TimerTask() {
             override fun run() {
-                try {
-                } catch (e: Exception) {
-                }
-            }
-        }
-        timer!!.schedule(timerTask, 0, 30000)
-    }
-
-    var timer2: Timer? = null
-    var timerTask2: TimerTask? = null
-
-    private fun connectWebsocket() {
-        if (timer2 != null) timer2!!.purge()
-        if (timerTask2 != null) timerTask2!!.cancel()
-        timer2 = Timer()
-        timerTask2 = object : TimerTask() {
-            override fun run() {
-//                WebsocketUtil.connectWS()//定时检测Websocket;如有断开;及时联接
-                if (!TcpClientHandler.connecteds) {
+                if (!TcpClientHandler.getConnected()) {
                     EventBus.getDefault().post(MessageEvent("", 14))
                     if (!TextUtils.isEmpty(Constants.sip_id)) {
-                        // 连接socket:登录
                         SocketManager.getInstance().connect(Urls.WS, Constants.sip_id, 0)
                     }
-
                 }
             }
         }
-        timer2!!.schedule(timerTask2, 8000, 5000)
+        rtcTimer!!.schedule(rtcTimerTask, 8000, 5000)
     }
 
-    var timer3: Timer? = null
-    var timerTask3: TimerTask? = null
-
-    private fun connectWebsocket2() {
-        if (timer3 != null) timer3!!.purge()
-        if (timerTask3 != null) timerTask3!!.cancel()
-        timer3 = Timer()
-        timerTask3 = object : TimerTask() {
+    var resendVoiceTimer: Timer? = null
+    var resendVoiceTimerTask: TimerTask? = null
+
+    /**
+     * 重发拨出成功和去电的挂断命令
+     */
+    private fun resendVoiceCallAndSuccess() {
+        val _this = this
+        if (resendVoiceTimer != null) resendVoiceTimer!!.purge()
+        if (resendVoiceTimerTask != null) resendVoiceTimerTask!!.cancel()
+        resendVoiceTimer = Timer()
+        resendVoiceTimerTask = object : TimerTask() {
             override fun run() {
-//                WebsocketUtil.connectWS()//定时检测Websocket;如有断开;及时联接
-                    if (TcpClientHandler.connecteds && tcpModel != null) {
-
-                        var interactionVO: InteractionVO? = null
-                        if (tcpModel!!.data.javaClass.name == String::class.java.name) {
-                            interactionVO = Gson().fromJson(tcpModel?.data.toString(), InteractionVO::class.java)
-                        } else {
-                            interactionVO = tcpModel?.data as InteractionVO
-                        }
-//                Log.e(TAG, "tcpModel" + interactionVO!!.id!!)
-//                Log.e(TAG, "tcpModel" + tcpModel?.toJson())
+                if (!TcpClientHandler.getConnected()) {
+                    //断开连接后亮屏
+                    Util.wakeUpAndUnlock(_this)
+                } else if (tcpModel != null){
+                    var interactionVO: InteractionVO? = null
+                    if (tcpModel!!.data.javaClass.name == String::class.java.name) {
+                        interactionVO = Gson().fromJson(tcpModel?.data.toString(), InteractionVO::class.java)
+                    } else {
+                        interactionVO = tcpModel?.data as InteractionVO
+                    }
 
-                        //todo 给服务器发送挂断 tcp
-                        if (interactionVO != null) {
-                            if (tcpModel?.type == TcpType.VOICE) {
-                                if (tcpModel?.action === TcpAction.VoiceAction.SUCCESS) {
-                                    val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.toId, interactionVO.id)
-                                    TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-                                } else if (tcpModel?.action === TcpAction.VoiceAction.CALL) {
-                                    val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.fromId, interactionVO.id)
-                                    TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-                                }
+                    if (interactionVO != null) {
+                        if (tcpModel?.type == TcpType.VOICE) {
+                            if (tcpModel?.action === TcpAction.VoiceAction.SUCCESS) {
+                                val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.toId, interactionVO.id)
+                                TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
+                            } else if (tcpModel?.action === TcpAction.VoiceAction.CALL) {
+                                val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.fromId, interactionVO.id)
+                                TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
                             }
-
                         }
-                        tcpModel = null
+                    }
+                    tcpModel = null
                 }
             }
         }
-        timer3!!.schedule(timerTask3, 2000, 1000)
+        resendVoiceTimer!!.schedule(resendVoiceTimerTask, 2000, 2000)
     }
 
     override fun onDestroy() {
@@ -145,7 +121,6 @@ class APPService : Service() {
             countDownTimer.cancel()
         }
         stopForeground(true)// 停止前台服务--参数:表示是否移除之前的通知
-        EventBus.getDefault().unregister(this)
     }
 
     inner class ServiceBinder : Binder() {
@@ -156,7 +131,6 @@ class APPService : Service() {
     fun initCountDownTimer() {
         countDownTimer = object : CountDownTimer(CALL_TIMEOUT * 1000L, 1000) {
             override fun onTick(millisUntilFinished: Long) {
-
             }
 
             override fun onFinish() {
@@ -166,11 +140,8 @@ class APPService : Service() {
                 } else {
                     interactionVO = tcpModel?.data as InteractionVO
                 }
-//                Log.e(TAG, "tcpModel" + interactionVO!!.id!!)
-//                Log.e(TAG, "tcpModel" + tcpModel?.toJson())
 
-
-                //todo 给服务器发送挂断 tcp
+                //给服务器发送挂断 tcp
                 if (interactionVO != null) {
                     if (tcpModel?.type == TcpType.VOICE) {
                         if (tcpModel?.action === TcpAction.VoiceAction.SUCCESS) {
@@ -187,86 +158,4 @@ class APPService : Service() {
             }
         }
     }
-
-//    companion object {
-//        fun hangUp() {
-//
-//        }
-//    }
-
-
-    @Subscribe(threadMode = ThreadMode.MAIN)
-    fun onMoonEvent(messageEvent: MessageEvent) {
-        if (messageEvent.tag == Constants.EVENT_TCP_BREAK) {
-            tcpModel = messageEvent.getMessage() as TcpModel
-//            countDownTimer.start()
-
-//            Thread(Runnable {
-//                while (isThread) {
-//                    if (TcpClientHandler.connecteds) {
-//
-//                        var interactionVO: InteractionVO? = null
-//                        if (tcpModel!!.data.javaClass.name == String::class.java.name) {
-//                            interactionVO = Gson().fromJson(tcpModel?.data.toString(), InteractionVO::class.java)
-//                        } else {
-//                            interactionVO = tcpModel?.data as InteractionVO
-//                        }
-////                Log.e(TAG, "tcpModel" + interactionVO!!.id!!)
-////                Log.e(TAG, "tcpModel" + tcpModel?.toJson())
-//
-//
-//                        //todo 给服务器发送挂断 tcp
-//                        if (interactionVO != null) {
-//                            if (tcpModel?.type == TcpType.VOICE) {
-//                                if (tcpModel?.action === TcpAction.VoiceAction.SUCCESS) {
-//                                    val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.toId, interactionVO.id)
-//                                    TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-//                                } else if (tcpModel?.action === TcpAction.VoiceAction.CALL) {
-//                                    val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.fromId, interactionVO.id)
-//                                    TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-//                                }
-//                            }
-//
-//                        }
-//                        tcpModel = null
-//                        isThread = false
-//                    }
-//                    try {
-//                        Thread.sleep(1000)
-//                    } catch (e: InterruptedException) {
-//                        e.printStackTrace()
-//                    }
-//                }
-//
-//            }).start()
-
-        } else if (messageEvent.tag == Constants.EVENT_TCP_RETRANSMISSION) {
-//            var interactionVO: InteractionVO? = null
-//            if (tcpModel!!.data.javaClass.name == String::class.java.name) {
-//                interactionVO = Gson().fromJson(tcpModel?.data.toString(), InteractionVO::class.java)
-//            } else {
-//                interactionVO = tcpModel?.data as InteractionVO
-//            }
-////                Log.e(TAG, "tcpModel" + interactionVO!!.id!!)
-////                Log.e(TAG, "tcpModel" + tcpModel?.toJson())
-//
-//
-//            //todo 给服务器发送挂断 tcp
-//            if (interactionVO != null) {
-//                if (tcpModel?.type == TcpType.VOICE) {
-//                    if (tcpModel?.action === TcpAction.VoiceAction.SUCCESS) {
-//                        val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.toId, interactionVO.id)
-//                        TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-//                    } else if (tcpModel?.action === TcpAction.VoiceAction.CALL) {
-//                        val voiceUtilTcpModel = VoiceUtil.voiceHandoff(Integer.parseInt(Constants.ids), tcpModel?.fromId, interactionVO.id)
-//                        TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
-//                    }
-//                }
-//
-//            }
-//            tcpModel = null
-//        }
-
-        }
-    }
 }

+ 2 - 2
home/src/main/code/com/wdkl/ncs/android/component/home/settingconfig/SettingConfig.java

@@ -12,7 +12,7 @@ public class SettingConfig {
     private static final int CountdownTime = 15;
 
     /**
-     * 获取播报次数
+     * 获取转发时间
      *
      * @return
      */
@@ -21,7 +21,7 @@ public class SettingConfig {
     }
 
     /**
-     * 设置播报次数
+     * 设置转发时间
      *
      * @param value
      */

+ 1 - 0
home/src/main/res/layout/activity_app_update.xml

@@ -5,6 +5,7 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="#ffffff"
+        android:keepScreenOn="true"
         android:orientation="vertical">
 
         <TextView

+ 1 - 0
home/src/main/res/layout/activity_sos_emergency_call.xml

@@ -3,6 +3,7 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:keepScreenOn="true"
     android:background="#FFE6E8">
 
     <LinearLayout

+ 1 - 0
home/src/main/res/layout/activity_web_rtc_voip_audio_ringing.xml

@@ -2,6 +2,7 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:keepScreenOn="true"
     android:background="#FFE6E8">
 
     <LinearLayout

+ 1 - 0
home/src/main/res/layout/watch_activity_event_detail.xml

@@ -4,6 +4,7 @@
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:keepScreenOn="true"
         android:background="#FFBDC3">
 
         <LinearLayout

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

@@ -34,9 +34,9 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
     private static Integer totalRetryTimes = 0;
     //是否连接成功
     private static Boolean connected = false;
-     //连接断开变量
-    public static Boolean connecteds = false;
-
+    public static Boolean getConnected(){
+        return connected;
+    }
 
     //连接成功执行的方法
     @Override
@@ -45,7 +45,6 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
         Log.i(TAG,"tcp连接成功");
         this.ctx = ctx;
         connected = true;
-        connecteds = true;
         retryTimes = 0;
 //        TcpModel tcpModel = DeviceUtil.deviceConnect(Constants.Companion.getImei());
 //        TcpClient.getInstance().sendMsg(tcpModel.toJson());
@@ -62,8 +61,8 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         super.channelInactive(ctx);
         connected = false;
-        connecteds = false;
         Log.i(TAG, "TcpClientHandler 失去连接");
+
         reConnect(ctx);
     }
 
@@ -104,7 +103,6 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
         cause.printStackTrace();
         ctx.close();
         connected = false;
-        connecteds = false;
         System.out.println("TcpClientHandler 失去连接,错误引起");
     }
 

+ 10 - 1
readme.md

@@ -25,7 +25,16 @@
 在发布新版本时,可以直接将Unreleased区块中的内容移动至新发 布版本的描述区块就可以了
 
 ---
-## [1.0.0] - 2020-07-03
+## [1.0.1] version 2 - 2020-07-03
+### Added
+- 等待通话界面常亮
+- 事件语音界面常亮
+- 升级界面常亮
+- SOS界面常亮
+### Changed
+- 优化AppService,监测TCP断线亮屏
+---
+## [1.0.0] version 1 - 2020-07-03
 ### Changed
 - 使用物联卡时,网络状态的判断出错的略过
 - 根据重新配置的coturn服务端,改善P2P NAT穿透的隧道表现