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,310 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import { Track, type Room } from 'gravix-rtc';
|
|
4
|
+
import { androidAudioFor } from '../android/bindings';
|
|
5
|
+
import { gravixMicMute, type GravixMicTrackLike } from '../android/micMute';
|
|
6
|
+
import { androidNoiseSuppressionStats } from '../android/noiseSuppression';
|
|
7
|
+
import { GravixAndroidRoomMusic } from '../android/roomMusic';
|
|
8
|
+
import { unsupported } from '../unsupported';
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_MUSIC_OPTIONS,
|
|
11
|
+
type GravixMusicSource,
|
|
12
|
+
type GravixMusicOptions,
|
|
13
|
+
type GravixMusicState,
|
|
14
|
+
type GravixMusicStartOptions,
|
|
15
|
+
} from './roomMusicTypes';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Android: the song is decoded natively and mixed into the published mic
|
|
19
|
+
* (one stream, `MusicMixerEngine`), with monitor, mic volume, ducking, loop,
|
|
20
|
+
* seek and the 0.12.2 mute rules. Not ported yet on React Native:
|
|
21
|
+
* `asset` sources (copy the file out and use `file`), the lyric-sync
|
|
22
|
+
* `gx.music` messages (`syncPosition`, `remotePositionNow` stays undefined),
|
|
23
|
+
* `musicMaxBitrate` / `disableDtxWhileMusic` (use the core's publish options).
|
|
24
|
+
*/
|
|
25
|
+
export class AndroidRoomMusic {
|
|
26
|
+
readonly options: Readonly<Required<GravixMusicOptions>>;
|
|
27
|
+
private room: Room | null = null;
|
|
28
|
+
private native: GravixAndroidRoomMusic | null = null;
|
|
29
|
+
private current: GravixMusicState = { status: 'idle', positionMs: 0 };
|
|
30
|
+
private stampAt = 0;
|
|
31
|
+
private unlisten: Array<() => void> = [];
|
|
32
|
+
|
|
33
|
+
constructor(options: GravixMusicOptions = {}) {
|
|
34
|
+
this.options = Object.freeze({ ...DEFAULT_MUSIC_OPTIONS, ...options });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get state(): GravixMusicState {
|
|
38
|
+
return this.current;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private android(op: string): GravixAndroidRoomMusic {
|
|
42
|
+
if (!androidAudioFor('roomMusic')) unsupported('roomMusic', op);
|
|
43
|
+
if (!this.native) {
|
|
44
|
+
const o = this.options;
|
|
45
|
+
this.native = new GravixAndroidRoomMusic({
|
|
46
|
+
musicVolume: o.musicVolume,
|
|
47
|
+
micVolume: o.micVolume,
|
|
48
|
+
ducking: o.ducking,
|
|
49
|
+
duckLevel: o.duckLevel,
|
|
50
|
+
loop: o.loop,
|
|
51
|
+
monitor: o.monitor,
|
|
52
|
+
continueWhileMicMuted: o.continueWhileMicMuted,
|
|
53
|
+
continueWhileMicReleased: o.continueWhileMicReleased,
|
|
54
|
+
pauseOnInterruption: o.pauseOnInterruption,
|
|
55
|
+
});
|
|
56
|
+
this.unlisten.push(
|
|
57
|
+
this.native.onCompleted(() => {
|
|
58
|
+
this.set({ status: 'idle', positionMs: 0 });
|
|
59
|
+
this.micAfterMusic().catch(() => {});
|
|
60
|
+
}),
|
|
61
|
+
this.native.onError((p) =>
|
|
62
|
+
this.set({
|
|
63
|
+
status: 'error',
|
|
64
|
+
error: String(p?.message ?? p?.code ?? 'error'),
|
|
65
|
+
})
|
|
66
|
+
),
|
|
67
|
+
this.native.onInterruption((p) => {
|
|
68
|
+
if (p?.active === true)
|
|
69
|
+
this.set({ status: 'paused', positionMs: this.positionNow() });
|
|
70
|
+
else if (p?.resumed === true) this.set({ status: 'playing' });
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return this.native;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private set(patch: Partial<GravixMusicState>): void {
|
|
78
|
+
this.current = { ...this.current, ...patch };
|
|
79
|
+
this.stampAt = Date.now();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async run(
|
|
83
|
+
op: string,
|
|
84
|
+
fn: (m: GravixAndroidRoomMusic) => Promise<unknown>
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
await fn(this.android(op));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The published mic track (null before it is published). */
|
|
90
|
+
private micTrack():
|
|
91
|
+
(GravixMicTrackLike & { mediaStreamTrack?: { id?: string } }) | null {
|
|
92
|
+
const pub = this.room?.localParticipant.getTrackPublication(
|
|
93
|
+
Track.Source.Microphone
|
|
94
|
+
);
|
|
95
|
+
return (
|
|
96
|
+
(pub?.track as unknown as GravixMicTrackLike & {
|
|
97
|
+
mediaStreamTrack?: { id?: string };
|
|
98
|
+
}) ?? null
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private relaxed = false;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* WebRTC NS / AGC / HPF relaxed while the song plays (Flutter relaxVoiceProcessing).
|
|
106
|
+
* Given back to WebRTC's defaults only while neither Gravix NS nor the singer
|
|
107
|
+
* capture is on (both want WebRTC's NS / AGC off).
|
|
108
|
+
*/
|
|
109
|
+
private async relax(on: boolean): Promise<void> {
|
|
110
|
+
if (!this.options.relaxVoiceProcessing || this.relaxed === on) return;
|
|
111
|
+
this.relaxed = on;
|
|
112
|
+
if (!on && !(await webrtcProcessingWanted())) return;
|
|
113
|
+
const id = this.micTrack()?.mediaStreamTrack?.id;
|
|
114
|
+
const b = androidAudioFor('roomMusic');
|
|
115
|
+
if (!id || !b) return;
|
|
116
|
+
try {
|
|
117
|
+
await b.call('setAudioProcessingOptions', {
|
|
118
|
+
trackId: id,
|
|
119
|
+
echoCancellation: true,
|
|
120
|
+
noiseSuppression: !on,
|
|
121
|
+
autoGainControl: !on,
|
|
122
|
+
highPassFilter: !on,
|
|
123
|
+
});
|
|
124
|
+
} catch {
|
|
125
|
+
// best effort: the song still plays through WebRTC's processing
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private async micAfterMusic(): Promise<void> {
|
|
130
|
+
const t = this.micTrack();
|
|
131
|
+
if (t && gravixMicMute.muteKind !== 'none')
|
|
132
|
+
await gravixMicMute.musicEnded(t);
|
|
133
|
+
await this.relax(false);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Binds the controller to a connected room (the published mic carries the mix). */
|
|
137
|
+
attach(room: Room): void {
|
|
138
|
+
this.android('attach');
|
|
139
|
+
this.room = room;
|
|
140
|
+
// A core mute (setMicrophoneEnabled(false)) during a voice-only mute takes the mute
|
|
141
|
+
// over: give back the module mute / recorder, or a later core unmute stays silent.
|
|
142
|
+
const lp = room.localParticipant as unknown as {
|
|
143
|
+
on(
|
|
144
|
+
e: string,
|
|
145
|
+
l: (pub: { source?: string; track?: unknown }) => void
|
|
146
|
+
): void;
|
|
147
|
+
off(
|
|
148
|
+
e: string,
|
|
149
|
+
l: (pub: { source?: string; track?: unknown }) => void
|
|
150
|
+
): void;
|
|
151
|
+
};
|
|
152
|
+
const onMuted = (pub: { source?: string; track?: unknown }) => {
|
|
153
|
+
if (pub?.source !== Track.Source.Microphone || !pub.track) return;
|
|
154
|
+
gravixMicMute.coreMuted(pub.track as GravixMicTrackLike).catch(() => {});
|
|
155
|
+
};
|
|
156
|
+
lp.on('trackMuted', onMuted);
|
|
157
|
+
this.unlisten.push(() => lp.off('trackMuted', onMuted));
|
|
158
|
+
}
|
|
159
|
+
/** Checks the source; the native decoder opens it on `start`. */
|
|
160
|
+
async prepare(source: GravixMusicSource): Promise<void> {
|
|
161
|
+
this.android('prepare');
|
|
162
|
+
sourcePath(source);
|
|
163
|
+
}
|
|
164
|
+
async start(
|
|
165
|
+
source: GravixMusicSource,
|
|
166
|
+
options: GravixMusicStartOptions = {}
|
|
167
|
+
): Promise<void> {
|
|
168
|
+
const m = this.android('start');
|
|
169
|
+
// A disabled mic has no record thread: nothing would clock the mixer and the room
|
|
170
|
+
// would hear nothing (Flutter re-opens the capture for the song; not ported yet).
|
|
171
|
+
if (this.micTrack()?.isMuted) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
'roomMusic.start: the microphone is muted; unmute it first (mute during the song with setMicMuted(true))'
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
this.set({
|
|
177
|
+
status: 'loading',
|
|
178
|
+
source,
|
|
179
|
+
title: options.title,
|
|
180
|
+
positionMs: 0,
|
|
181
|
+
error: undefined,
|
|
182
|
+
});
|
|
183
|
+
try {
|
|
184
|
+
const durationMs = await m.start(sourcePath(source), {
|
|
185
|
+
loop: options.loop ?? this.options.loop,
|
|
186
|
+
musicVolume: options.volume ?? m.currentOptions.musicVolume,
|
|
187
|
+
});
|
|
188
|
+
this.set({
|
|
189
|
+
status: 'playing',
|
|
190
|
+
durationMs: durationMs >= 0 ? durationMs : undefined,
|
|
191
|
+
});
|
|
192
|
+
await this.relax(true);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
this.set({ status: 'error', error: String(e) });
|
|
195
|
+
throw e;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
pause(): Promise<void> {
|
|
199
|
+
return this.run('pause', async (m) => {
|
|
200
|
+
await m.pause();
|
|
201
|
+
this.set({ status: 'paused', positionMs: this.positionNow() });
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
resume(): Promise<void> {
|
|
205
|
+
return this.run('resume', async (m) => {
|
|
206
|
+
await m.resume();
|
|
207
|
+
this.set({ status: 'playing' });
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
stop(): Promise<void> {
|
|
211
|
+
return this.run('stop', async (m) => {
|
|
212
|
+
await m.stop();
|
|
213
|
+
this.set({ status: 'idle', positionMs: 0, durationMs: undefined });
|
|
214
|
+
await this.micAfterMusic();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
seek(positionMs: number): Promise<void> {
|
|
218
|
+
return this.run('seek', async (m) => {
|
|
219
|
+
await m.seek(positionMs);
|
|
220
|
+
this.set({ positionMs });
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
setMusicVolume(volume: number): Promise<void> {
|
|
224
|
+
return this.run('setMusicVolume', (m) => m.setMusicVolume(volume));
|
|
225
|
+
}
|
|
226
|
+
setMicVolume(volume: number): Promise<void> {
|
|
227
|
+
return this.run('setMicVolume', (m) => m.setMicVolume(volume));
|
|
228
|
+
}
|
|
229
|
+
setDucking(on: boolean): Promise<void> {
|
|
230
|
+
return this.run('setDucking', (m) => m.setDucking(on));
|
|
231
|
+
}
|
|
232
|
+
setLoop(on: boolean): Promise<void> {
|
|
233
|
+
return this.run('setLoop', (m) => m.setLoop(on));
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Android: mutes / unmutes the mic while the song plays with the 0.12.2
|
|
237
|
+
* rules: `continueWhileMicMuted` keeps the song going out (voice zeroed,
|
|
238
|
+
* the publication stays live); with `GravixMicRelease.setMuteReleasesMic(true)`
|
|
239
|
+
* and `continueWhileMicReleased` the recorder is released too (OS mic
|
|
240
|
+
* indicator off). Without music, or with those off, it is a plain track mute.
|
|
241
|
+
*/
|
|
242
|
+
async setMicMuted(muted: boolean): Promise<void> {
|
|
243
|
+
this.android('setMicMuted');
|
|
244
|
+
const t = this.micTrack();
|
|
245
|
+
if (!t) throw new Error('roomMusic.setMicMuted: no published microphone');
|
|
246
|
+
const playing =
|
|
247
|
+
this.current.status === 'playing' || this.current.status === 'paused';
|
|
248
|
+
if (muted) {
|
|
249
|
+
if (!playing || !this.options.continueWhileMicMuted) {
|
|
250
|
+
await t.mute();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
await gravixMicMute.muteForMusic(
|
|
254
|
+
t,
|
|
255
|
+
gravixMicMute.muteReleasesMic && this.options.continueWhileMicReleased
|
|
256
|
+
);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (!(await gravixMicMute.unmuteFromMusic(t))) await t.unmute();
|
|
260
|
+
}
|
|
261
|
+
/** The singer's song position now, extrapolated from the last native stamp. */
|
|
262
|
+
positionNow(): number {
|
|
263
|
+
this.android('positionNow');
|
|
264
|
+
const c = this.current;
|
|
265
|
+
if (c.status !== 'playing') return c.positionMs;
|
|
266
|
+
const p = c.positionMs + (Date.now() - this.stampAt);
|
|
267
|
+
return c.durationMs !== undefined ? Math.min(p, c.durationMs) : p;
|
|
268
|
+
}
|
|
269
|
+
/** A listener's view of a singer's position (lyric sync over `gx.music`; not on React Native yet). */
|
|
270
|
+
remotePositionNow(_participantIdentity: string): number | undefined {
|
|
271
|
+
this.android('remotePositionNow');
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
async dispose(): Promise<void> {
|
|
275
|
+
for (const u of this.unlisten.splice(0)) u();
|
|
276
|
+
if (this.native && this.current.status !== 'idle') {
|
|
277
|
+
await this.native.stop().catch(() => {});
|
|
278
|
+
await this.micAfterMusic().catch(() => {});
|
|
279
|
+
}
|
|
280
|
+
this.native = null;
|
|
281
|
+
this.room = null;
|
|
282
|
+
this.current = { status: 'idle', positionMs: 0 };
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** False while Gravix NS runs or the native singer half is on (WebRTC's NS / AGC stay off). */
|
|
287
|
+
async function webrtcProcessingWanted(): Promise<boolean> {
|
|
288
|
+
try {
|
|
289
|
+
const s = await androidNoiseSuppressionStats();
|
|
290
|
+
if (!s) return true;
|
|
291
|
+
const ours = s.eng === 'rnnoise' || s.eng === 'dfn3';
|
|
292
|
+
return !ours && s.singerMode !== true;
|
|
293
|
+
} catch {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** The native source string: a file path or a content:// uri. */
|
|
299
|
+
function sourcePath(source: GravixMusicSource): string {
|
|
300
|
+
switch (source.kind) {
|
|
301
|
+
case 'file':
|
|
302
|
+
return source.path;
|
|
303
|
+
case 'contentUri':
|
|
304
|
+
return source.uri;
|
|
305
|
+
default:
|
|
306
|
+
throw new Error(
|
|
307
|
+
'roomMusic: asset sources are not supported on React Native Android yet; copy the asset to a file and use GravixMusicSource.file'
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import type { Room } from 'gravix-rtc';
|
|
4
|
+
import { unsupported, unsupportedAsync } from '../unsupported';
|
|
5
|
+
import {
|
|
6
|
+
iosAttach,
|
|
7
|
+
iosCall,
|
|
8
|
+
isIos,
|
|
9
|
+
onIosAudioEvent,
|
|
10
|
+
iosFeature,
|
|
11
|
+
} from '../ios/iosAudio';
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_MUSIC_OPTIONS,
|
|
14
|
+
type GravixMusicSource,
|
|
15
|
+
type GravixMusicOptions,
|
|
16
|
+
type GravixMusicState,
|
|
17
|
+
type GravixMusicStartOptions,
|
|
18
|
+
} from './roomMusicTypes';
|
|
19
|
+
|
|
20
|
+
type SingerRoom = {
|
|
21
|
+
singerMode?: boolean;
|
|
22
|
+
setSingerMode(
|
|
23
|
+
on: boolean,
|
|
24
|
+
options?: {
|
|
25
|
+
maxBitrate?: number;
|
|
26
|
+
disableDtx?: boolean;
|
|
27
|
+
echoCancellation?: boolean;
|
|
28
|
+
}
|
|
29
|
+
): Promise<unknown>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** Flutter `GravixRoomMusic.staleReading` / `maxExtrapolation`. */
|
|
33
|
+
const STALE_READING_MS = 200;
|
|
34
|
+
const MAX_EXTRAPOLATION_MS = 750;
|
|
35
|
+
|
|
36
|
+
type NativeMusicState = {
|
|
37
|
+
active?: boolean;
|
|
38
|
+
paused?: boolean;
|
|
39
|
+
positionMs?: number;
|
|
40
|
+
positionAgeUs?: number;
|
|
41
|
+
durationMs?: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** iOS: a file path or `file://` URL for the native decoder. */
|
|
45
|
+
function iosPath(source: GravixMusicSource): string {
|
|
46
|
+
if (source.kind === 'file') return source.path;
|
|
47
|
+
if (source.kind === 'asset') {
|
|
48
|
+
throw new Error(
|
|
49
|
+
'roomMusic on iOS needs a file path: resolve the asset to a local file first'
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
throw new Error('roomMusic: contentUri sources are Android only');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function clamp01(v: number | undefined, d: number): number {
|
|
56
|
+
return typeof v === 'number' && Number.isFinite(v)
|
|
57
|
+
? Math.min(Math.max(v, 0), 1)
|
|
58
|
+
: d;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* iOS: the song is mixed natively after noise suppression and the voice
|
|
63
|
+
* effect (Flutter 0.12 post-effect route). A mute that releases the mic also
|
|
64
|
+
* silences the song for listeners and holds its position (iOS has no
|
|
65
|
+
* voice-only mute). Lyric sync (`gx.music`) is not part of the iOS native
|
|
66
|
+
* port; see docs/IOS_NATIVE_HOOKS.md.
|
|
67
|
+
*
|
|
68
|
+
* iOS applies musicVolume, micVolume, ducking, duckLevel, loop, monitor and
|
|
69
|
+
* postEffectMix. musicMaxBitrate / disableDtxWhileMusic / relaxVoiceProcessing
|
|
70
|
+
* go through gravix-rtc's `room.setSingerMode(true, ...)` while the song
|
|
71
|
+
* plays (needs {@link IosRoomMusic.attach}; an app-owned singer mode is left
|
|
72
|
+
* alone) and are undone when it stops. Not applied on iOS:
|
|
73
|
+
* pauseOnInterruption, continueWhileMicMuted, continueWhileMicReleased,
|
|
74
|
+
* syncPosition.
|
|
75
|
+
*/
|
|
76
|
+
export class IosRoomMusic {
|
|
77
|
+
readonly options: Readonly<Required<GravixMusicOptions>>;
|
|
78
|
+
|
|
79
|
+
private st: GravixMusicState = { status: 'idle', positionMs: 0 };
|
|
80
|
+
private sampledAt = 0;
|
|
81
|
+
/** Age of the native position stamp at the last reading (ms). */
|
|
82
|
+
private readingAgeMs = 0;
|
|
83
|
+
private timer: ReturnType<typeof setInterval> | null = null;
|
|
84
|
+
private offCompleted: (() => void) | null = null;
|
|
85
|
+
private room: SingerRoom | null = null;
|
|
86
|
+
/** Singer mode was turned on by this controller (undo on stop). */
|
|
87
|
+
private singerOurs = false;
|
|
88
|
+
|
|
89
|
+
constructor(options: GravixMusicOptions = {}) {
|
|
90
|
+
this.options = Object.freeze({ ...DEFAULT_MUSIC_OPTIONS, ...options });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get state(): GravixMusicState {
|
|
94
|
+
return this.st;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Binds the controller to a connected room (the published mic carries the mix). */
|
|
98
|
+
attach(room: Room): void {
|
|
99
|
+
if (!iosFeature('roomMusic')) unsupported('roomMusic', 'attach');
|
|
100
|
+
// iOS: the mix runs in the capture chain of whatever mic is published;
|
|
101
|
+
// the room is for the music bitrate / DTX (singer mode).
|
|
102
|
+
this.room = room as unknown as SingerRoom;
|
|
103
|
+
}
|
|
104
|
+
/** Decodes ahead so `start` begins without a gap. */
|
|
105
|
+
async prepare(source: GravixMusicSource): Promise<void> {
|
|
106
|
+
if (!iosFeature('roomMusic'))
|
|
107
|
+
return unsupportedAsync('roomMusic', 'prepare');
|
|
108
|
+
iosPath(source); // validates; iOS opens the file on start
|
|
109
|
+
}
|
|
110
|
+
async start(
|
|
111
|
+
source: GravixMusicSource,
|
|
112
|
+
options?: GravixMusicStartOptions
|
|
113
|
+
): Promise<void> {
|
|
114
|
+
if (!iosFeature('roomMusic')) return unsupportedAsync('roomMusic', 'start');
|
|
115
|
+
const o = this.options;
|
|
116
|
+
if (!o.postEffectMix) {
|
|
117
|
+
throw new Error('roomMusic on iOS supports only postEffectMix: true');
|
|
118
|
+
}
|
|
119
|
+
await iosAttach();
|
|
120
|
+
this.st = {
|
|
121
|
+
status: 'loading',
|
|
122
|
+
source,
|
|
123
|
+
positionMs: 0,
|
|
124
|
+
title: options?.title,
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const r = await iosCall<{ durationMs?: number }>('music.start', {
|
|
128
|
+
source: iosPath(source),
|
|
129
|
+
musicVolume: clamp01(options?.volume ?? o.musicVolume, 1),
|
|
130
|
+
micVolume: clamp01(o.micVolume, 1),
|
|
131
|
+
ducking: o.ducking,
|
|
132
|
+
duckLevel: clamp01(o.duckLevel, 0.35),
|
|
133
|
+
monitor: o.monitor,
|
|
134
|
+
loop: options?.loop ?? o.loop,
|
|
135
|
+
postMix: true,
|
|
136
|
+
});
|
|
137
|
+
this.st = {
|
|
138
|
+
status: 'playing',
|
|
139
|
+
source,
|
|
140
|
+
positionMs: 0,
|
|
141
|
+
durationMs:
|
|
142
|
+
typeof r?.durationMs === 'number' ? r.durationMs : undefined,
|
|
143
|
+
title: options?.title,
|
|
144
|
+
};
|
|
145
|
+
this.sampledAt = Date.now();
|
|
146
|
+
this.watch();
|
|
147
|
+
await this.singerOn();
|
|
148
|
+
} catch (e) {
|
|
149
|
+
this.st = {
|
|
150
|
+
status: 'error',
|
|
151
|
+
source,
|
|
152
|
+
positionMs: 0,
|
|
153
|
+
error: String((e as Error)?.message ?? e),
|
|
154
|
+
};
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async pause(): Promise<void> {
|
|
159
|
+
if (!iosFeature('roomMusic')) return unsupportedAsync('roomMusic', 'pause');
|
|
160
|
+
await iosCall('music.pause');
|
|
161
|
+
await this.refresh();
|
|
162
|
+
}
|
|
163
|
+
async resume(): Promise<void> {
|
|
164
|
+
if (!iosFeature('roomMusic'))
|
|
165
|
+
return unsupportedAsync('roomMusic', 'resume');
|
|
166
|
+
await iosCall('music.resume');
|
|
167
|
+
await this.refresh();
|
|
168
|
+
}
|
|
169
|
+
async stop(): Promise<void> {
|
|
170
|
+
if (!iosFeature('roomMusic')) return unsupportedAsync('roomMusic', 'stop');
|
|
171
|
+
await iosCall('music.stop');
|
|
172
|
+
this.idle();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Music bitrate / DTX / processing for the song (Flutter music session). */
|
|
176
|
+
private async singerOn(): Promise<void> {
|
|
177
|
+
const r = this.room;
|
|
178
|
+
const o = this.options;
|
|
179
|
+
if (!r || typeof r.setSingerMode !== 'function' || r.singerMode) return;
|
|
180
|
+
if (!o.disableDtxWhileMusic && o.musicMaxBitrate <= 0) return;
|
|
181
|
+
this.singerOurs = true;
|
|
182
|
+
try {
|
|
183
|
+
await r.setSingerMode(true, {
|
|
184
|
+
maxBitrate: o.musicMaxBitrate > 0 ? o.musicMaxBitrate : undefined,
|
|
185
|
+
disableDtx: o.disableDtxWhileMusic,
|
|
186
|
+
echoCancellation: true,
|
|
187
|
+
});
|
|
188
|
+
} catch {
|
|
189
|
+
// the song plays at the voice bitrate
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private singerOff(): void {
|
|
194
|
+
if (!this.singerOurs) return;
|
|
195
|
+
this.singerOurs = false;
|
|
196
|
+
this.room?.setSingerMode(false)?.catch?.(() => {});
|
|
197
|
+
}
|
|
198
|
+
async seek(positionMs: number): Promise<void> {
|
|
199
|
+
if (!iosFeature('roomMusic')) return unsupportedAsync('roomMusic', 'seek');
|
|
200
|
+
await iosCall('music.seekTo', {
|
|
201
|
+
positionMs: Math.max(0, Math.round(positionMs)),
|
|
202
|
+
});
|
|
203
|
+
await this.refresh();
|
|
204
|
+
}
|
|
205
|
+
async setMusicVolume(volume: number): Promise<void> {
|
|
206
|
+
if (!iosFeature('roomMusic'))
|
|
207
|
+
return unsupportedAsync('roomMusic', 'setMusicVolume');
|
|
208
|
+
await iosCall('music.setVolume', { volume: clamp01(volume, 1) });
|
|
209
|
+
}
|
|
210
|
+
async setMicVolume(volume: number): Promise<void> {
|
|
211
|
+
if (!iosFeature('roomMusic'))
|
|
212
|
+
return unsupportedAsync('roomMusic', 'setMicVolume');
|
|
213
|
+
await iosCall('music.setMicVolume', { volume: clamp01(volume, 1) });
|
|
214
|
+
}
|
|
215
|
+
async setDucking(on: boolean): Promise<void> {
|
|
216
|
+
if (!iosFeature('roomMusic'))
|
|
217
|
+
return unsupportedAsync('roomMusic', 'setDucking');
|
|
218
|
+
await iosCall('music.setDucking', {
|
|
219
|
+
on,
|
|
220
|
+
level: clamp01(this.options.duckLevel, 0.35),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async setLoop(on: boolean): Promise<void> {
|
|
224
|
+
if (!iosFeature('roomMusic'))
|
|
225
|
+
return unsupportedAsync('roomMusic', 'setLoop');
|
|
226
|
+
await iosCall('music.setLoop', { on });
|
|
227
|
+
}
|
|
228
|
+
/** The singer's song position now, extrapolated from the last native stamp. */
|
|
229
|
+
positionNow(): number {
|
|
230
|
+
if (!iosFeature('roomMusic'))
|
|
231
|
+
return unsupported('roomMusic', 'positionNow');
|
|
232
|
+
if (this.st.status !== 'playing') return this.st.positionMs;
|
|
233
|
+
// Flutter rules: a native reading older than STALE_READING_MS means the
|
|
234
|
+
// song is not advancing (capture stopped / muted): hold at the reading;
|
|
235
|
+
// never run more than MAX_EXTRAPOLATION_MS past it.
|
|
236
|
+
if (this.readingAgeMs > STALE_READING_MS) return this.st.positionMs;
|
|
237
|
+
const age = Math.min(
|
|
238
|
+
Math.max(Date.now() - this.sampledAt, 0),
|
|
239
|
+
MAX_EXTRAPOLATION_MS
|
|
240
|
+
);
|
|
241
|
+
const p = this.st.positionMs + age;
|
|
242
|
+
return this.st.durationMs ? Math.min(p, this.st.durationMs) : p;
|
|
243
|
+
}
|
|
244
|
+
/** A listener's view of a singer's position (lyric sync over `gx.music`). */
|
|
245
|
+
remotePositionNow(_participantIdentity: string): number | undefined {
|
|
246
|
+
return unsupported('roomMusic', 'remotePositionNow');
|
|
247
|
+
}
|
|
248
|
+
async dispose(): Promise<void> {
|
|
249
|
+
if (isIos() && this.st.status !== 'idle') {
|
|
250
|
+
try {
|
|
251
|
+
await iosCall('music.stop');
|
|
252
|
+
} catch {
|
|
253
|
+
// already stopped
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
this.idle();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private watch(): void {
|
|
260
|
+
if (!this.offCompleted) {
|
|
261
|
+
this.offCompleted = onIosAudioEvent('music.onCompleted', () =>
|
|
262
|
+
this.idle()
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (!this.timer) {
|
|
266
|
+
this.timer = setInterval(() => {
|
|
267
|
+
this.refresh().catch(() => {});
|
|
268
|
+
}, 500);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private idle(): void {
|
|
273
|
+
this.singerOff();
|
|
274
|
+
if (this.timer) clearInterval(this.timer);
|
|
275
|
+
this.timer = null;
|
|
276
|
+
this.offCompleted?.();
|
|
277
|
+
this.offCompleted = null;
|
|
278
|
+
this.st = { status: 'idle', positionMs: 0 };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private async refresh(): Promise<void> {
|
|
282
|
+
const m = await iosCall<NativeMusicState>('music.getState');
|
|
283
|
+
if (!m.active) {
|
|
284
|
+
if (this.st.status === 'playing' || this.st.status === 'paused')
|
|
285
|
+
this.idle();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this.st = {
|
|
289
|
+
...this.st,
|
|
290
|
+
status: m.paused ? 'paused' : 'playing',
|
|
291
|
+
positionMs: Math.max(0, Number(m.positionMs ?? 0)),
|
|
292
|
+
durationMs:
|
|
293
|
+
typeof m.durationMs === 'number' && m.durationMs >= 0
|
|
294
|
+
? m.durationMs
|
|
295
|
+
: this.st.durationMs,
|
|
296
|
+
};
|
|
297
|
+
this.readingAgeMs = Math.round(Number(m.positionAgeUs ?? 0) / 1000);
|
|
298
|
+
this.sampledAt = Date.now() - this.readingAgeMs;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Room music / karaoke: a local audio file mixed into the published
|
|
5
|
+
* microphone (Flutter `GravixRoomMusic`). Native-only: until the platform
|
|
6
|
+
* implements it, every call throws `GravixUnsupportedError`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Where the song comes from (Flutter `GravixMusicSource`). */
|
|
10
|
+
export type GravixMusicSource =
|
|
11
|
+
| { kind: 'file'; path: string }
|
|
12
|
+
| { kind: 'contentUri'; uri: string }
|
|
13
|
+
| { kind: 'asset'; key: string };
|
|
14
|
+
|
|
15
|
+
export const GravixMusicSource = {
|
|
16
|
+
file: (path: string): GravixMusicSource => ({ kind: 'file', path }),
|
|
17
|
+
/** Android `content://` uri (e.g. from a document picker). */
|
|
18
|
+
contentUri: (uri: string): GravixMusicSource => ({ kind: 'contentUri', uri }),
|
|
19
|
+
/** A file bundled with the app. */
|
|
20
|
+
asset: (key: string): GravixMusicSource => ({ kind: 'asset', key }),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Same fields and defaults as Flutter `GravixMusicOptions` (0.12.2). */
|
|
24
|
+
export interface GravixMusicOptions {
|
|
25
|
+
/** Song level in the mix, 0..1. Default 1. */
|
|
26
|
+
musicVolume?: number;
|
|
27
|
+
/** Voice level in the mix, 0..1. Default 1. */
|
|
28
|
+
micVolume?: number;
|
|
29
|
+
/** Lower the song while the singer talks. Default false. */
|
|
30
|
+
ducking?: boolean;
|
|
31
|
+
/** Song level while ducked, 0..1. Default 0.35. */
|
|
32
|
+
duckLevel?: number;
|
|
33
|
+
loop?: boolean;
|
|
34
|
+
/** The singer hears the song locally. Default true. */
|
|
35
|
+
monitor?: boolean;
|
|
36
|
+
/** Mic bitrate while music plays, bps. Default 96000. */
|
|
37
|
+
musicMaxBitrate?: number;
|
|
38
|
+
/** The song keeps going out while the mic is muted. Default true. */
|
|
39
|
+
continueWhileMicMuted?: boolean;
|
|
40
|
+
/** The song keeps going out while mute has released the mic (0.12.2, Android). Default true. */
|
|
41
|
+
continueWhileMicReleased?: boolean;
|
|
42
|
+
pauseOnInterruption?: boolean;
|
|
43
|
+
disableDtxWhileMusic?: boolean;
|
|
44
|
+
relaxVoiceProcessing?: boolean;
|
|
45
|
+
/** Mix after the voice effect so the effect stays on while the song plays. Default true. */
|
|
46
|
+
postEffectMix?: boolean;
|
|
47
|
+
/** Send `gx.music` position messages so listeners can sync lyrics. Default true. */
|
|
48
|
+
syncPosition?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const DEFAULT_MUSIC_OPTIONS: Readonly<Required<GravixMusicOptions>> =
|
|
52
|
+
Object.freeze({
|
|
53
|
+
musicVolume: 1.0,
|
|
54
|
+
micVolume: 1.0,
|
|
55
|
+
ducking: false,
|
|
56
|
+
duckLevel: 0.35,
|
|
57
|
+
loop: false,
|
|
58
|
+
monitor: true,
|
|
59
|
+
musicMaxBitrate: 96000,
|
|
60
|
+
continueWhileMicMuted: true,
|
|
61
|
+
continueWhileMicReleased: true,
|
|
62
|
+
pauseOnInterruption: true,
|
|
63
|
+
disableDtxWhileMusic: true,
|
|
64
|
+
relaxVoiceProcessing: true,
|
|
65
|
+
postEffectMix: true,
|
|
66
|
+
syncPosition: true,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export type GravixMusicStatus =
|
|
70
|
+
'idle' | 'loading' | 'playing' | 'paused' | 'error';
|
|
71
|
+
|
|
72
|
+
export interface GravixMusicState {
|
|
73
|
+
status: GravixMusicStatus;
|
|
74
|
+
source?: GravixMusicSource;
|
|
75
|
+
positionMs: number;
|
|
76
|
+
durationMs?: number;
|
|
77
|
+
title?: string;
|
|
78
|
+
error?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A singer position sample (Flutter `GravixMusicPosition`). */
|
|
82
|
+
export interface GravixMusicPosition {
|
|
83
|
+
positionMs: number;
|
|
84
|
+
sampledAt: number;
|
|
85
|
+
playing: boolean;
|
|
86
|
+
durationMs?: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Data topic of the listener lyric-sync messages (Flutter `kGravixMusicSyncTopic`). */
|
|
90
|
+
export const GRAVIX_MUSIC_SYNC_TOPIC = 'gx.music';
|
|
91
|
+
|
|
92
|
+
export interface GravixMusicStartOptions {
|
|
93
|
+
loop?: boolean;
|
|
94
|
+
volume?: number;
|
|
95
|
+
trackId?: string;
|
|
96
|
+
title?: string;
|
|
97
|
+
}
|