Commit f8c9b9a
authored
feat: manage audio centrally in the SDK (#3288)
This pull request refactors and modernizes the audio attachment
components, improving state management, playback control, and code
clarity. The most significant changes are the migration to a centralized
audio player state store, deprecation of legacy callback props, and
improved handling for both audio and voice recording attachments. These
updates enhance maintainability and user experience across both Expo and
native platforms.
Starting this PR, integrators can choose to have only a single player
instance at a time which can be controlled using the
`allowConcurrentAudioPlayback` prop of the Channel component where
`false` is the new default. This behaviour is done in parity with React
SDK and as per decision.
### **Audio Attachment Component Refactor and State Management
Improvements**
* Migrated audio playback state (play/pause, progress, duration,
playback rate) from local props and callbacks to a centralized state
store via `useAudioPlayerControl` and `useStateStore`, removing the need
for deprecated callback props like `onLoad`, `onPlayPause`, and
`onProgress`.
[[1]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL1-R176)
[[2]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL273-R205)
* Updated UI and logic to use new state values (`isPlaying`, `progress`,
`duration`, `currentPlaybackRate`) for rendering controls, progress
bars, and playback speed, replacing legacy props and local state.
[[1]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL311-R231)
[[2]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL347-R277)
[[3]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL370-R291)
[[4]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL380-R300)
[[5]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL393-R313)
### **Voice Recording and Audio Attachment Handling**
* Improved detection and handling of voice recordings using the new
`isVoiceRecordingAttachment` helper, ensuring correct duration and title
display, and simplifying logic for both audio and voice recording types.
[[1]](diffhunk://#diff-d9e0483e9e85e351477d959f53b229e12d576be2e9bfa5bbff4dc04b70c5de0bL331-R251)
[[2]](diffhunk://#diff-689763e88588fba421d39abbb74f3ca6853eac3cf45f74f1dc95855bbea86f99L4-R4)
### **File Attachment Group Updates**
* Deprecated legacy callback props (`onLoad`, `onProgress`) in
`FileAttachmentGroup`, updating documentation and usage to encourage
migration to the new state management approach. Also added `message`
prop for better context handling.
[[1]](diffhunk://#diff-689763e88588fba421d39abbb74f3ca6853eac3cf45f74f1dc95855bbea86f99L20-R23)
[[2]](diffhunk://#diff-689763e88588fba421d39abbb74f3ca6853eac3cf45f74f1dc95855bbea86f99L52-R59)
[[3]](diffhunk://#diff-689763e88588fba421d39abbb74f3ca6853eac3cf45f74f1dc95855bbea86f99L62-R76)
### **Native and Expo Audio Player Integration**
* Improved Expo audio player integration by subscribing to status events
earlier and fixing seek logic to use seconds instead of milliseconds,
ensuring more accurate playback control.
[[1]](diffhunk://#diff-236979f75b937086a72522395304eefdd19108179da9b8a76fa32ed31032da12R102-R103)
[[2]](diffhunk://#diff-236979f75b937086a72522395304eefdd19108179da9b8a76fa32ed31032da12L139-R141)
[[3]](diffhunk://#diff-037ceecf6320e1a12857962f434b303715602833cd0f4209d1dd090fdc99d55eR134-R136)
### **Progress and Wavefrom progress control performance**
Improved the progress and waveform progress bar performance by **10x**
as previously the animations were slow and not adhereing to the pattern
that could make it fast.
These changes collectively modernize the audio attachment experience,
making it more robust and easier to maintain.1 parent c4089d0 commit f8c9b9a
File tree
25 files changed
+1056
-332
lines changed- package
- expo-package/src/optionalDependencies
- native-package/src/optionalDependencies
- src
- components
- Attachment
- Channel
- MessageInput
- components
- AttachmentPreview
- AudioRecorder
- hooks
- ProgressControl
- contexts
- audioPlayerContext
- hooks
- state-store
- store
25 files changed
+1056
-332
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| |||
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
139 | | - | |
140 | | - | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
| |||
0 commit comments