From c83fb6b36c262804f1d32fc67f700f9491ee0f2f Mon Sep 17 00:00:00 2001 From: imndx Date: Tue, 10 May 2022 22:29:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8E=A5=E5=90=AC=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=8C=87=E5=AE=9A=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddParticipantsMessageContent.java | 16 +++++++++ .../JoinCallRequestMessageContent.java | 34 ++++++++++++++++++- .../kit/conversation/OngoingCallAdapter.java | 3 +- .../chat/kit/voip/MultiCallActivity.java | 8 +++-- .../chat/kit/voip/MultiCallAudioFragment.java | 2 +- .../chat/kit/voip/VoipCallService.java | 2 +- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/client/src/main/java/cn/wildfirechat/message/AddParticipantsMessageContent.java b/client/src/main/java/cn/wildfirechat/message/AddParticipantsMessageContent.java index 6361f16fb..ae7ad194d 100644 --- a/client/src/main/java/cn/wildfirechat/message/AddParticipantsMessageContent.java +++ b/client/src/main/java/cn/wildfirechat/message/AddParticipantsMessageContent.java @@ -77,10 +77,14 @@ public ParticipantStatus[] newArray(int size) { private String callId; private String initiator; private String pin; + // autoAnswer 为 true 时,只允许包含一个用户 private List participants; private List existParticipants; private boolean audioOnly; + // 设置为 true 时,新用户被邀请加入会议时,SDK会自动接听,然后加入通话 private boolean autoAnswer; + // 自动接听时,由那个端进行处理 + private String clientId; public AddParticipantsMessageContent() { } @@ -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(); @@ -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(); @@ -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); @@ -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) { @@ -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 CREATOR = new Creator() { diff --git a/client/src/main/java/cn/wildfirechat/message/JoinCallRequestMessageContent.java b/client/src/main/java/cn/wildfirechat/message/JoinCallRequestMessageContent.java index fbeade05a..9b8d4dfe3 100644 --- a/client/src/main/java/cn/wildfirechat/message/JoinCallRequestMessageContent.java +++ b/client/src/main/java/cn/wildfirechat/message/JoinCallRequestMessageContent.java @@ -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; @@ -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; @@ -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 @@ -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 CREATOR = new Creator() { diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/conversation/OngoingCallAdapter.java b/uikit/src/main/java/cn/wildfire/chat/kit/conversation/OngoingCallAdapter.java index 56af39ec9..18114814f 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/conversation/OngoingCallAdapter.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/conversation/OngoingCallAdapter.java @@ -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; @@ -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); } }); diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallActivity.java b/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallActivity.java index 409db7e09..c09610376 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallActivity.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallActivity.java @@ -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; @@ -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; @@ -233,11 +233,13 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d List 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); + } } } } diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallAudioFragment.java b/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallAudioFragment.java index 57583596e..a83d06491 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallAudioFragment.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/voip/MultiCallAudioFragment.java @@ -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) { diff --git a/uikit/src/main/java/cn/wildfire/chat/kit/voip/VoipCallService.java b/uikit/src/main/java/cn/wildfire/chat/kit/voip/VoipCallService.java index 4643cf9df..bd0711825 100644 --- a/uikit/src/main/java/cn/wildfire/chat/kit/voip/VoipCallService.java +++ b/uikit/src/main/java/cn/wildfire/chat/kit/voip/VoipCallService.java @@ -482,7 +482,7 @@ public void onReceiveMessage(List messages, boolean hasMore) { if (session.getCallId().equals(request.getCallId()) && session.getInitiator().equals(ChatManager.Instance().getUserId())) { List ps = new ArrayList<>(); ps.add(message.sender); - session.inviteNewParticipants(ps, true); + session.inviteNewParticipants(ps, request.getClientId(), true); } } }