@stream-io/noise-cancellation-react-native 0.1.0

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 (50) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +219 -0
  3. package/README.md +9 -0
  4. package/android/build.gradle +90 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationAudioProcessingController.kt +15 -0
  9. package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationReactNative.kt +26 -0
  10. package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationReactNativeModule.kt +55 -0
  11. package/android/src/main/java/io/getstream/rn/noisecancellation/NoiseCancellationReactNativePackage.kt +17 -0
  12. package/dist/commonjs/index.js +140 -0
  13. package/dist/commonjs/index.js.map +1 -0
  14. package/dist/commonjs/package.json +1 -0
  15. package/dist/commonjs/types.js +2 -0
  16. package/dist/commonjs/types.js.map +1 -0
  17. package/dist/module/index.js +132 -0
  18. package/dist/module/index.js.map +1 -0
  19. package/dist/module/package.json +1 -0
  20. package/dist/module/types.js +2 -0
  21. package/dist/module/types.js.map +1 -0
  22. package/dist/typescript/index.d.ts +77 -0
  23. package/dist/typescript/index.d.ts.map +1 -0
  24. package/dist/typescript/types.d.ts +27 -0
  25. package/dist/typescript/types.d.ts.map +1 -0
  26. package/ios/Classes/AudioFilters.swift +22 -0
  27. package/ios/Classes/AudioManager.h +19 -0
  28. package/ios/Classes/AudioManager.m +50 -0
  29. package/ios/Classes/AudioProcessingAdapter.h +26 -0
  30. package/ios/Classes/AudioProcessingAdapter.m +105 -0
  31. package/ios/Classes/NeuralEngineProvider.swift +12 -0
  32. package/ios/Classes/NoiseCancellationFilter.swift +83 -0
  33. package/ios/Classes/NoiseCancellationManagerObjc.m +32 -0
  34. package/ios/Classes/StreamAudioFilterCapturePostProcessingModule.swift +88 -0
  35. package/ios/Classes/StreamAudioProcessingModule.swift +58 -0
  36. package/ios/Headers/NoiseCancellationManagerObjc.h +12 -0
  37. package/ios/NoiseCancellationManager.swift +42 -0
  38. package/ios/NoiseCancellationReactNative-Bridging-Header.h +2 -0
  39. package/ios/NoiseCancellationReactNative.mm +23 -0
  40. package/ios/NoiseCancellationReactNative.swift +45 -0
  41. package/ios/Utils/DisposableBag/DisposableBag.swift +82 -0
  42. package/ios/Utils/Queues/LockQueuing.swift +22 -0
  43. package/ios/Utils/Queues/RecursiveQueue.swift +40 -0
  44. package/ios/Utils/Queues/UnfairQueue.swift +57 -0
  45. package/ios/Utils/SerialActor/SerialActor.swift +64 -0
  46. package/ios/Utils/SerialActor/SerialActorQueue.swift +84 -0
  47. package/package.json +69 -0
  48. package/src/index.ts +141 -0
  49. package/src/types.ts +30 -0
  50. package/stream-io-noise-cancellation-react-native.podspec +49 -0
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@stream-io/noise-cancellation-react-native",
3
+ "version": "0.1.0",
4
+ "description": "Noise cancellation for the Stream React Native Video SDK",
5
+ "main": "dist/commonjs/index.js",
6
+ "module": "dist/module/index.js",
7
+ "types": "dist/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "dist",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!ios/build",
18
+ "!android/build",
19
+ "!android/gradle",
20
+ "!android/gradlew",
21
+ "!android/gradlew.bat",
22
+ "!android/local.properties",
23
+ "!**/__tests__",
24
+ "!**/__fixtures__",
25
+ "!**/__mocks__",
26
+ "!**/.*"
27
+ ],
28
+ "scripts": {
29
+ "typecheck": "tsc --noEmit",
30
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
31
+ "clean": "rimraf android/build && rimraf dist",
32
+ "build": "yarn clean && bob build"
33
+ },
34
+ "keywords": [
35
+ "react-native",
36
+ "ios",
37
+ "android"
38
+ ],
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/GetStream/stream-video-js.git"
42
+ },
43
+ "author": "https://getstream.io <support@getstream.io> (https://github.com/GetStream)",
44
+ "license": "See license in LICENSE",
45
+ "bugs": {
46
+ "url": "https://github.com/GetStream/stream-video-js/issues"
47
+ },
48
+ "homepage": "https://github.com/GetStream/stream-video-js#readme",
49
+ "devDependencies": {
50
+ "@stream-io/react-native-webrtc": "^125.3.0",
51
+ "react-native": "^0.79.2",
52
+ "react-native-builder-bob": "^0.37.0",
53
+ "rimraf": "^6.0.1",
54
+ "typescript": "^5.8.3"
55
+ },
56
+ "peerDependencies": {
57
+ "@stream-io/react-native-webrtc": ">=125.3.0",
58
+ "react-native": "*"
59
+ },
60
+ "react-native-builder-bob": {
61
+ "source": "src",
62
+ "output": "dist",
63
+ "targets": [
64
+ "commonjs",
65
+ "module",
66
+ "typescript"
67
+ ]
68
+ }
69
+ }
package/src/index.ts ADDED
@@ -0,0 +1,141 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import type { Events, INoiseCancellation } from './types';
3
+
4
+ const LINKING_ERROR =
5
+ `The package '@stream-io/noise-cancellation-react-native' doesn't seem to be linked. Make sure: \n\n` +
6
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
7
+ '- You rebuilt the app after installing the package\n' +
8
+ '- You are not using Expo Go\n';
9
+
10
+ const NoiseCancellationReactNative = NativeModules.NoiseCancellationReactNative
11
+ ? NativeModules.NoiseCancellationReactNative
12
+ : new Proxy(
13
+ {},
14
+ {
15
+ get() {
16
+ throw new Error(LINKING_ERROR);
17
+ },
18
+ },
19
+ );
20
+
21
+ /**
22
+ * A wrapper around the native stream noise cancellation SDK.
23
+ */
24
+ export class NoiseCancellation implements INoiseCancellation {
25
+ private readonly listeners: Partial<Record<keyof Events, Array<any>>> = {};
26
+
27
+ /**
28
+ * Checks if the noise cancellation is supported on this platform.
29
+ * Make sure you call this method before trying to enable the noise cancellation.
30
+ */
31
+ isSupported = () => true;
32
+
33
+ /**
34
+ * Checks if the noise cancellation can be automatically enabled for the current device.
35
+ * In react native, it will be auto enabled only if the device supports advanced audio processing.
36
+ */
37
+ canAutoEnable = deviceSupportsAdvancedAudioProcessing;
38
+
39
+ init = () => Promise.resolve();
40
+
41
+ /**
42
+ * Enables the noise cancellation.
43
+ */
44
+ enable = () => {
45
+ NoiseCancellationReactNative.setEnabled(true);
46
+ this.dispatch('change', true);
47
+ };
48
+
49
+ /**
50
+ * Disables the noise cancellation.
51
+ */
52
+ disable = () => {
53
+ NoiseCancellationReactNative.setEnabled(false);
54
+ this.dispatch('change', false);
55
+ };
56
+
57
+ /**
58
+ * Disposes the instance and releases all resources.
59
+ */
60
+ dispose = async () => Promise.resolve();
61
+
62
+ // no-op in React Native
63
+ setSuppressionLevel = () => {};
64
+
65
+ isEnabled = async () => {
66
+ return isEnabled();
67
+ };
68
+
69
+ /**
70
+ * A utility method convenient for our Microphone filters API.
71
+ * Not relevant in React Native.
72
+ */
73
+ toFilter = () => (mediaStream: MediaStream) => {
74
+ return { output: mediaStream };
75
+ };
76
+
77
+ /**
78
+ * Registers the given callback to the event type;
79
+ *
80
+ * @param event the event to listen.
81
+ * @param callback the callback to call.
82
+ */
83
+ on = <E extends keyof Events, T = Events[E]>(event: E, callback: T) => {
84
+ (this.listeners[event] ??= [] as T[]).push(callback);
85
+ return () => {
86
+ this.off(event, callback);
87
+ };
88
+ };
89
+
90
+ /**
91
+ * Unregisters the given callback for the event type.
92
+ *
93
+ * @param event the event.
94
+ * @param callback the callback to unregister.
95
+ */
96
+ off = <E extends keyof Events, T = Events[E]>(event: E, callback: T) => {
97
+ const listeners = this.listeners[event] || [];
98
+ this.listeners[event] = listeners.filter((cb) => cb !== callback);
99
+ };
100
+
101
+ /**
102
+ * Dispatches a new event payload for the given event type.
103
+ *
104
+ * @param event the event.
105
+ * @param payload the payload.
106
+ */
107
+ private dispatch = <E extends keyof Events, P = Parameters<Events[E]>[0]>(
108
+ event: E,
109
+ payload: P,
110
+ ) => {
111
+ const listeners = this.listeners[event] || [];
112
+ for (const listener of listeners) {
113
+ listener(payload);
114
+ }
115
+ };
116
+ }
117
+
118
+ /**
119
+ * Checks if noise cancellation is currently enabled.
120
+ * @returns A promise that resolves with a boolean indicating if noise cancellation is enabled.
121
+ */
122
+ export const isEnabled = (): Promise<boolean> => {
123
+ return NoiseCancellationReactNative.isEnabled();
124
+ };
125
+
126
+ /**
127
+ * Enables or disables noise cancellation.
128
+ * @param enabled - Whether to enable or disable noise cancellation.
129
+ * @returns A promise that resolves when the operation is complete.
130
+ */
131
+ export const setEnabled = (enabled: boolean): Promise<boolean> => {
132
+ return NoiseCancellationReactNative.setEnabled(enabled);
133
+ };
134
+
135
+ /**
136
+ * Checks if the device supports advanced audio processing required for noise cancellation.
137
+ * @returns A promise that resolves with a boolean indicating if the device supports advanced audio processing.
138
+ */
139
+ export const deviceSupportsAdvancedAudioProcessing = (): Promise<boolean> => {
140
+ return NoiseCancellationReactNative.deviceSupportsAdvancedAudioProcessing();
141
+ };
package/src/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ export interface INoiseCancellation {
2
+ isSupported: () => boolean | Promise<boolean>;
3
+ init: () => Promise<void>;
4
+ canAutoEnable?: () => Promise<boolean>;
5
+ isEnabled: () => Promise<boolean>;
6
+ enable: () => void;
7
+ disable: () => void;
8
+ dispose: () => Promise<void>;
9
+ setSuppressionLevel: (level: number) => void;
10
+ toFilter: () => (mediaStream: MediaStream) => {
11
+ output: MediaStream;
12
+ };
13
+ on: <E extends keyof Events, T = Events[E]>(
14
+ event: E,
15
+ callback: T,
16
+ ) => () => void;
17
+ off: <E extends keyof Events, T = Events[E]>(event: E, callback: T) => void;
18
+ }
19
+
20
+ /**
21
+ * A list of events one can subscribe to.
22
+ */
23
+ export type Events = {
24
+ /**
25
+ * Fires when Noise Cancellation state changes.
26
+ *
27
+ * @param enabled true when enabled, false otherwise.
28
+ */
29
+ change: (enabled: boolean) => void;
30
+ };
@@ -0,0 +1,49 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "stream-io-noise-cancellation-react-native"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => '13.0' }
15
+ s.source = { :git => "https://github.com/GetStream/stream-video-js.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
18
+ s.dependency "stream-react-native-webrtc"
19
+ s.dependency 'StreamVideoNoiseCancellation'
20
+
21
+ public_header_files = 'ios/Headers/*.h'
22
+ # Swift/Objective-C compatibility https://blog.cocoapods.org/CocoaPods-1.5.0/
23
+ s.pod_target_xcconfig = {
24
+ 'DEFINES_MODULE' => 'YES'
25
+ }
26
+
27
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
28
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
29
+ if respond_to?(:install_modules_dependencies, true)
30
+ install_modules_dependencies(s)
31
+ else
32
+ s.dependency "React-Core"
33
+
34
+ # Don't install the dependencies when we run `pod install` in the old architecture.
35
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
36
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
37
+ s.pod_target_xcconfig = {
38
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
39
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
40
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
41
+ }
42
+ s.dependency "React-Codegen"
43
+ s.dependency "RCT-Folly"
44
+ s.dependency "RCTRequired"
45
+ s.dependency "RCTTypeSafety"
46
+ s.dependency "ReactCommon/turbomodule/core"
47
+ end
48
+ end
49
+ end