react-native-audio-api 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +2 -0
  2. package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +1 -0
  3. package/ios/audioapi/ios/core/IOSAudioRecorder.h +2 -1
  4. package/lib/commonjs/AudioAPIModule/AudioAPIModule.js +90 -0
  5. package/lib/commonjs/AudioAPIModule/AudioAPIModule.js.map +1 -0
  6. package/lib/commonjs/AudioAPIModule/globals.d.js +6 -0
  7. package/lib/commonjs/AudioAPIModule/globals.d.js.map +1 -0
  8. package/lib/commonjs/AudioAPIModule/index.js +14 -0
  9. package/lib/commonjs/AudioAPIModule/index.js.map +1 -0
  10. package/lib/commonjs/api.js +14 -24
  11. package/lib/commonjs/api.js.map +1 -1
  12. package/lib/commonjs/core/AudioContext.js +4 -7
  13. package/lib/commonjs/core/AudioContext.js.map +1 -1
  14. package/lib/commonjs/core/BaseAudioContext.js +8 -7
  15. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  16. package/lib/commonjs/core/OfflineAudioContext.js +3 -6
  17. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  18. package/lib/commonjs/system/AudioManager.js +1 -7
  19. package/lib/commonjs/system/AudioManager.js.map +1 -1
  20. package/lib/commonjs/utils/index.js +9 -22
  21. package/lib/commonjs/utils/index.js.map +1 -1
  22. package/lib/module/AudioAPIModule/AudioAPIModule.js +87 -0
  23. package/lib/module/AudioAPIModule/AudioAPIModule.js.map +1 -0
  24. package/lib/module/AudioAPIModule/globals.d.js +4 -0
  25. package/lib/module/AudioAPIModule/globals.d.js.map +1 -0
  26. package/lib/module/AudioAPIModule/index.js +4 -0
  27. package/lib/module/AudioAPIModule/index.js.map +1 -0
  28. package/lib/module/api.js +17 -28
  29. package/lib/module/api.js.map +1 -1
  30. package/lib/module/core/AudioContext.js +4 -7
  31. package/lib/module/core/AudioContext.js.map +1 -1
  32. package/lib/module/core/BaseAudioContext.js +9 -8
  33. package/lib/module/core/BaseAudioContext.js.map +1 -1
  34. package/lib/module/core/OfflineAudioContext.js +3 -6
  35. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  36. package/lib/module/system/AudioManager.js +1 -7
  37. package/lib/module/system/AudioManager.js.map +1 -1
  38. package/lib/module/utils/index.js +8 -21
  39. package/lib/module/utils/index.js.map +1 -1
  40. package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts +36 -0
  41. package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts.map +1 -0
  42. package/lib/typescript/AudioAPIModule/index.d.ts +2 -0
  43. package/lib/typescript/AudioAPIModule/index.d.ts.map +1 -0
  44. package/lib/typescript/api.d.ts +17 -26
  45. package/lib/typescript/api.d.ts.map +1 -1
  46. package/lib/typescript/core/AudioContext.d.ts +1 -1
  47. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  48. package/lib/typescript/core/BaseAudioContext.d.ts +4 -4
  49. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  50. package/lib/typescript/core/OfflineAudioContext.d.ts +1 -1
  51. package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
  52. package/lib/typescript/system/AudioManager.d.ts +2 -2
  53. package/lib/typescript/system/AudioManager.d.ts.map +1 -1
  54. package/lib/typescript/utils/index.d.ts +1 -11
  55. package/lib/typescript/utils/index.d.ts.map +1 -1
  56. package/package.json +5 -8
  57. package/scripts/validate-worklets-version.js +4 -5
  58. package/src/AudioAPIModule/AudioAPIModule.ts +122 -0
  59. package/src/AudioAPIModule/globals.d.ts +35 -0
  60. package/src/AudioAPIModule/index.ts +1 -0
  61. package/src/api.ts +20 -72
  62. package/src/core/AudioContext.ts +4 -7
  63. package/src/core/BaseAudioContext.ts +58 -47
  64. package/src/core/OfflineAudioContext.ts +4 -7
  65. package/src/system/AudioManager.ts +9 -19
  66. package/src/utils/index.ts +9 -35
