gravix-rtc-react-native 0.0.0-stage → 0.2.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.
- package/CHANGELOG.md +134 -0
- package/LICENSE +20 -0
- package/LICENSES/Apache-2.0.txt +175 -0
- package/NOTICE +68 -0
- package/README.md +313 -2
- package/android/build.gradle +137 -0
- package/android/consumer-rules.pro +29 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/cpp/CMakeLists.txt +48 -0
- package/android/src/main/cpp/gx_dfn_engine.c +332 -0
- package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
- package/android/src/main/cpp/gx_ns_jni.c +162 -0
- package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
- package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
- package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
- package/docs/FEATURE_MATRIX.md +192 -0
- package/docs/IOS_NATIVE_HOOKS.md +190 -0
- package/gravix-rtc-react-native.podspec +49 -0
- package/ios/GravixRtc.h +7 -0
- package/ios/GravixRtc.mm +273 -0
- package/ios/GravixRtcSetup.h +29 -0
- package/ios/GravixRtcSetup.m +52 -0
- package/ios/audio/GravixRtcIosAudio.m +157 -0
- package/ios/audio/GxAudioDevice.h +62 -0
- package/ios/audio/GxAudioDevice.m +857 -0
- package/ios/audio/GxAudioSetup.h +34 -0
- package/ios/audio/GxAudioSetup.m +70 -0
- package/ios/audio/GxCompat.swift +53 -0
- package/ios/audio/GxIosAudio.swift +99 -0
- package/ios/audio/GxMusicController.swift +150 -0
- package/ios/audio/GxMusicPost.swift +362 -0
- package/ios/audio/GxNoiseProcessor.swift +718 -0
- package/ios/audio/GxNsDfn3CoreML.swift +195 -0
- package/ios/audio/GxNsStudioEngine.swift +237 -0
- package/ios/audio/GxNsStudioPack.swift +212 -0
- package/ios/audio/GxVoiceFx.swift +161 -0
- package/ios/audio/gx_adm_state.h +153 -0
- package/ios/gxcore/apple/gx_music_post.c +312 -0
- package/ios/gxcore/apple/gx_pcm.c +30 -0
- package/ios/gxcore/apple/gxns_build.h +19 -0
- package/ios/gxcore/apple/gxns_ios.c +17 -0
- package/ios/gxcore/apple/include/gx_fx.h +3 -0
- package/ios/gxcore/apple/include/gx_music_post.h +88 -0
- package/ios/gxcore/apple/include/gx_ns.h +3 -0
- package/ios/gxcore/apple/include/gx_pcm.h +33 -0
- package/ios/gxcore/apple/include/gxns_ios.h +18 -0
- package/ios/gxcore/apple/include/module.modulemap +10 -0
- package/ios/gxcore/apple/shim/rnnoise.h +2 -0
- package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
- package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
- package/ios/gxcore/apple/units/gx_ns.c +7 -0
- package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
- package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
- package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
- package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
- package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
- package/lib/module/android/bindings.js +49 -0
- package/lib/module/android/bindings.js.map +1 -0
- package/lib/module/android/index.js +13 -0
- package/lib/module/android/index.js.map +1 -0
- package/lib/module/android/micMute.js +341 -0
- package/lib/module/android/micMute.js.map +1 -0
- package/lib/module/android/nativeAudio.js +47 -0
- package/lib/module/android/nativeAudio.js.map +1 -0
- package/lib/module/android/noiseSuppression.js +170 -0
- package/lib/module/android/noiseSuppression.js.map +1 -0
- package/lib/module/android/roomMusic.js +142 -0
- package/lib/module/android/roomMusic.js.map +1 -0
- package/lib/module/android/singerMode.js +31 -0
- package/lib/module/android/singerMode.js.map +1 -0
- package/lib/module/android/voiceEffects.js +65 -0
- package/lib/module/android/voiceEffects.js.map +1 -0
- package/lib/module/audio/AudioManager.js +79 -0
- package/lib/module/audio/AudioManager.js.map +1 -0
- package/lib/module/audio/AudioSession.js +90 -0
- package/lib/module/audio/AudioSession.js.map +1 -0
- package/lib/module/audio/remoteVolume.js +54 -0
- package/lib/module/audio/remoteVolume.js.map +1 -0
- package/lib/module/components/VideoView.js +109 -0
- package/lib/module/components/VideoView.js.map +1 -0
- package/lib/module/features/audioScenario.js +53 -0
- package/lib/module/features/audioScenario.js.map +1 -0
- package/lib/module/features/beauty.js +828 -0
- package/lib/module/features/beauty.js.map +1 -0
- package/lib/module/features/micRelease.js +89 -0
- package/lib/module/features/micRelease.js.map +1 -0
- package/lib/module/features/noiseSuppression.js +213 -0
- package/lib/module/features/noiseSuppression.js.map +1 -0
- package/lib/module/features/roomMusic.js +90 -0
- package/lib/module/features/roomMusic.js.map +1 -0
- package/lib/module/features/roomMusicAndroid.js +294 -0
- package/lib/module/features/roomMusicAndroid.js.map +1 -0
- package/lib/module/features/roomMusicIos.js +250 -0
- package/lib/module/features/roomMusicIos.js.map +1 -0
- package/lib/module/features/roomMusicTypes.js +53 -0
- package/lib/module/features/roomMusicTypes.js.map +1 -0
- package/lib/module/features/screenShare.js +22 -0
- package/lib/module/features/screenShare.js.map +1 -0
- package/lib/module/features/singerMode.js +73 -0
- package/lib/module/features/singerMode.js.map +1 -0
- package/lib/module/features/voiceEffects.js +148 -0
- package/lib/module/features/voiceEffects.js.map +1 -0
- package/lib/module/hooks/context.js +34 -0
- package/lib/module/hooks/context.js.map +1 -0
- package/lib/module/hooks/hooks.js +145 -0
- package/lib/module/hooks/hooks.js.map +1 -0
- package/lib/module/hooks/types.js +4 -0
- package/lib/module/hooks/types.js.map +1 -0
- package/lib/module/hooks/useRoomEvents.js +30 -0
- package/lib/module/hooks/useRoomEvents.js.map +1 -0
- package/lib/module/index.js +43 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/ios/autoAttach.js +14 -0
- package/lib/module/ios/autoAttach.js.map +1 -0
- package/lib/module/ios/iosAudio.js +149 -0
- package/lib/module/ios/iosAudio.js.map +1 -0
- package/lib/module/join/appStateLifecycle.js +54 -0
- package/lib/module/join/appStateLifecycle.js.map +1 -0
- package/lib/module/micPolicy.js +249 -0
- package/lib/module/micPolicy.js.map +1 -0
- package/lib/module/native/NativeGravixAudio.js +18 -0
- package/lib/module/native/NativeGravixAudio.js.map +1 -0
- package/lib/module/native/NativeGravixRtc.js +13 -0
- package/lib/module/native/NativeGravixRtc.js.map +1 -0
- package/lib/module/native/module.js +23 -0
- package/lib/module/native/module.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/polyfills/DOMException.js +22 -0
- package/lib/module/polyfills/DOMException.js.map +1 -0
- package/lib/module/polyfills/early.js +18 -0
- package/lib/module/polyfills/early.js.map +1 -0
- package/lib/module/polyfills/event.js +71 -0
- package/lib/module/polyfills/event.js.map +1 -0
- package/lib/module/polyfills/sha256.js +92 -0
- package/lib/module/polyfills/sha256.js.map +1 -0
- package/lib/module/polyfills/subtleHmac.js +91 -0
- package/lib/module/polyfills/subtleHmac.js.map +1 -0
- package/lib/module/polyfills/textCoding.js +164 -0
- package/lib/module/polyfills/textCoding.js.map +1 -0
- package/lib/module/registerGlobals.js +135 -0
- package/lib/module/registerGlobals.js.map +1 -0
- package/lib/module/unsupported.js +90 -0
- package/lib/module/unsupported.js.map +1 -0
- package/lib/module/version.js +7 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/android/bindings.d.ts +14 -0
- package/lib/typescript/src/android/bindings.d.ts.map +1 -0
- package/lib/typescript/src/android/index.d.ts +9 -0
- package/lib/typescript/src/android/index.d.ts.map +1 -0
- package/lib/typescript/src/android/micMute.d.ts +124 -0
- package/lib/typescript/src/android/micMute.d.ts.map +1 -0
- package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
- package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
- package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
- package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
- package/lib/typescript/src/android/roomMusic.d.ts +80 -0
- package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
- package/lib/typescript/src/android/singerMode.d.ts +27 -0
- package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
- package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
- package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
- package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
- package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
- package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
- package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
- package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
- package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
- package/lib/typescript/src/components/VideoView.d.ts +44 -0
- package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
- package/lib/typescript/src/features/audioScenario.d.ts +24 -0
- package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
- package/lib/typescript/src/features/beauty.d.ts +377 -0
- package/lib/typescript/src/features/beauty.d.ts.map +1 -0
- package/lib/typescript/src/features/micRelease.d.ts +28 -0
- package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
- package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
- package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusic.d.ts +41 -0
- package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
- package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
- package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
- package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
- package/lib/typescript/src/features/screenShare.d.ts +12 -0
- package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
- package/lib/typescript/src/features/singerMode.d.ts +20 -0
- package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
- package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
- package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
- package/lib/typescript/src/hooks/context.d.ts +12 -0
- package/lib/typescript/src/hooks/context.d.ts.map +1 -0
- package/lib/typescript/src/hooks/hooks.d.ts +54 -0
- package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
- package/lib/typescript/src/hooks/types.d.ts +8 -0
- package/lib/typescript/src/hooks/types.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
- package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +37 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
- package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
- package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
- package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
- package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
- package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
- package/lib/typescript/src/micPolicy.d.ts +104 -0
- package/lib/typescript/src/micPolicy.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
- package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
- package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
- package/lib/typescript/src/native/module.d.ts +7 -0
- package/lib/typescript/src/native/module.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
- package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/early.d.ts +2 -0
- package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/event.d.ts +2 -0
- package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
- package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
- package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
- package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
- package/lib/typescript/src/registerGlobals.d.ts +42 -0
- package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
- package/lib/typescript/src/unsupported.d.ts +42 -0
- package/lib/typescript/src/unsupported.d.ts.map +1 -0
- package/lib/typescript/src/version.d.ts +3 -0
- package/lib/typescript/src/version.d.ts.map +1 -0
- package/metro/index.js +39 -0
- package/metro/noise-stub.js +10 -0
- package/native/gxfx/include/gx_fx.h +82 -0
- package/native/gxfx/src/gx_fx.cpp +527 -0
- package/native/gxfx/third_party/README.md +4 -0
- package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
- package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
- package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
- package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
- package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
- package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
- package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
- package/native/gxns/CMakeLists.txt +67 -0
- package/native/gxns/include/gx_ns.h +285 -0
- package/native/gxns/src/gx_ns.c +1518 -0
- package/native/gxns/src/gx_ns_timer.c +84 -0
- package/native/gxns/src/gx_ns_timer.h +29 -0
- package/native/gxns/third_party/VENDOR.md +43 -0
- package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
- package/native/gxns/third_party/rnnoise/COPYING +31 -0
- package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
- package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
- package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
- package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
- package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
- package/native/gxns/third_party/rnnoise/src/common.h +48 -0
- package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
- package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
- package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
- package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
- package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
- package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
- package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
- package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
- package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
- package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
- package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
- package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
- package/native/gxns/third_party/speexdsp/COPYING +35 -0
- package/native/gxns/third_party/speexdsp/arch.h +232 -0
- package/native/gxns/third_party/speexdsp/resample.c +1239 -0
- package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
- package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
- package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
- package/package.json +186 -4
- package/src/android/bindings.ts +61 -0
- package/src/android/index.ts +10 -0
- package/src/android/micMute.ts +422 -0
- package/src/android/nativeAudio.ts +94 -0
- package/src/android/noiseSuppression.ts +209 -0
- package/src/android/roomMusic.ts +193 -0
- package/src/android/singerMode.ts +53 -0
- package/src/android/voiceEffects.ts +126 -0
- package/src/audio/AudioManager.ts +111 -0
- package/src/audio/AudioSession.ts +190 -0
- package/src/audio/remoteVolume.ts +58 -0
- package/src/components/VideoView.tsx +152 -0
- package/src/features/audioScenario.ts +58 -0
- package/src/features/beauty.ts +1057 -0
- package/src/features/micRelease.ts +108 -0
- package/src/features/noiseSuppression.ts +251 -0
- package/src/features/roomMusic.ts +106 -0
- package/src/features/roomMusicAndroid.ts +310 -0
- package/src/features/roomMusicIos.ts +300 -0
- package/src/features/roomMusicTypes.ts +97 -0
- package/src/features/screenShare.ts +19 -0
- package/src/features/singerMode.ts +70 -0
- package/src/features/voiceEffects.ts +245 -0
- package/src/hooks/context.tsx +38 -0
- package/src/hooks/hooks.ts +247 -0
- package/src/hooks/types.ts +10 -0
- package/src/hooks/useRoomEvents.ts +35 -0
- package/src/index.tsx +134 -0
- package/src/ios/autoAttach.ts +11 -0
- package/src/ios/iosAudio.ts +202 -0
- package/src/join/appStateLifecycle.ts +55 -0
- package/src/micPolicy.ts +312 -0
- package/src/native/NativeGravixAudio.ts +30 -0
- package/src/native/NativeGravixRtc.ts +38 -0
- package/src/native/module.ts +22 -0
- package/src/polyfills/DOMException.ts +20 -0
- package/src/polyfills/early.ts +16 -0
- package/src/polyfills/event.ts +88 -0
- package/src/polyfills/sha256.ts +112 -0
- package/src/polyfills/subtleHmac.ts +124 -0
- package/src/polyfills/textCoding.ts +197 -0
- package/src/registerGlobals.ts +201 -0
- package/src/unsupported.ts +139 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import { hmacSha256 } from './sha256';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A `crypto.subtle` stand-in for Hermes that supports exactly what
|
|
7
|
+
* gravix-rtc's `createToken` (local HS256 join tokens) needs:
|
|
8
|
+
* `importKey('raw', key, { name: 'HMAC', hash: 'SHA-256' }, ...)` and
|
|
9
|
+
* `sign('HMAC', key, data)`. Every other call rejects with NotSupportedError,
|
|
10
|
+
* so E2EE (which needs AES-GCM/HKDF) still reports itself unsupported.
|
|
11
|
+
*
|
|
12
|
+
* Installed by `registerGlobals()` only when `globalThis.crypto.subtle` is
|
|
13
|
+
* missing; a real WebCrypto (e.g. a native polyfill) always wins.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const KEY_BYTES = Symbol('gravixHmacKey');
|
|
17
|
+
|
|
18
|
+
type ShimKey = {
|
|
19
|
+
type: 'secret';
|
|
20
|
+
algorithm: { name: 'HMAC' };
|
|
21
|
+
[KEY_BYTES]: Uint8Array;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function toBytes(data: unknown): Uint8Array {
|
|
25
|
+
if (data instanceof Uint8Array) return data;
|
|
26
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
27
|
+
if (ArrayBuffer.isView(data)) {
|
|
28
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
29
|
+
}
|
|
30
|
+
throw new TypeError('Expected a BufferSource');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function notSupported(op: string): Promise<never> {
|
|
34
|
+
const Err = (
|
|
35
|
+
globalThis as { DOMException?: new (m: string, n: string) => Error }
|
|
36
|
+
).DOMException;
|
|
37
|
+
const msg = `crypto.subtle.${op} is not available in React Native (gravix-rtc-react-native ships only HMAC-SHA256)`;
|
|
38
|
+
return Promise.reject(
|
|
39
|
+
Err ? new Err(msg, 'NotSupportedError') : new Error(msg)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function algName(alg: unknown): string {
|
|
44
|
+
return typeof alg === 'string'
|
|
45
|
+
? alg
|
|
46
|
+
: String((alg as { name?: string })?.name ?? '');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function hashName(alg: unknown): string {
|
|
50
|
+
const hash = (alg as { hash?: unknown })?.hash;
|
|
51
|
+
return typeof hash === 'string'
|
|
52
|
+
? hash
|
|
53
|
+
: String((hash as { name?: string })?.name ?? '');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const gravixSubtleHmac = {
|
|
57
|
+
__gravixShim: true as const,
|
|
58
|
+
importKey(
|
|
59
|
+
format: string,
|
|
60
|
+
keyData: unknown,
|
|
61
|
+
algorithm: unknown,
|
|
62
|
+
_extractable: boolean,
|
|
63
|
+
_usages: string[]
|
|
64
|
+
): Promise<ShimKey> {
|
|
65
|
+
if (
|
|
66
|
+
format !== 'raw' ||
|
|
67
|
+
algName(algorithm).toUpperCase() !== 'HMAC' ||
|
|
68
|
+
hashName(algorithm).toUpperCase() !== 'SHA-256'
|
|
69
|
+
) {
|
|
70
|
+
return notSupported(`importKey(${format}, ${algName(algorithm)})`);
|
|
71
|
+
}
|
|
72
|
+
// Copy: the caller may reuse its buffer.
|
|
73
|
+
const bytes = new Uint8Array(toBytes(keyData));
|
|
74
|
+
return Promise.resolve({
|
|
75
|
+
type: 'secret',
|
|
76
|
+
algorithm: { name: 'HMAC' },
|
|
77
|
+
[KEY_BYTES]: bytes,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
sign(algorithm: unknown, key: ShimKey, data: unknown): Promise<ArrayBuffer> {
|
|
81
|
+
if (
|
|
82
|
+
algName(algorithm).toUpperCase() !== 'HMAC' ||
|
|
83
|
+
!key ||
|
|
84
|
+
!(KEY_BYTES in key)
|
|
85
|
+
) {
|
|
86
|
+
return notSupported(`sign(${algName(algorithm)})`);
|
|
87
|
+
}
|
|
88
|
+
const sig = hmacSha256(key[KEY_BYTES], toBytes(data));
|
|
89
|
+
return Promise.resolve(
|
|
90
|
+
sig.buffer.slice(
|
|
91
|
+
sig.byteOffset,
|
|
92
|
+
sig.byteOffset + sig.byteLength
|
|
93
|
+
) as ArrayBuffer
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
verify: () => notSupported('verify'),
|
|
97
|
+
digest: () => notSupported('digest'),
|
|
98
|
+
encrypt: () => notSupported('encrypt'),
|
|
99
|
+
decrypt: () => notSupported('decrypt'),
|
|
100
|
+
deriveKey: () => notSupported('deriveKey'),
|
|
101
|
+
deriveBits: () => notSupported('deriveBits'),
|
|
102
|
+
generateKey: () => notSupported('generateKey'),
|
|
103
|
+
exportKey: () => notSupported('exportKey'),
|
|
104
|
+
wrapKey: () => notSupported('wrapKey'),
|
|
105
|
+
unwrapKey: () => notSupported('unwrapKey'),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** Installs the shim when there is no `crypto.subtle`. Returns whether it did. */
|
|
109
|
+
export function installSubtleHmacShim(): boolean {
|
|
110
|
+
const g = globalThis as { crypto?: { subtle?: unknown } };
|
|
111
|
+
if (!g.crypto) {
|
|
112
|
+
(g as { crypto: object }).crypto = {};
|
|
113
|
+
}
|
|
114
|
+
if (g.crypto!.subtle) return false;
|
|
115
|
+
try {
|
|
116
|
+
(g.crypto as { subtle: unknown }).subtle = gravixSubtleHmac;
|
|
117
|
+
} catch {
|
|
118
|
+
Object.defineProperty(g.crypto, 'subtle', {
|
|
119
|
+
value: gravixSubtleHmac,
|
|
120
|
+
configurable: true,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UTF-8 TextEncoder/TextDecoder for runtimes that lack them (older Hermes has
|
|
5
|
+
* TextEncoder only; @bufbuild/protobuf in gravix-rtc decodes signalling strings
|
|
6
|
+
* with TextDecoder). Installed only when missing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-bitwise */
|
|
10
|
+
function encodeUtf8(input: string): Uint8Array {
|
|
11
|
+
const out: number[] = [];
|
|
12
|
+
for (let i = 0; i < input.length; i++) {
|
|
13
|
+
let c = input.charCodeAt(i);
|
|
14
|
+
if (c >= 0xd800 && c <= 0xdbff && i + 1 < input.length) {
|
|
15
|
+
const d = input.charCodeAt(i + 1);
|
|
16
|
+
if (d >= 0xdc00 && d <= 0xdfff) {
|
|
17
|
+
c = 0x10000 + ((c - 0xd800) << 10) + (d - 0xdc00);
|
|
18
|
+
i++;
|
|
19
|
+
}
|
|
20
|
+
} else if (c >= 0xd800 && c <= 0xdfff) {
|
|
21
|
+
c = 0xfffd;
|
|
22
|
+
}
|
|
23
|
+
if (c < 0x80) out.push(c);
|
|
24
|
+
else if (c < 0x800) out.push(0xc0 | (c >> 6), 0x80 | (c & 63));
|
|
25
|
+
else if (c < 0x10000)
|
|
26
|
+
out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
|
|
27
|
+
else
|
|
28
|
+
out.push(
|
|
29
|
+
0xf0 | (c >> 18),
|
|
30
|
+
0x80 | ((c >> 12) & 63),
|
|
31
|
+
0x80 | ((c >> 6) & 63),
|
|
32
|
+
0x80 | (c & 63)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return new Uint8Array(out);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class FatalDecodeError extends TypeError {
|
|
39
|
+
constructor() {
|
|
40
|
+
super('TextDecoder: the encoded data was not valid utf-8');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function decodeUtf8(bytes: Uint8Array, dropBom = true, fatal = false): string {
|
|
45
|
+
let out = '';
|
|
46
|
+
let i = 0;
|
|
47
|
+
// A BOM at the start is dropped, as TextDecoder does by default.
|
|
48
|
+
if (dropBom && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf)
|
|
49
|
+
i = 3;
|
|
50
|
+
const chunk: number[] = [];
|
|
51
|
+
const flush = () => {
|
|
52
|
+
out += String.fromCharCode.apply(null, chunk);
|
|
53
|
+
chunk.length = 0;
|
|
54
|
+
};
|
|
55
|
+
while (i < bytes.length) {
|
|
56
|
+
const b = bytes[i]!;
|
|
57
|
+
let cp = 0xfffd;
|
|
58
|
+
let need = 0;
|
|
59
|
+
if (b < 0x80) {
|
|
60
|
+
cp = b;
|
|
61
|
+
} else if (b >= 0xc2 && b < 0xe0) {
|
|
62
|
+
need = 1;
|
|
63
|
+
cp = b & 0x1f;
|
|
64
|
+
} else if (b >= 0xe0 && b < 0xf0) {
|
|
65
|
+
need = 2;
|
|
66
|
+
cp = b & 0x0f;
|
|
67
|
+
} else if (b >= 0xf0 && b < 0xf5) {
|
|
68
|
+
need = 3;
|
|
69
|
+
cp = b & 0x07;
|
|
70
|
+
}
|
|
71
|
+
i++;
|
|
72
|
+
let ok = true;
|
|
73
|
+
for (let k = 0; k < need; k++) {
|
|
74
|
+
const n = bytes[i];
|
|
75
|
+
if (n === undefined || (n & 0xc0) !== 0x80) {
|
|
76
|
+
ok = false;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
cp = (cp << 6) | (n & 0x3f);
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
if (
|
|
83
|
+
!ok ||
|
|
84
|
+
(need === 2 && cp < 0x800) ||
|
|
85
|
+
(need === 3 && (cp < 0x10000 || cp > 0x10ffff)) ||
|
|
86
|
+
(cp >= 0xd800 && cp <= 0xdfff) ||
|
|
87
|
+
(need === 0 && b >= 0x80)
|
|
88
|
+
) {
|
|
89
|
+
if (fatal) throw new FatalDecodeError();
|
|
90
|
+
cp = 0xfffd;
|
|
91
|
+
}
|
|
92
|
+
if (cp >= 0x10000) {
|
|
93
|
+
cp -= 0x10000;
|
|
94
|
+
chunk.push(0xd800 + (cp >> 10), 0xdc00 + (cp & 0x3ff));
|
|
95
|
+
} else {
|
|
96
|
+
chunk.push(cp);
|
|
97
|
+
}
|
|
98
|
+
if (chunk.length > 4096) flush();
|
|
99
|
+
}
|
|
100
|
+
flush();
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
/* eslint-enable no-bitwise */
|
|
104
|
+
|
|
105
|
+
class GravixTextEncoder {
|
|
106
|
+
readonly encoding = 'utf-8';
|
|
107
|
+
encode(input = ''): Uint8Array {
|
|
108
|
+
return encodeUtf8(String(input));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Length of an incomplete UTF-8 sequence at the end of [b] (0..3): the bytes
|
|
114
|
+
* a streaming decode keeps for the next chunk.
|
|
115
|
+
*/
|
|
116
|
+
function incompleteTail(b: Uint8Array): number {
|
|
117
|
+
for (let back = 1; back <= Math.min(3, b.length); back++) {
|
|
118
|
+
const x = b[b.length - back]!;
|
|
119
|
+
if (x >= 0x80 && x < 0xc0) continue; // continuation: look further back
|
|
120
|
+
const need = x >= 0xf0 && x < 0xf5 ? 3 : x >= 0xe0 ? 2 : x >= 0xc2 ? 1 : 0;
|
|
121
|
+
return need >= back ? back : 0;
|
|
122
|
+
}
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** WHATWG TextDecoder, utf-8 only, with `fatal`, `ignoreBOM` and `{stream}`. */
|
|
127
|
+
class GravixTextDecoder {
|
|
128
|
+
readonly encoding = 'utf-8';
|
|
129
|
+
readonly fatal: boolean;
|
|
130
|
+
readonly ignoreBOM: boolean;
|
|
131
|
+
private pending: Uint8Array = new Uint8Array(0);
|
|
132
|
+
private started = false;
|
|
133
|
+
constructor(
|
|
134
|
+
label = 'utf-8',
|
|
135
|
+
options: { fatal?: boolean; ignoreBOM?: boolean } = {}
|
|
136
|
+
) {
|
|
137
|
+
const l = String(label).toLowerCase();
|
|
138
|
+
if (l !== 'utf-8' && l !== 'utf8' && l !== 'unicode-1-1-utf-8') {
|
|
139
|
+
throw new RangeError(
|
|
140
|
+
`TextDecoder: only utf-8 is supported, got '${label}'`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
this.fatal = options.fatal === true;
|
|
144
|
+
this.ignoreBOM = options.ignoreBOM === true;
|
|
145
|
+
}
|
|
146
|
+
decode(
|
|
147
|
+
input?: ArrayBuffer | ArrayBufferView,
|
|
148
|
+
options: { stream?: boolean } = {}
|
|
149
|
+
): string {
|
|
150
|
+
let bytes = !input
|
|
151
|
+
? new Uint8Array(0)
|
|
152
|
+
: input instanceof ArrayBuffer
|
|
153
|
+
? new Uint8Array(input)
|
|
154
|
+
: new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
155
|
+
if (this.pending.length > 0) {
|
|
156
|
+
const joined = new Uint8Array(this.pending.length + bytes.length);
|
|
157
|
+
joined.set(this.pending, 0);
|
|
158
|
+
joined.set(bytes, this.pending.length);
|
|
159
|
+
bytes = joined;
|
|
160
|
+
}
|
|
161
|
+
const stream = options.stream === true;
|
|
162
|
+
let keep = stream ? incompleteTail(bytes) : 0;
|
|
163
|
+
// a stream start may still be a partial BOM
|
|
164
|
+
if (stream && !this.started && bytes.length < 3) keep = bytes.length;
|
|
165
|
+
const body = keep > 0 ? bytes.subarray(0, bytes.length - keep) : bytes;
|
|
166
|
+
this.pending =
|
|
167
|
+
keep > 0 ? bytes.slice(bytes.length - keep) : new Uint8Array(0);
|
|
168
|
+
const dropBom = !this.ignoreBOM && !this.started;
|
|
169
|
+
if (body.length > 0) this.started = true;
|
|
170
|
+
let out: string;
|
|
171
|
+
try {
|
|
172
|
+
out = decodeUtf8(body, dropBom, this.fatal);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
this.reset();
|
|
175
|
+
throw e;
|
|
176
|
+
}
|
|
177
|
+
if (!stream) this.reset();
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
private reset(): void {
|
|
181
|
+
this.pending = new Uint8Array(0);
|
|
182
|
+
this.started = false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function installTextCoding(): void {
|
|
187
|
+
const g = globalThis as { TextEncoder?: unknown; TextDecoder?: unknown };
|
|
188
|
+
if (typeof g.TextEncoder === 'undefined') g.TextEncoder = GravixTextEncoder;
|
|
189
|
+
if (typeof g.TextDecoder === 'undefined') g.TextDecoder = GravixTextDecoder;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const __test = {
|
|
193
|
+
encodeUtf8,
|
|
194
|
+
decodeUtf8,
|
|
195
|
+
GravixTextDecoder,
|
|
196
|
+
GravixTextEncoder,
|
|
197
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Copyright 2023-2026 LiveKit, Inc.
|
|
2
|
+
// Modifications Copyright 2026 Gravity Compile.
|
|
3
|
+
// Licensed under the Apache License, Version 2.0; see LICENSES/Apache-2.0.txt.
|
|
4
|
+
|
|
5
|
+
import 'well-known-symbols/Symbol.asyncIterator/auto';
|
|
6
|
+
import 'well-known-symbols/Symbol.iterator/auto';
|
|
7
|
+
import { registerGlobals as webrtcRegisterGlobals } from 'react-native-webrtc';
|
|
8
|
+
import { PixelRatio, Platform } from 'react-native';
|
|
9
|
+
import { setupURLPolyfill } from 'react-native-url-polyfill';
|
|
10
|
+
import {
|
|
11
|
+
CountQueuingStrategy,
|
|
12
|
+
ReadableStream,
|
|
13
|
+
TransformStream,
|
|
14
|
+
WritableStream,
|
|
15
|
+
} from 'web-streams-polyfill';
|
|
16
|
+
import {
|
|
17
|
+
setupIOSAudioManagement,
|
|
18
|
+
type IOSAudioSessionPolicy,
|
|
19
|
+
} from './audio/AudioManager';
|
|
20
|
+
import { Room } from 'gravix-rtc';
|
|
21
|
+
import { installRemoteVolumeHook } from './audio/remoteVolume';
|
|
22
|
+
import { gravixRoomMicPolicy, installRoomMicHooks } from './micPolicy';
|
|
23
|
+
import { installDOMException } from './polyfills/DOMException';
|
|
24
|
+
import { installSubtleHmacShim } from './polyfills/subtleHmac';
|
|
25
|
+
import { installTextCoding } from './polyfills/textCoding';
|
|
26
|
+
|
|
27
|
+
export interface RegisterGlobalsOptions {
|
|
28
|
+
/**
|
|
29
|
+
* iOS: let the audio engine configure and activate the AVAudioSession as
|
|
30
|
+
* playout/recording start and stop (see `setupIOSAudioManagement`).
|
|
31
|
+
* Default true. No effect on Android.
|
|
32
|
+
*/
|
|
33
|
+
autoConfigureAudioSession?: boolean;
|
|
34
|
+
/** iOS: prefer the loudspeaker while publishing the mic. Default true. */
|
|
35
|
+
preferSpeakerOutput?: boolean;
|
|
36
|
+
/** iOS: a custom per-engine-state session policy. */
|
|
37
|
+
iosAudioSessionPolicy?: IOSAudioSessionPolicy;
|
|
38
|
+
/**
|
|
39
|
+
* Install the HMAC-SHA256-only `crypto.subtle` stand-in when the runtime has
|
|
40
|
+
* no WebCrypto, so local join tokens (`createToken`,
|
|
41
|
+
* `GravixTokenProvider.local`) work on Hermes. Default true.
|
|
42
|
+
*/
|
|
43
|
+
cryptoHmacShim?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Mute releases the microphone on every Room (Flutter 0.12.1+ default):
|
|
46
|
+
* iOS (Gravix audio device) closes the mic input on mute, Android mics published while muted get their
|
|
47
|
+
* recorder closed. Default true; `false` is the one-flag rollback (no room
|
|
48
|
+
* hook installed, the plain core mute).
|
|
49
|
+
*/
|
|
50
|
+
muteReleasesMic?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What the gravix-rtc core reads to tell it runs in React Native (`getReactNativeOs`). */
|
|
54
|
+
export type GravixReactNativeGlobal = {
|
|
55
|
+
platform: string;
|
|
56
|
+
devicePixelRatio: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
let registered = false;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Installs WebRTC and the web APIs gravix-rtc needs into the React Native
|
|
63
|
+
* runtime. Call once, at app start, before any `Room` is created.
|
|
64
|
+
* Safe to call more than once.
|
|
65
|
+
*/
|
|
66
|
+
export function registerGlobals(options: RegisterGlobalsOptions = {}): void {
|
|
67
|
+
const opts = {
|
|
68
|
+
autoConfigureAudioSession: true,
|
|
69
|
+
preferSpeakerOutput: true,
|
|
70
|
+
cryptoHmacShim: true,
|
|
71
|
+
muteReleasesMic: true,
|
|
72
|
+
...options,
|
|
73
|
+
};
|
|
74
|
+
if (registered) return;
|
|
75
|
+
registered = true;
|
|
76
|
+
|
|
77
|
+
installDOMException();
|
|
78
|
+
webrtcRegisterGlobals();
|
|
79
|
+
if (opts.autoConfigureAudioSession) {
|
|
80
|
+
setupIOSAudioManagement(
|
|
81
|
+
opts.preferSpeakerOutput,
|
|
82
|
+
opts.iosAudioSessionPolicy
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const info: GravixReactNativeGlobal = {
|
|
86
|
+
platform: Platform.OS,
|
|
87
|
+
devicePixelRatio: PixelRatio.get(),
|
|
88
|
+
};
|
|
89
|
+
(
|
|
90
|
+
globalThis as { GravixReactNativeGlobal?: GravixReactNativeGlobal }
|
|
91
|
+
).GravixReactNativeGlobal = info;
|
|
92
|
+
setupURLPolyfill();
|
|
93
|
+
fixUserAgent();
|
|
94
|
+
shimPromiseAllSettled();
|
|
95
|
+
shimArrayAt();
|
|
96
|
+
shimCryptoRandom();
|
|
97
|
+
installTextCoding();
|
|
98
|
+
if (opts.cryptoHmacShim) installSubtleHmacShim();
|
|
99
|
+
installGlobalEventTarget();
|
|
100
|
+
gravixRoomMicPolicy.releasesMic = opts.muteReleasesMic;
|
|
101
|
+
if (opts.muteReleasesMic) installRoomMicHooks(Room);
|
|
102
|
+
installRemoteVolumeHook(Room);
|
|
103
|
+
shimWebStreams();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Test hook: lets a test call `registerGlobals` again. @internal */
|
|
107
|
+
export function __resetRegisterGlobalsForTests(): void {
|
|
108
|
+
registered = false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function fixUserAgent() {
|
|
112
|
+
// webrtc-adapter (bundled in gravix-rtc) reads navigator.userAgent.
|
|
113
|
+
const nav = (
|
|
114
|
+
globalThis as { navigator?: { userAgent?: string; product?: string } }
|
|
115
|
+
).navigator;
|
|
116
|
+
if (nav && nav.userAgent === undefined) {
|
|
117
|
+
nav.userAgent = nav.product ?? 'Unknown';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function shimPromiseAllSettled() {
|
|
122
|
+
if (typeof Promise.allSettled !== 'function') {
|
|
123
|
+
require('promise.allsettled').shim();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function shimArrayAt() {
|
|
128
|
+
// sdp-transform uses Array.prototype.at.
|
|
129
|
+
if (!Array.prototype.at) {
|
|
130
|
+
require('array.prototype.at').shim();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* eslint-disable no-bitwise */
|
|
135
|
+
type CryptoLike = {
|
|
136
|
+
getRandomValues?: <T extends ArrayBufferView | null>(arr: T) => T;
|
|
137
|
+
randomUUID?: () => string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
function shimCryptoRandom() {
|
|
141
|
+
const g = globalThis as { crypto?: CryptoLike };
|
|
142
|
+
if (!g.crypto) (g as { crypto: object }).crypto = {};
|
|
143
|
+
const c = g.crypto as CryptoLike;
|
|
144
|
+
if (typeof c.getRandomValues !== 'function') {
|
|
145
|
+
// Used for ids only (never for key material: E2EE is not supported here).
|
|
146
|
+
c.getRandomValues = (<T extends ArrayBufferView | null>(arr: T): T => {
|
|
147
|
+
if (arr) {
|
|
148
|
+
const bytes = new Uint8Array(
|
|
149
|
+
arr.buffer,
|
|
150
|
+
arr.byteOffset,
|
|
151
|
+
arr.byteLength
|
|
152
|
+
);
|
|
153
|
+
for (let i = 0; i < bytes.length; i++)
|
|
154
|
+
bytes[i] = (Math.random() * 256) | 0;
|
|
155
|
+
}
|
|
156
|
+
return arr;
|
|
157
|
+
}) as CryptoLike['getRandomValues'];
|
|
158
|
+
}
|
|
159
|
+
if (typeof c.randomUUID !== 'function') {
|
|
160
|
+
c.randomUUID = (() =>
|
|
161
|
+
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (ch) => {
|
|
162
|
+
const r = (Math.random() * 16) | 0;
|
|
163
|
+
const v = ch === 'x' ? r : (r & 0x3) | 0x8;
|
|
164
|
+
return v.toString(16);
|
|
165
|
+
})) as CryptoLike['randomUUID'];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/* eslint-enable no-bitwise */
|
|
169
|
+
|
|
170
|
+
function shimWebStreams() {
|
|
171
|
+
const g = globalThis as Record<string, unknown>;
|
|
172
|
+
if (typeof g.WritableStream === 'undefined')
|
|
173
|
+
g.WritableStream = WritableStream;
|
|
174
|
+
if (typeof g.ReadableStream === 'undefined')
|
|
175
|
+
g.ReadableStream = ReadableStream;
|
|
176
|
+
if (typeof g.CountQueuingStrategy === 'undefined')
|
|
177
|
+
g.CountQueuingStrategy = CountQueuingStrategy;
|
|
178
|
+
if (typeof g.TransformStream === 'undefined')
|
|
179
|
+
g.TransformStream = TransformStream;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* React Native's global object (`window`) has no add/removeEventListener;
|
|
184
|
+
* gravix-rtc's `startRegionMeasurement()` without `networkEvents` falls back
|
|
185
|
+
* to `window` (online / offline). Listeners are kept but never fire: pass
|
|
186
|
+
* `networkEvents` (e.g. from @react-native-community/netinfo) for real ones.
|
|
187
|
+
*/
|
|
188
|
+
function installGlobalEventTarget(): void {
|
|
189
|
+
const g = globalThis as {
|
|
190
|
+
addEventListener?: unknown;
|
|
191
|
+
removeEventListener?: unknown;
|
|
192
|
+
dispatchEvent?: unknown;
|
|
193
|
+
EventTarget?: new () => EventTarget;
|
|
194
|
+
};
|
|
195
|
+
if (typeof g.addEventListener === 'function' || !g.EventTarget) return;
|
|
196
|
+
const t = new g.EventTarget();
|
|
197
|
+
g.addEventListener = t.addEventListener.bind(t);
|
|
198
|
+
g.removeEventListener = t.removeEventListener.bind(t);
|
|
199
|
+
if (typeof g.dispatchEvent !== 'function')
|
|
200
|
+
g.dispatchEvent = t.dispatchEvent.bind(t);
|
|
201
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { nativeModuleOrNull } from './native/module';
|
|
5
|
+
import { GRAVIX_RTC_RN_VERSION } from './version';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Native-only Gravix features (Flutter gravix_rtc parity). Each one is gated
|
|
9
|
+
* on a per-platform capability the native module reports; while it is false,
|
|
10
|
+
* every call of that feature throws {@link GravixUnsupportedError}.
|
|
11
|
+
*
|
|
12
|
+
* Keep in sync with `NATIVE_FEATURES` in the Android `GravixRtcModule.kt` and
|
|
13
|
+
* `GravixNativeFeatures()` in the iOS `GravixRtc.mm`.
|
|
14
|
+
*/
|
|
15
|
+
export const NATIVE_FEATURES = [
|
|
16
|
+
'voiceEffects',
|
|
17
|
+
'roomMusic',
|
|
18
|
+
'muteReleasesMic',
|
|
19
|
+
'noiseSuppression',
|
|
20
|
+
'singerMode',
|
|
21
|
+
'audioScenario',
|
|
22
|
+
'screenShareService',
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
export type GravixNativeFeature = (typeof NATIVE_FEATURES)[number];
|
|
26
|
+
|
|
27
|
+
export interface GravixCapabilities {
|
|
28
|
+
/** 'android' | 'ios' | another `Platform.OS`. */
|
|
29
|
+
platform: string;
|
|
30
|
+
/** Version of the linked native module, or null when it is not linked. */
|
|
31
|
+
nativeVersion: string | null;
|
|
32
|
+
/** Whether `GravixRtc.setup` (Android) / `GravixRtcSetup.setup` (iOS) ran. */
|
|
33
|
+
setUp: boolean;
|
|
34
|
+
features: Record<GravixNativeFeature, boolean>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Thrown by a native-only feature on a platform where it is not implemented yet. */
|
|
38
|
+
export class GravixUnsupportedError extends Error {
|
|
39
|
+
readonly code = 'not_supported_on_platform' as const;
|
|
40
|
+
readonly feature: GravixNativeFeature;
|
|
41
|
+
readonly operation: string;
|
|
42
|
+
readonly platform: string;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
feature: GravixNativeFeature,
|
|
46
|
+
operation: string,
|
|
47
|
+
platform: string
|
|
48
|
+
) {
|
|
49
|
+
super(
|
|
50
|
+
`${feature}.${operation} is not yet supported on this platform (${platform}) ` +
|
|
51
|
+
`by gravix-rtc-react-native ${GRAVIX_RTC_RN_VERSION}. ` +
|
|
52
|
+
'Check isFeatureSupported() before calling it.'
|
|
53
|
+
);
|
|
54
|
+
this.name = 'GravixUnsupportedError';
|
|
55
|
+
this.feature = feature;
|
|
56
|
+
this.operation = operation;
|
|
57
|
+
this.platform = platform;
|
|
58
|
+
Object.setPrototypeOf(this, GravixUnsupportedError.prototype);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function allFalse(): Record<GravixNativeFeature, boolean> {
|
|
63
|
+
const out = {} as Record<GravixNativeFeature, boolean>;
|
|
64
|
+
for (const f of NATIVE_FEATURES) out[f] = false;
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let cached: GravixCapabilities | undefined;
|
|
69
|
+
|
|
70
|
+
/** The native capability map (read once, then cached). Without the native module every feature is false. */
|
|
71
|
+
export function getCapabilities(): GravixCapabilities {
|
|
72
|
+
if (cached) return cached;
|
|
73
|
+
const features = allFalse();
|
|
74
|
+
const native = nativeModuleOrNull();
|
|
75
|
+
let reported: Partial<GravixCapabilities> | undefined;
|
|
76
|
+
try {
|
|
77
|
+
reported = native
|
|
78
|
+
? (native.getCapabilities() as Partial<GravixCapabilities>)
|
|
79
|
+
: undefined;
|
|
80
|
+
} catch {
|
|
81
|
+
reported = undefined;
|
|
82
|
+
}
|
|
83
|
+
const nativeFeatures = (reported?.features ?? {}) as Partial<
|
|
84
|
+
Record<string, unknown>
|
|
85
|
+
>;
|
|
86
|
+
for (const f of NATIVE_FEATURES) features[f] = nativeFeatures[f] === true;
|
|
87
|
+
cached = {
|
|
88
|
+
platform:
|
|
89
|
+
typeof reported?.platform === 'string' ? reported.platform : Platform.OS,
|
|
90
|
+
nativeVersion:
|
|
91
|
+
typeof reported?.nativeVersion === 'string'
|
|
92
|
+
? reported.nativeVersion
|
|
93
|
+
: null,
|
|
94
|
+
setUp: reported?.setUp === true,
|
|
95
|
+
features,
|
|
96
|
+
};
|
|
97
|
+
return cached;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Whether a native-only feature is available on this platform. */
|
|
101
|
+
export function isFeatureSupported(feature: GravixNativeFeature): boolean {
|
|
102
|
+
return getCapabilities().features[feature] === true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Throws {@link GravixUnsupportedError} while `feature` is not supported here.
|
|
107
|
+
* When the native side reports it supported but this JS layer has no binding
|
|
108
|
+
* for `operation` yet, that is an SDK bug, reported as a plain Error.
|
|
109
|
+
*/
|
|
110
|
+
export function unsupported(
|
|
111
|
+
feature: GravixNativeFeature,
|
|
112
|
+
operation: string
|
|
113
|
+
): never {
|
|
114
|
+
const caps = getCapabilities();
|
|
115
|
+
if (!caps.features[feature]) {
|
|
116
|
+
throw new GravixUnsupportedError(feature, operation, caps.platform);
|
|
117
|
+
}
|
|
118
|
+
throw new Error(
|
|
119
|
+
`gravix-rtc-react-native: native ${feature} is reported available on ${caps.platform} ` +
|
|
120
|
+
`but ${feature}.${operation} has no JS binding in ${GRAVIX_RTC_RN_VERSION}`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Async form of {@link unsupported} for promise-returning APIs. */
|
|
125
|
+
export function unsupportedAsync(
|
|
126
|
+
feature: GravixNativeFeature,
|
|
127
|
+
operation: string
|
|
128
|
+
): Promise<never> {
|
|
129
|
+
try {
|
|
130
|
+
return unsupported(feature, operation);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
return Promise.reject(e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Test hook. @internal */
|
|
137
|
+
export function __resetCapabilitiesForTests(): void {
|
|
138
|
+
cached = undefined;
|
|
139
|
+
}
|
package/src/version.ts
ADDED