Skip to content

Commit

Permalink
自动接听时,指定客户端
Browse files Browse the repository at this point in the history
  • Loading branch information
imndx committed May 10, 2022
1 parent 1be4a7f commit c83fb6b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ public ParticipantStatus[] newArray(int size) {
private String callId;
private String initiator;
private String pin;
// autoAnswer 为 true 时,只允许包含一个用户
private List<String> participants;
private List<ParticipantStatus> existParticipants;
private boolean audioOnly;
// 设置为 true 时,新用户被邀请加入会议时,SDK会自动接听,然后加入通话
private boolean autoAnswer;
// 自动接听时,由那个端进行处理
private String clientId;

public AddParticipantsMessageContent() {
}
Expand Down Expand Up @@ -150,6 +154,14 @@ public void setAutoAnswer(boolean autoAnswer) {
this.autoAnswer = autoAnswer;
}

public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

@Override
public MessagePayload encode() {
MessagePayload payload = super.encode();
Expand Down Expand Up @@ -180,6 +192,7 @@ public MessagePayload encode() {

objWrite.put("existParticipants", array);
objWrite.put("autoAnswer", this.autoAnswer);
objWrite.put("clientId", this.clientId);
payload.binaryContent = objWrite.toString().getBytes();

JSONObject pushDataWrite = new JSONObject();
Expand Down Expand Up @@ -221,6 +234,7 @@ public void decode(MessagePayload payload) {

array = jsonObject.getJSONArray("existParticipants");
autoAnswer = jsonObject.optBoolean("autoAnswer");
clientId = jsonObject.optString("clientId");
existParticipants = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
Expand Down Expand Up @@ -274,6 +288,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(this.audioOnly ? (byte) 1 : (byte) 0);
dest.writeByte(this.autoAnswer? (byte) 1 : (byte) 0);
dest.writeString(pin);
dest.writeString(this.clientId);
}

protected AddParticipantsMessageContent(Parcel in) {
Expand All @@ -286,6 +301,7 @@ protected AddParticipantsMessageContent(Parcel in) {
this.audioOnly = in.readByte() != 0;
this.autoAnswer = in.readByte() != 0;
this.pin = in.readString();
this.clientId = in.readString();
}

public static final Creator<AddParticipantsMessageContent> CREATOR = new Creator<AddParticipantsMessageContent>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import android.os.Parcel;

import org.json.JSONException;
import org.json.JSONObject;

import cn.wildfirechat.message.core.ContentTag;
import cn.wildfirechat.message.core.MessageContentType;
import cn.wildfirechat.message.core.MessagePayload;
Expand All @@ -14,6 +17,7 @@
@ContentTag(type = MessageContentType.ContentType_Call_Join_Call_Request, flag = PersistFlag.Transparent)
public class JoinCallRequestMessageContent extends MessageContent {
private String callId;
private String clientId;

public String getCallId() {
return callId;
Expand All @@ -23,23 +27,48 @@ public void setCallId(String callId) {
this.callId = callId;
}

public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public JoinCallRequestMessageContent() {
}

public JoinCallRequestMessageContent(String callId) {
public JoinCallRequestMessageContent(String callId, String clientId) {
this.callId = callId;
this.clientId = clientId;
}

@Override
public MessagePayload encode() {
MessagePayload payload = super.encode();
payload.content = this.callId;
JSONObject object = new JSONObject();
try {
object.put("clientId", clientId);
payload.binaryContent = object.toString().getBytes();
} catch (JSONException e) {
e.printStackTrace();
}

return payload;
}

@Override
public void decode(MessagePayload payload) {
this.callId = payload.content;
if (payload.binaryContent != null) {
try {
JSONObject object = new JSONObject(new String(payload.binaryContent));
this.clientId = object.optString("clientId");
} catch (JSONException e) {
e.printStackTrace();
}
}
}

@Override
Expand All @@ -56,15 +85,18 @@ public int describeContents() {
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(this.callId);
dest.writeString(this.clientId);
}

public void readFromParcel(Parcel source) {
this.callId = source.readString();
this.clientId = source.readString();
}

protected JoinCallRequestMessageContent(Parcel in) {
super(in);
this.callId = in.readString();
this.clientId = in.readString();
}

public static final Creator<JoinCallRequestMessageContent> CREATOR = new Creator<JoinCallRequestMessageContent>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import cn.wildfire.chat.kit.R2;
import cn.wildfirechat.message.JoinCallRequestMessageContent;
import cn.wildfirechat.message.Message;
import cn.wildfirechat.message.MessageContent;
import cn.wildfirechat.message.MultiCallOngoingMessageContent;
import cn.wildfirechat.model.UserInfo;
import cn.wildfirechat.remote.ChatManager;
Expand Down Expand Up @@ -52,7 +51,7 @@ public void onBindViewHolder(@NonNull OngoingCallViewHolder holder, int position
holder.joinButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MessageContent messageContent = new JoinCallRequestMessageContent(ongoingMessageContent.getCallId());
JoinCallRequestMessageContent messageContent = new JoinCallRequestMessageContent(ongoingMessageContent.getCallId(), ChatManager.Instance().getClientId());
ChatManager.Instance().sendMessage(message.conversation, messageContent, new String[]{ongoingMessageContent.getInitiator()}, 0, null);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cn.wildfire.chat.kit.voip;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
Expand All @@ -21,7 +22,6 @@
import cn.wildfire.chat.kit.group.PickGroupMemberActivity;
import cn.wildfirechat.avenginekit.AVAudioManager;
import cn.wildfirechat.avenginekit.AVEngineKit;
import cn.wildfirechat.avenginekit.VideoProfile;
import cn.wildfirechat.model.GroupInfo;
import cn.wildfirechat.remote.ChatManager;

Expand Down Expand Up @@ -233,11 +233,13 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
List<String> newParticipants = data.getStringArrayListExtra(PickGroupMemberActivity.EXTRA_RESULT);
if (newParticipants != null && !newParticipants.isEmpty()) {
AVEngineKit.CallSession session = getEngineKit().getCurrentSession();
session.inviteNewParticipants(newParticipants, true);
session.inviteNewParticipants(newParticipants);
}
}
} else {
super.onActivityResult(requestCode, resultCode, data);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void didChangeState(AVEngineKit.CallState callState) {
return;
}
AVEngineKit.CallSession callSession = AVEngineKit.Instance().getCurrentSession();
if (callState == AVEngineKit.CallState.Connected) {
if (callSession != null && callState == AVEngineKit.CallState.Connected) {
updateParticipantStatus(callSession);
} else if (callState == AVEngineKit.CallState.Idle) {
if (getActivity() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ public void onReceiveMessage(List<Message> messages, boolean hasMore) {
if (session.getCallId().equals(request.getCallId()) && session.getInitiator().equals(ChatManager.Instance().getUserId())) {
List<String> ps = new ArrayList<>();
ps.add(message.sender);
session.inviteNewParticipants(ps, true);
session.inviteNewParticipants(ps, request.getClientId(), true);
}
}
}
Expand Down

0 comments on commit c83fb6b

Please sign in to comment.