@@ -1 +1 @@
1
- {"version":3,"file":"AudioManager.d.ts","sourceRoot":"","sources":["../../../src/system/AudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAqB,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAYtE,cAAM,YAAY;IAChB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;;IAKtD,4BAA4B,IAAI,MAAM;IAItC,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D,sBAAsB,CAAC,OAAO,EAAE,cAAc;IAS9C,wBAAwB;IAIxB,iBAAiB,CAAC,IAAI,EAAE,cAAc;IAItC,mBAAmB;IAInB,yBAAyB,CAAC,OAAO,EAAE,OAAO;IAI1C;;;;;;;;;;;;OAYG;IACH,sBAAsB,CAAC,OAAO,EAAE,OAAO;IAIvC,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC,mBAAmB,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO;IAIlE,sBAAsB,CAAC,IAAI,SAAS,eAAe,EACjD,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAClC,sBAAsB;IAInB,2BAA2B,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIxD,yBAAyB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAItD,cAAc,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAGlD;;AAED,wBAAkC"}
1
+ {"version":3,"file":"AudioManager.d.ts","sourceRoot":"","sources":["../../../src/system/AudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,cAAM,YAAY;IAChB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;;IAKtD,4BAA4B,IAAI,MAAM;IAItC,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D,sBAAsB,CAAC,OAAO,EAAE,cAAc;IAS9C,wBAAwB;IAIxB,iBAAiB,CAAC,IAAI,EAAE,cAAc;IAItC,mBAAmB;IAInB,yBAAyB,CAAC,OAAO,EAAE,OAAO;IAI1C;;;;;;;;;;;;OAYG;IACH,sBAAsB,CAAC,OAAO,EAAE,OAAO;IAIvC,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC,mBAAmB,CAAC,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO;IAIlE,sBAAsB,CAAC,IAAI,SAAS,eAAe,EACjD,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAClC,sBAAsB;IAInB,2BAA2B,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIxD,yBAAyB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAItD,cAAc,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAGlD;;AAED,wBAAkC"}
@@ -1,13 +1,3 @@
1
- import type { ShareableWorkletCallback } from '../interfaces';
2
- interface SimplifiedWorkletModule {
3
- makeShareableCloneRecursive: (workletCallback: ShareableWorkletCallback) => ShareableWorkletCallback;
4
- createWorkletRuntime: (options?: any) => any;
5
- }
6
- export declare function clamp(value: number, min: number, max: number): number;
7
- export declare let isWorkletsVersionSupported: boolean;
8
- export declare let workletsVersion: string;
9
- export declare const supportedWorkletsVersions: string[];
10
- export declare let workletsModule: SimplifiedWorkletModule;
11
1
  export declare function assertWorkletsEnabled(): void;
12
- export {};
2
+ export declare function clamp(value: number, min: number, max: number): number;
13
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE9D,UAAU,uBAAuB;IAC/B,2BAA2B,EAAE,CAC3B,eAAe,EAAE,wBAAwB,KACtC,wBAAwB,CAAC;IAG9B,oBAAoB,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;CAC9C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAGD,eAAO,IAAI,0BAA0B,SAAQ,CAAC;AAC9C,eAAO,IAAI,eAAe,QAAY,CAAC;AACvC,eAAO,MAAM,yBAAyB,UAAqB,CAAC;AAC5D,eAAO,IAAI,cAAc,EAAE,uBAAuB,CAAC;AAEnD,wBAAgB,qBAAqB,SAWpC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,SAapC;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-audio-api",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification",
5
5
  "bin": {
6
6
  "setup-rn-audio-api-web": "./scripts/setup-rn-audio-api-web.js"
@@ -83,13 +83,7 @@
83
83
  },
84
84
  "peerDependencies": {
85
85
  "react": "*",
86
- "react-native": "*",
87
- "react-native-worklets": ">= 0.6.0"
88
- },
89
- "peerDependenciesMeta": {
90
- "react-native-worklets": {
91
- "optional": true
92
- }
86
+ "react-native": "*"
93
87
  },
94
88
  "devDependencies": {
95
89
  "@babel/cli": "^7.20.0",
@@ -164,5 +158,8 @@
164
158
  "type": "module-legacy",
165
159
  "languages": "cpp",
166
160
  "version": "0.37.1"
161
+ },
162
+ "dependencies": {
163
+ "semver": "^7.7.3"
167
164
  }
168
165
  }
@@ -1,9 +1,8 @@
1
1
  'use strict';
2
+
2
3
  const semverPrerelease = require('semver/functions/prerelease');
3
- const validWorkletsVersions = [
4
- '0.6.0',
5
- '0.6.1',
6
- ];
4
+
5
+ const validWorkletsVersions = ['0.6.0', '0.6.1'];
7
6
 
8
7
  function validateVersion() {
9
8
  let workletsVersion;
@@ -22,7 +21,7 @@ function validateVersion() {
22
21
 
23
22
  if (!validateVersion()) {
24
23
  console.warn(
25
- '[RNAudioApi] Incompatible version of react-native-audio-worklets detected. Please install a compatible version if you want to use worklet nodes in react-native-audio-api.',
24
+ '[RNAudioApi] Incompatible version of react-native-audio-worklets detected. Please install a compatible version if you want to use worklet nodes in react-native-audio-api.'
26
25
  );
27
26
  process.exit(1);
28
27
  }
@@ -0,0 +1,122 @@
1
+ import type { ShareableWorkletCallback } from '../interfaces';
2
+ import { NativeAudioAPIModule } from '../specs';
3
+
4
+ // Hint: Copied from react-native-worklets
5
+ // Doesn't really matter what is inside, just need a unique type
6
+ interface WorkletRuntime {
7
+ __hostObjectWorkletRuntime: never;
8
+ readonly name: string;
9
+ }
10
+
11
+ interface IWorkletsModule {
12
+ makeShareableCloneRecursive: (
13
+ workletCallback: ShareableWorkletCallback
14
+ ) => ShareableWorkletCallback;
15
+
16
+ createWorkletRuntime: (runtimeName: string) => WorkletRuntime;
17
+ }
18
+
19
+ class AudioAPIModule {
20
+ #workletsModule_: IWorkletsModule | null = null;
21
+ #canUseWorklets_ = false;
22
+ #workletsVersion = 'unknown';
23
+ #workletsAvailable_ = false;
24
+
25
+ public supportedWorkletsVersion = ['0.6.0', '0.6.1'];
26
+
27
+ constructor() {
28
+ // Important! Verify and import worklets first
29
+ // otherwise the native module installation might crash
30
+ // if react-native-worklets is not imported before audio-api
31
+ this.#verifyWorklets();
32
+
33
+ if (this.#verifyInstallation()) {
34
+ return;
35
+ }
36
+
37
+ if (!NativeAudioAPIModule) {
38
+ throw new Error(
39
+ `Failed to install react-native-audio-api: The native module could not be found.`
40
+ );
41
+ }
42
+
43
+ NativeAudioAPIModule.install();
44
+ }
45
+
46
+ #verifyWorklets(): boolean {
47
+ try {
48
+ const workletsPackage = require('react-native-worklets');
49
+ const workletsPackageJson = require('react-native-worklets/package.json');
50
+ this.#workletsVersion = workletsPackageJson.version;
51
+ this.#workletsAvailable_ = true;
52
+
53
+ this.#canUseWorklets_ = this.supportedWorkletsVersion.includes(
54
+ workletsPackageJson.version
55
+ );
56
+
57
+ if (this.#canUseWorklets_) {
58
+ this.#workletsModule_ = workletsPackage;
59
+ }
60
+
61
+ return this.#canUseWorklets_;
62
+ } catch {
63
+ this.#canUseWorklets_ = false;
64
+ return false;
65
+ }
66
+ }
67
+
68
+ #verifyInstallation(): boolean {
69
+ return (
70
+ global.createAudioContext != null &&
71
+ global.createOfflineAudioContext != null &&
72
+ global.createAudioRecorder != null &&
73
+ global.createAudioDecoder != null &&
74
+ global.createAudioStretcher != null &&
75
+ global.AudioEventEmitter != null
76
+ );
77
+ }
78
+
79
+ get workletsModule(): IWorkletsModule | null {
80
+ return this.#workletsModule_;
81
+ }
82
+
83
+ /**
84
+ * Indicates whether react-native-worklets are installed in matching version,
85
+ * for usage with react-native-audio-api.
86
+ */
87
+ get canUseWorklets(): boolean {
88
+ return this.#canUseWorklets_;
89
+ }
90
+
91
+ /** Returns the installed worklets version or 'unknown'. */
92
+ get workletsVersion(): string {
93
+ return this.#workletsVersion;
94
+ }
95
+
96
+ /**
97
+ * Indicates whether react-native-worklets are installed, regardless of
98
+ * version support. Useful for asserting compatibility.
99
+ */
100
+ get areWorkletsAvailable(): boolean {
101
+ return this.#workletsAvailable_;
102
+ }
103
+
104
+ /**
105
+ * Indicates whether the installed react-native-worklets version is supported.
106
+ * Useful for asserting compatibility.
107
+ */
108
+ get isWorkletsVersionSupported(): boolean {
109
+ // Note: if areWorkletsAvailable is true, canUseWorklets is equivalent to version check
110
+ return this.#canUseWorklets_;
111
+ }
112
+
113
+ public createAudioRuntime(): WorkletRuntime | null {
114
+ if (!this.#canUseWorklets_) {
115
+ return null;
116
+ }
117
+
118
+ return this.#workletsModule_!.createWorkletRuntime('AudioWorkletRuntime');
119
+ }
120
+ }
121
+
122
+ export default new AudioAPIModule();
@@ -0,0 +1,35 @@
1
+ import type {
2
+ IAudioContext,
3
+ IAudioDecoder,
4
+ IAudioEventEmitter,
5
+ IAudioRecorder,
6
+ IAudioStretcher,
7
+ IOfflineAudioContext,
8
+ } from '../interfaces';
9
+ import type { AudioRecorderOptions } from '../types';
10
+
11
+ /* eslint-disable no-var */
12
+ declare global {
13
+ var createAudioContext: (
14
+ sampleRate: number,
15
+ initSuspended: boolean,
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ audioWorkletRuntime: any
18
+ ) => IAudioContext;
19
+ var createOfflineAudioContext: (
20
+ numberOfChannels: number,
21
+ length: number,
22
+ sampleRate: number,
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ audioWorkletRuntime: any
25
+ ) => IOfflineAudioContext;
26
+
27
+ var createAudioRecorder: (options: AudioRecorderOptions) => IAudioRecorder;
28
+
29
+ var createAudioDecoder: () => IAudioDecoder;
30
+
31
+ var createAudioStretcher: () => IAudioStretcher;
32
+
33
+ var AudioEventEmitter: IAudioEventEmitter;
34
+ }
35
+ /* eslint-disable no-var */
@@ -0,0 +1 @@
1
+ export { default } from './AudioAPIModule';
package/src/api.ts CHANGED
@@ -1,110 +1,58 @@
1
- import { NativeAudioAPIModule } from './specs';
2
- import { AudioRecorderOptions } from './types';
3
- import type {
4
- IAudioContext,
5
- IAudioDecoder,
6
- IAudioRecorder,
7
- IAudioStretcher,
8
- IOfflineAudioContext,
9
- IAudioEventEmitter,
10
- } from './interfaces';
1
+ import './AudioAPIModule';
11
2
 
