Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Samples/Stream Video & Audio Chat SDK/0.8.18.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task JoinAsync(string callId, bool create = true)

Debug.Log($"Join call, create: {create}, callId: {callId}");
await Client.JoinCallAsync(StreamCallType.Default, callId, create, ring: true, notify: false);

if (_autoEnableMicrophone)
{
Client.AudioDeviceManager.SetEnabled(true);
Expand Down Expand Up @@ -111,7 +111,7 @@ public void ToggleMusic(bool loop = true, bool forceStop = false)
{
throw new ArgumentNullException($"{nameof(_musicClip)} is not assigned.");
}

var audioSource = gameObject.GetComponent<AudioSource>();
if (audioSource == null)
{
Expand All @@ -123,7 +123,7 @@ public void ToggleMusic(bool loop = true, bool forceStop = false)
audioSource.Stop();
return;
}

audioSource.clip = _musicClip;
audioSource.loop = loop;
audioSource.Play();
Expand Down Expand Up @@ -175,7 +175,45 @@ protected async void OnDestroy()
Client.Dispose();
Client = null;
}


#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
protected void OnApplicationPause(bool pauseStatus)
{
if (Client == null)
{
return;
}

if (pauseStatus)
{
// App is going to background
Client.PauseAndroidAudioPlayback();
_wasAudioPublishEnabledOnPause = Client.AudioDeviceManager.IsEnabled;
_wasVideoPublishEnabledOnPause = Client.VideoDeviceManager.IsEnabled;

Client.AudioDeviceManager.SetEnabled(false);
Client.VideoDeviceManager.SetEnabled(false);
}
else
{
// App is coming to foreground
Client.ResumeAndroidAudioPlayback();

if (_wasAudioPublishEnabledOnPause)
{
Client.AudioDeviceManager.SetEnabled(true);
_wasAudioPublishEnabledOnPause = false;
}

if (_wasVideoPublishEnabledOnPause)
{
Client.VideoDeviceManager.SetEnabled(true);
_wasVideoPublishEnabledOnPause = false;
}
}
}
#endif

/// <summary>
/// API success response template when using Stream's Demo Credentials
/// </summary>
Expand Down Expand Up @@ -212,24 +250,27 @@ private string _info

[SerializeField]
private string _userToken = "";

[Header("Background Music in a call")]
[SerializeField]
private AudioClip _musicClip = null;

[SerializeField]
private bool _playOnCallStart = false;

[Header("Auto-enable devices on joining a call")]
[SerializeField]
private bool _autoEnableCamera = false;

[SerializeField]
private bool _autoEnableMicrophone = false;

private StreamClientConfig _clientConfig;
private IStreamCall _activeCall;

private bool _wasAudioPublishEnabledOnPause;
private bool _wasVideoPublishEnabledOnPause;

private async Task ConnectToStreamAsync(AuthCredentials credentials)
{
var credentialsEmpty = string.IsNullOrEmpty(credentials.ApiKey) &&
Expand Down Expand Up @@ -299,9 +340,11 @@ private void OnCallEnded(IStreamCall call)

if (_activeCall.Participants == null)
{
Debug.LogError("Active call participants were null when trying to end it. call is null " + (call == null));
Debug.LogError("Active call participants were null when trying to end it. call is null " +
(call == null));
return;
}

var callId = _activeCall.Id;
var localParticipant = _activeCall.Participants.First(p => p.IsLocalParticipant);
Client.SendDebugLogs(call.Id, localParticipant.SessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task JoinAsync(string callId, bool create = true)

Debug.Log($"Join call, create: {create}, callId: {callId}");
await Client.JoinCallAsync(StreamCallType.Default, callId, create, ring: true, notify: false);

if (_autoEnableMicrophone)
{
Client.AudioDeviceManager.SetEnabled(true);
Expand Down Expand Up @@ -111,7 +111,7 @@ public void ToggleMusic(bool loop = true, bool forceStop = false)
{
throw new ArgumentNullException($"{nameof(_musicClip)} is not assigned.");
}

var audioSource = gameObject.GetComponent<AudioSource>();
if (audioSource == null)
{
Expand All @@ -123,7 +123,7 @@ public void ToggleMusic(bool loop = true, bool forceStop = false)
audioSource.Stop();
return;
}

audioSource.clip = _musicClip;
audioSource.loop = loop;
audioSource.Play();
Expand Down Expand Up @@ -175,7 +175,45 @@ protected async void OnDestroy()
Client.Dispose();
Client = null;
}


#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
protected void OnApplicationPause(bool pauseStatus)
{
if (Client == null)
{
return;
}

if (pauseStatus)
{
// App is going to background
Client.PauseAndroidAudioPlayback();
_wasAudioPublishEnabledOnPause = Client.AudioDeviceManager.IsEnabled;
_wasVideoPublishEnabledOnPause = Client.VideoDeviceManager.IsEnabled;

Client.AudioDeviceManager.SetEnabled(false);
Client.VideoDeviceManager.SetEnabled(false);
}
else
{
// App is coming to foreground
Client.ResumeAndroidAudioPlayback();

if (_wasAudioPublishEnabledOnPause)
{
Client.AudioDeviceManager.SetEnabled(true);
_wasAudioPublishEnabledOnPause = false;
}

if (_wasVideoPublishEnabledOnPause)
{
Client.VideoDeviceManager.SetEnabled(true);
_wasVideoPublishEnabledOnPause = false;
}
}
}
#endif

/// <summary>
/// API success response template when using Stream's Demo Credentials
/// </summary>
Expand Down Expand Up @@ -212,24 +250,27 @@ private string _info

[SerializeField]
private string _userToken = "";

[Header("Background Music in a call")]
[SerializeField]
private AudioClip _musicClip = null;

[SerializeField]
private bool _playOnCallStart = false;

[Header("Auto-enable devices on joining a call")]
[SerializeField]
private bool _autoEnableCamera = false;

[SerializeField]
private bool _autoEnableMicrophone = false;

private StreamClientConfig _clientConfig;
private IStreamCall _activeCall;

private bool _wasAudioPublishEnabledOnPause;
private bool _wasVideoPublishEnabledOnPause;

private async Task ConnectToStreamAsync(AuthCredentials credentials)
{
var credentialsEmpty = string.IsNullOrEmpty(credentials.ApiKey) &&
Expand Down Expand Up @@ -299,9 +340,11 @@ private void OnCallEnded(IStreamCall call)

if (_activeCall.Participants == null)
{
Debug.LogError("Active call participants were null when trying to end it. call is null " + (call == null));
Debug.LogError("Active call participants were null when trying to end it. call is null " +
(call == null));
return;
}

var callId = _activeCall.Id;
var localParticipant = _activeCall.Participants.First(p => p.IsLocalParticipant);
Client.SendDebugLogs(call.Id, localParticipant.SessionId);
Expand Down
Loading