|
@@ -1,8 +1,10 @@
|
|
|
package com.wdkl.ncs.android.middleware.tcp.channel;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
+import com.wdkl.ncs.android.lib.base.BaseApplication;
|
|
|
import com.wdkl.ncs.android.middleware.common.Constants;
|
|
|
import com.wdkl.ncs.android.middleware.model.vo.InteractionVO;
|
|
|
import com.wdkl.ncs.android.middleware.tcp.dto.TcpModel;
|
|
@@ -27,37 +29,21 @@ public class DeviceChannel {
|
|
|
public static int callId = 0;
|
|
|
|
|
|
public static TcpModel handleTcpReceived(TcpModel tcpModel){
|
|
|
- /*TcpModel responseTcpModel = new TcpModel();
|
|
|
- responseTcpModel.setType(TcpType.CALLBACK);
|
|
|
- responseTcpModel.setAction(TcpAction.CallbackAction.SUCCESS);
|
|
|
- responseTcpModel.setFromId(Constants.Companion.getDeviceId());
|
|
|
- responseTcpModel.setToId(tcpModel.getFromId());
|
|
|
-
|
|
|
- //处理重复
|
|
|
- String tcpJsonStr = tcpModel.toJson();
|
|
|
- Long currentTime = System.currentTimeMillis();
|
|
|
- if (lastTcp.get(tcpJsonStr)!=null && currentTime/1000 - lastTcp.get(tcpJsonStr)/1000 <1){
|
|
|
- return responseTcpModel;
|
|
|
- }
|
|
|
- lastTcp.clear();
|
|
|
- lastTcp.put(tcpModel.toJson(), System.currentTimeMillis());*/
|
|
|
|
|
|
TcpModel responseTcpModel = null;
|
|
|
|
|
|
-// Log.e(TAG,"收到tcp消息 DeviceChannel "+tcpJsonStr);
|
|
|
+ //Log.d(TAG,"收到tcp消息 DeviceChannel "+tcpModel.toJson());
|
|
|
|
|
|
switch (tcpModel.getType()){
|
|
|
case VOICE:
|
|
|
if (tcpModel.getAction()==TcpAction.VoiceAction.SUCCESS) {
|
|
|
EventBus.getDefault().post(new MessageEvent(tcpModel, Constants.EVENT_NEW_TCP));
|
|
|
- //EventBus.getDefault().post(new MessageEvent(tcpModel, 1));
|
|
|
} else if(tcpModel.getAction() == TcpAction.VoiceAction.CALL){
|
|
|
if (calling) {
|
|
|
Log.d(TAG,"通话中,来电 " + tcpModel.getFromId() + "<>" + callId);
|
|
|
//相同来源,重新建立通话
|
|
|
if (tcpModel.getFromId().equals(callId)){
|
|
|
EventBus.getDefault().post(new MessageEvent(tcpModel, Constants.EVENT_NEW_TCP));
|
|
|
- //EventBus.getDefault().post(new MessageEvent(tcpModel, 11));
|
|
|
} else {
|
|
|
InteractionVO interactionVO = new Gson().fromJson(tcpModel.getData().toString(), InteractionVO.class);
|
|
|
responseTcpModel = VoiceUtil.voiceCalling(Constants.Companion.getDeviceId(), tcpModel.getFromId(), interactionVO.getId());
|
|
@@ -66,7 +52,6 @@ public class DeviceChannel {
|
|
|
}
|
|
|
} else { //得到通话
|
|
|
EventBus.getDefault().post(new MessageEvent(tcpModel, Constants.EVENT_NEW_TCP));
|
|
|
- //EventBus.getDefault().post(new MessageEvent(tcpModel, 1));
|
|
|
}
|
|
|
} else if ((tcpModel.getAction() == TcpAction.VoiceAction.ACCEPT) //我方呼出,对方接受
|
|
|
|| (tcpModel.getAction() == TcpAction.VoiceAction.REJECT) //我方呼出,对方拒绝
|
|
@@ -85,12 +70,12 @@ public class DeviceChannel {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
EventBus.getDefault().post(new MessageEvent(tm, Constants.EVENT_NEW_TCP));
|
|
|
- //EventBus.getDefault().post(new MessageEvent(tm, 2));
|
|
|
}
|
|
|
}).start();
|
|
|
} else {
|
|
|
EventBus.getDefault().post(new MessageEvent(tcpModel, Constants.EVENT_NEW_TCP));
|
|
|
- //EventBus.getDefault().post(new MessageEvent(tcpModel, 2));
|
|
|
+ //发广播通知
|
|
|
+ //sendCallBroadcast(tcpModel);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -156,4 +141,17 @@ public class DeviceChannel {
|
|
|
|
|
|
return responseTcpModel;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private static void sendCallBroadcast(TcpModel tcpModel) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setAction(Constants.call_action);
|
|
|
+ intent.putExtra(Constants.action_name, tcpModel.getAction().getName());
|
|
|
+ if (tcpModel.getData() != null) {
|
|
|
+ InteractionVO interactionVO = new Gson().fromJson(tcpModel.getData().toString(), InteractionVO.class);
|
|
|
+ intent.putExtra(Constants.interaction_id, interactionVO.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseApplication.appContext.sendBroadcast(intent);
|
|
|
+ }
|
|
|
}
|