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.
Files changed (378) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +20 -0
  3. package/LICENSES/Apache-2.0.txt +175 -0
  4. package/NOTICE +68 -0
  5. package/README.md +313 -2
  6. package/android/build.gradle +137 -0
  7. package/android/consumer-rules.pro +29 -0
  8. package/android/src/main/AndroidManifest.xml +9 -0
  9. package/android/src/main/cpp/CMakeLists.txt +48 -0
  10. package/android/src/main/cpp/gx_dfn_engine.c +332 -0
  11. package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
  12. package/android/src/main/cpp/gx_ns_jni.c +162 -0
  13. package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
  14. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
  15. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
  16. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
  17. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
  18. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
  19. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
  20. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
  21. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
  22. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
  23. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
  24. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
  25. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
  26. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
  27. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
  28. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
  29. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
  30. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
  31. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
  32. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
  33. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
  34. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
  35. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
  36. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
  37. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
  38. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
  39. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
  40. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
  41. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
  42. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
  43. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
  44. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
  45. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
  46. package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
  47. package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
  48. package/docs/FEATURE_MATRIX.md +192 -0
  49. package/docs/IOS_NATIVE_HOOKS.md +190 -0
  50. package/gravix-rtc-react-native.podspec +49 -0
  51. package/ios/GravixRtc.h +7 -0
  52. package/ios/GravixRtc.mm +273 -0
  53. package/ios/GravixRtcSetup.h +29 -0
  54. package/ios/GravixRtcSetup.m +52 -0
  55. package/ios/audio/GravixRtcIosAudio.m +157 -0
  56. package/ios/audio/GxAudioDevice.h +62 -0
  57. package/ios/audio/GxAudioDevice.m +857 -0
  58. package/ios/audio/GxAudioSetup.h +34 -0
  59. package/ios/audio/GxAudioSetup.m +70 -0
  60. package/ios/audio/GxCompat.swift +53 -0
  61. package/ios/audio/GxIosAudio.swift +99 -0
  62. package/ios/audio/GxMusicController.swift +150 -0
  63. package/ios/audio/GxMusicPost.swift +362 -0
  64. package/ios/audio/GxNoiseProcessor.swift +718 -0
  65. package/ios/audio/GxNsDfn3CoreML.swift +195 -0
  66. package/ios/audio/GxNsStudioEngine.swift +237 -0
  67. package/ios/audio/GxNsStudioPack.swift +212 -0
  68. package/ios/audio/GxVoiceFx.swift +161 -0
  69. package/ios/audio/gx_adm_state.h +153 -0
  70. package/ios/gxcore/apple/gx_music_post.c +312 -0
  71. package/ios/gxcore/apple/gx_pcm.c +30 -0
  72. package/ios/gxcore/apple/gxns_build.h +19 -0
  73. package/ios/gxcore/apple/gxns_ios.c +17 -0
  74. package/ios/gxcore/apple/include/gx_fx.h +3 -0
  75. package/ios/gxcore/apple/include/gx_music_post.h +88 -0
  76. package/ios/gxcore/apple/include/gx_ns.h +3 -0
  77. package/ios/gxcore/apple/include/gx_pcm.h +33 -0
  78. package/ios/gxcore/apple/include/gxns_ios.h +18 -0
  79. package/ios/gxcore/apple/include/module.modulemap +10 -0
  80. package/ios/gxcore/apple/shim/rnnoise.h +2 -0
  81. package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
  82. package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
  83. package/ios/gxcore/apple/units/gx_ns.c +7 -0
  84. package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
  85. package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
  86. package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
  87. package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
  88. package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
  89. package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
  90. package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
  91. package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
  92. package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
  93. package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
  94. package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
  95. package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
  96. package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
  97. package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
  98. package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
  99. package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
  100. package/lib/module/android/bindings.js +49 -0
  101. package/lib/module/android/bindings.js.map +1 -0
  102. package/lib/module/android/index.js +13 -0
  103. package/lib/module/android/index.js.map +1 -0
  104. package/lib/module/android/micMute.js +341 -0
  105. package/lib/module/android/micMute.js.map +1 -0
  106. package/lib/module/android/nativeAudio.js +47 -0
  107. package/lib/module/android/nativeAudio.js.map +1 -0
  108. package/lib/module/android/noiseSuppression.js +170 -0
  109. package/lib/module/android/noiseSuppression.js.map +1 -0
  110. package/lib/module/android/roomMusic.js +142 -0
  111. package/lib/module/android/roomMusic.js.map +1 -0
  112. package/lib/module/android/singerMode.js +31 -0
  113. package/lib/module/android/singerMode.js.map +1 -0
  114. package/lib/module/android/voiceEffects.js +65 -0
  115. package/lib/module/android/voiceEffects.js.map +1 -0
  116. package/lib/module/audio/AudioManager.js +79 -0
  117. package/lib/module/audio/AudioManager.js.map +1 -0
  118. package/lib/module/audio/AudioSession.js +90 -0
  119. package/lib/module/audio/AudioSession.js.map +1 -0
  120. package/lib/module/audio/remoteVolume.js +54 -0
  121. package/lib/module/audio/remoteVolume.js.map +1 -0
  122. package/lib/module/components/VideoView.js +109 -0
  123. package/lib/module/components/VideoView.js.map +1 -0
  124. package/lib/module/features/audioScenario.js +53 -0
  125. package/lib/module/features/audioScenario.js.map +1 -0
  126. package/lib/module/features/beauty.js +828 -0
  127. package/lib/module/features/beauty.js.map +1 -0
  128. package/lib/module/features/micRelease.js +89 -0
  129. package/lib/module/features/micRelease.js.map +1 -0
  130. package/lib/module/features/noiseSuppression.js +213 -0
  131. package/lib/module/features/noiseSuppression.js.map +1 -0
  132. package/lib/module/features/roomMusic.js +90 -0
  133. package/lib/module/features/roomMusic.js.map +1 -0
  134. package/lib/module/features/roomMusicAndroid.js +294 -0
  135. package/lib/module/features/roomMusicAndroid.js.map +1 -0
  136. package/lib/module/features/roomMusicIos.js +250 -0
  137. package/lib/module/features/roomMusicIos.js.map +1 -0
  138. package/lib/module/features/roomMusicTypes.js +53 -0
  139. package/lib/module/features/roomMusicTypes.js.map +1 -0
  140. package/lib/module/features/screenShare.js +22 -0
  141. package/lib/module/features/screenShare.js.map +1 -0
  142. package/lib/module/features/singerMode.js +73 -0
  143. package/lib/module/features/singerMode.js.map +1 -0
  144. package/lib/module/features/voiceEffects.js +148 -0
  145. package/lib/module/features/voiceEffects.js.map +1 -0
  146. package/lib/module/hooks/context.js +34 -0
  147. package/lib/module/hooks/context.js.map +1 -0
  148. package/lib/module/hooks/hooks.js +145 -0
  149. package/lib/module/hooks/hooks.js.map +1 -0
  150. package/lib/module/hooks/types.js +4 -0
  151. package/lib/module/hooks/types.js.map +1 -0
  152. package/lib/module/hooks/useRoomEvents.js +30 -0
  153. package/lib/module/hooks/useRoomEvents.js.map +1 -0
  154. package/lib/module/index.js +43 -0
  155. package/lib/module/index.js.map +1 -0
  156. package/lib/module/ios/autoAttach.js +14 -0
  157. package/lib/module/ios/autoAttach.js.map +1 -0
  158. package/lib/module/ios/iosAudio.js +149 -0
  159. package/lib/module/ios/iosAudio.js.map +1 -0
  160. package/lib/module/join/appStateLifecycle.js +54 -0
  161. package/lib/module/join/appStateLifecycle.js.map +1 -0
  162. package/lib/module/micPolicy.js +249 -0
  163. package/lib/module/micPolicy.js.map +1 -0
  164. package/lib/module/native/NativeGravixAudio.js +18 -0
  165. package/lib/module/native/NativeGravixAudio.js.map +1 -0
  166. package/lib/module/native/NativeGravixRtc.js +13 -0
  167. package/lib/module/native/NativeGravixRtc.js.map +1 -0
  168. package/lib/module/native/module.js +23 -0
  169. package/lib/module/native/module.js.map +1 -0
  170. package/lib/module/package.json +1 -0
  171. package/lib/module/polyfills/DOMException.js +22 -0
  172. package/lib/module/polyfills/DOMException.js.map +1 -0
  173. package/lib/module/polyfills/early.js +18 -0
  174. package/lib/module/polyfills/early.js.map +1 -0
  175. package/lib/module/polyfills/event.js +71 -0
  176. package/lib/module/polyfills/event.js.map +1 -0
  177. package/lib/module/polyfills/sha256.js +92 -0
  178. package/lib/module/polyfills/sha256.js.map +1 -0
  179. package/lib/module/polyfills/subtleHmac.js +91 -0
  180. package/lib/module/polyfills/subtleHmac.js.map +1 -0
  181. package/lib/module/polyfills/textCoding.js +164 -0
  182. package/lib/module/polyfills/textCoding.js.map +1 -0
  183. package/lib/module/registerGlobals.js +135 -0
  184. package/lib/module/registerGlobals.js.map +1 -0
  185. package/lib/module/unsupported.js +90 -0
  186. package/lib/module/unsupported.js.map +1 -0
  187. package/lib/module/version.js +7 -0
  188. package/lib/module/version.js.map +1 -0
  189. package/lib/typescript/package.json +1 -0
  190. package/lib/typescript/src/android/bindings.d.ts +14 -0
  191. package/lib/typescript/src/android/bindings.d.ts.map +1 -0
  192. package/lib/typescript/src/android/index.d.ts +9 -0
  193. package/lib/typescript/src/android/index.d.ts.map +1 -0
  194. package/lib/typescript/src/android/micMute.d.ts +124 -0
  195. package/lib/typescript/src/android/micMute.d.ts.map +1 -0
  196. package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
  197. package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
  198. package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
  199. package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
  200. package/lib/typescript/src/android/roomMusic.d.ts +80 -0
  201. package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
  202. package/lib/typescript/src/android/singerMode.d.ts +27 -0
  203. package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
  204. package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
  205. package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
  206. package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
  207. package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
  208. package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
  209. package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
  210. package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
  211. package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
  212. package/lib/typescript/src/components/VideoView.d.ts +44 -0
  213. package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
  214. package/lib/typescript/src/features/audioScenario.d.ts +24 -0
  215. package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
  216. package/lib/typescript/src/features/beauty.d.ts +377 -0
  217. package/lib/typescript/src/features/beauty.d.ts.map +1 -0
  218. package/lib/typescript/src/features/micRelease.d.ts +28 -0
  219. package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
  220. package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
  221. package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
  222. package/lib/typescript/src/features/roomMusic.d.ts +41 -0
  223. package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
  224. package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
  225. package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
  226. package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
  227. package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
  228. package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
  229. package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
  230. package/lib/typescript/src/features/screenShare.d.ts +12 -0
  231. package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
  232. package/lib/typescript/src/features/singerMode.d.ts +20 -0
  233. package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
  234. package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
  235. package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
  236. package/lib/typescript/src/hooks/context.d.ts +12 -0
  237. package/lib/typescript/src/hooks/context.d.ts.map +1 -0
  238. package/lib/typescript/src/hooks/hooks.d.ts +54 -0
  239. package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
  240. package/lib/typescript/src/hooks/types.d.ts +8 -0
  241. package/lib/typescript/src/hooks/types.d.ts.map +1 -0
  242. package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
  243. package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
  244. package/lib/typescript/src/index.d.ts +37 -0
  245. package/lib/typescript/src/index.d.ts.map +1 -0
  246. package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
  247. package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
  248. package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
  249. package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
  250. package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
  251. package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
  252. package/lib/typescript/src/micPolicy.d.ts +104 -0
  253. package/lib/typescript/src/micPolicy.d.ts.map +1 -0
  254. package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
  255. package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
  256. package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
  257. package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
  258. package/lib/typescript/src/native/module.d.ts +7 -0
  259. package/lib/typescript/src/native/module.d.ts.map +1 -0
  260. package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
  261. package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
  262. package/lib/typescript/src/polyfills/early.d.ts +2 -0
  263. package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
  264. package/lib/typescript/src/polyfills/event.d.ts +2 -0
  265. package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
  266. package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
  267. package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
  268. package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
  269. package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
  270. package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
  271. package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
  272. package/lib/typescript/src/registerGlobals.d.ts +42 -0
  273. package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
  274. package/lib/typescript/src/unsupported.d.ts +42 -0
  275. package/lib/typescript/src/unsupported.d.ts.map +1 -0
  276. package/lib/typescript/src/version.d.ts +3 -0
  277. package/lib/typescript/src/version.d.ts.map +1 -0
  278. package/metro/index.js +39 -0
  279. package/metro/noise-stub.js +10 -0
  280. package/native/gxfx/include/gx_fx.h +82 -0
  281. package/native/gxfx/src/gx_fx.cpp +527 -0
  282. package/native/gxfx/third_party/README.md +4 -0
  283. package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
  284. package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
  285. package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
  286. package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
  287. package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
  288. package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
  289. package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
  290. package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
  291. package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
  292. package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
  293. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
  294. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
  295. package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
  296. package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
  297. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
  298. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
  299. package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
  300. package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
  301. package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
  302. package/native/gxns/CMakeLists.txt +67 -0
  303. package/native/gxns/include/gx_ns.h +285 -0
  304. package/native/gxns/src/gx_ns.c +1518 -0
  305. package/native/gxns/src/gx_ns_timer.c +84 -0
  306. package/native/gxns/src/gx_ns_timer.h +29 -0
  307. package/native/gxns/third_party/VENDOR.md +43 -0
  308. package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
  309. package/native/gxns/third_party/rnnoise/COPYING +31 -0
  310. package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
  311. package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
  312. package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
  313. package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
  314. package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
  315. package/native/gxns/third_party/rnnoise/src/common.h +48 -0
  316. package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
  317. package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
  318. package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
  319. package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
  320. package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
  321. package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
  322. package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
  323. package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
  324. package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
  325. package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
  326. package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
  327. package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
  328. package/native/gxns/third_party/speexdsp/COPYING +35 -0
  329. package/native/gxns/third_party/speexdsp/arch.h +232 -0
  330. package/native/gxns/third_party/speexdsp/resample.c +1239 -0
  331. package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
  332. package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
  333. package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
  334. package/package.json +186 -4
  335. package/src/android/bindings.ts +61 -0
  336. package/src/android/index.ts +10 -0
  337. package/src/android/micMute.ts +422 -0
  338. package/src/android/nativeAudio.ts +94 -0
  339. package/src/android/noiseSuppression.ts +209 -0
  340. package/src/android/roomMusic.ts +193 -0
  341. package/src/android/singerMode.ts +53 -0
  342. package/src/android/voiceEffects.ts +126 -0
  343. package/src/audio/AudioManager.ts +111 -0
  344. package/src/audio/AudioSession.ts +190 -0
  345. package/src/audio/remoteVolume.ts +58 -0
  346. package/src/components/VideoView.tsx +152 -0
  347. package/src/features/audioScenario.ts +58 -0
  348. package/src/features/beauty.ts +1057 -0
  349. package/src/features/micRelease.ts +108 -0
  350. package/src/features/noiseSuppression.ts +251 -0
  351. package/src/features/roomMusic.ts +106 -0
  352. package/src/features/roomMusicAndroid.ts +310 -0
  353. package/src/features/roomMusicIos.ts +300 -0
  354. package/src/features/roomMusicTypes.ts +97 -0
  355. package/src/features/screenShare.ts +19 -0
  356. package/src/features/singerMode.ts +70 -0
  357. package/src/features/voiceEffects.ts +245 -0
  358. package/src/hooks/context.tsx +38 -0
  359. package/src/hooks/hooks.ts +247 -0
  360. package/src/hooks/types.ts +10 -0
  361. package/src/hooks/useRoomEvents.ts +35 -0
  362. package/src/index.tsx +134 -0
  363. package/src/ios/autoAttach.ts +11 -0
  364. package/src/ios/iosAudio.ts +202 -0
  365. package/src/join/appStateLifecycle.ts +55 -0
  366. package/src/micPolicy.ts +312 -0
  367. package/src/native/NativeGravixAudio.ts +30 -0
  368. package/src/native/NativeGravixRtc.ts +38 -0
  369. package/src/native/module.ts +22 -0
  370. package/src/polyfills/DOMException.ts +20 -0
  371. package/src/polyfills/early.ts +16 -0
  372. package/src/polyfills/event.ts +88 -0
  373. package/src/polyfills/sha256.ts +112 -0
  374. package/src/polyfills/subtleHmac.ts +124 -0
  375. package/src/polyfills/textCoding.ts +197 -0
  376. package/src/registerGlobals.ts +201 -0
  377. package/src/unsupported.ts +139 -0
  378. package/src/version.ts +4 -0
