-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8e57a7
commit 0bbf990
Showing
6 changed files
with
323 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
uikit/src/main/java/cn/wildfire/chat/kit/voip/conference/ConferenceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cn.wildfire.chat.kit.voip.conference; | ||
|
||
import androidx.lifecycle.ViewModelProviders; | ||
|
||
import java.util.List; | ||
|
||
import cn.wildfire.chat.kit.viewmodel.MessageViewModel; | ||
import cn.wildfire.chat.kit.voip.conference.message.ConferenceChangeModelContent; | ||
import cn.wildfire.chat.kit.voip.conference.message.ConferenceKickoffMemberContent; | ||
import cn.wildfirechat.avenginekit.AVEngineKit; | ||
import cn.wildfirechat.message.Message; | ||
import cn.wildfirechat.model.Conversation; | ||
import cn.wildfirechat.remote.ChatManager; | ||
import cn.wildfirechat.remote.OnReceiveMessageListener; | ||
|
||
public class ConferenceManager implements OnReceiveMessageListener { | ||
public interface ConferenceManagerEventCallback { | ||
void onChangeModeRequest(String conferenceId, boolean audience); | ||
void onKickoffRequest(String conferenceId); | ||
} | ||
|
||
private ConferenceManagerEventCallback callback; | ||
public static ConferenceManager managerInstance = null; | ||
|
||
public static synchronized ConferenceManager Instance() { | ||
if(managerInstance == null) { | ||
managerInstance = new ConferenceManager(); | ||
} | ||
return managerInstance; | ||
} | ||
|
||
private ConferenceManager() { | ||
ChatManager.Instance().addOnReceiveMessageListener(this); | ||
} | ||
|
||
public void setCallback(ConferenceManagerEventCallback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
public void requestChangeModel(String conferenceId, String userId, boolean audience) { | ||
ConferenceChangeModelContent content = new ConferenceChangeModelContent(conferenceId, audience); | ||
Conversation conversation = new Conversation(Conversation.ConversationType.Single, userId); | ||
ChatManager.Instance().sendMessage(conversation, content, null, 0, null); | ||
} | ||
|
||
public void requestLeave(String conferenceId, String userId) { | ||
ConferenceKickoffMemberContent content = new ConferenceKickoffMemberContent(conferenceId); | ||
Conversation conversation = new Conversation(Conversation.ConversationType.Single, userId); | ||
ChatManager.Instance().sendMessage(conversation, content, null, 0, null); | ||
} | ||
|
||
public void changeModel(String conferenceId, boolean audience) { | ||
if(AVEngineKit.Instance().getCurrentSession() != null | ||
&& AVEngineKit.Instance().getCurrentSession().isConference() | ||
&& AVEngineKit.Instance().getCurrentSession().getCallId().equals(conferenceId)) | ||
AVEngineKit.Instance().getCurrentSession().switchAudience(audience); | ||
} | ||
|
||
@Override | ||
public void onReceiveMessage(List<Message> messages, boolean hasMore) { | ||
if(AVEngineKit.Instance().getCurrentSession() != null | ||
&& AVEngineKit.Instance().getCurrentSession().isConference()) { | ||
for (Message msg : messages) { | ||
if (msg.content instanceof ConferenceChangeModelContent) { | ||
ConferenceChangeModelContent content = (ConferenceChangeModelContent) msg.content; | ||
if (callback != null) { | ||
callback.onChangeModeRequest(content.getCallId(), content.isAudience()); | ||
} | ||
} else if (msg.content instanceof ConferenceKickoffMemberContent) { | ||
ConferenceKickoffMemberContent content = (ConferenceKickoffMemberContent) msg.content; | ||
if (callback != null) { | ||
callback.onKickoffRequest(content.getCallId()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
.../main/java/cn/wildfire/chat/kit/voip/conference/message/ConferenceChangeModelContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright (c) 2020 WildFireChat. All rights reserved. | ||
*/ | ||
|
||
package cn.wildfire.chat.kit.voip.conference.message; | ||
|
||
import android.os.Parcel; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import cn.wildfirechat.message.Message; | ||
import cn.wildfirechat.message.MessageContent; | ||
import cn.wildfirechat.message.core.ContentTag; | ||
import cn.wildfirechat.message.core.MessagePayload; | ||
import cn.wildfirechat.message.core.PersistFlag; | ||
|
||
import static cn.wildfirechat.message.core.MessageContentType.ContentType_Call_Start; | ||
import static cn.wildfirechat.message.core.MessageContentType.ContentType_Conference_Change_Model; | ||
|
||
/** | ||
* Created by heavyrain lee on 2017/12/6. | ||
*/ | ||
|
||
@ContentTag(type = ContentType_Conference_Change_Model, flag = PersistFlag.Transparent) | ||
public class ConferenceChangeModelContent extends MessageContent { | ||
private String callId; | ||
private boolean audience; | ||
|
||
|
||
public ConferenceChangeModelContent() { | ||
} | ||
|
||
public ConferenceChangeModelContent(String callId, boolean audience) { | ||
this.callId = callId; | ||
this.audience = audience; | ||
} | ||
|
||
public String getCallId() { | ||
return callId; | ||
} | ||
|
||
public void setCallId(String callId) { | ||
this.callId = callId; | ||
} | ||
|
||
public boolean isAudience() { | ||
return audience; | ||
} | ||
|
||
public void setAudience(boolean audience) { | ||
this.audience = audience; | ||
} | ||
|
||
@Override | ||
public MessagePayload encode() { | ||
MessagePayload payload = super.encode(); | ||
payload.content = callId; | ||
|
||
try { | ||
JSONObject objWrite = new JSONObject(); | ||
if (audience) { | ||
objWrite.put("a", audience); | ||
} | ||
|
||
payload.binaryContent = objWrite.toString().getBytes(); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
return payload; | ||
} | ||
|
||
|
||
@Override | ||
public void decode(MessagePayload payload) { | ||
callId = payload.content; | ||
|
||
try { | ||
if (payload.binaryContent != null) { | ||
JSONObject jsonObject = new JSONObject(new String(payload.binaryContent)); | ||
audience = jsonObject.optBoolean("a", false); | ||
} | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public String digest(Message message) { | ||
return "[网络电话]"; | ||
} | ||
|
||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
super.writeToParcel(dest, flags); | ||
dest.writeString(this.callId); | ||
dest.writeInt(this.audience ? 1 : 0); | ||
} | ||
|
||
protected ConferenceChangeModelContent(Parcel in) { | ||
super(in); | ||
this.callId = in.readString(); | ||
this.audience = in.readInt() == 1; | ||
} | ||
|
||
public static final Creator<ConferenceChangeModelContent> CREATOR = new Creator<ConferenceChangeModelContent>() { | ||
@Override | ||
public ConferenceChangeModelContent createFromParcel(Parcel source) { | ||
return new ConferenceChangeModelContent(source); | ||
} | ||
|
||
@Override | ||
public ConferenceChangeModelContent[] newArray(int size) { | ||
return new ConferenceChangeModelContent[size]; | ||
} | ||
}; | ||
} |
91 changes: 91 additions & 0 deletions
91
...ain/java/cn/wildfire/chat/kit/voip/conference/message/ConferenceKickoffMemberContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2020 WildFireChat. All rights reserved. | ||
*/ | ||
|
||
package cn.wildfire.chat.kit.voip.conference.message; | ||
|
||
import android.os.Parcel; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import cn.wildfirechat.message.Message; | ||
import cn.wildfirechat.message.MessageContent; | ||
import cn.wildfirechat.message.core.ContentTag; | ||
import cn.wildfirechat.message.core.MessagePayload; | ||
import cn.wildfirechat.message.core.PersistFlag; | ||
|
||
import static cn.wildfirechat.message.core.MessageContentType.ContentType_Conference_Change_Model; | ||
import static cn.wildfirechat.message.core.MessageContentType.ContentType_Conference_Kickoff_Member; | ||
|
||
/** | ||
* Created by heavyrain lee on 2017/12/6. | ||
*/ | ||
|
||
@ContentTag(type = ContentType_Conference_Kickoff_Member, flag = PersistFlag.Transparent) | ||
public class ConferenceKickoffMemberContent extends MessageContent { | ||
private String callId; | ||
|
||
|
||
public ConferenceKickoffMemberContent() { | ||
} | ||
|
||
public ConferenceKickoffMemberContent(String callId) { | ||
this.callId = callId; | ||
} | ||
|
||
public String getCallId() { | ||
return callId; | ||
} | ||
|
||
public void setCallId(String callId) { | ||
this.callId = callId; | ||
} | ||
|
||
@Override | ||
public MessagePayload encode() { | ||
MessagePayload payload = super.encode(); | ||
payload.content = callId; | ||
return payload; | ||
} | ||
|
||
|
||
@Override | ||
public void decode(MessagePayload payload) { | ||
callId = payload.content; | ||
} | ||
|
||
@Override | ||
public String digest(Message message) { | ||
return "[网络电话]"; | ||
} | ||
|
||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
super.writeToParcel(dest, flags); | ||
dest.writeString(this.callId); | ||
} | ||
|
||
protected ConferenceKickoffMemberContent(Parcel in) { | ||
super(in); | ||
this.callId = in.readString(); | ||
} | ||
|
||
public static final Creator<ConferenceKickoffMemberContent> CREATOR = new Creator<ConferenceKickoffMemberContent>() { | ||
@Override | ||
public ConferenceKickoffMemberContent createFromParcel(Parcel source) { | ||
return new ConferenceKickoffMemberContent(source); | ||
} | ||
|
||
@Override | ||
public ConferenceKickoffMemberContent[] newArray(int size) { | ||
return new ConferenceKickoffMemberContent[size]; | ||
} | ||
}; | ||
} |