Skip to content

Commit 502bec9

Browse files
authored
Merge pull request #182 from GetStream/feature/uni-135-fix-callparticipants-not-always-containing-the-local
Fix issue where call.Participants did not always contain the local pa…
2 parents 3eb01e6 + dd841e0 commit 502bec9

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public async Task StopAsync(string reason = "")
415415
}
416416
catch (Exception e)
417417
{
418-
_logs.Error($"Failed to send final stats on leave: {e.Message}");
418+
_logs.Warning($"Failed to send final stats on leave: {e.Message}");
419419
}
420420

421421
#if STREAM_DEBUG_ENABLED

Packages/StreamVideo/Runtime/Core/LowLevelClient/WebSockets/SfuWebSocket.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void SendLeaveCallRequest(string reason = "")
7777

7878
if (reason == null)
7979
{
80-
throw new ArgumentException($"{nameof(reason)} is null.");
80+
reason = "reason not provided";
8181
}
8282

8383
#if STREAM_DEBUG_ENABLED
@@ -298,15 +298,22 @@ protected override async Task OnDisconnectingAsync(string closeMessage)
298298

299299
using (new TimeLogScope("Sending leave call request", Logs.Info))
300300
{
301-
SendLeaveCallRequest(closeMessage);
302-
303-
for (int i = 0; i < 60; i++)
301+
try
304302
{
305-
if (SendQueueCount > 0)
303+
SendLeaveCallRequest(closeMessage);
304+
305+
for (int i = 0; i < 60; i++)
306306
{
307-
await Task.Delay(5);
307+
if (SendQueueCount > 0)
308+
{
309+
await Task.Delay(5);
310+
}
308311
}
309312
}
313+
catch (Exception e)
314+
{
315+
Logs.Warning("Failed to send LeaveCallRequest during disconnect: " + e.Message);
316+
}
310317
}
311318

312319
await base.OnDisconnectingAsync(closeMessage);

Packages/StreamVideo/Runtime/Core/Models/CallSession.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ void IStateLoadableFrom<CallSessionResponseInternalDTO, CallSession>.LoadFromDto
5353
_acceptedBy.TryReplaceValuesFromDto(dto.AcceptedBy);
5454
EndedAt = dto.EndedAt;
5555
Id = dto.Id;
56-
_participants.TryReplaceTrackedObjects(dto.Participants, cache.CallParticipants);
57-
_participantsCountByRole.TryReplaceValuesFromDto(dto.ParticipantsCountByRole);
56+
57+
// CallSessionResponseInternalDTO usually (or always?) contains no participants. Participants are updated from the SFU join response
58+
// But SFU response can arrive before API response, so we can't override participants here because this clears the list
59+
foreach (var dtoParticipant in dto.Participants)
60+
{
61+
var participant = cache.TryCreateOrUpdate(dtoParticipant);
62+
if (!_participants.Contains(participant))
63+
{
64+
_participants.Add(participant);
65+
}
66+
}
67+
68+
// StreamTODO: figure out how to best handle this. Should we update it from coordinator or only the SFU
69+
//_participantsCountByRole.TryReplaceValuesFromDto(dto.ParticipantsCountByRole);
5870
_rejectedBy.TryReplaceValuesFromDto(dto.RejectedBy);
5971
StartedAt = dto.StartedAt;
6072
LiveEndedAt = dto.LiveEndedAt;

0 commit comments

Comments
 (0)