diff --git a/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18.meta b/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18.meta new file mode 100644 index 00000000..d252a5fd --- /dev/null +++ b/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0e877e983999bbc42a9e80e7b68900b2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18/Video & Audio Chat Example Project/Scripts/StreamVideoManager.cs b/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18/Video & Audio Chat Example Project/Scripts/StreamVideoManager.cs index 8313591f..c92ec2a1 100644 --- a/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18/Video & Audio Chat Example Project/Scripts/StreamVideoManager.cs +++ b/Assets/Samples/Stream Video & Audio Chat SDK/0.8.18/Video & Audio Chat Example Project/Scripts/StreamVideoManager.cs @@ -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); @@ -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(); if (audioSource == null) { @@ -123,7 +123,7 @@ public void ToggleMusic(bool loop = true, bool forceStop = false) audioSource.Stop(); return; } - + audioSource.clip = _musicClip; audioSource.loop = loop; audioSource.Play(); @@ -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 + /// /// API success response template when using Stream's Demo Credentials /// @@ -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) && @@ -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); diff --git a/Packages/StreamVideo/Samples~/VideoChat/Scripts/StreamVideoManager.cs b/Packages/StreamVideo/Samples~/VideoChat/Scripts/StreamVideoManager.cs index 8313591f..c92ec2a1 100644 --- a/Packages/StreamVideo/Samples~/VideoChat/Scripts/StreamVideoManager.cs +++ b/Packages/StreamVideo/Samples~/VideoChat/Scripts/StreamVideoManager.cs @@ -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); @@ -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(); if (audioSource == null) { @@ -123,7 +123,7 @@ public void ToggleMusic(bool loop = true, bool forceStop = false) audioSource.Stop(); return; } - + audioSource.clip = _musicClip; audioSource.loop = loop; audioSource.Play(); @@ -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 + /// /// API success response template when using Stream's Demo Credentials /// @@ -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) && @@ -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);