ソースを参照

1.支持多分机呼叫
2.设备无摄像头则只能进行语音通话,但能显示对方视频画面

weizhengliang 3 年 前
コミット
e16ff59d85

+ 19 - 3
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/fragment/SkyCallFragment.kt

@@ -545,10 +545,10 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
                         } else if (curTcpModel.getAction() == TcpAction.VoiceAction.CALLING) {
                             //我方呼出,对方通话中
                             showMessage("对方正在忙线中,暂时无法接听!")
-                            AppTool.Time.delay(1000) {
+                            /*AppTool.Time.delay(1000) {
                                 RingPlayHelper.stopRingTone()
                                 cancelCall()
-                            }
+                            }*/
                         } else if (curTcpModel.getAction() == TcpAction.VoiceAction.SUCCESS) {
                             //呼叫成功
                             //本机呼叫的时候tcpModel为空,只有呼叫成功的时候才能获得对应tcp相关数据
@@ -580,6 +580,22 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
                 }
             }
 
+            Constant.EVENT_CALL_MSG -> {
+                //分机呼叫主机时,主机打过来了
+                val tcpModel = messageEvent.message as TcpModel
+                if (tcpModel.getAction() == TcpAction.VoiceAction.CALL) {
+                    interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
+                    fromId = tcpModel.fromId
+                    Constant.fromId = tcpModel.fromId
+                    Constant.interactionId = interactionVO?.id
+                    Constant.CALL_STATE = Constant.CALL_CALLING
+
+                    RingPlayHelper.stopRingTone()
+                    VoiceUtil.acceptAudioCall(Constant.DEVICE_ID, fromId, interactionVO?.id)
+                    acceptCall()
+                }
+            }
+
             //外部呼叫按键
             Constant.EVENT_SERIAL_EVENT -> {
                 if (messageEvent.message is String) {
@@ -591,7 +607,7 @@ class SkyCallFragment: BaseCallFragment(), CallSession.CallSessionCallback {
                         cancelCall()
                     } else if (serialAction.equals("accept")) {
                         RingPlayHelper.stopRingTone()
-                        Constant.CALL_STATE = Constant.CALL_INCOMING
+                        Constant.CALL_STATE = Constant.CALL_CALLING
                         VoiceUtil.acceptAudioCall(Constant.DEVICE_ID, fromId, interactionVO?.id)
                         acceptCall()
                     } else if (serialAction.equals("handoff")) {

+ 5 - 3
middleware/src/main/code/com/wdkl/ncs/android/middleware/common/Constant.java

@@ -63,9 +63,6 @@ public class Constant {
     //客户ID
     public static Integer CUSTOM_ID = -1;
 
-    //SIP host
-    public static String SIP_HOST = "192.168.101.1";
-
     //SIP ID
     public static String SIP_ID = "";
 
@@ -173,4 +170,9 @@ public class Constant {
      * 串口消息
      */
     public static final int EVENT_SERIAL_EVENT = 0x10;
+
+    /**
+     * 呼叫消息
+     */
+    public static final int EVENT_CALL_MSG = 0x11;
 }

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

@@ -11,6 +11,7 @@ import com.wdkl.ncs.android.middleware.tcp.enums.TcpAction;
 
 import org.greenrobot.eventbus.EventBus;
 
+import static com.wdkl.ncs.android.middleware.common.Constant.EVENT_CALL_MSG;
 import static com.wdkl.ncs.android.middleware.common.Constant.EVENT_TCP_MSG;
 
 /**
@@ -36,11 +37,15 @@ public class DeviceChannel {
                 if (tcpModel.getAction()==TcpAction.VoiceAction.CALL){ //语音呼入
                     //todo: 判断当前是否通话
                     // 当前正在通话中或有新的来电或正在呼叫,直接返回该状态给服务器
-                    if (Constant.CALL_STATE != Constant.CALL_STANDBY){
+                    if (Constant.CALL_STATE == Constant.CALL_INCOMING || Constant.CALL_STATE == Constant.CALL_CALLING){
                         InteractionVO interactionVO = new Gson().fromJson(tcpModel.getData().toString(), InteractionVO.class);
                         responseTcpModel = VoiceUtil.voiceCalling(Constant.DEVICE_ID, tcpModel.getFromId(), interactionVO.getId());
                         return responseTcpModel;
-                    } else {
+                    } if (Constant.CALL_STATE == Constant.CALL_OUTGOING) {
+                        //当前分机正在呼叫主机,此时主机再呼叫该分机则分机直接接通进入通话
+                        Constant.CALL_STATE = Constant.CALL_CALLING;
+                        EventBus.getDefault().post(new MessageEvent(tcpModel, EVENT_CALL_MSG));
+                    } else  {
                         //todo: 通话界面展现,data中服务器传过来呼入名称;从接口重新获取左侧数据
                         // 当前待机状态,返回呼叫成功,并切换到呼叫界面
                         Constant.CALL_STATE = Constant.CALL_INCOMING;

+ 8 - 6
webrtc/src/main/java/com/wdkl/core/socket/SocketManager.java

@@ -222,17 +222,19 @@ public class SocketManager implements IEvent {
         // 发送广播
         mContext.sendBroadcast(intent);*/
 
+        receivedIncomingCall(room, audioOnly, inviteId, userList);
+    }
+
+    private void receivedIncomingCall(String room, boolean audioOnly, String inviteId, String userList) {
+        SkyEngineKit.init(new VoipEvent());
+        boolean b = false;
         //如果设备不带摄像头则只能语音通话
         if (Constant.supportCamera) {
-            receivedIncomingCall(room, audioOnly, inviteId, userList);
+            b = SkyEngineKit.Instance().startInCall(mContext, room, inviteId, audioOnly);
         } else {
-            receivedIncomingCall(room, true, inviteId, userList);
+            b = SkyEngineKit.Instance().startInCall(mContext, room, inviteId, true);
         }
-    }
 
-    private void receivedIncomingCall(String room, boolean audioOnly, String inviteId, String userList) {
-        SkyEngineKit.init(new VoipEvent());
-        boolean b = SkyEngineKit.Instance().startInCall(mContext, room, inviteId, audioOnly);
         if (b) {
             if (audioOnly) {
                 EventBus.getDefault().post(new MessageEvent("audio_call", Constant.EVENT_SIP_CALL_STATUS));