Explorar o código

## [1.1.29] version 48 - 2020-08-11
### Changed
- 建立通话后,如果不是连接状态,则挂断
- 去掉重复连接RTC
- 去掉websocket本身的断开重连
### Fixed
- 修复事件界面黑屏恢复后增加条目的问题

allen %!s(int64=3) %!d(string=hai) anos
pai
achega
3608d1325e

+ 4 - 13
WebRTC/src/main/java/com/wdkl/core/socket/MyWebSocket.java

@@ -1,11 +1,14 @@
 package com.wdkl.core.socket;
 
 import android.annotation.SuppressLint;
+import android.os.Handler;
+import android.os.Looper;
 import android.util.Log;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.wdkl.core.util.StringUtil;
+import com.wdkl.ncs.android.lib.utils.AppTool;
 
 import org.java_websocket.client.WebSocketClient;
 import org.java_websocket.handshake.ServerHandshake;
@@ -38,12 +41,6 @@ public class MyWebSocket extends WebSocketClient {
     public void onClose(int code, String reason, boolean remote) {
         Log.e("dds_error", "onClose:" + reason + "remote:" + remote);
         if (connectFlag) {
-            try {
-                Thread.sleep(3000);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-            this.iEvent.reConnect();
         } else {
             this.iEvent.logout("onClose");
         }
@@ -54,13 +51,7 @@ public class MyWebSocket extends WebSocketClient {
     public void onError(Exception ex) {
         Log.e("dds_error", "onError:" + ex.toString());
         this.iEvent.logout("onError");
-//        connectFlag = false;
-        try {
-            Thread.sleep(3000);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        this.iEvent.reConnect();
+        connectFlag = false;
     }
 
     @Override

+ 3 - 1
WebRTC/src/main/java/com/wdkl/core/socket/SocketManager.java

@@ -103,8 +103,10 @@ public class SocketManager implements IEvent {
 
     public void unConnect() {
         if (webSocket != null) {
+            if (webSocket.isOpen()){
+                webSocket.close();
+            }
             webSocket.setConnectFlag(false);
-            webSocket.close();
             webSocket = null;
         }
 

+ 2 - 2
build.gradle

@@ -47,12 +47,12 @@ buildscript {
     /**
      * APP版本码
      */
-    ext.app_version_code = 44
+    ext.app_version_code = 48
 
     /**
      * APP版本号
      */
-    ext.app_version = "1.1.25"
+    ext.app_version = "1.1.29"
 
     /**
      * 项目依赖库

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

@@ -62,8 +62,7 @@ class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventLis
         HomeLaunch.component.inject(this)
     }
 
-    override fun onStart() {
-        super.onStart()
+    override fun init() {
         //TTS初始化
 //        SpeechUtil.getInstance().init(BaseApplication.appContext)
 //        SpeechUtil.getInstance().startSpeechThread()
@@ -107,10 +106,6 @@ class NewEventListActivity : BaseActivity<NewEventListPresenter,ActivityEventLis
         renderData(listData)
     }
 
-    override fun init() {
-
-    }
-
     override fun bindEvent() {
 
     }

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

@@ -3,7 +3,6 @@ package com.wdkl.ncs.android.component.home.activity
 import android.app.Activity
 import android.bluetooth.BluetoothAdapter
 import android.bluetooth.BluetoothHeadset
-import android.graphics.Color
 import android.os.Bundle
 import android.os.CountDownTimer
 import android.os.Handler
@@ -37,7 +36,6 @@ import kotlinx.android.synthetic.main.activity_sip_voip_audio.call_duration_tv
 import kotlinx.android.synthetic.main.activity_sip_voip_audio.hang_up_imagev
 import kotlinx.android.synthetic.main.activity_sip_voip_audio.room_number_tv
 import kotlinx.android.synthetic.main.activity_web_rtc_voip_audio.*
-import kotlinx.android.synthetic.main.watch_activity_home2.*
 import org.greenrobot.eventbus.EventBus
 import org.greenrobot.eventbus.Subscribe
 import org.greenrobot.eventbus.ThreadMode
@@ -61,7 +59,7 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
     //呼叫倒计时
     lateinit var countDownTimer: CountDownTimer
     private var isClick = true //是否可点击
-
+    private var createEnabled = true
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -99,7 +97,9 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
         }
 
         if (action == CALLING) {
-            createCallout()
+            AppTool.Time.delay(500) {
+                createCallout()
+            }
 
             call_duration_tv.visibility = View.VISIBLE
             call_duration_tv.text = "连接中...."
@@ -112,10 +112,6 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
         }
     }
 
-    override fun onStart() {
-        super.onStart()
-    }
-
     fun init() {
         hang_up_imagev.setOnClickListener(this)
         hands_free_image.setOnClickListener(this)
@@ -134,9 +130,14 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
 
     fun createCallout(){
         Handler().postDelayed({
+            if (gEngineKit?.currentSession?.state != EnumType.CallState.Connected){
+                //showMessage("连接失败")
+                gEngineKit?.endCall()
+                finish()
+            }
             call_duration_tv.base = SystemClock.elapsedRealtime()
             call_duration_tv.start()
-        }, 3500)
+        }, 2900)
 
         val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
         if ((interactionVO.fromClerkId!=null && interactionVO.fromClerkId>=0) && interactionVO.fromDeviceId!=Constants.deviceId){
@@ -162,32 +163,38 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
                 }
             },1000)
         } else {
-            var room = UUID.randomUUID().toString() + System.currentTimeMillis()
-            Log.d(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
-            gEngineKit?.currentSession?.setCallState(EnumType.CallState.Idle)
-            val outCallResult = gEngineKit?.startOutCall(applicationContext, room, targetId, true)
-            val session = gEngineKit?.currentSession
-            if (session == null){
-                showMessage("通话失败,请重试1")
-                AppTool.Time.delay(800) {
-                    finish()
-                }
-            } else {
-                session.setSessionCallback(this)
-                Log.d(TAG+"_peer"," 呼出状态: myId = ${session?.mMyId} , targetId = ${session?.mTargetId}, roomId = ${session?.roomId}, state = ${session?.state}, outCallResult = $outCallResult")
-                if (outCallResult!!) {
-                    setAudioDeviceOut(session)
-                } else if (session.state == EnumType.CallState.Connected || session.state == EnumType.CallState.Connecting){
-                    setAudioDeviceOut(session)
-                } else {
-                    if (session.state != EnumType.CallState.Idle) {
-                        showMessage("对方忙线中2")
-                    } else {
-                        showMessage("通话失败,请重试")
-                    }
+            if (createEnabled) {
+                var room = UUID.randomUUID().toString() + System.currentTimeMillis()
+                Log.d(TAG, "生成的房间号room " + room + "sipid targetId" + targetId)
+                //gEngineKit?.currentSession?.setCallState(EnumType.CallState.Idle)
+                val outCallResult = gEngineKit?.startOutCall(applicationContext, room, targetId, true)
+                val session = gEngineKit?.currentSession
+                if (session == null) {
+                    showMessage("通话失败,请重试1")
                     AppTool.Time.delay(800) {
                         finish()
                     }
+                } else {
+                    session.setSessionCallback(this)
+                    Log.d(TAG + "_peer", " 呼出状态: myId = ${session?.mMyId} , targetId = ${session?.mTargetId}, roomId = ${session?.roomId}, state = ${session?.state}, outCallResult = $outCallResult")
+                    if (outCallResult!!) {
+                        setAudioDeviceOut(session)
+                    } else if (session.state == EnumType.CallState.Connected || session.state == EnumType.CallState.Connecting) {
+                        setAudioDeviceOut(session)
+                    } else {
+                        if (session.state != EnumType.CallState.Idle) {
+                            showMessage("对方忙线中2")
+                        } else {
+                            showMessage("通话失败,请重试")
+                        }
+                        AppTool.Time.delay(300) {
+                            finish()
+                        }
+                    }
+                }
+            } else {
+                AppTool.Time.delay(200) {
+                    finish()
                 }
             }
         }
@@ -285,7 +292,9 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
                 Log.i(TAG, "对方接听电话啦")
                 call_duration_tv.visibility = View.VISIBLE
                 call_duration_tv.text = "连接中...."
-                createCallout()
+                AppTool.Time.delay(600) {
+                    createCallout()
+                }
             } else if (tcpModel.action == TcpAction.VoiceAction.HANDOFF) { //对方挂断
 
                 var interactionVO: InteractionVO? = null
@@ -298,7 +307,8 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
                 if (interactionVO!!.id == currentTnVO.id){
                     call_duration_tv.stop()
                     showMessage("对方挂断")
-                    gEngineKit?.currentSession?.leave()
+                    createEnabled = false
+                    gEngineKit?.endCall()
                     finish()
                 }
             } else if (tcpModel.action === TcpAction.VoiceAction.REJECT) {
@@ -311,20 +321,33 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
                 val currentTnVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
                 if (interactionVO!!.id == currentTnVO.id){
                     showMessage("对方拒绝接听")
+                    createEnabled = false
+                    gEngineKit?.endCall()
                     finish()
                 }
 
             } else if (tcpModel.action === TcpAction.VoiceAction.CALLING) {
+                createEnabled = false
+                gEngineKit?.endCall()
                 //showMessage("对方正在通话")
                 AppTool.Time.delay(800) {
                     finish()
                 }
             } else if (tcpModel.action === TcpAction.VoiceAction.FAILED) {
+                gEngineKit?.endCall()
                 //voiceStatus.setText("对方拒绝");
                 showMessage("呼叫失败,对方可能不在线")
+                createEnabled = false
                 AppTool.Time.delay(800) {
                     finish()
                 }
+            } else if (tcpModel.action === TcpAction.VoiceAction.CANCEL) {
+                showMessage("对方取消")
+                createEnabled = false
+                gEngineKit?.endCall()
+                AppTool.Time.delay(400) {
+                    finish()
+                }
             }
         }
     }
@@ -348,7 +371,14 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
         }
         MediaPlayHelper.getInstance().stopMusic()
         EventBus.getDefault().unregister(this)
-        gEngineKit?.currentSession?.setCallState(EnumType.CallState.Idle)
+
+    }
+
+    override fun finish() {
+        if (gEngineKit?.currentSession?.state != EnumType.CallState.Idle){
+            gEngineKit?.endCall()
+        }
+        super.finish()
     }
 
     override fun onResume() {
@@ -366,7 +396,7 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
         gEngineKit?.endCall()
         runOnUiThread(Runnable {
             //showMessage("对方挂断")
-            AppTool.Time.delay(800) {
+            AppTool.Time.delay(200) {
                 finish()
             }
         })
@@ -399,16 +429,12 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
         runOnUiThread(Runnable {
             when (var1) {
                 CallEndReason.Busy -> {
-                    showMessage("对方忙线中3")
-                    gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
-                        finish()
-                    }
+                    handOffCall()
                 }
                 CallEndReason.AcceptByOtherClient -> {
                     showMessage("通话中")
                     gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
+                    AppTool.Time.delay(200) {
                         finish()
                     }
                 }
@@ -418,38 +444,42 @@ class WebRTCVoipAudioActivity : Activity(), View.OnClickListener, CallSessionCal
                 CallEndReason.MediaError -> {
                     showMessage("媒体错误")
                     gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
+                    AppTool.Time.delay(200) {
                         finish()
                     }
                 }
                 CallEndReason.OpenCameraFailure -> {
                     showMessage("打开摄像头错误")
                     gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
+                    AppTool.Time.delay(200) {
                         finish()
                     }
                 }
                 CallEndReason.RemoteHangup -> {
-                    //showMessage("对方挂断")
+                    showMessage("对方挂断")
+                    gEngineKit?.endCall()
+                    AppTool.Time.delay(200) {
+                        finish()
+                    }
                 }
                 CallEndReason.RemoteSignalError -> {
                     showMessage("对方网络断开")
                     gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
+                    AppTool.Time.delay(200) {
                         finish()
                     }
                 }
                 CallEndReason.SignalError -> {
                     showMessage("连接断开")
                     gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
+                    AppTool.Time.delay(200) {
                         finish()
                     }
                 }
                 CallEndReason.Timeout -> {
                     showMessage("对方未接听")
                     gEngineKit?.endCall()
-                    AppTool.Time.delay(800) {
+                    AppTool.Time.delay(200) {
                         finish()
                     }
                 }

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

@@ -22,6 +22,7 @@ import com.wdkl.ncs.android.component.home.broadcast.MyMediaButtonReceiver
 import com.wdkl.ncs.android.component.home.settingconfig.SettingConfig
 import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
 import com.wdkl.ncs.android.component.nursehome.common.Constants
+import com.wdkl.ncs.android.lib.utils.AppTool
 import com.wdkl.ncs.android.middleware.model.vo.InteractionVO
 import com.wdkl.ncs.android.middleware.tcp.TcpClient
 import com.wdkl.ncs.android.middleware.tcp.channel.DeviceChannel

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

@@ -53,6 +53,7 @@ class WdKeepAliveService : AbsWorkService() {
     override fun startWork() {
         EventBus.getDefault().register(this)
 
+        /*
         if (!SocketManager.getInstance().connectFlag){
             Thread(Runnable {
                 run {
@@ -64,6 +65,7 @@ class WdKeepAliveService : AbsWorkService() {
                 }
             }).start()
         }
+         */
 
         checkNetState()
     }
@@ -293,22 +295,26 @@ class WdKeepAliveService : AbsWorkService() {
                     if (!EventBus.getDefault().isRegistered(this@WdKeepAliveService)) {
                         EventBus.getDefault().register(this@WdKeepAliveService)
                     }
-                    TcpClient.getInstance().sendMsg("0")
 
-                    if (NetHelper.getInstance().getNetworkState(this@WdKeepAliveService) == NetHelper.NETWORK_NONE || !TcpClientHandler.getConnected()) {
-                        Log.w(TAG, "断网唤醒CPU")
-                        val wakeLock = Util.getCpuWakeLock(this@WdKeepAliveService)
-                        wakeLock.acquire(1000)
-                        if (TcpClient.getInstance().channel==null || TcpClient.getInstance().bootstrap == null) {
-                            TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat,iTcpCallBack)
-                        } else if (!TcpClient.getInstance().channel.isActive && TcpClient.getInstance().retryTimes<30){
-                            TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat,iTcpCallBack)
-                        }
-                    } else {
-                        if (SocketManager.getInstance().connectFlag){
-                            EventBus.getDefault().post(MessageEvent(TcpModel(),Constants.EVENT_RTC_STATE))
+                    if (NetHelper.getInstance().getNetworkState(this@WdKeepAliveService) != NetHelper.NETWORK_NONE) {
+                        if (!TcpClientHandler.getConnected()) {
+                            Log.w(TAG, "断网唤醒CPU")
+                            val wakeLock = Util.getCpuWakeLock(this@WdKeepAliveService)
+                            wakeLock.acquire(1000)
+                            if (TcpClient.getInstance().retryTimes < 30) {
+                                if (TcpClient.getInstance().channel == null || TcpClient.getInstance().bootstrap == null) {
+                                    TcpClient.getInstance().init(Constants.tcpServer, Constants.tcpPort, Constants.heartBeat, iTcpCallBack)
+                                } else if (!TcpClient.getInstance().channel.isActive) {
+                                    TcpClient.getInstance().doConnect(iTcpCallBack)
+                                }
+                            }
                         } else {
-                            iTcpCallBack.connected()
+                            TcpClient.getInstance().sendMsg("0")
+                            if (SocketManager.getInstance().connectFlag){
+                                EventBus.getDefault().post(MessageEvent(TcpModel(),Constants.EVENT_RTC_STATE))
+                            } else {
+                                iTcpCallBack.connected()
+                            }
                         }
                     }
                 }

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

@@ -195,7 +195,7 @@ public class AnrFcExceptionUtil implements Thread.UncaughtExceptionHandler {
                 }
                 FileOutputStream fos = new FileOutputStream(path + fileName);
                 fos.write(sb.toString().getBytes());
-                Log.i(TAG, "saveCrashInfo2File: "+sb.toString());
+                Log.e(TAG, "saveCrashInfo2File: "+sb.toString());
                 fos.close();
             }
             return fileName;

+ 5 - 1
keepalive/src/main/java/com/wdkl/ncs/keepbackground/work/DaemonEnv.java

@@ -63,7 +63,11 @@ public final class DaemonEnv {
             Log.d("sj_keep", "启动并绑定服务 :"+serviceClass.getSimpleName());
             final Intent intent = new Intent(context, serviceClass);
             startServiceSafely(context, serviceClass);
-            context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
+            try {
+                context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
+            }catch (Exception ex){
+                Log.e("sj_keep",ex.toString());
+            }
         }
     }
 

+ 8 - 8
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 = 2;
+    private Integer retrySeconds = 5;
     //重试计数
     public Integer retryTimes = 1;
 
@@ -46,10 +46,10 @@ public class TcpClient {
 
     //初始化Netty Tcp Client 并连接
     public synchronized void init(String serverIP, Integer serverPort, Integer heartBeatSeconds, ITcpCallBack iTcpCallBack) {
-        if (bootstrap!=null){
-            doConnect(iTcpCallBack);
-            return;
-        }
+//        if (bootstrap!=null){
+//            doConnect(iTcpCallBack);
+//            return;
+//        }
 
         final Integer hbSeconds = heartBeatSeconds;
         bootstrap = new Bootstrap();
@@ -102,7 +102,6 @@ public class TcpClient {
                     channelFuture.channel().eventLoop().schedule(new Runnable() {
                         @Override
                         public void run() {
-                            retryTimes++;
                             if (retryTimes > 30) {
                                 System.out.println("TcpClient 重试" + (retryTimes - 1) + "次,结束");
 
@@ -114,9 +113,10 @@ public class TcpClient {
                                         doConnect(iTcpCallBack);
                                     }
                                 },60*10, TimeUnit.SECONDS);
-                                return;
+                            } else {
+                                retryTimes++;
+                                doConnect(iTcpCallBack);
                             }
-                            doConnect(iTcpCallBack);
                         }
                     }, retrySeconds, TimeUnit.SECONDS);
                 }

+ 16 - 0
readme.md

@@ -26,6 +26,22 @@
 
 ---
 
+## [1.1.29] version 48 - 2020-08-11
+### Changed
+- 建立通话后,如果不是连接状态,则挂断
+- 去掉重复连接RTC
+- 去掉websocket本身的断开重连
+### Fixed
+- 修复事件界面黑屏恢复后增加条目的问题
+
+---
+
+## [1.1.28] version 47 - 2020-08-10
+### Fixed
+- 通话连接中挂断问题
+
+---
+
 ## [1.1.25] version 44 - 2020-08-10
 ### Fixed
 - TCP重连BUG

+ 0 - 1
rtc-chat/src/main/java/com/wdkl/skywebrtc/CallSession.java

@@ -61,7 +61,6 @@ public class CallSession implements EngineCallback {
         iEngine.init(this);
     }
 
-
     // ----------------------------------------各种控制--------------------------------------------
 
     // 创建房间

+ 4 - 0
rtc-chat/src/main/java/com/wdkl/skywebrtc/SkyEngineKit.java

@@ -1,6 +1,7 @@
 package com.wdkl.skywebrtc;
 
 import android.content.Context;
+import android.text.TextUtils;
 import android.util.Log;
 
 import com.wdkl.skywebrtc.except.NotInitializedException;
@@ -132,6 +133,9 @@ public class SkyEngineKit {
             } else {
                 if (mCurrentCallSession.getState() == EnumType.CallState.Outgoing) {
                     mCurrentCallSession.sendCancel();
+                    if (!TextUtils.isEmpty(mCurrentCallSession.getRoomId())){
+                        mCurrentCallSession.leave();
+                    }
                 } else {
                     // 已经接通,挂断电话
                     mCurrentCallSession.leave();