Skip to content

Commit 9d3465c

Browse files
authored
Merge pull request #164 from GetStream/feature/uni-122-fix-black-screen-issue
Feature/uni 122 fix black screen issue
2 parents 63f8147 + 7807b61 commit 9d3465c

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,15 @@ private void TryExecuteSubscribeToTracks()
601601
/// </summary>
602602
private async Task SubscribeToTracksAsync()
603603
{
604+
if (ActiveCall.Participants == null || !ActiveCall.Participants.Any())
605+
{
606+
#if STREAM_DEBUG_ENABLED
607+
_logs.Info($"{nameof(SubscribeToTracksAsync)} Ignored - No participants in the call to subscribe tracks for");
608+
#endif
609+
610+
return;
611+
}
612+
604613
if (_trackSubscriptionRequestInProgress)
605614
{
606615
QueueTracksSubscriptionRequest();
@@ -609,6 +618,7 @@ private async Task SubscribeToTracksAsync()
609618

610619
_trackSubscriptionRequestInProgress = true;
611620

621+
// StreamTodo: validate that the very first call to SubscribeToTracksAsync is correct because ActiveCall.Participants may not have been updated yet
612622
var tracks = GetDesiredTracksDetails();
613623

614624
var request = new UpdateSubscriptionsRequest
@@ -953,7 +963,7 @@ private void UpdateParticipantTracksState(string userId, string sessionId, Track
953963
return;
954964
}
955965

956-
participant.SetTrackEnabled(trackType, isEnabled);
966+
participant.NotifyTrackEnabled(trackType, isEnabled);
957967

958968
ActiveCall.NotifyTrackStateChanged(participant, trackType, isEnabled);
959969
}

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,6 @@ public void Dispose()
230230
_logs.Warning($"Disposing PeerConnection [{_peerType}]");
231231
#endif
232232

233-
#if STREAM_NATIVE_AUDIO
234-
if (PublisherAudioTrack != null)
235-
{
236-
//StreamTODO: call this when PublisherAudioTrack is set to null
237-
PublisherAudioTrack.StopLocalAudioCapture();
238-
}
239-
#endif
240-
241233
_mediaInputProvider.AudioInputChanged -= OnAudioInputChanged;
242234
_mediaInputProvider.VideoSceneInputChanged -= OnVideoSceneInputChanged;
243235
_mediaInputProvider.VideoInputChanged -= OnVideoInputChanged;
@@ -252,13 +244,28 @@ public void Dispose()
252244
_peerConnection.OnConnectionStateChange -= OnConnectionStateChange;
253245
_peerConnection.OnTrack -= OnTrack;
254246

247+
#if STREAM_NATIVE_AUDIO
248+
if (PublisherAudioTrack != null)
249+
{
250+
//StreamTODO: call this when PublisherAudioTrack is set to null
251+
PublisherAudioTrack.StopLocalAudioCapture();
252+
}
253+
#endif
254+
255+
if (_publisherVideoTrackTexture != null)
256+
{
257+
_publisherVideoTrackTexture.Release();
258+
_publisherVideoTrackTexture = null;
259+
}
260+
255261
PublisherAudioTrack?.Stop();
256262
PublisherVideoTrack?.Stop();
257263
PublisherAudioTrack = null;
258264
PublisherVideoTrack = null;
259265

260266
_tracer?.Trace(PeerConnectionTraceKey.Close, null);
261267
_peerConnection.Close();
268+
_peerConnection.Dispose();
262269

263270
#if STREAM_DEBUG_ENABLED
264271
_logs.Warning($"Disposed PeerConnection [{_peerType}]");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public interface IStreamVideoCallParticipant : IStreamStatefulModel, IHasCustomD
1717
/// </summary>
1818
event ParticipantTrackChangedHandler TrackAdded;
1919

20+
/// <summary>
21+
/// A track <see cref="IStreamTrack.IsEnabled"/> state changed for this participant.
22+
/// </summary>
23+
event ParticipantTrackChangedHandler TrackIsEnabledChanged;
24+
2025
/// <summary>
2126
/// Is this participant "pinned" in the call meaning it will have precedence in <see cref="IStreamCall.SortedParticipants"/> list
2227
/// </summary>

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal sealed class StreamVideoCallParticipant : StreamStatefulModelBase<Strea
2121
IStreamVideoCallParticipant
2222
{
2323
public event ParticipantTrackChangedHandler TrackAdded;
24+
public event ParticipantTrackChangedHandler TrackIsEnabledChanged;
2425

2526
public bool IsLocalParticipant => UserSessionId == Client.InternalLowLevelClient.RtcSession.SessionId;
2627

@@ -244,7 +245,8 @@ internal void SetTrack(TrackType type, MediaStreamTrack mediaStreamTrack, out IS
244245
TrackAdded?.Invoke(this, streamTrack);
245246
}
246247

247-
internal void SetTrackEnabled(TrackType type, bool enabled)
248+
// This is only called for remote participants
249+
internal void NotifyTrackEnabled(TrackType type, bool enabled)
248250
{
249251
var streamTrack = GetStreamTrack(type);
250252
if (streamTrack == null)
@@ -258,9 +260,15 @@ internal void SetTrackEnabled(TrackType type, bool enabled)
258260
$"[Participant] Local: {IsLocalParticipant}, Session ID: {SessionId} set track enabled of type {type} to {enabled}");
259261
#endif
260262

261-
streamTrack.SetEnabled(enabled);
263+
//StreamTodo: this would break a track in the following scenario:
264+
// Host tracks are auto-enabled when joining the call -> VideoDeviceManager.SetEnabled(true) right after JoinCallAsync)
265+
// Join call by host and watcher
266+
// Disable track on host -> this causes watcher to disable the track as well
267+
// Leave the call as host and re-join -> the track is re-enabled on host side but watcher still has it disabled
268+
//streamTrack.SetEnabled(enabled);
262269

263270
//StreamTodo: we should trigger some event that track status changed
271+
TrackIsEnabledChanged?.Invoke(this, streamTrack);
264272
}
265273

266274
internal void SetIsPinned(bool isPinned) => IsPinned = isPinned;

0 commit comments

Comments
 (0)