12
- /* eslint-disable no-var */
13
- declare global {
14
- var createAudioContext: (
15
- sampleRate: number,
16
- initSuspended: boolean,
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- audioWorkletRuntime: any
19
- ) => IAudioContext;
20
- var createOfflineAudioContext: (
21
- numberOfChannels: number,
22
- length: number,
23
- sampleRate: number,
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- audioWorkletRuntime: any
26
- ) => IOfflineAudioContext;
27
-
28
- var createAudioRecorder: (options: AudioRecorderOptions) => IAudioRecorder;
29
-
30
- var createAudioDecoder: () => IAudioDecoder;
31
-
32
- var createAudioStretcher: () => IAudioStretcher;
33
-
34
- var AudioEventEmitter: IAudioEventEmitter;
35
- }
36
- /* eslint-disable no-var */
37
-
38
- if (
39
- global.createAudioContext == null ||
40
- global.createOfflineAudioContext == null ||
41
- global.createAudioRecorder == null ||
42
- global.createAudioDecoder == null ||
43
- global.createAudioStretcher == null ||
44
- global.AudioEventEmitter == null
45
- ) {
46
- if (!NativeAudioAPIModule) {
47
- throw new Error(
48
- `Failed to install react-native-audio-api: The native module could not be found.`
49
- );
50
- }
51
-
52
- NativeAudioAPIModule.install();
53
- }
54
-
55
- export { default as WorkletNode } from './core/WorkletNode';
56
- export { default as WorkletSourceNode } from './core/WorkletSourceNode';
57
- export { default as WorkletProcessingNode } from './core/WorkletProcessingNode';
58
- export { default as RecorderAdapterNode } from './core/RecorderAdapterNode';
3
+ export { default as AnalyserNode } from './core/AnalyserNode';
59
4
  export { default as AudioBuffer } from './core/AudioBuffer';