@@ -0,0 +1,19 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import { unsupportedAsync } from '../unsupported';
4
+
5
+ /**
6
+ * Screen share needs a foreground service (Android MediaProjection) or a
7
+ * broadcast upload extension (iOS). react-native-webrtc has the
8
+ * capture parts; the Gravix wiring (service, extension, app-group setup) is
9
+ * not done yet. `localParticipant.setScreenShareEnabled` may work on Android
10
+ * when the app declares the media-projection service itself.
11
+ */
12
+ export const GravixScreenShare = {
13
+ start(): Promise<void> {
14
+ return unsupportedAsync('screenShareService', 'start');
15
+ },
16
+ stop(): Promise<void> {
17
+ return unsupportedAsync('screenShareService', 'stop');
18
+ },
19
+ };
@@ -0,0 +1,70 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import { androidAudioFor } from '../android/bindings';
4
+ import { setAndroidSingerMode } from '../android/singerMode';
5
+ import { GravixUnsupportedError, unsupportedAsync } from '../unsupported';
6
+ import { iosAttach, iosCall, iosFeature } from '../ios/iosAudio';
7
+
8
+ /**
9
+ * Singer mode, native half. The publish half (processing off, DTX off,
10
+ * 96 kbps) is gravix-rtc's `room.setSingerMode(on, options)` and works in React
11
+ * Native today. What needs native code is the recorder source switch and the
12
+ * level normaliser (Flutter `GravixSingerCaptureSource`, `GxSingerSource.kt`).
13
+ *
14
+ * iOS (as in Flutter): there is no recorder source switch (the voice
15
+ * processing unit belongs to the audio session); singer mode bypasses the
16
+ * Gravix noise suppression chain instead. Any source other than `keep`
17
+ * turns that bypass on, `keep` turns it off. The level normaliser is Android
18
+ * only.
19
+ */
20
+ export type GravixSingerCaptureSource =
21
+ 'keep' | 'mic' | 'voiceRecognition' | 'unprocessed';
22
+
23
+ const singer = { source: 'keep' as GravixSingerCaptureSource, level: false };
24
+
25
+ /**
26
+ * Android: one native call (Flutter `nsSetSingerMode`). The native singer half
27
+ * is on while a source other than `keep` or the level normaliser is set: our
28
+ * NS / AGC / pause expander are bypassed, the recorder re-opens with the
29
+ * source (no audio device module rebuild). `setCaptureSource('keep')` plus
30
+ * `setLevelNormaliser(false)` turns it off.
31
+ */
32
+ async function applySinger(op: string): Promise<void> {
33
+ if (!androidAudioFor('singerMode')) {
34
+ return unsupportedAsync('singerMode', op);
35
+ }
36
+ const on = singer.source !== 'keep' || singer.level;
37
+ const r = await setAndroidSingerMode(on, {
38
+ source: singer.source,
39
+ levelNormalizer: singer.level,
40
+ });
41
+ if (!r.ok) throw new Error(`singerMode.${op}: the native side refused`);
42
+ }
43
+
44
+ export const GravixSingerCapture = {
45
+ /** Switches the Android/iOS recorder source while singer mode is on. */
46
+ async setCaptureSource(source: GravixSingerCaptureSource): Promise<void> {
47
+ if (androidAudioFor('singerMode')) {
48
+ singer.source = source;
49
+ return applySinger('setCaptureSource');
50
+ }
51
+ if (!iosFeature('singerMode'))
52
+ return unsupportedAsync('singerMode', 'setCaptureSource');
53
+ singer.source = source;
54
+ await iosAttach();
55
+ await iosCall('nsSetSingerMode', { on: source !== 'keep', source });
56
+ },
57
+ /** Singer level normaliser (makeup gain, pause guard) in the capture chain. Android only. */
58
+ setLevelNormaliser(on: boolean): Promise<void> {
59
+ if (androidAudioFor('singerMode')) {
60
+ singer.level = on;
61
+ return applySinger('setLevelNormaliser');
62
+ }
63
+ if (iosFeature('singerMode')) {
64
+ return Promise.reject(
65
+ new GravixUnsupportedError('singerMode', 'setLevelNormaliser', 'ios')
66
+ );
67
+ }
68
+ return unsupportedAsync('singerMode', 'setLevelNormaliser');
69
+ },
70
+ };
@@ -0,0 +1,245 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import { androidAudioFor } from '../android/bindings';
4
+ import {
5
+ androidVoiceEffectStats,
6
+ benchmarkAndroidVoiceEffect,
7
+ setAndroidVoiceEffect,
8
+ } from '../android/voiceEffects';
9
+ import { unsupportedAsync } from '../unsupported';
10
+ import {
11
+ iosAttach,
12
+ iosCall,
13
+ onIosAudioEvent,
14
+ iosFeature,
15
+ } from '../ios/iosAudio';
16
+
17
+ /**
18
+ * Voice effects applied to the published microphone (Flutter
19
+ * `GravixVoiceEffect`, 35 effects + `none`). Native-only: until the platform
20
+ * implements it, {@link GravixVoiceEffects.set} throws `GravixUnsupportedError`.
21
+ */
22
+ export const GRAVIX_VOICE_EFFECTS = [
23
+ 'none',
24
+ 'studio',
25
+ 'hall',
26
+ 'robot',
27
+ 'girl',
28
+ 'transformer',
29
+ 'boy',
30
+ 'child',
31
+ 'woman',
32
+ 'man',
33
+ 'foreigner',
34
+ 'ethereal',
35
+ 'magnetic',
36
+ 'fresh',
37
+ 'energetic',
38
+ 'rich',
39
+ 'muffled',
40
+ 'round',
41
+ 'falsetto',
42
+ 'full',
43
+ 'clear',
44
+ 'resonant',
45
+ 'loudClear',
46
+ 'softRoom',
47
+ 'largeRoom',
48
+ 'valley',
49
+ 'basement',
50
+ 'ktv',
51
+ 'enhancedKtv',
52
+ 'popular',
53
+ 'rock',
54
+ 'vocalConcert',
55
+ 'gramophone',
56
+ 'autotuneMajorC',
57
+ 'autotuneMinorA',
58
+ 'autotuneHarmonicMinor',
59
+ ] as const;
60
+
61
+ export type GravixVoiceEffect = (typeof GRAVIX_VOICE_EFFECTS)[number];
62
+
63
+ /** Why the active effect differs from the requested one (Flutter `GravixVoiceEffectReason`). */
64
+ export type GravixVoiceEffectReason =
65
+ 'ok' | 'platformUnsupported' | 'libraryMissing' | 'watchdog' | 'failed';
66
+
67
+ export interface GravixVoiceEffectState {
68
+ /** The requested effect. */
69
+ effect: GravixVoiceEffect;
70
+ /** The effect actually running in the capture chain. */
71
+ active: GravixVoiceEffect;
72
+ reason: GravixVoiceEffectReason;
73
+ /** True while room music bypasses the effect. */
74
+ musicBypass: boolean;
75
+ /** Added capture latency, ms. */
76
+ latencyMs: number;
77
+ }
78
+
79
+ export interface GravixVoiceEffectBenchmark {
80
+ effect: GravixVoiceEffect;
81
+ p50Us: number;
82
+ p95Us: number;
83
+ maxUs: number;
84
+ latencyMs: number;
85
+ }
86
+
87
+ export function isGravixVoiceEffect(v: unknown): v is GravixVoiceEffect {
88
+ return (
89
+ typeof v === 'string' &&
90
+ (GRAVIX_VOICE_EFFECTS as readonly string[]).includes(v)
91
+ );
92
+ }
93
+
94
+ const INITIAL: GravixVoiceEffectState = {
95
+ effect: 'none',
96
+ active: 'none',
97
+ reason: 'ok',
98
+ musicBypass: false,
99
+ latencyMs: 0,
100
+ };
101
+
102
+ type NativeFxState = {
103
+ ok?: boolean;
104
+ reason?: string;
105
+ effect?: string;
106
+ active?: string;
107
+ musicBypass?: boolean;
108
+ watchdog?: boolean;
109
+ latencyMs?: number;
110
+ };
111
+
112
+ function fxReason(m: NativeFxState): GravixVoiceEffectReason {
113
+ if (m.watchdog) return 'watchdog';
114
+ if (m.ok === false) return 'failed';
115
+ return 'ok';
116
+ }
117
+
118
+ /** Singleton like Flutter's `GravixVoiceEffects.instance`. */
119
+ export class GravixVoiceEffects {
120
+ static readonly instance = new GravixVoiceEffects();
121
+
122
+ private current: GravixVoiceEffectState = INITIAL;
123
+ private listening = false;
124
+
125
+ private constructor() {}
126
+
127
+ /** The last known state. */
128
+ get state(): GravixVoiceEffectState {
129
+ return this.current;
130
+ }
131
+
132
+ private apply(m: NativeFxState): GravixVoiceEffectState {
133
+ const effect = isGravixVoiceEffect(m.effect)
134
+ ? m.effect
135
+ : this.current.effect;
136
+ const active = isGravixVoiceEffect(m.active) ? m.active : 'none';
137
+ this.current = {
138
+ effect,
139
+ active,
140
+ reason: fxReason(m),
141
+ musicBypass: m.musicBypass === true,
142
+ latencyMs: typeof m.latencyMs === 'number' ? m.latencyMs : 0,
143
+ };
144
+ return this.current;
145
+ }
146
+
147
+ private listen(): void {
148
+ if (this.listening) return;
149
+ this.listening = true;
150
+ // iOS: watchdog / music bypass changes pushed by the capture chain
151
+ onIosAudioEvent('onVoiceEffects', (m) => this.apply(m as NativeFxState));
152
+ }
153
+
154
+ /** Selects an effect for the published mic; resolves true when the native chain took it. */
155
+ async set(effect: GravixVoiceEffect): Promise<boolean> {
156
+ if (androidAudioFor('voiceEffects')) {
157
+ // Android: gxfx on WebRTC's capture post-processing slot
158
+ const r = await setAndroidVoiceEffect(effect);
159
+ this.current = {
160
+ ...this.current,
161
+ effect,
162
+ active: r.active ?? (r.ok ? effect : 'none'),
163
+ reason: effectReason(r.reason),
164
+ latencyMs: r.latencyMs ?? this.current.latencyMs,
165
+ };
166
+ return r.ok;
167
+ }
168
+ if (!iosFeature('voiceEffects'))
169
+ return unsupportedAsync('voiceEffects', 'set');
170
+ if (!isGravixVoiceEffect(effect))
171
+ throw new Error(`unknown voice effect: ${String(effect)}`);
172
+ await iosAttach();
173
+ this.listen();
174
+ const m = await iosCall<NativeFxState>('fxConfigure', { effect });
175
+ this.apply({ ...m, effect });
176
+ return m.ok === true;
177
+ }
178
+
179
+ /** Re-reads the native state. */
180
+ async refresh(): Promise<GravixVoiceEffectState> {
181
+ if (androidAudioFor('voiceEffects')) {
182
+ const s = await androidVoiceEffectStats();
183
+ if (s) {
184
+ this.current = {
185
+ effect: s.effect,
186
+ active: s.active,
187
+ reason: s.watchdog
188
+ ? 'watchdog'
189
+ : s.active === s.effect
190
+ ? 'ok'
191
+ : this.current.reason,
192
+ musicBypass: s.musicBypass,
193
+ latencyMs: s.latencyMs,
194
+ };
195
+ }
196
+ return this.current;
197
+ }
198
+ if (!iosFeature('voiceEffects'))
199
+ return unsupportedAsync('voiceEffects', 'refresh');
200
+ return this.apply(await iosCall<NativeFxState>('fxStats'));
201
+ }
202
+
203
+ /** Measures one effect's processing cost on this device (Flutter default: 5 s). */
204
+ async benchmark(
205
+ effect: GravixVoiceEffect,
206
+ seconds = 5
207
+ ): Promise<GravixVoiceEffectBenchmark> {
208
+ let m: Record<string, unknown>;
209
+ if (androidAudioFor('voiceEffects')) {
210
+ m = ((await benchmarkAndroidVoiceEffect(effect, 48000, seconds)) ??
211
+ {}) as Record<string, unknown>;
212
+ } else if (iosFeature('voiceEffects')) {
213
+ m = await iosCall<Record<string, unknown>>('fxBenchmark', {
214
+ effect,
215
+ seconds: Math.max(1, Math.round(seconds)),
216
+ rate: 48000,
217
+ });
218
+ } else {
219
+ return unsupportedAsync('voiceEffects', 'benchmark');
220
+ }
221
+ if (m.ok !== true)
222
+ throw new Error(
223
+ `voice effect benchmark failed: ${String(m.reason ?? 'failed')}`
224
+ );
225
+ return {
226
+ effect,
227
+ p50Us: Number(m.p50Us ?? 0),
228
+ p95Us: Number(m.p95Us ?? 0),
229
+ maxUs: Number(m.maxUs ?? 0),
230
+ latencyMs: Number(m.latencyMs ?? 0),
231
+ };
232
+ }
233
+ }
234
+
235
+ /** Android native reason (ok | unknown_effect | library_missing | failed) -> the public one. */
236
+ function effectReason(r: string): GravixVoiceEffectReason {
237
+ switch (r) {
238
+ case 'ok':
239
+ return 'ok';
240
+ case 'library_missing':
241
+ return 'libraryMissing';
242
+ default:
243
+ return 'failed';
244
+ }
245
+ }
@@ -0,0 +1,38 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import type { Room } from 'gravix-rtc';
4
+ import { createContext, type ReactNode, useContext } from 'react';
5
+
6
+ const GravixRoomContext = createContext<Room | undefined>(undefined);
7
+
8
+ /** Makes `room` the default for every hook below it. */
9
+ export function GravixRoomProvider({
10
+ room,
11
+ children,
12
+ }: {
13
+ room: Room;
14
+ children?: ReactNode;
15
+ }) {
16
+ return (
17
+ <GravixRoomContext.Provider value={room}>
18
+ {children}
19
+ </GravixRoomContext.Provider>
20
+ );
21
+ }
22
+
23
+ /** The room from `GravixRoomProvider`, or undefined. */
24
+ export function useRoomContext(): Room | undefined {
25
+ return useContext(GravixRoomContext);
26
+ }
27
+
28
+ /** `room` if given, else the provider's; throws when there is neither. */
29
+ export function useEnsureRoom(room?: Room): Room {
30
+ const ctx = useRoomContext();
31
+ const r = room ?? ctx;
32
+ if (!r) {
33
+ throw new Error(
34
+ 'No Room: pass one to the hook or wrap the tree in <GravixRoomProvider room={room}>'
35
+ );
36
+ }
37
+ return r;
38
+ }
@@ -0,0 +1,247 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import {
4
+ ConnectionQuality,
5
+ ConnectionState,
6
+ type LocalParticipant,
7
+ type Participant,
8
+ ParticipantEvent,
9
+ type RemoteParticipant,
10
+ type Room,
11
+ RoomEvent,
12
+ Track,
13
+ } from 'gravix-rtc';
14
+ import { useEffect, useMemo, useReducer } from 'react';
15
+ import { gravixRoomMicPolicy } from '../micPolicy';
16
+ import { useEnsureRoom } from './context';
17
+ import type { TrackReference } from './types';
18
+ import { type Emitter, useRoomEvents } from './useRoomEvents';
19
+
20
+ const PARTICIPANT_EVENTS: readonly RoomEvent[] = [
21
+ RoomEvent.Connected,
22
+ RoomEvent.Disconnected,
23
+ RoomEvent.Reconnected,
24
+ RoomEvent.ParticipantConnected,
25
+ RoomEvent.ParticipantDisconnected,
26
+ RoomEvent.ParticipantNameChanged,
27
+ RoomEvent.ParticipantMetadataChanged,
28
+ RoomEvent.ParticipantAttributesChanged,
29
+ ];
30
+
31
+ const TRACK_EVENTS: readonly RoomEvent[] = [
32
+ ...PARTICIPANT_EVENTS,
33
+ RoomEvent.TrackPublished,
34
+ RoomEvent.TrackUnpublished,
35
+ RoomEvent.TrackSubscribed,
36
+ RoomEvent.TrackUnsubscribed,
37
+ RoomEvent.TrackMuted,
38
+ RoomEvent.TrackUnmuted,
39
+ RoomEvent.LocalTrackPublished,
40
+ RoomEvent.LocalTrackUnpublished,
41
+ RoomEvent.TrackSubscriptionStatusChanged,
42
+ ];
43
+
44
+ /** The room's connection state. */
45
+ export function useConnectionState(room?: Room): ConnectionState {
46
+ const r = useEnsureRoom(room);
47
+ useRoomEvents(r, [RoomEvent.ConnectionStateChanged]);
48
+ return r.state;
49
+ }
50
+
51
+ /** Remote participants, in join order. */
52
+ export function useRemoteParticipants(room?: Room): RemoteParticipant[] {
53
+ const r = useEnsureRoom(room);
54
+ const v = useRoomEvents(r, PARTICIPANT_EVENTS);
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ return useMemo(() => Array.from(r.remoteParticipants.values()), [r, v]);
57
+ }
58
+
59
+ /** The local participant first, then the remote ones. */
60
+ export function useParticipants(room?: Room): Participant[] {
61
+ const r = useEnsureRoom(room);
62
+ const remotes = useRemoteParticipants(r);
63
+ return useMemo(
64
+ () => [r.localParticipant as Participant, ...remotes],
65
+ [r, remotes]
66
+ );
67
+ }
68
+
69
+ /** The local participant (re-renders on its mic/camera changes). */
70
+ export function useLocalParticipant(room?: Room): LocalParticipant {
71
+ const r = useEnsureRoom(room);
72
+ useRoomEvents(r, [
73
+ RoomEvent.LocalTrackPublished,
74
+ RoomEvent.LocalTrackUnpublished,
75
+ RoomEvent.TrackMuted,
76
+ RoomEvent.TrackUnmuted,
77
+ RoomEvent.Connected,
78
+ ]);
79
+ return r.localParticipant;
80
+ }
81
+
82
+ /**
83
+ * The local mic is muted: the core mute OR an Android voice-only music mute
84
+ * (`GravixRoomMusic.setMicMuted`), which leaves `track.isMuted` false. Use it
85
+ * for the mic button instead of `isMicrophoneEnabled`.
86
+ */
87
+ export function useMicMuted(room?: Room): boolean {
88
+ const r = useEnsureRoom(room);
89
+ useRoomEvents(r, [
90
+ RoomEvent.LocalTrackPublished,
91
+ RoomEvent.LocalTrackUnpublished,
92
+ RoomEvent.TrackMuted,
93
+ RoomEvent.TrackUnmuted,
94
+ RoomEvent.Disconnected,
95
+ ]);
96
+ const [, bump] = useReducer((n: number) => n + 1, 0);
97
+ useEffect(() => gravixRoomMicPolicy.onMicMuteChanged(bump), []);
98
+ return gravixRoomMicPolicy.isMicMuted(r as never);
99
+ }
100
+
101
+ /** Participants speaking now, loudest first (server `ActiveSpeakersChanged`). */
102
+ export function useActiveSpeakers(room?: Room): Participant[] {
103
+ const r = useEnsureRoom(room);
104
+ useRoomEvents(r, [RoomEvent.ActiveSpeakersChanged, RoomEvent.Disconnected]);
105
+ return r.activeSpeakers;
106
+ }
107
+
108
+ export interface UseTracksOptions {
109
+ /** Default: camera, microphone, screen share. */
110
+ sources?: Track.Source[];
111
+ /** Only remote tracks that are subscribed (local ones are always included). Default false. */
112
+ onlySubscribed?: boolean;
113
+ }
114
+
115
+ const DEFAULT_SOURCES = [
116
+ Track.Source.Camera,
117
+ Track.Source.Microphone,
118
+ Track.Source.ScreenShare,
119
+ ];
120
+
121
+ /** Track references of every participant, filtered by source. */
122
+ export function useTracks(
123
+ options: UseTracksOptions = {},
124
+ room?: Room
125
+ ): TrackReference[] {
126
+ const r = useEnsureRoom(room);
127
+ const v = useRoomEvents(r, TRACK_EVENTS);
128
+ const sources = options.sources ?? DEFAULT_SOURCES;
129
+ const sourcesKey = sources.join(',');
130
+ const onlySubscribed = options.onlySubscribed ?? false;
131
+ return useMemo(
132
+ () => collectTracks(r, sources, onlySubscribed),
133
+ // eslint-disable-next-line react-hooks/exhaustive-deps
134
+ [r, v, sourcesKey, onlySubscribed]
135
+ );
136
+ }
137
+
138
+ /** @internal exported for tests */
139
+ export function collectTracks(
140
+ room: Room,
141
+ sources: Track.Source[],
142
+ onlySubscribed: boolean
143
+ ): TrackReference[] {
144
+ const out: TrackReference[] = [];
145
+ const participants: Participant[] = [
146
+ room.localParticipant,
147
+ ...room.remoteParticipants.values(),
148
+ ];
149
+ for (const participant of participants) {
150
+ for (const publication of participant.trackPublications.values()) {
151
+ if (!sources.includes(publication.source)) continue;
152
+ const isLocal = participant === room.localParticipant;
153
+ if (onlySubscribed && !isLocal && !publication.isSubscribed) continue;
154
+ out.push({ participant, publication, source: publication.source });
155
+ }
156
+ }
157
+ return out;
158
+ }
159
+
160
+ export interface ParticipantState {
161
+ identity: string;
162
+ name: string | undefined;
163
+ metadata: string | undefined;
164
+ isSpeaking: boolean;
165
+ audioLevel: number;
166
+ isMicrophoneEnabled: boolean;
167
+ isCameraEnabled: boolean;
168
+ isScreenShareEnabled: boolean;
169
+ connectionQuality: ConnectionQuality;
170
+ cameraTrack: TrackReference | undefined;
171
+ microphoneTrack: TrackReference | undefined;
172
+ }
173
+
174
+ const PARTICIPANT_STATE_EVENTS: readonly ParticipantEvent[] = [
175
+ ParticipantEvent.IsSpeakingChanged,
176
+ ParticipantEvent.TrackMuted,
177
+ ParticipantEvent.TrackUnmuted,
178
+ ParticipantEvent.TrackPublished,
179
+ ParticipantEvent.TrackUnpublished,
180
+ ParticipantEvent.TrackSubscribed,
181
+ ParticipantEvent.TrackUnsubscribed,
182
+ ParticipantEvent.LocalTrackPublished,
183
+ ParticipantEvent.LocalTrackUnpublished,
184
+ ParticipantEvent.ConnectionQualityChanged,
185
+ ParticipantEvent.ParticipantMetadataChanged,
186
+ ParticipantEvent.ParticipantNameChanged,
187
+ ];
188
+
189
+ /** One participant's speaking/mic/camera/quality state (Flutter `onUserMuteAudio` & co). */
190
+ export function useParticipant(participant: Participant): ParticipantState {
191
+ const [, bump] = useReducer((n: number) => n + 1, 0);
192
+ useEffect(() => {
193
+ const h = () => bump();
194
+ const emitter = participant as unknown as Emitter;
195
+ for (const e of PARTICIPANT_STATE_EVENTS) emitter.on(e, h);
196
+ bump();
197
+ return () => {
198
+ for (const e of PARTICIPANT_STATE_EVENTS) emitter.off(e, h);
199
+ };
200
+ }, [participant]);
201
+ const ref = (source: Track.Source): TrackReference | undefined => {
202
+ const publication = participant.getTrackPublication(source);
203
+ return publication ? { participant, publication, source } : undefined;
204
+ };
205
+ return {
206
+ identity: participant.identity,
207
+ name: participant.name,
208
+ metadata: participant.metadata,
209
+ isSpeaking: participant.isSpeaking,
210
+ audioLevel: participant.audioLevel,
211
+ isMicrophoneEnabled: participant.isMicrophoneEnabled,
212
+ isCameraEnabled: participant.isCameraEnabled,
213
+ isScreenShareEnabled: participant.isScreenShareEnabled,
214
+ connectionQuality: participant.connectionQuality,
215
+ cameraTrack: ref(Track.Source.Camera),
216
+ microphoneTrack: ref(Track.Source.Microphone),
217
+ };
218
+ }
219
+
220
+ export interface UseRoomResult {
221
+ room: Room;
222
+ connectionState: ConnectionState;
223
+ isConnected: boolean;
224
+ participants: Participant[];
225
+ activeSpeakers: Participant[];
226
+ tracks: TrackReference[];
227
+ }
228
+
229
+ /** Everything a simple room screen needs, in one hook. */
230
+ export function useRoom(
231
+ room?: Room,
232
+ options?: UseTracksOptions
233
+ ): UseRoomResult {
234
+ const r = useEnsureRoom(room);
235
+ const connectionState = useConnectionState(r);
236
+ const participants = useParticipants(r);
237
+ const activeSpeakers = useActiveSpeakers(r);
238
+ const tracks = useTracks(options, r);
239
+ return {
240
+ room: r,
241
+ connectionState,
242
+ isConnected: connectionState === ConnectionState.Connected,
243
+ participants,
244
+ activeSpeakers,
245
+ tracks,
246
+ };
247
+ }
@@ -0,0 +1,10 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import type { Participant, Track, TrackPublication } from 'gravix-rtc';
4
+
5
+ /** A participant's track slot (published or not yet subscribed). */
6
+ export interface TrackReference {
7
+ participant: Participant;
8
+ publication: TrackPublication;
9
+ source: Track.Source;
10
+ }
@@ -0,0 +1,35 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import type { Room, RoomEvent } from 'gravix-rtc';
4
+ import { useEffect, useReducer } from 'react';
5
+
6
+ /**
7
+ * Re-renders when `room` emits any of `events`. The hooks derive their values
8
+ * from the room on each render, so there is no copied state to go stale.
9
+ * @internal
10
+ */
11
+ /** @internal */
12
+ export type Emitter = {
13
+ on(event: string, handler: () => void): unknown;
14
+ off(event: string, handler: () => void): unknown;
15
+ };
16
+
17
+ export function useRoomEvents(
18
+ room: Room,
19
+ events: readonly RoomEvent[]
20
+ ): number {
21
+ const [version, bump] = useReducer((n: number) => n + 1, 0);
22
+ const key = events.join('|');
23
+ useEffect(() => {
24
+ const handler = () => bump();
25
+ const emitter = room as unknown as Emitter;
26
+ for (const e of events) emitter.on(e, handler);
27
+ // The room may have changed state between render and this effect.
28
+ bump();
29
+ return () => {
30
+ for (const e of events) emitter.off(e, handler);
31
+ };
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, [room, key]);
34
+ return version;
35
+ }