Skip to content

Commit

Permalink
Fix CallEnded event being called twice for the local user when local …
Browse files Browse the repository at this point in the history
…user ends the call. EndCallAsync doesn't need to call LeaveCallAsync because it will be called by the received `call.ended` event
  • Loading branch information
sierpinskid committed Feb 13, 2025
1 parent d785506 commit 43acb5e
Showing 1 changed file with 17 additions and 8 deletions.
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 43acb5e

Please sign in to comment.