60
- export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
61
5
  export { default as AudioBufferQueueSourceNode } from './core/AudioBufferQueueSourceNode';
6
+ export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
62
7
  export { default as AudioContext } from './core/AudioContext';
63
- export { default as OfflineAudioContext } from './core/OfflineAudioContext';
8
+ export { decodeAudioData, decodePCMInBase64 } from './core/AudioDecoder';
64
9
  export { default as AudioDestinationNode } from './core/AudioDestinationNode';
65
10
  export { default as AudioNode } from './core/AudioNode';
66
- export { default as AnalyserNode } from './core/AnalyserNode';
67
11
  export { default as AudioParam } from './core/AudioParam';
12
+ export { default as AudioRecorder } from './core/AudioRecorder';
68
13
  export { default as AudioScheduledSourceNode } from './core/AudioScheduledSourceNode';
14
+ export { default as changePlaybackSpeed } from './core/AudioStretcher';
69
15
  export { default as BaseAudioContext } from './core/BaseAudioContext';
70
16
  export { default as BiquadFilterNode } from './core/BiquadFilterNode';
17
+ export { default as ConstantSourceNode } from './core/ConstantSourceNode';
18
+ export { default as ConvolverNode } from './core/ConvolverNode';
71
19
  export { default as GainNode } from './core/GainNode';
