Skip to content

Commit f689616

Browse files
authored
Merge pull request #173 from GetStream/feature/uni-128-fix-subscribetotracksasync-null-exception
Try fix SubscribeToTracksAsync NullReferenceException
2 parents 88ed143 + 8bc6ac6 commit f689616

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

Assets/Samples/Stream Video & Audio Chat SDK/0.8.8.meta renamed to Assets/Samples/Stream Video & Audio Chat SDK/0.8.10.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ private void ClearSession()
536536

537537
ActiveCall = null;
538538
CallState = CallingState.Unknown;
539+
_httpClient = null;
539540

540541
_trackSubscriptionRequested = false;
541542
_trackSubscriptionRequestInProgress = false;
@@ -585,10 +586,11 @@ private void TryExecuteSubscribeToTracks()
585586
/// </summary>
586587
private async Task SubscribeToTracksAsync()
587588
{
588-
if (ActiveCall.Participants == null || !ActiveCall.Participants.Any())
589+
if (ActiveCall?.Participants == null || !ActiveCall.Participants.Any())
589590
{
590591
#if STREAM_DEBUG_ENABLED
591-
_logs.Error($"{nameof(SubscribeToTracksAsync)} Ignored - No participants in the call to subscribe tracks for");
592+
_logs.Error(
593+
$"{nameof(SubscribeToTracksAsync)} Ignored - No participants in the call to subscribe tracks for");
592594
#endif
593595

594596
return;
@@ -624,7 +626,7 @@ private async Task SubscribeToTracksAsync()
624626
return;
625627
}
626628

627-
if (response.Error != null)
629+
if (response?.Error != null)
628630
{
629631
_logs.Error(response.Error.Message);
630632
}
@@ -639,6 +641,12 @@ private IEnumerable<TrackSubscriptionDetails> GetDesiredTracksDetails()
639641

640642
foreach (var participant in ActiveCall.Participants)
641643
{
644+
if (participant == null)
645+
{
646+
_logs.Error("Cannot subscribe to tracks - participant is null");
647+
continue;
648+
}
649+
642650
if (participant.IsLocalParticipant)
643651
{
644652
continue;
@@ -652,9 +660,16 @@ private IEnumerable<TrackSubscriptionDetails> GetDesiredTracksDetails()
652660
//This was before changing the IUpdateableFrom<CallParticipantResponseInternalDTO, StreamVideoCallParticipant>.UpdateFromDto
653661
//to extract UserId from User obj
654662

663+
var userId = GetUserId(participant);
664+
if (string.IsNullOrEmpty(userId))
665+
{
666+
_logs.Error($"Cannot subscribe to {trackType} - participant UserId is null or empty. SessionID: {participant.SessionId}");
667+
continue;
668+
}
669+
655670
yield return new TrackSubscriptionDetails
656671
{
657-
UserId = GetUserId(participant),
672+
UserId = userId,
658673
SessionId = participant.SessionId,
659674
TrackType = trackType,
660675
Dimension = requestedVideoResolution.ToVideoDimension()
@@ -1051,8 +1066,15 @@ private void OnSfuDominantSpeakerChanged(DominantSpeakerChanged dominantSpeakerC
10511066
private void OnSfuWebSocketOnError(SfuError obj)
10521067
{
10531068
_sfuTracer?.Trace(PeerConnectionTraceKey.SfuError, obj);
1069+
if (CallState == CallingState.Offline)
1070+
{
1071+
return;
1072+
}
1073+
10541074
_logs.Error(
10551075
$"Sfu Error - Code: {obj.Error_.Code}, Message: {obj.Error_.Message}, ShouldRetry: {obj.Error_.ShouldRetry}");
1076+
1077+
//StreamTODO: add event here
10561078
}
10571079

10581080
private void OnSfuPinsUpdated(PinsChanged pinsChanged)
@@ -1148,6 +1170,15 @@ private async Task<TResponse> RpcCallAsync<TRequest, TResponse>(TRequest request
11481170
{
11491171
//StreamTodo: use rpcCallAsync.GetMethodInfo().Name; instead debugRequestName
11501172

1173+
if (_httpClient == null)
1174+
{
1175+
var errorMsg
1176+
= $"[RPC Call: {debugRequestName}] Failed - Attempted to execute RPC call but HttpClient is not yet initialized. " +
1177+
$"CallState: {CallState}, ActiveCall: {ActiveCall != null}, SessionId: {SessionId ?? "null"}";
1178+
_logs.Error(errorMsg);
1179+
throw new InvalidOperationException(errorMsg);
1180+
}
1181+
11511182
var skipTracing = debugRequestName == nameof(GeneratedAPI.SendStats);
11521183

11531184
// Trace the RPC request (except SendStats to avoid noise)

0 commit comments

Comments
 (0)