Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.Objects;


/**
Expand All @@ -77,6 +78,7 @@ public class EaseCallKit {
private EaseCallState callState = EaseCallState.CALL_IDLE;
private String channelName;
private String fromUserId; //被叫获取主叫的
private String groupId;
public static String deviceId = "android_";
public String clallee_devId;
private String callID = null;
Expand Down Expand Up @@ -272,26 +274,35 @@ public void startSingleCall(final EaseCallType type, final String user,final Ma
* 邀请加入多人通话
* 注意:在相关activity结束时需要调用{@link #releaseCall()},防止出现内存泄漏
* @param users 用户ID列表(环信ID列表)
* @param groupId 群组id
* @param ext 扩展字段(用户扩展字段)
*/
public void startInviteMultipleCall(final String[] users,final Map<String, Object> ext){
startInviteMultipleCall(users, ext, defaultMultiVideoCls);
public void startInviteMultipleCall(final String[] users,String groupId,final Map<String, Object> ext){
startInviteMultipleCall(users, groupId,ext, defaultMultiVideoCls);
}

/**
* 邀请加入多人通话
* 注意:在相关activity结束时需要调用{@link #releaseCall()},防止出现内存泄漏
* @param users 用户ID列表(环信ID列表)
* @param conversationId 群组id
* @param ext 扩展字段(用户扩展字段)
* @param cls 继承自{@link EaseMultipleVideoActivity}的activity
*/
public void startInviteMultipleCall(final String[] users,final Map<String, Object> ext, Class<? extends EaseMultipleVideoActivity> cls){
public void startInviteMultipleCall(final String[] users, String conversationId,final Map<String, Object> ext, Class<? extends EaseMultipleVideoActivity> cls){
if(callState != EaseCallState.CALL_IDLE && callType != EaseCallType.CONFERENCE_CALL){
if(callListener != null){
callListener.onCallError(EaseCallError.PROCESS_ERROR,CALL_PROCESS_ERROR.CALL_STATE_ERROR.code,"current state is busy");
}
return;
}
if (conversationId == null || conversationId.isEmpty()) {
if(callListener != null){
callListener.onCallError(EaseCallError.PROCESS_ERROR,CALL_PROCESS_ERROR.CALL_STATE_ERROR.code,"conversation id doesn't be empty");
}
return;
}
groupId = conversationId;
if(users == null || users.length == 0) {
if(curCallCls != null){
inviteeUsers.clear();
Expand Down Expand Up @@ -349,9 +360,10 @@ public Class<? extends EaseBaseCallActivity> getCurrentCallClass() {

/**
* If you call {@link #startSingleCall(EaseCallType, String, Map)}, {@link #startSingleCall(EaseCallType, String, Map, Class)}
* or {@link #startInviteMultipleCall(String[], Map)}, you should call the method of {@link #releaseCall()} when the {@link #curCallCls} is finishing.
* or {@link #startInviteMultipleCall(String[], String,Map)}, you should call the method of {@link #releaseCall()} when the {@link #curCallCls} is finishing.
*/
public void releaseCall() {
groupId = null;
if(curCallCls != null) {
curCallCls = null;
}
Expand All @@ -367,7 +379,7 @@ private void addMessageListener() {
public void onMessageReceived(List<EMMessage> messages) {
for(EMMessage message: messages){
String messageType = message.getStringAttribute(EaseMsgUtils.CALL_MSG_TYPE, "");
EMLog.d(TAG,"Receive msg:" + message.getMsgId() + " from:" + message.getFrom()+ " messageType:"+ messageType);
EMLog.d(TAG,"Receive msg:" + message.getMsgId() + " from:" + message.getFrom() + " to:" + message.getTo() + " messageType:"+ messageType);
//有关通话控制信令
if(TextUtils.equals(messageType, EaseMsgUtils.CALL_MSG_INFO)
&& !TextUtils.equals(message.getFrom(), EMClient.getInstance().getCurrentUser())) {
Expand Down Expand Up @@ -447,14 +459,20 @@ public void onMessageReceived(List<EMMessage> messages) {
public void onCmdMessageReceived(List<EMMessage> messages) {
for(EMMessage message: messages){
String messageType = message.getStringAttribute(EaseMsgUtils.CALL_MSG_TYPE, "");
EMLog.d(TAG,"Receive cmdmsg:" + message.getMsgId() + " from:" + message.getFrom() + " messageType:"+ messageType);
EMLog.d(TAG,"Receive cmd msg:" + message.getMsgId() + " from:" + message.getFrom() + " to:" + message.getTo() + " messageType:"+ messageType);
if (message.getChatType() == EMMessage.ChatType.GroupChat) {
groupId = message.conversationId();
}
//有关通话控制信令
if(TextUtils.equals(messageType, EaseMsgUtils.CALL_MSG_INFO)
&& !TextUtils.equals(message.getFrom(), EMClient.getInstance().getCurrentUser())) {
if(TextUtils.equals(messageType, EaseMsgUtils.CALL_MSG_INFO) && !TextUtils.equals(message.getFrom(), EMClient.getInstance().getCurrentUser())) {
String action = message.getStringAttribute(EaseMsgUtils.CALL_ACTION, "");
String callerDevId = message.getStringAttribute(EaseMsgUtils.CALL_DEVICE_ID, "");
String fromCallId = message.getStringAttribute(EaseMsgUtils.CLL_ID, "");
String fromUser = message.getFrom();
if (message.getChatType() == EMMessage.ChatType.GroupChat) {
groupId = message.conversationId();
fromUser = message.conversationId();
}
String channel = message.getStringAttribute(EaseMsgUtils.CALL_CHANNELNAME, "");
EaseCallAction callAction = EaseCallAction.getfrom(action);
switch (callAction){
Expand All @@ -475,6 +493,8 @@ public void onCmdMessageReceived(List<EMMessage> messages) {
//发布消息
EaseLiveDataBus.get().with(EaseCallType.SINGLE_VIDEO_CALL.toString()).postValue(event);
}
//清理群组id缓存
groupId = null;
break;
case CALL_ALERT:
String calleedDeviceId = message.getStringAttribute(EaseMsgUtils.CALLED_DEVICE_ID, "");
Expand All @@ -494,6 +514,8 @@ public void onCmdMessageReceived(List<EMMessage> messages) {
if(!vaild){
//通话无效
callInfoMap.remove(fromCallId);
//清理群组id缓存
groupId = null;
}else{
//收到callId 有效
if(callState == EaseCallState.CALL_IDLE){
Expand All @@ -515,6 +537,8 @@ public void onCmdMessageReceived(List<EMMessage> messages) {
//通话无效
callInfoMap.remove(fromCallId);
timeHandler.stopTime();
//清理群组id缓存
groupId = null;
}
}
}
Expand All @@ -529,6 +553,8 @@ public void onCmdMessageReceived(List<EMMessage> messages) {
event.callerDevId = callerDevId;
event.callId = fromCallId;
event.userId = fromUser;
//清理群组id缓存
groupId = null;
//发布消息
EaseLiveDataBus.get().with(EaseCallType.SINGLE_VIDEO_CALL.toString()).postValue(event);
break;
Expand Down Expand Up @@ -682,6 +708,10 @@ public String getFromUserId(){
return fromUserId;
}

public String getGroupId() {
return groupId;
}

public boolean getIsComingCall(){
return isComingCall;
}
Expand Down Expand Up @@ -727,11 +757,12 @@ private String getProcessNameByApplication() {
*/
private void sendCmdMsg(BaseEvent event,String username){
final EMMessage message = EMMessage.createSendMessage(EMMessage.Type.CMD);
message.setTo(username);
String action="rtcCall";
EMCmdMessageBody cmdBody = new EMCmdMessageBody(action);
message.addBody(cmdBody);

message.setTo(username);
EMLog.d(TAG, "发送cmd回复信息 " + " from: " + message.getFrom() + " to: " + message.getTo());
message.setAttribute(EaseMsgUtils.CALL_ACTION, event.callAction.state);
message.setAttribute(EaseMsgUtils.CALL_DEVICE_ID, event.callerDevId);
message.setAttribute(EaseMsgUtils.CLL_ID,event.callId);
Expand All @@ -743,18 +774,18 @@ private void sendCmdMsg(BaseEvent event,String username){
}else if(event.callAction == EaseCallAction.CALL_ALERT){
message.setAttribute(EaseMsgUtils.CALLED_DEVICE_ID, deviceId);
}
final EMConversation conversation = EMClient.getInstance().chatManager().getConversation(username, EMConversation.EMConversationType.Chat, true);
// final EMConversation conversation = EMClient.getInstance().chatManager().getConversation(username, EMConversation.EMConversationType.Chat, true);
message.setMessageStatusCallback(new EMCallBack() {
@Override
public void onSuccess() {
EMLog.d(TAG, "Invite call success");
conversation.removeMessage(message.getMsgId());
// conversation.removeMessage(message.getMsgId());
}

@Override
public void onError(int code, String error) {
EMLog.e(TAG, "Invite call error " + code + ", " + error);
conversation.removeMessage(message.getMsgId());
// conversation.removeMessage(message.getMsgId());
if(callListener != null){
callListener.onCallError(EaseCallError.IM_ERROR,code,error);
}
Expand Down Expand Up @@ -896,8 +927,10 @@ public void sendCmdMsg(BaseEvent event,String username, EMCallBack callBack){
final EMMessage message = EMMessage.createSendMessage(EMMessage.Type.CMD);
String action="rtcCall";
EMCmdMessageBody cmdBody = new EMCmdMessageBody(action);
message.setTo(username);
message.addBody(cmdBody);

message.setTo(username);

if(event.callAction.equals(EaseCallAction.CALL_VIDEO_TO_VOICE) ||
event.callAction.equals(EaseCallAction.CALL_CANCEL)){
cmdBody.deliverOnlineOnly(false);
Expand All @@ -922,12 +955,12 @@ public void sendCmdMsg(BaseEvent event,String username, EMCallBack callBack){
message.setAttribute(EaseMsgUtils.CALL_DEVICE_ID, ((AnswerEvent) event).callerDevId);
message.setAttribute(EaseMsgUtils.CALLED_TRANSE_VOICE, ((AnswerEvent) event).transVoice);
}
final EMConversation conversation = EMClient.getInstance().chatManager().getConversation(username, EMConversation.EMConversationType.Chat, true);
// final EMConversation conversation = EMClient.getInstance().chatManager().getConversation(username, EMConversation.EMConversationType.Chat, true);
message.setMessageStatusCallback(new EMCallBack() {
@Override
public void onSuccess() {
EMLog.d(TAG, "Invite call success");
conversation.removeMessage(message.getMsgId());
// conversation.removeMessage(message.getMsgId());
if(event.callAction == EaseCallAction.CALL_CANCEL){
exitCall();
}else if(event.callAction == EaseCallAction.CALL_CONFIRM_CALLEE){
Expand All @@ -942,9 +975,9 @@ public void onSuccess() {
@Override
public void onError(int code, String error) {
EMLog.e(TAG, "Invite call error " + code + ", " + error);
if(conversation != null){
conversation.removeMessage(message.getMsgId());
}
// if(conversation != null){
// conversation.removeMessage(message.getMsgId());
// }
if(event.callAction == EaseCallAction.CALL_CANCEL){
//退出频道
exitCall();
Expand Down Expand Up @@ -975,6 +1008,7 @@ public void run() {
//重置状态
setCallState(EaseCallState.CALL_IDLE);
setCallID(null);
groupId = null;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
*/
public interface EaseCallKitListener{
/**
* 邀请好友进行多人通话
* 邀请群成员进行多人通话
* @param context
* @param groupId 群组id
* @param users 当前通话中已经存在的成员
* @param ext 自定义扩展字段
*/
void onInviteUsers(Context context,String []users,JSONObject ext);
void onInviteUsers(Context context,String groupId,String []users,JSONObject ext);


/**
Expand Down
Loading