Skip to content

Commit

Permalink
Merge pull request #133 from GetStream/feature/uni-78-fix-callended-e…
Browse files Browse the repository at this point in the history
…vent-being-called-twice

Fix CallEnded event being called twice for the local user
  • Loading branch information
sierpinskid authored Feb 14, 2025
2 parents d785506 + df1f06d commit 2ae865b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ public async Task SendWebRtcStats(SendStatsRequest request)

if (response.Error != null)
{
_logs.Error(response.Error.Message);
// StreamTodo: perhaps failure on stats sending should be silent? This can return "call not found" if call ended before `call.ended` event was received
// Maybe we can wait 1-2s before displaying the error to cover this case

_logs.Warning("Sending webRTC stats failed: " + response.Error.Message);
_logs.ErrorIfDebug("Sending webRTC stats failed: " + response.Error.Message);
}
}

Expand Down
25 changes: 17 additions & 8 deletions Packages/StreamVideo/Runtime/Core/StreamVideoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,9 @@ void IStreamVideoClientEventsListener.Destroy()

Task IInternalStreamVideoClient.LeaveCallAsync(IStreamCall call) => LeaveCallAsync(call);

async Task IInternalStreamVideoClient.EndCallAsync(IStreamCall call)
{
//StreamTodo: check if call is active
await InternalLowLevelClient.InternalVideoClientApi.EndCallAsync(call.Type, call.Id);
await LeaveCallAsync(call);
}
// Leaving the call will be triggered by the received `call.ended` event
Task IInternalStreamVideoClient.EndCallAsync(IStreamCall call)
=> InternalLowLevelClient.InternalVideoClientApi.EndCallAsync(call.Type, call.Id);

Task IInternalStreamVideoClient.StartHLSAsync(IStreamCall call)
=> InternalLowLevelClient.InternalVideoClientApi.StartBroadcastingAsync(call.Type, call.Id);
Expand Down Expand Up @@ -390,8 +387,15 @@ public Task SendDebugLogs(string callId, string participantId)

private async Task LeaveCallAsync(IStreamCall call)
{
//StreamTodo: check if call is active
await InternalLowLevelClient.RtcSession.StopAsync();
try
{
await InternalLowLevelClient.RtcSession.StopAsync();
}
catch (Exception e)
{
_logs.Exception(e);
}

CallEnded?.Invoke(call);
}

Expand Down Expand Up @@ -506,6 +510,11 @@ private void OnInternalCallUpdatedEvent(CallUpdatedEventInternalDTO eventData)
private void OnInternalCallEndedEvent(CallEndedEventInternalDTO eventData)
{
var call = _cache.TryCreateOrUpdate(eventData.Call);
if (call == null)
{
_logs.Error($"Received call ended event for a call that doesn't exist. {nameof(eventData.Call.Cid)}:" + eventData?.Call?.Cid);
return;
}
call.LeaveAsync().LogIfFailed();
}

Expand Down

0 comments on commit 2ae865b

Please sign in to comment.