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,828 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Beauty / camera video effects: the React Native twin of Flutter gravix_rtc's
|
|
7
|
+
* `GravixVideoEffect` / `GravixCameraEffect` / `GravixBeautyEffect` and the
|
|
8
|
+
* camera part of `GravixRoomService` (reference: gravix_rtc 0.12.2, 5c4d44c).
|
|
9
|
+
*
|
|
10
|
+
* Thin wiring over the OPTIONAL peer packages `react-native-gravix-effects` +
|
|
11
|
+
* `react-native-gravix-effects-webrtc` (Android). They are loaded lazily; an
|
|
12
|
+
* app without them builds and runs, `GravixBeautyEffect.canOwnCamera()` answers
|
|
13
|
+
* false and {@link GravixRoomCamera} opens the normal camera instead (Flutter:
|
|
14
|
+
* a stripped native SDK).
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const beauty = new GravixBeautyEffect({ licenseToken });
|
|
18
|
+
* const camera = new GravixRoomCamera(room, { videoEffect: beauty });
|
|
19
|
+
* await camera.setCameraEnabled(true); // opens the Gravix camera, publishes its track
|
|
20
|
+
* await camera.setVideoEffectParams({ look: 'glow' });
|
|
21
|
+
* await camera.setVideoEffectEnabled(false); // bypass, the camera keeps running
|
|
22
|
+
* await camera.switchCamera(); // same track, no republish
|
|
23
|
+
* await camera.setCameraEnabled(false); // unpublish + close the camera; on again replays enabled/params
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { LocalVideoTrack, RoomEvent, Track, VideoPreset } from 'gravix-rtc';
|
|
28
|
+
import { Platform } from 'react-native';
|
|
29
|
+
/**
|
|
30
|
+
* Flutter GravixRoomService's camera publish options: 800 kbps / 24 fps top
|
|
31
|
+
* layer, one 180p rung at 160 kbps / 24 fps, balanced degradation. Only these
|
|
32
|
+
* keys: codec, backup codec etc. stay the Room's publishDefaults.
|
|
33
|
+
*/
|
|
34
|
+
export const GRAVIX_CAMERA_PUBLISH_OPTIONS = {
|
|
35
|
+
simulcast: true,
|
|
36
|
+
videoEncoding: {
|
|
37
|
+
maxBitrate: 800_000,
|
|
38
|
+
maxFramerate: 24
|
|
39
|
+
},
|
|
40
|
+
degradationPreference: 'balanced',
|
|
41
|
+
videoSimulcastLayers: [new VideoPreset(320, 180, 160_000, 24)]
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The core's track constructor takes the web MediaStreamTrack type; react-native-webrtc's is that object at runtime. */
|
|
45
|
+
|
|
46
|
+
// ── the optional effects packages, structurally typed (no import of their types) ──
|
|
47
|
+
|
|
48
|
+
/** The part of `react-native-gravix-effects`' `GravixPackAvailability` this SDK reads. */
|
|
49
|
+
|
|
50
|
+
/** The part of `react-native-gravix-effects`' running `GravixCamera` this SDK drives. */
|
|
51
|
+
|
|
52
|
+
/** The part of `react-native-gravix-effects-webrtc`' output this SDK publishes. */
|
|
53
|
+
|
|
54
|
+
/** The module surface of `react-native-gravix-effects-webrtc` (it re-exports the core package). */
|
|
55
|
+
|
|
56
|
+
let moduleOverride;
|
|
57
|
+
let loaded;
|
|
58
|
+
function log(msg) {
|
|
59
|
+
// Owner rule: every step logs its reason. One tag so it can be grepped in logcat (ReactNativeJS).
|
|
60
|
+
console.log(`[gravix-beauty] ${msg}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The `react-native-gravix-effects-webrtc` module (it re-exports the whole
|
|
65
|
+
* `react-native-gravix-effects` API: `GravixCamera`, `GravixPreview`,
|
|
66
|
+
* `GravixLooks`, `GravixEffects` …), or null when the app does not have it.
|
|
67
|
+
* Flutter re-exports these from `gravix_rtc`; an optional peer cannot be
|
|
68
|
+
* re-exported statically, so React Native apps reach it here (or import the
|
|
69
|
+
* package directly).
|
|
70
|
+
*/
|
|
71
|
+
export function gravixEffects() {
|
|
72
|
+
if (moduleOverride !== undefined) return moduleOverride;
|
|
73
|
+
if (loaded !== undefined) return loaded;
|
|
74
|
+
try {
|
|
75
|
+
// Metro: a require inside try/catch is an optional dependency (allowOptionalDependencies, on by default).
|
|
76
|
+
loaded = require('react-native-gravix-effects-webrtc');
|
|
77
|
+
} catch (e) {
|
|
78
|
+
const msg = String(e);
|
|
79
|
+
log(/Unable to resolve|Cannot find module|Requiring unknown module/.test(msg) ? 'react-native-gravix-effects-webrtc is not installed; beauty effects are off' : `react-native-gravix-effects-webrtc failed to load (${msg}); beauty effects are off`);
|
|
80
|
+
loaded = null;
|
|
81
|
+
}
|
|
82
|
+
return loaded;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Test seam: replaces the optional package (null = not installed; undefined = back to the real one). */
|
|
86
|
+
export function setGravixEffectsModuleForTesting(m) {
|
|
87
|
+
moduleOverride = m;
|
|
88
|
+
loaded = undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ── the effect interfaces (Flutter gravix_video_effect.dart) ──
|
|
92
|
+
|
|
93
|
+
/** The local camera track an effect is asked to process. */
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A real-time effect on the LOCAL camera. Flutter `GravixVideoEffect`.
|
|
97
|
+
* {@link attach} answers true only when frames of that track really go
|
|
98
|
+
* through the effect (no silent fake success).
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* An effect that OWNS the camera and hands the SDK the finished picture as a
|
|
103
|
+
* track (Flutter `GravixCameraEffect`). {@link GravixBeautyEffect} is one.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
function isCameraEffect(e) {
|
|
107
|
+
return !!e && typeof e.openCamera === 'function' && typeof e.canOwnCamera === 'function';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ── the built-in beauty effect (Flutter gravix_beauty_effect.dart) ──
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Real-time beauty effects from Gravix Effects (looks, reshape, makeup,
|
|
114
|
+
* stickers, 3D) as a camera-owning effect. Android only; elsewhere, or when
|
|
115
|
+
* the effects packages are not installed, {@link canOwnCamera} is false and the
|
|
116
|
+
* room opens its normal camera.
|
|
117
|
+
*
|
|
118
|
+
* Parameters ({@link GravixRoomCamera.setVideoEffectParams}): `look` (built-in
|
|
119
|
+
* look name), `lookBytes` (base64 `.gfx`), `tone` / `region` / `reshape`
|
|
120
|
+
* (`Record<string, number | null>`, as `GravixCamera.setAdjustments`).
|
|
121
|
+
*/
|
|
122
|
+
export class GravixBeautyEffect {
|
|
123
|
+
name = 'gravix-beauty';
|
|
124
|
+
minFps = 24;
|
|
125
|
+
_camera = null;
|
|
126
|
+
_output = null;
|
|
127
|
+
_licensed = false;
|
|
128
|
+
constructor(options = {}) {
|
|
129
|
+
this.licenseToken = options.licenseToken ?? null;
|
|
130
|
+
this.fps = options.fps ?? 30;
|
|
131
|
+
this.textureFrames = options.textureFrames ?? false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The running Gravix camera while the room's camera is on (for `<GravixPreview camera={...}>`, looks, stats). */
|
|
135
|
+
get camera() {
|
|
136
|
+
return this._camera;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The published WebRTC track while the camera is on. */
|
|
140
|
+
get track() {
|
|
141
|
+
return this._output?.videoTrack ?? null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Whether the effects packages are installed and can run on this platform. */
|
|
145
|
+
static isAvailable() {
|
|
146
|
+
if (Platform.OS !== 'android') return false;
|
|
147
|
+
const m = gravixEffects();
|
|
148
|
+
try {
|
|
149
|
+
return !!m && m.GravixCamera.isSupported;
|
|
150
|
+
} catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The effects pack state (face models; `gravixEffectsPack=models` downloads them on first use). */
|
|
156
|
+
static async availability() {
|
|
157
|
+
if (!GravixBeautyEffect.isAvailable()) return null;
|
|
158
|
+
return gravixEffects().GravixEffects.availability();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Downloads the effects pack if it is not ready (Flutter README: "download the
|
|
163
|
+
* pack when the user opens beauty"). Resolves to the final state; null when
|
|
164
|
+
* the effects packages are not installed.
|
|
165
|
+
*/
|
|
166
|
+
static async ensurePack(onProgress) {
|
|
167
|
+
if (!GravixBeautyEffect.isAvailable()) return null;
|
|
168
|
+
const fx = gravixEffects().GravixEffects;
|
|
169
|
+
const a = await fx.availability();
|
|
170
|
+
if (a.isReady) return a;
|
|
171
|
+
log(`effects pack ${a.state}; downloading`);
|
|
172
|
+
const r = await fx.download({
|
|
173
|
+
onProgress
|
|
174
|
+
});
|
|
175
|
+
log(`effects pack download -> ${r.state}${r.code ? ` (${r.code})` : ''}`);
|
|
176
|
+
return r;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The effects licence status now (`OK`, `MISSING`, `INVALID_SIGNATURE`,
|
|
181
|
+
* `MALFORMED`, `WRONG_PACKAGE`, `WRONG_CERT`, `EXPIRED`, and after an
|
|
182
|
+
* online check `LIMIT`, `REVOKED`, `UNKNOWN_APP`), or null when the effects
|
|
183
|
+
* packages are not installed. Anything but `OK` draws the watermark; the
|
|
184
|
+
* native SDK renews the token online by itself.
|
|
185
|
+
*/
|
|
186
|
+
static async licenseStatus() {
|
|
187
|
+
if (!GravixBeautyEffect.isAvailable()) return null;
|
|
188
|
+
return gravixEffects().GravixCamera.licenseStatus();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Loads the face model and the engine ahead of the first camera open
|
|
193
|
+
* (Flutter `preload`). Safe to call more than once; false where the effect
|
|
194
|
+
* cannot run.
|
|
195
|
+
*/
|
|
196
|
+
async preload() {
|
|
197
|
+
if (!(await this.canOwnCamera())) return false;
|
|
198
|
+
try {
|
|
199
|
+
return await gravixEffects().GravixCamera.preload();
|
|
200
|
+
} catch (e) {
|
|
201
|
+
log(`preload failed: ${String(e)}`);
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async canOwnCamera() {
|
|
206
|
+
return GravixBeautyEffect.isAvailable();
|
|
207
|
+
}
|
|
208
|
+
async openCamera(options) {
|
|
209
|
+
await this.close();
|
|
210
|
+
const m = gravixEffects();
|
|
211
|
+
if (!m) throw new Error('gravix-beauty: react-native-gravix-effects-webrtc is not installed');
|
|
212
|
+
if (!this._licensed) {
|
|
213
|
+
const status = await m.GravixCamera.setLicense(this.licenseToken);
|
|
214
|
+
log(`license ${status}`);
|
|
215
|
+
this._licensed = true;
|
|
216
|
+
}
|
|
217
|
+
if (!(await m.GravixCamera.requestPermission())) {
|
|
218
|
+
throw new Error('gravix-beauty: camera permission denied');
|
|
219
|
+
}
|
|
220
|
+
const cam = await m.GravixCamera.start({
|
|
221
|
+
lens: options.position,
|
|
222
|
+
fps: options.fps || this.fps,
|
|
223
|
+
streamResolution: options.shortSide
|
|
224
|
+
});
|
|
225
|
+
try {
|
|
226
|
+
const out = await m.GravixWebRtc.attach(cam, {
|
|
227
|
+
textureFrames: this.textureFrames
|
|
228
|
+
});
|
|
229
|
+
this._camera = cam;
|
|
230
|
+
this._output = out;
|
|
231
|
+
log(`camera open: lens=${options.position} fps=${options.fps} stream=${cam.streamSize.width}x${cam.streamSize.height}`);
|
|
232
|
+
return out.videoTrack;
|
|
233
|
+
} catch (e) {
|
|
234
|
+
await cam.stop();
|
|
235
|
+
throw e;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async attach(target) {
|
|
239
|
+
const t = this._output?.videoTrack;
|
|
240
|
+
return !!t && target.track.mediaStreamTrack?.id === t.id;
|
|
241
|
+
}
|
|
242
|
+
detach() {
|
|
243
|
+
return this.close();
|
|
244
|
+
}
|
|
245
|
+
async switchCamera() {
|
|
246
|
+
const cam = this._camera;
|
|
247
|
+
if (!cam) throw new Error('gravix-beauty: the camera is not open');
|
|
248
|
+
return cam.switchCamera();
|
|
249
|
+
}
|
|
250
|
+
async setEnabled(enabled) {
|
|
251
|
+
await this._camera?.setEnabled(enabled);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Applies `look` / `lookBytes` (base64 .gfx), then the adjustment groups
|
|
256
|
+
* `tone` / `region` / `reshape` (values absolute, null removes one), then
|
|
257
|
+
* `lut` (built-in name) / `lutBytes` (base64 PNG; null for either resets the
|
|
258
|
+
* LUT). That is the replay order a new camera session needs. Each step runs
|
|
259
|
+
* even if an earlier one fails; the first error is rethrown at the end.
|
|
260
|
+
*/
|
|
261
|
+
async setParams(params) {
|
|
262
|
+
const cam = this._camera;
|
|
263
|
+
if (!cam) return;
|
|
264
|
+
let first;
|
|
265
|
+
const step = async f => {
|
|
266
|
+
try {
|
|
267
|
+
await f();
|
|
268
|
+
} catch (e) {
|
|
269
|
+
first ??= e;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const look = params.look;
|
|
273
|
+
if (typeof look === 'string') await step(() => cam.setBuiltinLook(look));
|
|
274
|
+
const bytes = params.lookBytes;
|
|
275
|
+
if (typeof bytes === 'string') await step(() => cam.setLookBytes(bytes));
|
|
276
|
+
const adj = v => {
|
|
277
|
+
if (!v || typeof v !== 'object') return undefined;
|
|
278
|
+
const out = {};
|
|
279
|
+
for (const [k, x] of Object.entries(v)) {
|
|
280
|
+
if (typeof x === 'number' || x === null) out[k] = x;else log(`adjustment "${k}" skipped: not a number`);
|
|
281
|
+
}
|
|
282
|
+
return out;
|
|
283
|
+
};
|
|
284
|
+
const tone = adj(params.tone);
|
|
285
|
+
const region = adj(params.region);
|
|
286
|
+
const reshape = adj(params.reshape);
|
|
287
|
+
if (tone || region || reshape) {
|
|
288
|
+
await step(async () => {
|
|
289
|
+
const warnings = await cam.setAdjustments({
|
|
290
|
+
tone,
|
|
291
|
+
region,
|
|
292
|
+
reshape
|
|
293
|
+
});
|
|
294
|
+
if (warnings.length) log(`adjustments: ${warnings.join(', ')}`);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if ('lut' in params || 'lutBytes' in params) {
|
|
298
|
+
const name = params.lut;
|
|
299
|
+
const png = params.lutBytes;
|
|
300
|
+
if (typeof name === 'string' && cam.setLut) await step(() => cam.setLut(name));else if (typeof png === 'string' && cam.setLutBytes) await step(() => cam.setLutBytes(png));else if (name == null && png == null && cam.resetLut) await step(() => cam.resetLut());else log('LUT param skipped: this effects package has no LUT call for it');
|
|
301
|
+
}
|
|
302
|
+
if (first !== undefined) throw first;
|
|
303
|
+
}
|
|
304
|
+
async close() {
|
|
305
|
+
const cam = this._camera;
|
|
306
|
+
const out = this._output;
|
|
307
|
+
this._camera = null;
|
|
308
|
+
this._output = null;
|
|
309
|
+
if (cam) {
|
|
310
|
+
try {
|
|
311
|
+
await cam.stop(); // also detaches the WebRTC output (its stop hook)
|
|
312
|
+
log('camera closed');
|
|
313
|
+
} finally {
|
|
314
|
+
await out?.detach().catch(() => undefined); // normally done by the stop hook
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const ADJUSTMENT_GROUPS = new Set(['tone', 'region', 'reshape']);
|
|
320
|
+
|
|
321
|
+
/** Merges effect params: later keys win; the adjustment groups merge name by name. @internal */
|
|
322
|
+
export function mergeEffectParams(prev, next) {
|
|
323
|
+
const out = {
|
|
324
|
+
...(prev ?? {})
|
|
325
|
+
};
|
|
326
|
+
for (const [k, v] of Object.entries(next)) {
|
|
327
|
+
const old = out[k];
|
|
328
|
+
if (ADJUSTMENT_GROUPS.has(k) && v && typeof v === 'object' && old && typeof old === 'object') {
|
|
329
|
+
out[k] = {
|
|
330
|
+
...old,
|
|
331
|
+
...v
|
|
332
|
+
};
|
|
333
|
+
} else if (ADJUSTMENT_GROUPS.has(k) && v && typeof v === 'object') {
|
|
334
|
+
out[k] = {
|
|
335
|
+
...v
|
|
336
|
+
}; // a copy: later changes by the app do not reach the replay
|
|
337
|
+
} else {
|
|
338
|
+
out[k] = v;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// a new look replaces the other look source
|
|
342
|
+
if ('look' in next && !('lookBytes' in next)) delete out.lookBytes;
|
|
343
|
+
if ('lookBytes' in next && !('look' in next)) delete out.look;
|
|
344
|
+
if ('lut' in next && !('lutBytes' in next)) delete out.lutBytes;
|
|
345
|
+
if ('lutBytes' in next && !('lut' in next)) delete out.lut;
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// ── the lifecycle binding (Flutter GravixVideoEffectBinding) ──
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Drives a {@link GravixVideoEffect} from the camera lifecycle and remembers
|
|
353
|
+
* the app's enabled / params so they are replayed after every attach.
|
|
354
|
+
* @internal exported for tests.
|
|
355
|
+
*/
|
|
356
|
+
export class GravixVideoEffectBinding {
|
|
357
|
+
_active = false;
|
|
358
|
+
_enabled = true;
|
|
359
|
+
_disposed = false;
|
|
360
|
+
|
|
361
|
+
/** Merge successive setParams maps for the replay (default true); false = Flutter's replace. */
|
|
362
|
+
|
|
363
|
+
constructor(effect, options = {}) {
|
|
364
|
+
this.effect = effect;
|
|
365
|
+
this.mergeParams = options.mergeParams ?? true;
|
|
366
|
+
}
|
|
367
|
+
get active() {
|
|
368
|
+
return this._active;
|
|
369
|
+
}
|
|
370
|
+
get enabled() {
|
|
371
|
+
return this._enabled;
|
|
372
|
+
}
|
|
373
|
+
get params() {
|
|
374
|
+
return this._params;
|
|
375
|
+
}
|
|
376
|
+
get target() {
|
|
377
|
+
return this._target;
|
|
378
|
+
}
|
|
379
|
+
get cameraOwner() {
|
|
380
|
+
return isCameraEffect(this.effect) ? this.effect : undefined;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** The capture frame rate: `base`, raised to the effect's minFps. */
|
|
384
|
+
captureFps(base) {
|
|
385
|
+
const min = this.effect?.minFps;
|
|
386
|
+
return min != null && min > base ? min : base;
|
|
387
|
+
}
|
|
388
|
+
setActive(v) {
|
|
389
|
+
if (this._active === v) return;
|
|
390
|
+
this._active = v;
|
|
391
|
+
this.onActiveChanged?.(v);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** The camera track is live (first start or after a flip). Never throws. */
|
|
395
|
+
async onCameraTrack(target) {
|
|
396
|
+
const fx = this.effect;
|
|
397
|
+
if (!fx || this._disposed) return false;
|
|
398
|
+
this._target = target;
|
|
399
|
+
let ok;
|
|
400
|
+
try {
|
|
401
|
+
ok = await fx.attach(target);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
log(`effect "${fx.name}" attach failed: ${String(e)}`);
|
|
404
|
+
ok = false;
|
|
405
|
+
}
|
|
406
|
+
if (this._disposed) return false;
|
|
407
|
+
if (ok) {
|
|
408
|
+
try {
|
|
409
|
+
if (this._params) await fx.setParams(this._params);
|
|
410
|
+
} catch (e) {
|
|
411
|
+
log(`effect "${fx.name}" params replay failed: ${String(e)}`);
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
await fx.setEnabled(this._enabled);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
log(`effect "${fx.name}" enable replay failed: ${String(e)}`);
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
log(`effect "${fx.name}" is not processing the camera track (attach answered false)`);
|
|
420
|
+
}
|
|
421
|
+
this.setActive(ok);
|
|
422
|
+
return ok;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** The camera stopped / the room went away. Never throws. */
|
|
426
|
+
async onCameraStopped() {
|
|
427
|
+
const fx = this.effect;
|
|
428
|
+
const wasAttached = this._target !== undefined;
|
|
429
|
+
this._target = undefined;
|
|
430
|
+
if (!this._disposed) this.setActive(false);
|
|
431
|
+
if (!fx || !wasAttached) return;
|
|
432
|
+
try {
|
|
433
|
+
await fx.detach();
|
|
434
|
+
} catch (e) {
|
|
435
|
+
log(`effect "${fx.name}" detach failed: ${String(e)}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
async setEnabled(enabled) {
|
|
439
|
+
this._enabled = enabled;
|
|
440
|
+
if (!this.effect || !this._active) return;
|
|
441
|
+
await this.effect.setEnabled(enabled);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Remembers `params` for the replay after the next attach and applies them
|
|
446
|
+
* now when the effect is active. With [mergeParams] (default) the replay map
|
|
447
|
+
* is the MERGE of every call (top-level keys; the `tone` / `region` /
|
|
448
|
+
* `reshape` groups name by name), so a look set by one call and sliders set
|
|
449
|
+
* by a later one both come back after a camera off/on. Flutter 0.12.2
|
|
450
|
+
* replaces the map instead (its baseline finding 3); `mergeParams: false`
|
|
451
|
+
* restores that behaviour. Live, only this call's params are applied.
|
|
452
|
+
*/
|
|
453
|
+
async setParams(params) {
|
|
454
|
+
this._params = this.mergeParams ? mergeEffectParams(this._params, params) : {
|
|
455
|
+
...params
|
|
456
|
+
};
|
|
457
|
+
if (!this.effect || !this._active) return;
|
|
458
|
+
await this.effect.setParams(this.mergeParams ? params : this._params);
|
|
459
|
+
}
|
|
460
|
+
async dispose() {
|
|
461
|
+
await this.onCameraStopped();
|
|
462
|
+
this._disposed = true;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** owner.detach() that never rejects (callers promise true / false). */
|
|
467
|
+
async function safeDetach(owner) {
|
|
468
|
+
try {
|
|
469
|
+
await owner.detach();
|
|
470
|
+
} catch (e) {
|
|
471
|
+
log(`closing the "${owner.name}" camera failed: ${String(e)}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ── the room camera (the camera part of Flutter GravixRoomService) ──
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* The room's camera with an optional video effect: Flutter
|
|
479
|
+
* `GravixRoomService.setCameraEnabled / switchCamera / setVideoEffectEnabled /
|
|
480
|
+
* setVideoEffectParams / videoEffectActive / cameraPosition`.
|
|
481
|
+
*
|
|
482
|
+
* With a camera-owning effect ({@link GravixBeautyEffect}) the effect opens the
|
|
483
|
+
* camera and this class publishes its track as the room's camera; off =
|
|
484
|
+
* unpublish + the effect closes the camera; on again = a fresh camera with the
|
|
485
|
+
* remembered enabled / params replayed. Without one (or when it cannot own the
|
|
486
|
+
* camera) the core's `localParticipant.setCameraEnabled` runs.
|
|
487
|
+
*
|
|
488
|
+
* Use this instead of `localParticipant.setCameraEnabled` for the camera:
|
|
489
|
+
* calling both opens two cameras.
|
|
490
|
+
*/
|
|
491
|
+
export class GravixRoomCamera {
|
|
492
|
+
_cameraEnabled = false;
|
|
493
|
+
_ownedTrack = null;
|
|
494
|
+
_queue = Promise.resolve();
|
|
495
|
+
_disposed = false;
|
|
496
|
+
listeners = new Set();
|
|
497
|
+
onDisconnected = () => {
|
|
498
|
+
this.serial(() => this.closeAfterLeave()).catch(() => undefined);
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* The room could not republish the camera after a full reconnect / region
|
|
502
|
+
* move (Flutter LocalTrackRepublishFailedEvent): the camera is off. An
|
|
503
|
+
* unpublish during the reconnect itself is not a loss (the same track is
|
|
504
|
+
* republished), so only this event counts.
|
|
505
|
+
*/
|
|
506
|
+
onRepublishFailed = info => {
|
|
507
|
+
const i = info;
|
|
508
|
+
const t = this._ownedTrack;
|
|
509
|
+
if (t && i?.track === t) {
|
|
510
|
+
log('the room could not republish the effect camera; closing the camera');
|
|
511
|
+
this.serial(() => this.closeAfterLeave()).catch(() => undefined);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (!t && i?.source === Track.Source.Camera && this._cameraEnabled) {
|
|
515
|
+
log('the room could not republish the camera; camera off');
|
|
516
|
+
this.serial(async () => {
|
|
517
|
+
this._cameraEnabled = false;
|
|
518
|
+
await this.binding.onCameraStopped();
|
|
519
|
+
this.emit();
|
|
520
|
+
}).catch(() => undefined);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
constructor(room, options = {}) {
|
|
524
|
+
this.room = room;
|
|
525
|
+
this.binding = new GravixVideoEffectBinding(options.videoEffect, {
|
|
526
|
+
mergeParams: options.mergeEffectParams
|
|
527
|
+
});
|
|
528
|
+
this.binding.onActiveChanged = () => this.emit();
|
|
529
|
+
this.baseFps = options.captureFps ?? 24;
|
|
530
|
+
this.shortSide = options.shortSide ?? 540;
|
|
531
|
+
this._position = options.cameraPosition ?? 'front';
|
|
532
|
+
this.openDuringConnect = options.openCameraDuringConnect ?? true;
|
|
533
|
+
this.publishOptions = options.publishOptions ?? GRAVIX_CAMERA_PUBLISH_OPTIONS;
|
|
534
|
+
room.on(RoomEvent.Disconnected, this.onDisconnected);
|
|
535
|
+
room.on(RoomEvent.LocalTrackRepublishFailed, this.onRepublishFailed);
|
|
536
|
+
}
|
|
537
|
+
get videoEffect() {
|
|
538
|
+
return this.binding.effect;
|
|
539
|
+
}
|
|
540
|
+
/** True while the effect reports it processes the live camera track. */
|
|
541
|
+
get videoEffectActive() {
|
|
542
|
+
return this.binding.active;
|
|
543
|
+
}
|
|
544
|
+
get isCameraEnabled() {
|
|
545
|
+
return this._cameraEnabled;
|
|
546
|
+
}
|
|
547
|
+
get cameraPosition() {
|
|
548
|
+
return this._position;
|
|
549
|
+
}
|
|
550
|
+
/** The published camera track (effect-owned or normal), if any. */
|
|
551
|
+
get localVideoTrack() {
|
|
552
|
+
const t = this.room.localParticipant?.getTrackPublication(Track.Source.Camera)?.track;
|
|
553
|
+
return t instanceof LocalVideoTrack ? t : undefined;
|
|
554
|
+
}
|
|
555
|
+
get state() {
|
|
556
|
+
return {
|
|
557
|
+
cameraEnabled: this._cameraEnabled,
|
|
558
|
+
videoEffectActive: this.binding.active,
|
|
559
|
+
cameraPosition: this._position
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** Subscribe to state changes; returns the unsubscribe function. */
|
|
564
|
+
addListener(listener) {
|
|
565
|
+
this.listeners.add(listener);
|
|
566
|
+
return () => this.listeners.delete(listener);
|
|
567
|
+
}
|
|
568
|
+
emit() {
|
|
569
|
+
const s = this.state;
|
|
570
|
+
for (const l of this.listeners) {
|
|
571
|
+
try {
|
|
572
|
+
l(s);
|
|
573
|
+
} catch {
|
|
574
|
+
/* a listener's error is its own */
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/** Calls run one after another; each waits for the one before it. */
|
|
580
|
+
serial(f) {
|
|
581
|
+
const run = this._queue.then(f, f);
|
|
582
|
+
this._queue = run.catch(() => undefined);
|
|
583
|
+
return run;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** Turn [videoEffect] on/off (a bypass; the camera keeps running). Remembered across camera off/on. */
|
|
587
|
+
setVideoEffectEnabled(enabled) {
|
|
588
|
+
return this.binding.setEnabled(enabled);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** Effect parameters; remembered and replayed after every camera open. */
|
|
592
|
+
setVideoEffectParams(params) {
|
|
593
|
+
return this.binding.setParams(params);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Camera on/off. Resolves true when the camera ended up as asked. The newest
|
|
598
|
+
* call decides: a call overtaken by a later one returns without touching the camera.
|
|
599
|
+
*/
|
|
600
|
+
setCameraEnabled(enabled) {
|
|
601
|
+
this._wanted = enabled;
|
|
602
|
+
return this.serial(async () => {
|
|
603
|
+
if (this._disposed) return false;
|
|
604
|
+
if (this._wanted !== enabled) return this._cameraEnabled === enabled; // overtaken
|
|
605
|
+
const ok = await this.applyCamera(enabled);
|
|
606
|
+
this.emit();
|
|
607
|
+
return ok;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Joins the room with the camera on (Flutter `connect(enableVideo: true)`).
|
|
613
|
+
* With an effect that owns the camera, the camera opens while the room
|
|
614
|
+
* connects and is published as soon as it is up; with the normal camera it
|
|
615
|
+
* is turned on right after the connect. The join declares `media: 'video'`
|
|
616
|
+
* unless `options.media` is set, so it never lands on an audio-only region.
|
|
617
|
+
* Rejects when the room does not connect (the camera opened for it is
|
|
618
|
+
* closed); otherwise resolves with the camera result, like
|
|
619
|
+
* {@link setCameraEnabled}.
|
|
620
|
+
*/
|
|
621
|
+
async connect(url, token, options = {}) {
|
|
622
|
+
this._wanted = true; // before any await: a later setCameraEnabled(false) wins
|
|
623
|
+
const opts = {
|
|
624
|
+
media: 'video',
|
|
625
|
+
...options
|
|
626
|
+
};
|
|
627
|
+
const owner = this.binding.cameraOwner;
|
|
628
|
+
if (!this.openDuringConnect || !owner || !(await owner.canOwnCamera())) {
|
|
629
|
+
await this.room.connect(url, token, opts);
|
|
630
|
+
if (this._wanted !== true || this._disposed) return this._cameraEnabled; // a newer off wins
|
|
631
|
+
return this.setCameraEnabled(true);
|
|
632
|
+
}
|
|
633
|
+
const connected = this.room.connect(url, token, opts);
|
|
634
|
+
const camera = this.serial(async () => {
|
|
635
|
+
if (this._disposed || this._cameraEnabled) {
|
|
636
|
+
await connected.catch(() => undefined);
|
|
637
|
+
return this._cameraEnabled;
|
|
638
|
+
}
|
|
639
|
+
if (this._wanted !== true) {
|
|
640
|
+
await connected.catch(() => undefined);
|
|
641
|
+
return this._cameraEnabled; // turned off before the camera opened
|
|
642
|
+
}
|
|
643
|
+
const opened = this.openOwnedTrack(owner);
|
|
644
|
+
const [up, track] = await Promise.all([connected.then(() => true, () => false), opened]);
|
|
645
|
+
if (!track) return false; // as setCameraEnabled: no fallback to the normal camera
|
|
646
|
+
if (!up || this._wanted !== true || this._disposed) {
|
|
647
|
+
track.stop();
|
|
648
|
+
await safeDetach(owner);
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
const ok = await this.publishOwned(owner, track);
|
|
652
|
+
this.emit();
|
|
653
|
+
return ok;
|
|
654
|
+
});
|
|
655
|
+
// settle both: a failed connect rejects only after the camera job closed its camera
|
|
656
|
+
const [c, cam] = await Promise.allSettled([connected, camera]);
|
|
657
|
+
if (c.status === 'rejected') throw c.reason;
|
|
658
|
+
return cam.status === 'fulfilled' ? cam.value : false;
|
|
659
|
+
}
|
|
660
|
+
async applyCamera(enabled) {
|
|
661
|
+
const lp = this.room.localParticipant;
|
|
662
|
+
if (!lp) return false;
|
|
663
|
+
const owner = this.binding.cameraOwner;
|
|
664
|
+
if (enabled) {
|
|
665
|
+
// the room dropped the effect track (e.g. republish disabled): reopen, Flutter's
|
|
666
|
+
// ownsTrack check. Only while connected: a reconnect republishes the same track.
|
|
667
|
+
if (this._ownedTrack && String(this.room.state) === 'connected' && this.localVideoTrack !== this._ownedTrack) {
|
|
668
|
+
await this.closeAfterLeave();
|
|
669
|
+
}
|
|
670
|
+
if (this._cameraEnabled) return true;
|
|
671
|
+
if (owner && (await owner.canOwnCamera())) {
|
|
672
|
+
return this.openOwned(owner);
|
|
673
|
+
}
|
|
674
|
+
return this.openNormal();
|
|
675
|
+
}
|
|
676
|
+
if (!this._cameraEnabled && !this._ownedTrack) return true;
|
|
677
|
+
if (this._ownedTrack) {
|
|
678
|
+
await this.closeOwned();
|
|
679
|
+
} else {
|
|
680
|
+
try {
|
|
681
|
+
await lp.setCameraEnabled(false);
|
|
682
|
+
} catch (e) {
|
|
683
|
+
log(`camera off failed: ${String(e)}`);
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
await this.binding.onCameraStopped();
|
|
687
|
+
}
|
|
688
|
+
this._cameraEnabled = false;
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
691
|
+
async openOwned(owner) {
|
|
692
|
+
const track = await this.openOwnedTrack(owner);
|
|
693
|
+
return track ? this.publishOwned(owner, track) : false;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** Opens the effect's camera; null when it could not. */
|
|
697
|
+
async openOwnedTrack(owner) {
|
|
698
|
+
try {
|
|
699
|
+
const mst = await owner.openCamera({
|
|
700
|
+
position: this._position,
|
|
701
|
+
fps: this.binding.captureFps(this.baseFps),
|
|
702
|
+
shortSide: this.shortSide
|
|
703
|
+
});
|
|
704
|
+
return new LocalVideoTrack(mst, undefined, true);
|
|
705
|
+
} catch (e) {
|
|
706
|
+
log(`"${owner.name}" could not open the camera: ${String(e)}`);
|
|
707
|
+
await safeDetach(owner);
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
async publishOwned(owner, track) {
|
|
712
|
+
try {
|
|
713
|
+
await this.room.localParticipant.publishTrack(track, {
|
|
714
|
+
...this.publishOptions,
|
|
715
|
+
source: Track.Source.Camera
|
|
716
|
+
});
|
|
717
|
+
} catch (e) {
|
|
718
|
+
log(`publishing the "${owner.name}" camera failed: ${String(e)}`);
|
|
719
|
+
await safeDetach(owner);
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
this._ownedTrack = track;
|
|
723
|
+
this._cameraEnabled = true;
|
|
724
|
+
await this.binding.onCameraTrack({
|
|
725
|
+
track
|
|
726
|
+
});
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
729
|
+
async closeOwned() {
|
|
730
|
+
const track = this._ownedTrack;
|
|
731
|
+
this._ownedTrack = null;
|
|
732
|
+
this._cameraEnabled = false;
|
|
733
|
+
if (track) {
|
|
734
|
+
try {
|
|
735
|
+
await this.room.localParticipant?.unpublishTrack(track, true);
|
|
736
|
+
} catch (e) {
|
|
737
|
+
log(`unpublishing the effect camera failed: ${String(e)}`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
// onCameraStopped detaches the effect, which closes the effect's camera.
|
|
741
|
+
const owner = this.binding.cameraOwner;
|
|
742
|
+
const hadTarget = this.binding.target !== undefined;
|
|
743
|
+
await this.binding.onCameraStopped();
|
|
744
|
+
if (owner && !hadTarget) await safeDetach(owner); // attach had answered false: still close it
|
|
745
|
+
}
|
|
746
|
+
async openNormal() {
|
|
747
|
+
const lp = this.room.localParticipant;
|
|
748
|
+
const fps = this.binding.captureFps(this.baseFps);
|
|
749
|
+
const s = this.shortSide;
|
|
750
|
+
try {
|
|
751
|
+
const pub = await lp.setCameraEnabled(true, {
|
|
752
|
+
facingMode: this._position === 'front' ? 'user' : 'environment',
|
|
753
|
+
resolution: {
|
|
754
|
+
width: Math.round(s * 16 / 9),
|
|
755
|
+
height: s,
|
|
756
|
+
frameRate: fps
|
|
757
|
+
}
|
|
758
|
+
}, this.publishOptions);
|
|
759
|
+
if (!pub) return false;
|
|
760
|
+
} catch (e) {
|
|
761
|
+
log(`camera on failed: ${String(e)}`);
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
this._cameraEnabled = true;
|
|
765
|
+
const t = this.localVideoTrack;
|
|
766
|
+
if (t && this.binding.effect) await this.binding.onCameraTrack({
|
|
767
|
+
track: t
|
|
768
|
+
});
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/** Front <-> back. With the effect owning the camera it flips its own lens (same track, no republish). */
|
|
773
|
+
switchCamera() {
|
|
774
|
+
return this.serial(async () => {
|
|
775
|
+
const owner = this.binding.cameraOwner;
|
|
776
|
+
if (owner && this._ownedTrack && this.binding.active) {
|
|
777
|
+
this._position = await owner.switchCamera();
|
|
778
|
+
this.emit();
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
// an effect track the effect is not processing: restarting it as a normal camera
|
|
782
|
+
// would stop it under the open Gravix camera
|
|
783
|
+
if (this._ownedTrack) return;
|
|
784
|
+
const t = this.localVideoTrack;
|
|
785
|
+
if (!t) return;
|
|
786
|
+
const next = this._position === 'front' ? 'back' : 'front';
|
|
787
|
+
await t.restartTrack({
|
|
788
|
+
facingMode: next === 'front' ? 'user' : 'environment'
|
|
789
|
+
});
|
|
790
|
+
this._position = next;
|
|
791
|
+
if (this.binding.effect) await this.binding.onCameraTrack({
|
|
792
|
+
track: t
|
|
793
|
+
});
|
|
794
|
+
this.emit();
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
async closeAfterLeave() {
|
|
798
|
+
const track = this._ownedTrack;
|
|
799
|
+
this._ownedTrack = null;
|
|
800
|
+
const wasEnabled = this._cameraEnabled;
|
|
801
|
+
this._cameraEnabled = false;
|
|
802
|
+
track?.stop();
|
|
803
|
+
const owner = this.binding.cameraOwner;
|
|
804
|
+
const hadTarget = this.binding.target !== undefined;
|
|
805
|
+
await this.binding.onCameraStopped();
|
|
806
|
+
if (owner && track && !hadTarget) await safeDetach(owner);
|
|
807
|
+
if (wasEnabled) this.emit();
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/** Closes the camera (effect or normal) and stops listening to the room. Call when the screen goes away. */
|
|
811
|
+
async dispose() {
|
|
812
|
+
this.room.off(RoomEvent.Disconnected, this.onDisconnected);
|
|
813
|
+
this.room.off(RoomEvent.LocalTrackRepublishFailed, this.onRepublishFailed);
|
|
814
|
+
this._wanted = false;
|
|
815
|
+
await this.serial(async () => {
|
|
816
|
+
try {
|
|
817
|
+
if (this._ownedTrack) await this.closeOwned();else if (this._cameraEnabled) await this.room.localParticipant?.setCameraEnabled(false);
|
|
818
|
+
} catch (e) {
|
|
819
|
+
log(`closing the camera on dispose failed: ${String(e)}`);
|
|
820
|
+
}
|
|
821
|
+
await this.binding.dispose();
|
|
822
|
+
this._disposed = true;
|
|
823
|
+
this._cameraEnabled = false;
|
|
824
|
+
});
|
|
825
|
+
this.listeners.clear();
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
//# sourceMappingURL=beauty.js.map
|