Create ParticipantDisplayItem when creating the connections

The ParticipantDisplayItem for "video" was created when a participant
joined the room, but the item for "screen" was created when the stream
for the screen was connected. Due to this the item for the remote screen
share just "popped up" once connected, but there was no hint of a
connection being established, like done with the video streams.

Now the ParticipantDisplayItems are created as soon as a
PeerConnectionWrapper is created and then updated as needed (for example
to set the user ID or the stream), which causes the item to immediately
appear and a progress bar to be shown until the connection is
established.

Although the ParticipantDisplayItem may be created on a different thread
(the main thread) than the PeerConnectionWrapper "runOnUiThread"
executes the enqueued messages in order (and it also establishes a
"happens-before" relation with further calls of "runOnUiThread" due to
the internal use of synchronized blocks, although it is not explicitly
documented), so the item will be already created when later updated.

This also holds true when an offer is received even before the
participant is seen as joined (a very rare case that can happen if the
signaling message with the updated participant list is lost for any
reason); the ParticipantDisplayItem is created when the offer is
received and it is later updated with the user ID once a new signaling
message with the updated participant list is received.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2022-11-21 22:05:04 +01:00
parent 29d0574667
commit 6e222e7cd2

View File

@ -1858,15 +1858,22 @@ public class CallActivity extends CallBaseActivity {
getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, VIDEO_STREAM_TYPE_VIDEO, false); getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, VIDEO_STREAM_TYPE_VIDEO, false);
String userId = userIdsBySessionId.get(sessionId); String userId = userIdsBySessionId.get(sessionId);
if (userId != null) {
runOnUiThread(() -> { runOnUiThread(() -> {
setupVideoStreamForLayout( boolean notifyDataSetChanged = false;
null, if (participantDisplayItems.get(sessionId + "-video") != null) {
sessionId, participantDisplayItems.get(sessionId + "-video").setUserId(userId);
userId, notifyDataSetChanged = true;
false, }
VIDEO_STREAM_TYPE_VIDEO); if (participantDisplayItems.get(sessionId + "-screen") != null) {
}); participantDisplayItems.get(sessionId + "-screen").setUserId(userId);
notifyDataSetChanged = true;
}
if (notifyDataSetChanged) {
participantsAdapter.notifyDataSetChanged();
}
});
}
} }
if (newSessions.size() > 0 && currentCallStatus != CallStatus.IN_CONVERSATION) { if (newSessions.size() > 0 && currentCallStatus != CallStatus.IN_CONVERSATION) {
@ -2024,6 +2031,18 @@ public class CallActivity extends CallBaseActivity {
signalingMessageReceiver.addListener(offerAnswerNickProvider.getScreenWebRtcMessageListener(), sessionId, "screen"); signalingMessageReceiver.addListener(offerAnswerNickProvider.getScreenWebRtcMessageListener(), sessionId, "screen");
} }
if (!publisher) {
runOnUiThread(() -> {
// userId is unknown here, but it will be got based on the session id, and the stream will be
// updated once it is added to the connection.
setupVideoStreamForLayout(
null,
sessionId,
false,
type);
});
}
if (publisher) { if (publisher) {
startSendingNick(); startSendingNick();
} }
@ -2227,14 +2246,7 @@ public class CallActivity extends CallBaseActivity {
public void onMessageEvent(MediaStreamEvent mediaStreamEvent) { public void onMessageEvent(MediaStreamEvent mediaStreamEvent) {
String participantDisplayItemId = mediaStreamEvent.getSession() + "-" + mediaStreamEvent.getVideoStreamType(); String participantDisplayItemId = mediaStreamEvent.getSession() + "-" + mediaStreamEvent.getVideoStreamType();
if (participantDisplayItems.get(participantDisplayItemId) == null) { if (participantDisplayItems.get(participantDisplayItemId) == null) {
// Initial setup, ignore media related properties as they will be set after it. return;
// userId is unknown from the event, but it will be got based on the session id.
setupVideoStreamForLayout(
null,
mediaStreamEvent.getSession(),
null,
false,
mediaStreamEvent.getVideoStreamType());
} }
boolean hasAtLeastOneVideoStream = false; boolean hasAtLeastOneVideoStream = false;
@ -2260,7 +2272,6 @@ public class CallActivity extends CallBaseActivity {
private void setupVideoStreamForLayout(@Nullable MediaStream mediaStream, private void setupVideoStreamForLayout(@Nullable MediaStream mediaStream,
String session, String session,
String userId,
boolean videoStreamEnabled, boolean videoStreamEnabled,
String videoStreamType) { String videoStreamType) {
PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(session, PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(session,
@ -2280,20 +2291,17 @@ public class CallActivity extends CallBaseActivity {
nick = offerAnswerNickProviders.get(session) != null ? offerAnswerNickProviders.get(session).getNick() : ""; nick = offerAnswerNickProviders.get(session) != null ? offerAnswerNickProviders.get(session).getNick() : "";
} }
String userId4Usage = userId; String userId = null;
if (hasMCU) {
if (userId4Usage == null) { userId = webSocketClient.getUserIdForSession(session);
if (hasMCU) { } else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) {
userId4Usage = webSocketClient.getUserIdForSession(session); userId = participantMap.get(session).getCalculatedActorId();
} else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) {
userId4Usage = participantMap.get(session).getCalculatedActorId();
}
} }
String defaultGuestNick = getResources().getString(R.string.nc_nick_guest); String defaultGuestNick = getResources().getString(R.string.nc_nick_guest);
ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(baseUrl, ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(baseUrl,
userId4Usage, userId,
session, session,
connected, connected,
nick, nick,