Skip to content

Commit

Permalink
Merge pull request #81 from GetStream/bugfix/example-project-fix-crea…
Browse files Browse the repository at this point in the history
…ting-a-call-after-leaving-previous

Fix UI screens subscribing to events on every show
  • Loading branch information
sierpinskid authored Mar 4, 2024
2 parents 1ce2d19 + fa4fbc5 commit 7131d0e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public void Init(StreamVideoManager streamVideoManager, UIManager uiManager)

// Hide every screen view by default. The UIManager controls which screen should become visible
_gameObject.SetActive(false);

OnInit();
}

public void Show(TInitArgs initArgs)
Expand All @@ -42,6 +44,8 @@ public void Hide()

protected StreamVideoManager VideoManager { get; private set; }
protected UIManager UIManager { get; private set; }

protected abstract void OnInit();

protected abstract void OnShow(TInitArgs initArgs);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using StreamVideo.Core;
using StreamVideo.Core.StatefulModels;
using TMPro;
using UnityEngine;
Expand All @@ -11,16 +10,16 @@ namespace StreamVideo.ExampleProject.UI.Screens
/// <summary>
/// Screen visible during the active call. Shows other participants
/// </summary>
public class CallScreenView : BaseScreenView<CallScreenView.InitArgs>
public class CallScreenView : BaseScreenView<CallScreenView.ShowArgs>
{
/// <summary>
/// Arguments required to initialize this screen when showing
/// </summary>
public readonly struct InitArgs
public readonly struct ShowArgs
{
public readonly IStreamCall ActiveCall;

public InitArgs(IStreamCall activeCall)
public ShowArgs(IStreamCall activeCall)
{
ActiveCall = activeCall;
}
Expand Down Expand Up @@ -51,12 +50,15 @@ private readonly Dictionary<string, ParticipantView> _participantSessionIdToView
private IStreamCall _activeCall;
private ParticipantView _currentDominantSpeakerView;

protected override void OnShow(InitArgs initArgs)
protected override void OnInit()
{
_activeCall = initArgs.ActiveCall;

_leaveBtn.onClick.AddListener(VideoManager.LeaveActiveCall);
_endBtn.onClick.AddListener(VideoManager.EndActiveCall);
}

protected override void OnShow(ShowArgs showArgs)
{
_activeCall = showArgs.ActiveCall;

// If local user is the call owner we can "end" the call for all participants, otherwise we can only "leave" the call
_endBtn.gameObject.SetActive(_activeCall.IsLocalUserOwner);
Expand Down Expand Up @@ -86,9 +88,6 @@ protected override void OnShow(InitArgs initArgs)

protected override void OnHide()
{
_leaveBtn.onClick.RemoveListener(VideoManager.LeaveActiveCall);
_endBtn.onClick.RemoveListener(VideoManager.EndActiveCall);

if (_activeCall != null)
{
_activeCall.ParticipantJoined -= OnParticipantJoined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace StreamVideo.ExampleProject.UI.Screens
/// <summary>
/// The main screen where a use can create a call or join
/// </summary>
public class MainScreenView : BaseScreenView<CallScreenView.InitArgs>
public class MainScreenView : BaseScreenView<CallScreenView.ShowArgs>
{
/// <summary>
/// Arguments required to initialize this screen when showing
/// </summary>
public readonly struct InitArgs
public readonly struct ShowArgs
{
}

public void Show() => base.Show(new CallScreenView.InitArgs());
public void Show() => base.Show(new CallScreenView.ShowArgs());

protected override void OnShow(CallScreenView.InitArgs initArgs)
protected override void OnInit()
{
_joinBtn.onClick.AddListener(OnJoinCallButtonClicked);
_createBtn.onClick.AddListener(OnCreateAndJoinCallButtonClicked);
Expand All @@ -45,7 +45,10 @@ protected override void OnShow(CallScreenView.InitArgs initArgs)

SmartPickDefaultCamera();
SmartPickDefaultMicrophone();

}

protected override void OnShow(CallScreenView.ShowArgs showArgs)
{
UIManager.ActiveCameraChanged += OnActiveCameraChanged;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void ShowMainScreen()
private void ShowCallScreen(IStreamCall call)
{
_mainScreen.Hide();
_callScreen.Show(new CallScreenView.InitArgs(call));
_callScreen.Show(new CallScreenView.ShowArgs(call));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public void Init(StreamVideoManager streamVideoManager, UIManager uiManager)

// Hide every screen view by default. The UIManager controls which screen should become visible
_gameObject.SetActive(false);

OnInit();
}

public void Show(TInitArgs initArgs)
Expand All @@ -42,6 +44,8 @@ public void Hide()

protected StreamVideoManager VideoManager { get; private set; }
protected UIManager UIManager { get; private set; }

protected abstract void OnInit();

protected abstract void OnShow(TInitArgs initArgs);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using StreamVideo.Core;
using StreamVideo.Core.StatefulModels;
using TMPro;
using UnityEngine;
Expand All @@ -11,16 +10,16 @@ namespace StreamVideo.ExampleProject.UI.Screens
/// <summary>
/// Screen visible during the active call. Shows other participants
/// </summary>
public class CallScreenView : BaseScreenView<CallScreenView.InitArgs>
public class CallScreenView : BaseScreenView<CallScreenView.ShowArgs>
{
/// <summary>
/// Arguments required to initialize this screen when showing
/// </summary>
public readonly struct InitArgs
public readonly struct ShowArgs
{
public readonly IStreamCall ActiveCall;

public InitArgs(IStreamCall activeCall)
public ShowArgs(IStreamCall activeCall)
{
ActiveCall = activeCall;
}
Expand Down Expand Up @@ -51,12 +50,15 @@ private readonly Dictionary<string, ParticipantView> _participantSessionIdToView
private IStreamCall _activeCall;
private ParticipantView _currentDominantSpeakerView;

protected override void OnShow(InitArgs initArgs)
protected override void OnInit()
{
_activeCall = initArgs.ActiveCall;

_leaveBtn.onClick.AddListener(VideoManager.LeaveActiveCall);
_endBtn.onClick.AddListener(VideoManager.EndActiveCall);
}

protected override void OnShow(ShowArgs showArgs)
{
_activeCall = showArgs.ActiveCall;

// If local user is the call owner we can "end" the call for all participants, otherwise we can only "leave" the call
_endBtn.gameObject.SetActive(_activeCall.IsLocalUserOwner);
Expand Down Expand Up @@ -86,9 +88,6 @@ protected override void OnShow(InitArgs initArgs)

protected override void OnHide()
{
_leaveBtn.onClick.RemoveListener(VideoManager.LeaveActiveCall);
_endBtn.onClick.RemoveListener(VideoManager.EndActiveCall);

if (_activeCall != null)
{
_activeCall.ParticipantJoined -= OnParticipantJoined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace StreamVideo.ExampleProject.UI.Screens
/// <summary>
/// The main screen where a use can create a call or join
/// </summary>
public class MainScreenView : BaseScreenView<CallScreenView.InitArgs>
public class MainScreenView : BaseScreenView<CallScreenView.ShowArgs>
{
/// <summary>
/// Arguments required to initialize this screen when showing
/// </summary>
public readonly struct InitArgs
public readonly struct ShowArgs
{
}

public void Show() => base.Show(new CallScreenView.InitArgs());
public void Show() => base.Show(new CallScreenView.ShowArgs());

protected override void OnShow(CallScreenView.InitArgs initArgs)
protected override void OnInit()
{
_joinBtn.onClick.AddListener(OnJoinCallButtonClicked);
_createBtn.onClick.AddListener(OnCreateAndJoinCallButtonClicked);
Expand All @@ -45,7 +45,10 @@ protected override void OnShow(CallScreenView.InitArgs initArgs)

SmartPickDefaultCamera();
SmartPickDefaultMicrophone();

}

protected override void OnShow(CallScreenView.ShowArgs showArgs)
{
UIManager.ActiveCameraChanged += OnActiveCameraChanged;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void ShowMainScreen()
private void ShowCallScreen(IStreamCall call)
{
_mainScreen.Hide();
_callScreen.Show(new CallScreenView.InitArgs(call));
_callScreen.Show(new CallScreenView.ShowArgs(call));
}
}
}

0 comments on commit 7131d0e

Please sign in to comment.