20
+ export { default as OfflineAudioContext } from './core/OfflineAudioContext';
72
21
  export { default as OscillatorNode } from './core/OscillatorNode';
22
+ export { default as RecorderAdapterNode } from './core/RecorderAdapterNode';
73
23
  export { default as StereoPannerNode } from './core/StereoPannerNode';
74
- export { default as AudioRecorder } from './core/AudioRecorder';
75
24
  export { default as StreamerNode } from './core/StreamerNode';
76
- export { default as ConstantSourceNode } from './core/ConstantSourceNode';
77
- export { default as AudioManager } from './system';
78
- export { default as ConvolverNode } from './core/ConvolverNode';
25
+ export { default as WorkletNode } from './core/WorkletNode';
26
+ export { default as WorkletProcessingNode } from './core/WorkletProcessingNode';
27
+ export { default as WorkletSourceNode } from './core/WorkletSourceNode';
79
28
  export { default as useSystemVolume } from './hooks/useSystemVolume';
80
- export { decodeAudioData, decodePCMInBase64 } from './core/AudioDecoder';
81
- export { default as changePlaybackSpeed } from './core/AudioStretcher';
29
+ export { default as AudioManager } from './system';
82
30
 
83
31
  export {
84
- OscillatorType,
32
+ AudioWorkletRuntime,
85
33
  BiquadFilterType,
86
34
  ChannelCountMode,
87
35
  ChannelInterpretation,
88
36
  ContextState,
89
- WindowType,
37
+ OscillatorType,
90
38
  PeriodicWaveConstraints,
91
- AudioWorkletRuntime,
39
+ WindowType,
92
40
  } from './types';
