Feat: Type-safe configureAVAudioSession function that ensures compatibility with AVAudioSessionModes #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@hirbod This is my first time contributing to open-source... like ever. So please feel free to crush my soul on how I did all of this.
The gist of it is, after reading all the docs: https://developer.apple.com/documentation/avfaudio/avaudiosession, it became clear that each
AVAudioSessionCategory
could only be used with specificAVAudioSessionModes
. I was pretty thorough in making sure that I have the compatible modes with each category.In order to make this type-safe, I needed to combine them into one function. I also used this to change the types of
AVAudioSessionMode
andAVAudioSessionCategory
to anenum
type so that could properly get good developer experience tool tips when mousing over each category.An example of this new function would be:
I also marked the
setCategory
function and thesetMode
function as deprecated using this new API.Among other changes, it would appear that the previously had
Alarm
category is no longer listed, and theAudioProcessing
category is listed as deprecated. https://developer.apple.com/documentation/avfaudio/avaudiosession/category-swift.structSo I removed the
Alarm
option and flagged theAudioProcessing
as deprecated.Now, one last comment. You'll note here: https://developer.apple.com/documentation/avfaudio/avaudiosession/setcategory(_:mode:policy:options:)
That setting this

AVAudioSessionCategory
also presents more options like options and policy.I think it would be fantastic to add these to the API for further configuration. Additionally I noticed while studying
react-native-vision-camera
Audio Session setup he has this code:I am not sure how we handle this in the
volume-manager
package, but may be other things to include as options?Maybe a final API would look like this??:
Anyway, thanks again!!