Ver código fonte

#FIXED 修复通话bug

weizhengliang 3 anos atrás
pai
commit
7efe8ff37f

+ 13 - 12
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/channel/DeviceChannel.java

@@ -61,23 +61,23 @@ public class DeviceChannel {
                 } else if (tcpModel.getAction()== TcpAction.VoiceAction.REJECT){ //我方呼出,对方拒绝
                     //todo: 清掉呼出的TcpModel,通话中界面更新 --- 显示对方拒绝并停留3秒,结束至正常界面;更新左侧
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 } else if (tcpModel.getAction()== TcpAction.VoiceAction.CALLING){ //我方呼出,对方通话中
                     //todo: 清掉呼出的TcpModel,通话中界面更新 --- 显示对方占线并停留3秒,结束至正常界面;更新左侧
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 } else if (tcpModel.getAction()== TcpAction.VoiceAction.FAILED){ //我方呼出,对方不在线,设备离线或其它错误
                     //todo: 清掉呼出的TcpModel,通话中界面更新 --- 显示对方离线并停留3秒,结束至正常界面;更新左侧
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 } else if (tcpModel.getAction()== TcpAction.VoiceAction.HANDOFF){ //对方挂断,不论我方呼出或呼入
                     //todo: 清掉呼出的TcpModel,通话中界面更新 --- 显示对方已挂断并停留3秒,结束至正常界面;更新左侧
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 }else if(tcpModel.getAction()== TcpAction.VoiceAction.CANCEL){
                     //todo: 清掉呼出的TcpModel,通话中界面更新 --- 显示对方已挂断并停留3秒,结束至正常界面;更新左侧
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 }else if(tcpModel.getAction()== TcpAction.VoiceAction.SUCCESS){
                     //todo 这个是自己点击了分机的呼叫 服务器返回给我数据 以供我 挂断时传输呼叫记录的id 因为分机在点击呼叫之前 是没有呼叫记录的
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
@@ -91,29 +91,30 @@ public class DeviceChannel {
                         responseTcpModel = VideoUtil.videoCalling(Constants.Companion.getIds(), tcpModel.getFromId(), interactionVO.getId());
                         return responseTcpModel;
                     } else {
+                        calling = true;
                         EventBus.getDefault().post(new MessageEvent(tcpModel, Constants.Companion.getEVENT_TCP_MSG()));
                     }
                 } else if (tcpModel.getAction()== TcpAction.VideoAction.ACCEPT){ //我方呼出,对方接受
-                    EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
                     calling = true;
+                    EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
                 } else if (tcpModel.getAction()== TcpAction.VideoAction.REJECT){ //我方呼出,对方拒绝
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 } else if (tcpModel.getAction()== TcpAction.VideoAction.CALLING){ //我方呼出,对方通话中
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 } else if (tcpModel.getAction()== TcpAction.VideoAction.FAILED){ //我方呼出,对方不在线,设备离线或其它错误
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 } else if (tcpModel.getAction()== TcpAction.VideoAction.HANDOFF){ //对方挂断,不论我方呼出或呼入
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 }else if(tcpModel.getAction()== TcpAction.VideoAction.CANCEL){
                     EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
-                    calling = false;
+                    //calling = false;
                 }else if(tcpModel.getAction()== TcpAction.VideoAction.SUCCESS){
-                    EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
                     calling = true;
+                    EventBus.getDefault().post(new MessageEvent(tcpModel,Constants.Companion.getEVENT_TCP_MSG()));
                 }
                 break;
             case IM:

+ 30 - 20
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/activity/NurseHomeActivity.kt

