Skip to content

Commit b79d033

Browse files
authored
Merge pull request #156 from GetStream/feature/uni-116-null-argument-for-userid-in
Add potential fix for occasional null ref UserId when constucting Tra…
2 parents 5422ea1 + ace6c25 commit b79d033

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,13 @@ private IEnumerable<TrackSubscriptionDetails> GetDesiredTracksDetails()
572572

573573
foreach (var trackType in trackTypes)
574574
{
575+
//StreamTODO: UserId is sometimes null here
576+
//This was before changing the IUpdateableFrom<CallParticipantResponseInternalDTO, StreamVideoCallParticipant>.UpdateFromDto
577+
//to extract UserId from User obj
578+
575579
yield return new TrackSubscriptionDetails
576580
{
577-
UserId = participant.UserId,
581+
UserId = GetUserId(participant),
578582
SessionId = participant.SessionId,
579583
TrackType = trackType,
580584
Dimension = requestedVideoResolution.ToVideoDimension()
@@ -583,6 +587,23 @@ private IEnumerable<TrackSubscriptionDetails> GetDesiredTracksDetails()
583587
}
584588
}
585589

590+
//StreamTodo: remove this, this is a workaround to Null UserId error
591+
private string GetUserId(IStreamVideoCallParticipant participant)
592+
{
593+
if (!string.IsNullOrEmpty(participant.UserId))
594+
{
595+
return participant.UserId;
596+
}
597+
598+
if (participant.User == null || string.IsNullOrEmpty(participant.User.Id))
599+
{
600+
throw new Exception(
601+
$"Both {nameof(IStreamVideoCallParticipant.UserId)} and {nameof(IStreamVideoCallParticipant.User)} ID are null or empty. No way to get the user ID");
602+
}
603+
604+
return participant.User.Id;
605+
}
606+
586607
private VideoResolution GetRequestedVideoResolution(IStreamVideoCallParticipant participant)
587608
{
588609
if (participant == null || participant.SessionId == null)

Packages/StreamVideo/Runtime/Core/StatefulModels/StreamVideoCallParticipant.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ void IUpdateableFrom<CallParticipantResponseInternalDTO, StreamVideoCallParticip
142142
Role = dto.Role;
143143
User = cache.TryCreateOrUpdate(dto.User);
144144
UserSessionId = dto.UserSessionId;
145+
146+
if (string.IsNullOrEmpty(UserId) && User != null)
147+
{
148+
UserId = User.Id;
149+
}
150+
151+
//StreamTodo: investigate why we either update UserId or User object
152+
//Depending on the update source we'll end up with one being empty
153+
//We can take UserId from user obj, but we can't easily get User obj give UserId in dto
154+
//Ideally, we'd only expose the User object -> check if this is possible
155+
156+
//StreamTodo: verify if we're using every piece of data received from API/SFU responses to update this object
145157
}
146158

147159
internal void LoadCustomDataFromOwningCallCustomData(Dictionary<string, object> participantCustomData)

0 commit comments

Comments
 (0)