Repository navigation
feat: app sounds #31055
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
feat: app sounds #31055
Changes from all commits
594d0c8
67923f1
087ca99
5b9a1ff
1adb767
d2fa21f
71d23b8
4a3a23a
83c640f
8ec87c7
35fc53a
e3a8071
bd1be47
c1cea21
c643469
270511d
37d573c
67d191b
e7bddc1
6f16784
38073a4
d7cc842
a55c062
bf889b3
a7eafea
9b081f5
11477c9
3f27579
203a441
e3ab465
a46900b
27a972f
7796a09
ed5b09b
eaaaafb
a57272e
e393ec4
598cd11
fc79b63
2dd1515
e9c4a55
5979ab3
334f187
80dba50
3b56e55
c383046
890da12
d0a7e35
a35955e
cb310a8
330dd8d
2224618
2447423
9f3bc13
8566418
92960b3
8f58872
231aaef
8478839
35a28ce
a20c54b
d29768b
3be083b
339133e
a69cadb
1e828f6
7ed56ec
748d554
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| diff --git a/node_modules/react-native-sound/RNSound/RNSound.h b/node_modules/react-native-sound/RNSound/RNSound.h | ||
| index 7f5b97b..1a3c840 100644 | ||
| --- a/node_modules/react-native-sound/RNSound/RNSound.h | ||
| +++ b/node_modules/react-native-sound/RNSound/RNSound.h | ||
| @@ -1,17 +1,7 @@ | ||
| -#if __has_include(<React/RCTBridgeModule.h>) | ||
| #import <React/RCTBridgeModule.h> | ||
| -#else | ||
| -#import "RCTBridgeModule.h" | ||
| -#endif | ||
| - | ||
| #import <AVFoundation/AVFoundation.h> | ||
| - | ||
| -#if __has_include(<React/RCTEventEmitter.h>) | ||
| #import <React/RCTEventEmitter.h> | ||
| -#else | ||
| -#import "RCTEventEmitter.h" | ||
| -#endif | ||
|
|
||
| @interface RNSound : RCTEventEmitter <RCTBridgeModule, AVAudioPlayerDelegate> | ||
| -@property (nonatomic, weak) NSNumber *_key; | ||
| +@property(nonatomic, weak) NSNumber *_key; | ||
| @end | ||
| diff --git a/node_modules/react-native-sound/RNSound/RNSound.m b/node_modules/react-native-sound/RNSound/RNSound.m | ||
| index df3784e..d34ac01 100644 | ||
| --- a/node_modules/react-native-sound/RNSound/RNSound.m | ||
| +++ b/node_modules/react-native-sound/RNSound/RNSound.m | ||
| @@ -1,10 +1,6 @@ | ||
| #import "RNSound.h" | ||
|
|
||
| -#if __has_include("RCTUtils.h") | ||
| -#import "RCTUtils.h" | ||
| -#else | ||
| #import <React/RCTUtils.h> | ||
| -#endif | ||
|
|
||
| @implementation RNSound { | ||
| NSMutableDictionary *_playerPool; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ function canUseBrowserNotifications(): Promise<boolean> { | |
| * @param icon Path to icon | ||
| * @param data extra data to attach to the notification | ||
| */ | ||
| function push(title: string, body = '', icon: string | ImageSourcePropType = '', data: LocalNotificationData = {}, onClick: LocalNotificationClickHandler = () => {}) { | ||
| function push(title: string, body = '', icon: string | ImageSourcePropType = '', data: LocalNotificationData = {}, onClick: LocalNotificationClickHandler = () => {}, silent = false) { | ||
| canUseBrowserNotifications().then((canUseNotifications) => { | ||
| if (!canUseNotifications) { | ||
| return; | ||
|
|
@@ -54,6 +54,7 @@ function push(title: string, body = '', icon: string | ImageSourcePropType = '', | |
| body, | ||
| icon: String(icon), | ||
| data, | ||
| silent, | ||
| }); | ||
| notificationCache[notificationID].onclick = () => { | ||
| onClick(); | ||
|
|
@@ -104,7 +105,7 @@ export default { | |
| reportID: report.reportID, | ||
| }; | ||
|
|
||
| push(title, body, icon, data, onClick); | ||
| push(title, body, icon, data, onClick, true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from here #53700 Passing |
||
| }, | ||
|
|
||
| pushModifiedExpenseNotification(report: Report, reportAction: ReportAction, onClick: LocalNotificationClickHandler, usesIcon = false) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| const config = {prefix: ''}; | ||
|
|
||
| export default config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| const config = {prefix: '/sounds/'}; | ||
|
|
||
| export default config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import Onyx from 'react-native-onyx'; | ||
| import Sound from 'react-native-sound'; | ||
| import type {ValueOf} from 'type-fest'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import config from './config'; | ||
|
|
||
| let isMuted = false; | ||
|
|
||
| Onyx.connect({ | ||
| key: ONYXKEYS.USER, | ||
| callback: (val) => (isMuted = !!val?.isMutedAllSounds), | ||
| }); | ||
|
|
||
| const SOUNDS = { | ||
| DONE: 'done', | ||
| SUCCESS: 'success', | ||
| ATTENTION: 'attention', | ||
| RECEIVE: 'receive', | ||
| } as const; | ||
|
|
||
| /** | ||
| * Creates a version of the given function that, when called, queues the execution and ensures that | ||
| * calls are spaced out by at least the specified `minExecutionTime`, even if called more frequently. This allows | ||
| * for throttling frequent calls to a function, ensuring each is executed with a minimum `minExecutionTime` between calls. | ||
| * Each call returns a promise that resolves when the function call is executed, allowing for asynchronous handling. | ||
| */ | ||
| function withMinimalExecutionTime<F extends (...args: Parameters<F>) => ReturnType<F>>(func: F, minExecutionTime: number) { | ||
| const queue: Array<[() => ReturnType<F>, (value?: unknown) => void]> = []; | ||
| let timerId: NodeJS.Timeout | null = null; | ||
|
|
||
| function processQueue() { | ||
| if (queue.length > 0) { | ||
| const next = queue.shift(); | ||
|
|
||
| if (!next) { | ||
| return; | ||
| } | ||
|
|
||
| const [nextFunc, resolve] = next; | ||
| nextFunc(); | ||
| resolve(); | ||
| timerId = setTimeout(processQueue, minExecutionTime); | ||
| } else { | ||
| timerId = null; | ||
| } | ||
| } | ||
|
|
||
| return function (...args: Parameters<F>) { | ||
| return new Promise((resolve) => { | ||
| queue.push([() => func(...args), resolve]); | ||
|
|
||
| if (!timerId) { | ||
| // If the timer isn't running, start processing the queue | ||
| processQueue(); | ||
| } | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| const playSound = (soundFile: ValueOf<typeof SOUNDS>) => { | ||
| const sound = new Sound(`${config.prefix}${soundFile}.mp3`, Sound.MAIN_BUNDLE, (error) => { | ||
| if (error || isMuted) { | ||
| return; | ||
| } | ||
|
|
||
| sound.play(); | ||
| }); | ||
| }; | ||
|
|
||
| export {SOUNDS}; | ||
| export default withMinimalExecutionTime(playSound, 300); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR added
react-native-web-soundfor app sounds on web, and it useshowler2.2.4 to play them.howlercallsAudioContext.resume()in its unlock handler and in_autoResume()but never handles a rejected promise.iOS Safari rejects
resume()when it can't start the audio session, for example during a phone call. That rejection went unhandled and showed up asInvalidStateError: Failed to start the audio device.This was fixed here: #102795
More information is available here: #102744