@@ -891,16 +891,20 @@ class NurseHomeActivity  : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
                         }
 
                     } else if (tcpModel.getAction() == TcpAction.VoiceAction.REJECT) {//对方拒绝
-                        Constants.CALL_STATE = Constants.CALL_STANDBY
-                        DeviceChannel.calling = false
-                        CallDialogHelper.dismissCallDialog()
-                        countDownTimer.cancel()
+                        if (Constants.interactionId == interactionVO.id) {
+                            Constants.CALL_STATE = Constants.CALL_STANDBY
+                            DeviceChannel.calling = false
+                            CallDialogHelper.dismissCallDialog()
+                            countDownTimer.cancel()
+                        }
                     } else if (tcpModel.getAction() == TcpAction.VoiceAction.CANCEL) {//对方取消
-                        Constants.CALL_STATE = Constants.CALL_STANDBY
-                        DeviceChannel.calling = false
-                        CallDialogHelper.dismissCallDialog()
-                        countDownTimer.cancel()
-                        transferCountDownTimer.cancel()
+                        if (Constants.interactionId == interactionVO.id) {
+                            Constants.CALL_STATE = Constants.CALL_STANDBY
+                            DeviceChannel.calling = false
+                            CallDialogHelper.dismissCallDialog()
+                            countDownTimer.cancel()
+                            transferCountDownTimer.cancel()
+                        }
                     } else if (tcpModel.getAction() == TcpAction.VoiceAction.CALLING) {//对方通话中
                         showMessage("对方忙线中")
                         Constants.CALL_STATE = Constants.CALL_STANDBY
@@ -914,11 +918,13 @@ class NurseHomeActivity  : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
                         CallDialogHelper.dismissCallDialog()
                         countDownTimer.cancel()
                     } else if (tcpModel.getAction() == TcpAction.VoiceAction.HANDOFF) {//对方挂断
-                        Constants.CALL_STATE = Constants.CALL_STANDBY
-                        DeviceChannel.calling = false
-                        CallDialogHelper.dismissCallDialog()
-                        countDownTimer.cancel()
-                        transferCountDownTimer.cancel()
+                        if (Constants.interactionId == interactionVO.id) {
+                            Constants.CALL_STATE = Constants.CALL_STANDBY
+                            DeviceChannel.calling = false
+                            CallDialogHelper.dismissCallDialog()
+                            countDownTimer.cancel()
+                            transferCountDownTimer.cancel()
+                        }
                     } else if (tcpModel.getAction() == TcpAction.VoiceAction.SUCCESS) {//服务器返回的呼叫成功tcp
                         Constants.interactionId = interactionVO.id
                         callTargetId = interactionVO.toDeviceId
@@ -1010,13 +1016,17 @@ class NurseHomeActivity  : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
                             SpeechUtil.getInstance().addSpeech("您有新的探视请求", false)
                         }
                     } else if (tcpModel.action == TcpAction.VideoAction.CANCEL) {
-                        Constants.CALL_STATE = Constants.CALL_STANDBY
-                        DeviceChannel.calling = false
-                        CallDialogHelper.dismissCallDialog()
+                        if (Constants.interactionId == interactionVO.id) {
+                            Constants.CALL_STATE = Constants.CALL_STANDBY
+                            DeviceChannel.calling = false
+                            CallDialogHelper.dismissCallDialog()
+                        }
                     } else if (tcpModel.action == TcpAction.VideoAction.HANDOFF) {
-                        Constants.CALL_STATE = Constants.CALL_STANDBY
-                        DeviceChannel.calling = false
-                        VisitingWindow.release()
+                        if (Constants.interactionId == interactionVO.id) {
+                            Constants.CALL_STATE = Constants.CALL_STANDBY
+                            DeviceChannel.calling = false
+                            VisitingWindow.release()
+                        }
                     } else if (tcpModel.action == TcpAction.VideoAction.SUCCESS) {
                         //显示探视窗口
                         Constants.CALL_STATE = Constants.CALL_VISITING

+ 10 - 6
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/fragment/SkyCallFragment.kt

@@ -70,8 +70,9 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
             0 -> {
                 //发起通话
                 outGoing = true
-                if (!startCall(targetId!!, onlyAudio)) {
+                if (targetId == null || !startCall(targetId!!, onlyAudio)) {
                     //通话失败,重置并返回主界面
+                    showMessage("创建通话失败!")
                     Constants.CALL_STATE = Constants.CALL_STANDBY
                     DeviceChannel.calling = false
                     VoiceUtil.handoffAudioCall(Constants.ids, fromId, interactionId)
@@ -135,7 +136,8 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
 
             Constants.CALL_STATE = Constants.CALL_STANDBY
             DeviceChannel.calling = false
-            sky_voice_call_timer.stop()
+            VoiceUtil.handoffAudioCall(Constants.ids, fromId, interactionId)
+            //sky_voice_call_timer.stop()
         }
     }
 
@@ -261,9 +263,11 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
                     if (session.state == EnumType.CallState.Connected){
                         showCalling(onlyAudio)
                     } else {
-                        showMessage("当前网络状态不佳,通话结束")
-                        gEngineKit?.endCall()
-                        callEnd()
+                        if (!callEnded) {
+                            showMessage("当前网络状态不佳,通话结束")
+                            gEngineKit?.endCall()
+                            callEnd()
+                        }
                     }
                 }, 3000)
             }
@@ -451,7 +455,7 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
                         if (curTcpModel.getAction() == TcpAction.VoiceAction.HANDOFF) {
                             //对方挂断,不论我方呼出或呼入
                             if (Constants.interactionId == curInteractionVO.id) {
-                                gEngineKit?.endCall()
+                                //gEngineKit?.endCall()
                                 callEnd()
                             }
                         }