Skip to content

Commit 38930e7

Browse files
authored
Merge pull request #228 from GetStream/bugfix/uni-189-fix-null-ref
Add null ref guards
2 parents 955169b + f58b89f commit 38930e7

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

Packages/StreamVideo/Runtime/Core/LowLevelClient/API/Internal/InternalApiClientBase.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ private async Task<TResponse> HttpRequest<TResponse>(HttpMethodType httpMethod,
113113
catch (Exception e)
114114
{
115115
LogRestCall(uri, endpoint, httpMethod, responseContent, success: false, logContent);
116-
throw new StreamDeserializationException(responseContent, typeof(TResponse), e);
116+
throw new StreamDeserializationException(responseContent, typeof(APIErrorInternalDTO), e);
117+
}
118+
119+
if (apiError == null)
120+
{
121+
LogRestCall(uri, endpoint, httpMethod, responseContent, success: false, logContent);
122+
throw new StreamDeserializationException(responseContent, typeof(APIErrorInternalDTO),
123+
new InvalidOperationException("Deserializer returned null"));
117124
}
118125

119126
if (apiError.Code != InvalidAuthTokenErrorCode)
@@ -165,6 +172,13 @@ private async Task<TResponse> HttpRequest<TResponse>(HttpMethodType httpMethod,
165172
try
166173
{
167174
var response = _serializer.Deserialize<TResponse>(responseContent);
175+
if (response == null)
176+
{
177+
LogRestCall(uri, endpoint, httpMethod, responseContent, success: false, logContent);
178+
throw new StreamDeserializationException(responseContent, typeof(TResponse),
179+
new InvalidOperationException("Deserializer returned null"));
180+
}
181+
168182
LogRestCall(uri, endpoint, httpMethod, responseContent, success: true, logContent);
169183
return response;
170184
}

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,8 @@ public async Task DoJoin(JoinCallData joinCallData, CancellationToken cancellati
490490
$"{nameof(DoJoin)} - Skipped join call request: callExists: {callCredentialsExists}, isRejoin: {isRejoin}, isMigration: {isMigration}");
491491
}
492492

493-
ActiveCall = call ?? throw new NullReferenceException(nameof(call));
494-
495-
if (ActiveCall.Credentials == null || string.IsNullOrEmpty(ActiveCall.Credentials.Token))
496-
{
497-
_logs.ErrorIfDebug($"{nameof(DoJoin)} - Missing credentials!");
498-
}
493+
ActiveCall = call;
494+
EnsureCallHasJoinCredentials(ActiveCall);
499495

500496
_httpClient = _httpClientFactory(ActiveCall);
501497

@@ -745,13 +741,46 @@ private async Task<StreamCall> ExecuteJoinRequest(JoinCallData data, Cancellatio
745741

746742
var joinCallResponse
747743
= await _lowLevelClient.InternalVideoClientApi.JoinCallAsync(data.Type, data.Id, joinCallRequest);
744+
if (joinCallResponse == null)
745+
{
746+
throw new InvalidOperationException(
747+
$"Join call API returned an empty response for `{data.Type}:{data.Id}`.");
748+
}
749+
748750
var streamCall = _cache.TryCreateOrUpdate(joinCallResponse);
751+
if (streamCall == null)
752+
{
753+
throw new InvalidOperationException(
754+
$"Join call API response could not be applied for `{data.Type}:{data.Id}`.");
755+
}
749756

750757
//StreamTODO: add ring accept logic. Check JS doJoinRequest
751758

752759
return streamCall;
753760
}
754761

762+
private static void EnsureCallHasJoinCredentials(StreamCall call)
763+
{
764+
if (call == null)
765+
{
766+
throw new InvalidOperationException("Join call response did not contain call data.");
767+
}
768+
769+
var credentials = call.Credentials;
770+
if (credentials == null || string.IsNullOrEmpty(credentials.Token))
771+
{
772+
throw new InvalidOperationException(
773+
$"Join call response for `{call.Cid}` is missing credentials or token.");
774+
}
775+
776+
var server = credentials.Server;
777+
if (server == null || string.IsNullOrEmpty(server.Url))
778+
{
779+
throw new InvalidOperationException(
780+
$"Join call response for `{call.Cid}` is missing SFU server URL.");
781+
}
782+
}
783+
755784
public Task StopAsync(string reason = "")
756785
{
757786
if (UseNativeAudioBindings)

0 commit comments

Comments
 (0)