93
41
 
94
42
  export {
95
43
  IOSCategory,
96
44
  IOSMode,
97
45
  IOSOption,
98
- SessionOptions,
99
- MediaState,
100
46
  LockScreenInfo,
47
+ MediaState,
101
48
  PermissionStatus,
49
+ SessionOptions,
102
50
  } from './system/types';
103
51
 
104
52
  export {
105
53
  IndexSizeError,
106
54
  InvalidAccessError,
107
55
  InvalidStateError,
108
- RangeError,
109
56
  NotSupportedError,
57
+ RangeError,
110
58
  } from './errors';
@@ -1,9 +1,9 @@
1
+ import AudioAPIModule from '../AudioAPIModule';
2
+ import { NotSupportedError } from '../errors';
1
3
  import { IAudioContext } from '../interfaces';
2
- import BaseAudioContext from './BaseAudioContext';
3
4
  import AudioManager from '../system';
4
5
  import { AudioContextOptions } from '../types';
5
- import { NotSupportedError } from '../errors';
6
- import { isWorkletsVersionSupported, workletsModule } from '../utils';
6
+ import BaseAudioContext from './BaseAudioContext';
7
7
 
8
8
  export default class AudioContext extends BaseAudioContext {
9
9
  constructor(options?: AudioContextOptions) {
@@ -16,11 +16,8 @@ export default class AudioContext extends BaseAudioContext {
16
16
  `The provided sampleRate is not supported: ${options.sampleRate}`
17
17
  );
18
18
  }
19
- let audioRuntime = null;
20
19
 
21
- if (isWorkletsVersionSupported) {
22
- audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
23
- }
20
+ const audioRuntime = AudioAPIModule.createAudioRuntime();
24
21
 
25
22
  super(
26
23
  global.createAudioContext(
@@ -1,23 +1,23 @@
1
+ import AudioAPIModule from '../AudioAPIModule';
1
2
  import { InvalidAccessError, NotSupportedError } from '../errors';
2
3
  import { IBaseAudioContext } from '../interfaces';
3
4
  import {
4
5
  AudioBufferBaseSourceNodeOptions,
5
- ContextState,
6
- PeriodicWaveConstraints,
7
6
  AudioWorkletRuntime,
7
+ ContextState,
8
8
  ConvolverNodeOptions,
9
+ PeriodicWaveConstraints,
9
10
  } from '../types';
10
- import { assertWorkletsEnabled, workletsModule } from '../utils';
11
- import WorkletSourceNode from './WorkletSourceNode';
12
- import WorkletProcessingNode from './WorkletProcessingNode';
11
+ import { assertWorkletsEnabled } from '../utils';
13
12
  import AnalyserNode from './AnalyserNode';
14
13
  import AudioBuffer from './AudioBuffer';
15
14
  import AudioBufferQueueSourceNode from './AudioBufferQueueSourceNode';
16
- import ConvolverNode from './ConvolverNode';
17
15
  import AudioBufferSourceNode from './AudioBufferSourceNode';
16
+ import { decodeAudioData, decodePCMInBase64 } from './AudioDecoder';
18
17
  import AudioDestinationNode from './AudioDestinationNode';
19
18
  import BiquadFilterNode from './BiquadFilterNode';
20
19
  import ConstantSourceNode from './ConstantSourceNode';
20
+ import ConvolverNode from './ConvolverNode';
21
21
  import GainNode from './GainNode';
22
22
  import OscillatorNode from './OscillatorNode';
23
23
  import PeriodicWave from './PeriodicWave';
@@ -25,7 +25,8 @@ import RecorderAdapterNode from './RecorderAdapterNode';
25
25
  import StereoPannerNode from './StereoPannerNode';
26
26
  import StreamerNode from './StreamerNode';
27
27
  import WorkletNode from './WorkletNode';
28
- import { decodeAudioData, decodePCMInBase64 } from './AudioDecoder';
28
+ import WorkletProcessingNode from './WorkletProcessingNode';
29
+ import WorkletSourceNode from './WorkletSourceNode';
29
30
 
30
31
  export default class BaseAudioContext {
31
32
  readonly destination: AudioDestinationNode;
@@ -81,21 +82,26 @@ export default class BaseAudioContext {
81
82
  `The number of input channels provided (${inputChannelCount}) can not be less than 1 or greater than 32`
82
83
  );
83
84
  }
85
+
84
86
  if (bufferLength < 1) {
85
87
  throw new NotSupportedError(
86
88
  `The buffer length provided (${bufferLength}) can not be less than 1`
87
89
  );
88
90
  }
91
+
89
92
  assertWorkletsEnabled();
90
- const shareableWorklet = workletsModule.makeShareableCloneRecursive(
91
- (audioBuffers: Array<ArrayBuffer>, channelCount: number) => {
92
- 'worklet';
93
- const floatAudioData: Array<Float32Array> = audioBuffers.map(
94
- (buffer) => new Float32Array(buffer)
95
- );
96
- callback(floatAudioData, channelCount);
97
- }
98
- );
93
+
94
+ const shareableWorklet =
95
+ AudioAPIModule.workletsModule!.makeShareableCloneRecursive(
96
+ (audioBuffers: Array<ArrayBuffer>, channelCount: number) => {
97
+ 'worklet';
98
+ const floatAudioData: Array<Float32Array> = audioBuffers.map(
99
+ (buffer) => new Float32Array(buffer)
100
+ );
101
+ callback(floatAudioData, channelCount);
102
+ }
103
+ );
104
+
99
105
  return new WorkletNode(
100
106
  this,
101
107
  this.context.createWorkletNode(
@@ -117,23 +123,26 @@ export default class BaseAudioContext {
117
123
  workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
118
124
  ): WorkletProcessingNode {
119
125
  assertWorkletsEnabled();
120
- const shareableWorklet = workletsModule.makeShareableCloneRecursive(
121
- (
122
- inputBuffers: Array<ArrayBuffer>,
123
- outputBuffers: Array<ArrayBuffer>,
124
- framesToProcess: number,
125
- currentTime: number
126
- ) => {
127
- 'worklet';
128
- const inputData: Array<Float32Array> = inputBuffers.map(
129
- (buffer) => new Float32Array(buffer, 0, framesToProcess)
130
- );
131
- const outputData: Array<Float32Array> = outputBuffers.map(
132
- (buffer) => new Float32Array(buffer, 0, framesToProcess)
133
- );
134
- callback(inputData, outputData, framesToProcess, currentTime);
135
- }
136
- );
126
+
127
+ const shareableWorklet =
128
+ AudioAPIModule.workletsModule!.makeShareableCloneRecursive(
129
+ (
130
+ inputBuffers: Array<ArrayBuffer>,
131
+ outputBuffers: Array<ArrayBuffer>,
132
+ framesToProcess: number,
133
+ currentTime: number
134
+ ) => {
135
+ 'worklet';
136
+ const inputData: Array<Float32Array> = inputBuffers.map(
137
+ (buffer) => new Float32Array(buffer, 0, framesToProcess)
138
+ );
139
+ const outputData: Array<Float32Array> = outputBuffers.map(
140
+ (buffer) => new Float32Array(buffer, 0, framesToProcess)
141
+ );
142
+ callback(inputData, outputData, framesToProcess, currentTime);
143
+ }
144
+ );
145
+
137
146
  return new WorkletProcessingNode(
138
147
  this,
139
148
  this.context.createWorkletProcessingNode(
@@ -153,20 +162,22 @@ export default class BaseAudioContext {
153
162
  workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
154
163
  ): WorkletSourceNode {
155
164
  assertWorkletsEnabled();
156
- const shareableWorklet = workletsModule.makeShareableCloneRecursive(
157
- (
158
- audioBuffers: Array<ArrayBuffer>,
159
- framesToProcess: number,
160
- currentTime: number,
161
- startOffset: number
162
- ) => {
163
- 'worklet';
164
- const floatAudioData: Array<Float32Array> = audioBuffers.map(
165
- (buffer) => new Float32Array(buffer)
166
- );
167
- callback(floatAudioData, framesToProcess, currentTime, startOffset);
168
- }
169
- );
165
+ const shareableWorklet =
166
+ AudioAPIModule.workletsModule!.makeShareableCloneRecursive(
167
+ (
168
+ audioBuffers: Array<ArrayBuffer>,
169
+ framesToProcess: number,
170
+ currentTime: number,
171
+ startOffset: number
172
+ ) => {
173
+ 'worklet';
174
+ const floatAudioData: Array<Float32Array> = audioBuffers.map(
175
+ (buffer) => new Float32Array(buffer)
176
+ );
177
+ callback(floatAudioData, framesToProcess, currentTime, startOffset);
178
+ }
179
+ );
180
+
170
181
  return new WorkletSourceNode(
171
182
  this,
172
183
  this.context.createWorkletSourceNode(
@@ -1,9 +1,9 @@
1
+ import AudioAPIModule from '../AudioAPIModule';
2
+ import { InvalidStateError, NotSupportedError } from '../errors';
1
3
  import { IOfflineAudioContext } from '../interfaces';
2
- import BaseAudioContext from './BaseAudioContext';
3
4
  import { OfflineAudioContextOptions } from '../types';
4
- import { InvalidStateError, NotSupportedError } from '../errors';
5
5
  import AudioBuffer from './AudioBuffer';
6
- import { isWorkletsVersionSupported, workletsModule } from '../utils';
6
+ import BaseAudioContext from './BaseAudioContext';
7
7
 
8
8
  export default class OfflineAudioContext extends BaseAudioContext {
9
9
  private isSuspended: boolean;
@@ -17,10 +17,7 @@ export default class OfflineAudioContext extends BaseAudioContext {
17
17
  arg1?: number,
18
18
  arg2?: number
19
19
  ) {
20
- let audioRuntime = null;
21
- if (isWorkletsVersionSupported) {
22
- audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
23
- }
20
+ const audioRuntime = AudioAPIModule.createAudioRuntime();
24
21
 
25
22
  if (typeof arg0 === 'object') {
26
23
  const { numberOfChannels, length, sampleRate } = arg0;
@@ -1,26 +1,16 @@
1
+ import { AudioEventEmitter, AudioEventSubscription } from '../events';
1
2
  import {
2
- SessionOptions,
3
- LockScreenInfo,
4
- PermissionStatus,
5
- AudioDevicesInfo,
6
- } from './types';
7
- import {
8
- SystemEventName,
9
- SystemEventCallback,
10
3
  RemoteCommandEventName,
4
+ SystemEventCallback,
5
+ SystemEventName,
11
6
  } from '../events/types';
12
7
  import { NativeAudioAPIModule } from '../specs';
13
- import { AudioEventEmitter, AudioEventSubscription } from '../events';
14
-
15
- if (global.AudioEventEmitter == null) {
16
- if (!NativeAudioAPIModule) {
17
- throw new Error(
18
- `Failed to install react-native-audio-api: The native module could not be found.`
19
- );
20
- }
21
-
22
- NativeAudioAPIModule.install();
23
- }
8
+ import {
9
+ AudioDevicesInfo,
10
+ LockScreenInfo,
11
+ PermissionStatus,
12
+ SessionOptions,
13
+ } from './types';
24
14
 
25
15
  class AudioManager {
26
16
  private readonly audioEventEmitter: AudioEventEmitter;