Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]Improve AudioSession management #639

Merged
merged 28 commits into from
Feb 13, 2025

Conversation

ipavlidakis
Copy link
Collaborator

@ipavlidakis ipavlidakis commented Jan 22, 2025

🔗 Issue Links

Tickets: [1, 2]

🎯 Goal

Provide a way for users to move audio volume to 0 using the device's physical buttons or the ControlCentre.

📝 Summary

We are now driving AudioSession configurations based on CallSettings and OwnCapabilities. However, due to the way that AVAudioSession stores volume profiles per category, we are forced to introduce a way to customise the functionality based on the use-cases. Spefically:

  • For calls where all participants are expected to be active it's recommended to do nothing and allow the SDK to use its default behaviour which doesn't allow the user to completely change volume to 0. (this is the expected behaviour iOS has for VoIP calls)
  • For livestream or calls where not all participants are expected to be active (some may be just viewers) it's recommended to only change the configuration for every Viewer, in your code like below:
try await call.updateAudioSessionPolicy(OwnCapabilitiesAudioSessionPolicy())

🛠 Implementation

During callSettings and ownCapabilities changes, the internal AudioSession component will ask the provided AudioSessionPolicy to provide the desired AVAudioSession configuration. It's expected that the configuration returned from the AudioSessionPolicy should be a valid change. Each policy works differently depending on the input CallSettings and OwnCapabilities:

  • DefaultAudioSessionPolicy:
    This policy is the one that Call objects use by default. The policy will always return the following configuration: category: .playAndRecord and categoryOptions: .allowBluetooth, .allowBluetoothA2DP, .allowAirPlay. While for mode it will toggle between .videoChat and .voiceChat depending on the speakerOn value on CallSettings. This policy doesn't allow zeroing the volume.

  • OwnCapabilitiesAudioSessionPolicy:
    The policy relies on both the provide CallSettings and OwnCapabilities to produce a valid AudioSessionConfiguration. The rules examined are the following:

  • if the user has no capability to sendAudio it always returns category: .playback, mode: .default, categoryOptions: [], ignoring the CallSettings.

  • If the user has capability to sendAudio:

    • if the CallSettings.audioOn == true or (CallSettings.speakerOn == true and the device is an iPhone): It returns category:. playAndRecord. Mode and and CategoryOptions are being calculated similarly to the DefaultAudioSessionPolicy.
  • In any other case it returns: category: .playback similarly on what it would return if the user had no capability to sendAudio.

🧪 Manual Testing Notes

  • You can use the AudioSession Policy debug option to try different policies

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • This change should receive manual QA
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (tutorial, CMS)

Copy link

github-actions bot commented Jan 22, 2025

2 Errors
🚫 Please use more than one word.
530b089
🚫 Please use more than one word.
46cd831
1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jan 22, 2025

SDK Size

title develop branch diff status
StreamVideo 7.46 MB 7.54 MB +90 KB 🟢
StreamVideoSwiftUI 2.07 MB 2.07 MB 0 KB 🟢
StreamVideoUIKit 2.21 MB 2.21 MB 0 KB 🟢
StreamWebRTC 9.85 MB 9.85 MB 0 KB 🟢

@ipavlidakis ipavlidakis force-pushed the enhancement/allow-muting-audio-during-call branch 3 times, most recently from f0bfe60 to 2b2d1f0 Compare January 31, 2025 14:54
@ipavlidakis ipavlidakis force-pushed the enhancement/allow-muting-audio-during-call branch 5 times, most recently from 194ea1a to 8c9003e Compare February 7, 2025 15:09
@ipavlidakis ipavlidakis self-assigned this Feb 7, 2025
@ipavlidakis ipavlidakis added bug Something isn't working enhancement New feature or request labels Feb 7, 2025
@ipavlidakis ipavlidakis marked this pull request as ready for review February 7, 2025 15:37
@ipavlidakis ipavlidakis requested a review from a team as a code owner February 7, 2025 15:37
@ipavlidakis ipavlidakis force-pushed the enhancement/allow-muting-audio-during-call branch 5 times, most recently from 926ef4b to 8590eb0 Compare February 12, 2025 17:55
Copy link
Collaborator

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things are looking great ✅ Just one question, and we also need to see the failed tests.

@ipavlidakis ipavlidakis force-pushed the enhancement/allow-muting-audio-during-call branch from eb35747 to 0ad953f Compare February 13, 2025 12:36
@ipavlidakis ipavlidakis merged commit 0e7b406 into develop Feb 13, 2025
13 of 14 checks passed
@ipavlidakis ipavlidakis deleted the enhancement/allow-muting-audio-during-call branch February 13, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants