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,312 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import { androidAudioFor } from './android/bindings';
4
+ import { gravixMicMute, type GravixMicMute } from './android/micMute';
5
+ import {
6
+ iosFeature,
7
+ iosMuteStopsMicTrack,
8
+ iosReleaseCaptureClose,
9
+ iosSetCaptureClosed,
10
+ } from './ios/iosAudio';
11
+
12
+ /**
13
+ * Mute releases the microphone, as the room default (Flutter 0.12.1+
14
+ * `GravixRoomService(muteReleasesMic: true)`), wired into EVERY gravix-rtc
15
+ * Room (also the ones GravixJoin creates) by {@link installRoomMicHooks}, which
16
+ * `registerGlobals()` runs. One-flag rollback:
17
+ * `registerGlobals({ muteReleasesMic: false })` (or
18
+ * `GravixMicRelease.setMuteReleasesMic(false)` at run time).
19
+ *
20
+ * - iOS (only with the Gravix audio device, Info.plist `GravixAudioDevice`;
21
+ * with WebRTC's built-in device `muteReleasesMic` is unsupported and the
22
+ * policy does nothing): every local mic mute closes the mic input of the
23
+ * Gravix audio device (`setCaptureClosed`), so the OS mic indicator goes
24
+ * off; an unmute reopens it at once. This is the ONLY mute path: the track
25
+ * is not also stopped (`stopOnMute`; react-native-webrtc 155's WebRTC keeps
26
+ * recording under a track stop, which only disables the track, and the
27
+ * unmute then paid a getUserMedia). Rollback: Info.plist
28
+ * `GravixMuteStopsMicTrack` = YES (`iosStopTrackOnMute` on the policy is an
29
+ * internal / test override). The close survives WebRTC's recording stop / start, so a muted
30
+ * mic republished after a reconnect never opens the input; it ends with an
31
+ * unmute, a fresh unmuted publish, or when the muted publication ends for
32
+ * good (final unpublish of a stopped track, room left: `releaseCaptureClose`,
33
+ * applied once WebRTC stops recording).
34
+ * - Android: every local mic mute closes the hardware recorder and every
35
+ * unmute reopens it (`GravixMicMute.setCaptureClosed`, the native capture
36
+ * seam; react-native-webrtc 155's WebRTC keeps recording under a plain
37
+ * mute). A mic published while already muted (also a reconnect republish)
38
+ * gets its recorder closed (`GravixMicMute.closeMutedCapture`). A core mute during a voice-only music mute
39
+ * hands the mute to the core; leaving the room gives the engine mute back.
40
+ */
41
+ export type MicPolicyPlatform = 'android' | 'ios' | null;
42
+
43
+ type PubLike = {
44
+ source?: string;
45
+ isMuted?: boolean;
46
+ track?: MicTrack;
47
+ };
48
+ type MicTrack = {
49
+ isMuted: boolean;
50
+ isUserProvided?: boolean;
51
+ stopOnMute?: boolean;
52
+ mediaStreamTrack: { enabled: boolean; readyState?: string; stop?(): void };
53
+ mute(): Promise<unknown>;
54
+ unmute(): Promise<unknown>;
55
+ };
56
+ type RoomLike = {
57
+ /** gravix-rtc `ConnectionState` ('reconnecting' while a full reconnect republishes). */
58
+ state?: string;
59
+ localParticipant?: {
60
+ audioTrackPublications?: Map<string, PubLike>;
61
+ };
62
+ };
63
+
64
+ const MIC = 'microphone';
65
+ const RECONNECTING = new Set(['reconnecting', 'signalReconnecting']);
66
+
67
+ function defaultPlatform(): MicPolicyPlatform {
68
+ if (androidAudioFor('muteReleasesMic')) return 'android';
69
+ if (iosFeature('muteReleasesMic')) return 'ios';
70
+ return null;
71
+ }
72
+
73
+ export class GravixRoomMicPolicy {
74
+ constructor(
75
+ private readonly platform: () => MicPolicyPlatform = defaultPlatform,
76
+ private readonly mic: GravixMicMute = gravixMicMute,
77
+ private readonly iosCapture: (
78
+ closed: boolean
79
+ ) => Promise<unknown> = iosSetCaptureClosed,
80
+ private readonly iosRelease: () => Promise<unknown> = iosReleaseCaptureClose,
81
+ private readonly iosStopsTrackDefault: () => boolean = iosMuteStopsMicTrack
82
+ ) {}
83
+
84
+ /**
85
+ * iOS rollback: also stop the mic track on mute (`stopOnMute`, the 0.2.0
86
+ * beta double path). null (default) = Info.plist `GravixMuteStopsMicTrack`.
87
+ */
88
+ iosStopTrackOnMute: boolean | null = null;
89
+
90
+ /** Whether an iOS mic gets `stopOnMute` (releasesMic AND the rollback flag). */
91
+ iosStopsTrackOnMute(): boolean {
92
+ if (!this.releasesMic) return false;
93
+ if (this.iosStopTrackOnMute !== null) return this.iosStopTrackOnMute;
94
+ try {
95
+ return this.iosStopsTrackDefault();
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+
101
+ /** Rooms whose muted mic holds the iOS device mic close (one device per process). */
102
+ private readonly iosClosedBy = new Set<RoomLike>();
103
+ /** Rooms that unpublished a muted mic and kept it (it may be published again), with the track. */
104
+ private readonly iosKeptMuted = new Map<RoomLike, MicTrack | undefined>();
105
+
106
+ /** iOS mic close / reopen; never throws. */
107
+ private iosClose(closed: boolean, room?: RoomLike): void {
108
+ if (closed) {
109
+ if (room) this.iosClosedBy.add(room);
110
+ } else {
111
+ this.iosClosedBy.clear(); // the device mic is open for every room again
112
+ }
113
+ try {
114
+ this.iosCapture(closed)?.catch?.(() => {});
115
+ } catch {
116
+ // the policy must never break the room's event flow
117
+ }
118
+ }
119
+
120
+ /**
121
+ * iOS: [room]'s muted publication ended for good. The device close ends once
122
+ * WebRTC stops recording (no input opens before), unless another room's
123
+ * muted mic still holds it. Never throws.
124
+ */
125
+ private iosReleaseFor(room: RoomLike): void {
126
+ if (!this.iosClosedBy.delete(room) || this.iosClosedBy.size > 0) return;
127
+ try {
128
+ this.iosRelease()?.catch?.(() => {});
129
+ } catch {
130
+ // the policy must never break the room's event flow
131
+ }
132
+ }
133
+
134
+ /** Mute releases the mic (default true). Mirrors the Android engine flag. */
135
+ get releasesMic(): boolean {
136
+ return this.mic.muteReleasesMic;
137
+ }
138
+ set releasesMic(on: boolean) {
139
+ this.mic.muteReleasesMic = on;
140
+ }
141
+
142
+ /**
143
+ * True while the local mic is muted: the core mute (`track.isMuted`) OR a
144
+ * voice-only music mute (Android), which the core does not see.
145
+ */
146
+ isMicMuted(room: RoomLike): boolean {
147
+ if (this.mic.muteKind !== 'none') return true;
148
+ let muted = false;
149
+ room.localParticipant?.audioTrackPublications?.forEach((p) => {
150
+ if (p.source === MIC && (p.track?.isMuted ?? p.isMuted)) muted = true;
151
+ });
152
+ return muted;
153
+ }
154
+
155
+ /** Voice-only mute changes (the core's TrackMuted / TrackUnmuted cover the rest). */
156
+ onMicMuteChanged(fn: () => void): () => void {
157
+ return this.mic.onChange(fn);
158
+ }
159
+
160
+ /** Room event tap (installed on `Room.prototype.emit`). Never throws into the core. */
161
+ onRoomEvent(room: RoomLike, event: string, args: unknown[]): void {
162
+ const platform = this.platform();
163
+ if (!platform) return;
164
+ switch (event) {
165
+ case 'localTrackPublished': {
166
+ const pub = args[0] as PubLike | undefined;
167
+ if (pub?.source !== MIC || !pub.track) return;
168
+ // a fresh unmuted mic must never inherit a mute close of an earlier publication
169
+ if (platform === 'android' && !pub.track.isMuted)
170
+ this.mic.setCaptureClosed?.(false)?.catch(() => {});
171
+ if (platform === 'ios') this.iosKeptMuted.delete(room);
172
+ if (platform === 'ios' && !pub.track.isMuted) this.iosClose(false);
173
+ // (iOS, muted: a reconnect republish; the device close held through
174
+ // WebRTC's recording restart, the mic never opened)
175
+ if (!this.releasesMic) return;
176
+ this.onMicPublished(platform, pub.track, room);
177
+ return;
178
+ }
179
+ case 'localTrackUnpublished': {
180
+ const pub = args[0] as PubLike | undefined;
181
+ // unpublished while muted (seat leave): the mute close ends with the publication
182
+ if (platform === 'android' && pub?.source === MIC)
183
+ this.mic.setCaptureClosed?.(false)?.catch(() => {});
184
+ // iOS: a full reconnect unpublishes and republishes the same live
185
+ // track (state 'reconnecting', track not stopped): the close stays, so
186
+ // the muted republish never opens the mic. A final unpublish stops
187
+ // the track (seat leave, room.disconnect()): release. A live muted
188
+ // track that is kept (reconnect, disconnect(false), unpublishTrack(t,
189
+ // false)) may be published again: the close stays until an unmute or
190
+ // an unmuted publish.
191
+ if (platform === 'ios' && pub?.source === MIC) {
192
+ const ended =
193
+ !pub.track || pub.track.mediaStreamTrack?.readyState === 'ended';
194
+ if (ended && !RECONNECTING.has(room.state ?? ''))
195
+ this.iosReleaseFor(room);
196
+ else if (pub.track?.isMuted) this.iosKeptMuted.set(room, pub.track);
197
+ }
198
+ return;
199
+ }
200
+ case 'trackMuted': {
201
+ const pub = args[0] as PubLike | undefined;
202
+ if (platform === 'ios') {
203
+ if (
204
+ this.releasesMic &&
205
+ pub?.source === MIC &&
206
+ args[1] === room.localParticipant
207
+ )
208
+ this.iosClose(true, room);
209
+ return;
210
+ }
211
+ if (
212
+ platform !== 'android' ||
213
+ pub?.source !== MIC ||
214
+ !pub.track ||
215
+ args[1] !== room.localParticipant
216
+ )
217
+ return;
218
+ this.mic.coreMuted(pub.track).catch(() => {});
219
+ if (this.releasesMic)
220
+ this.mic.setCaptureClosed?.(true)?.catch(() => {});
221
+ return;
222
+ }
223
+ case 'trackUnmuted': {
224
+ const pub = args[0] as PubLike | undefined;
225
+ if (pub?.source !== MIC || args[1] !== room.localParticipant) return;
226
+ if (platform === 'ios') this.iosClose(false);
227
+ else this.mic.setCaptureClosed?.(false)?.catch(() => {});
228
+ return;
229
+ }
230
+ case 'disconnected':
231
+ if (platform === 'android') this.mic.leave().catch(() => {});
232
+ // iOS: the room left; its close ends once WebRTC stops recording
233
+ // (not while another room's muted mic still holds it, and not when
234
+ // the room kept its live muted mic: a connect() during a reconnect
235
+ // runs disconnect(false) and the app may publish that mic again)
236
+ // A failed reconnect unpublishes the mic while still 'reconnecting'
237
+ // and stops it: the kept track has ended, so the close ends too
238
+ // (2026-12-01 review; else the gate stayed closed with no room).
239
+ if (platform === 'ios') {
240
+ const kept = this.iosKeptMuted.has(room);
241
+ const t = this.iosKeptMuted.get(room);
242
+ this.iosKeptMuted.delete(room);
243
+ const keptEnded =
244
+ kept &&
245
+ t?.mediaStreamTrack?.readyState === 'ended' &&
246
+ !this.iosStopsTrackOnMute();
247
+ if (kept && !keptEnded) this.iosClosedBy.delete(room);
248
+ else this.iosReleaseFor(room);
249
+ }
250
+ return;
251
+ }
252
+ }
253
+
254
+ private onMicPublished(
255
+ platform: 'android' | 'ios',
256
+ track: MicTrack,
257
+ room: RoomLike
258
+ ): void {
259
+ if (platform === 'ios') {
260
+ if (this.iosStopsTrackOnMute()) {
261
+ // rollback (GravixMuteStopsMicTrack): the track stop as a second path
262
+ track.stopOnMute = true;
263
+ const mst = track.mediaStreamTrack;
264
+ if (
265
+ track.isMuted &&
266
+ !track.isUserProvided &&
267
+ mst.readyState !== 'ended'
268
+ )
269
+ mst.stop?.();
270
+ }
271
+ if (track.isMuted) this.iosClose(true, room);
272
+ return;
273
+ }
274
+ if (track.isMuted) this.mic.closeMutedCapture(track).catch(() => {});
275
+ }
276
+ }
277
+
278
+ /** Process-wide policy (one audio device module per process). */
279
+ export const gravixRoomMicPolicy = new GravixRoomMicPolicy();
280
+
281
+ const PATCHED = '__gravixMicHooks';
282
+
283
+ /**
284
+ * Taps [RoomClass]'s `emit` so the policy sees every room's events, the Rooms
285
+ * GravixJoin builds included. Idempotent; the original emit always runs.
286
+ */
287
+ export function installRoomMicHooks(
288
+ RoomClass: unknown,
289
+ handler: (room: RoomLike, event: string, args: unknown[]) => void = (
290
+ r,
291
+ e,
292
+ a
293
+ ) => gravixRoomMicPolicy.onRoomEvent(r, e, a)
294
+ ): boolean {
295
+ const proto = (RoomClass as { prototype?: Record<string, unknown> })
296
+ ?.prototype;
297
+ if (!proto || typeof proto.emit !== 'function' || proto[PATCHED]) {
298
+ return false;
299
+ }
300
+ const original = proto.emit as (...a: unknown[]) => boolean;
301
+ proto.emit = function (this: RoomLike, event: string, ...args: unknown[]) {
302
+ const r = original.call(this, event, ...args);
303
+ try {
304
+ handler(this, event, args);
305
+ } catch {
306
+ // the policy must never break the room's event flow
307
+ }
308
+ return r;
309
+ };
310
+ Object.defineProperty(proto, PATCHED, { value: true });
311
+ return true;
312
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ /**
4
+ * Codegen spec of the Android-only `GravixAudio` TurboModule: the native audio
5
+ * features (voice effects, noise suppression, room music, singer capture,
6
+ * mute that releases the mic). One generic call keeps the spec stable while
7
+ * the method set follows the Flutter SDK's channel methods
8
+ * (`android/.../GravixNativeAudio.kt` lists them). Events go out as the
9
+ * device event `GravixAudioEvent` ({ name, payload }).
10
+ *
11
+ * iOS does not register this module (`TurboModuleRegistry.get` returns null).
12
+ * Keep this file free of imports other than `react-native`.
13
+ */
14
+ import {
15
+ TurboModuleRegistry,
16
+ type CodegenTypes,
17
+ type TurboModule,
18
+ } from 'react-native';
19
+
20
+ export interface Spec extends TurboModule {
21
+ /** Resolves with the method's result wrapped as `{ value }`. */
22
+ call(
23
+ method: string,
24
+ args: CodegenTypes.UnsafeObject
25
+ ): Promise<CodegenTypes.UnsafeObject>;
26
+ addListener(eventName: string): void;
27
+ removeListeners(count: number): void;
28
+ }
29
+
30
+ export default TurboModuleRegistry.get<Spec>('GravixAudio');
@@ -0,0 +1,38 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ /**
4
+ * Codegen spec of the `GravixRtc` TurboModule (Android: Kotlin, iOS: Obj-C++).
5
+ *
6
+ * Keep this file free of imports other than `react-native`: the codegen parser
7
+ * reads it statically.
8
+ */
9
+ import {
10
+ TurboModuleRegistry,
11
+ type CodegenTypes,
12
+ type TurboModule,
13
+ } from 'react-native';
14
+
15
+ export interface Spec extends TurboModule {
16
+ /**
17
+ * `{ platform, nativeVersion, features: { [feature]: boolean } }`.
18
+ * A feature flips to true once its native implementation lands; the JS stubs
19
+ * read this map (see `src/unsupported.ts`).
20
+ */
21
+ getCapabilities(): CodegenTypes.UnsafeObject;
22
+
23
+ configureAudio(config: CodegenTypes.UnsafeObject): Promise<void>;
24
+ startAudioSession(): Promise<void>;
25
+ stopAudioSession(): Promise<void>;
26
+ getAudioOutputs(): Promise<string[]>;
27
+ selectAudioOutput(deviceId: string): Promise<void>;
28
+ showAudioRoutePicker(): Promise<void>;
29
+ setAppleAudioConfiguration(config: CodegenTypes.UnsafeObject): Promise<void>;
30
+ /**
31
+ * iOS: the AVAudioSession configuration WebRTC's audio unit applies when
32
+ * audio starts (`RTCAudioSessionConfiguration.webRTCConfiguration`); null =
33
+ * the setup default. No-op on Android.
34
+ */
35
+ setWebRTCAudioConfiguration(config: CodegenTypes.UnsafeObject | null): void;
36
+ }
37
+
38
+ export default TurboModuleRegistry.get<Spec>('GravixRtc');
@@ -0,0 +1,22 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ import { Platform } from 'react-native';
4
+ import NativeGravixRtc, { type Spec } from './NativeGravixRtc';
5
+
6
+ export const LINKING_ERROR =
7
+ "The package 'gravix-rtc-react-native' doesn't seem to be linked. Make sure:\n\n" +
8
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
9
+ '- You rebuilt the app after installing the package\n' +
10
+ '- You are not using Expo Go (a development build works)\n';
11
+
12
+ /** The native module, or null when it is not linked (tests, Expo Go, web). */
13
+ export function nativeModuleOrNull(): Spec | null {
14
+ return NativeGravixRtc ?? null;
15
+ }
16
+
17
+ /** The native module; throws a clear linking error when it is missing. */
18
+ export function nativeModule(): Spec {
19
+ const m = nativeModuleOrNull();
20
+ if (!m) throw new Error(LINKING_ERROR);
21
+ return m;
22
+ }
@@ -0,0 +1,20 @@
1
+ // Copyright 2023-2026 LiveKit, Inc.
2
+ // Modifications Copyright 2026 Gravity Compile.
3
+ // Licensed under the Apache License, Version 2.0; see LICENSES/Apache-2.0.txt.
4
+
5
+ /** DOMException is missing in some React Native runtimes; gravix-rtc and fetch/AbortController use it. */
6
+ export function installDOMException(): void {
7
+ const g = globalThis as { DOMException?: unknown };
8
+ if (typeof g.DOMException !== 'undefined') return;
9
+ class GravixDOMException extends Error {
10
+ readonly code: number;
11
+ constructor(message = '', name?: string) {
12
+ super(message);
13
+ this.message = message;
14
+ this.name = name ?? 'Error';
15
+ this.code = 0;
16
+ Object.setPrototypeOf(this, GravixDOMException.prototype);
17
+ }
18
+ }
19
+ g.DOMException = GravixDOMException;
20
+ }
@@ -0,0 +1,16 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ /**
4
+ * Side-effect module, imported by src/index.tsx BEFORE the gravix-rtc core is
5
+ * re-exported: the core uses `new TextDecoder()` and `extends DOMException` at
6
+ * module scope and `instanceof Event` in its connect path, and Hermes / React
7
+ * Native 0.83 have none of them (Fable B1, M1). Each install keeps a
8
+ * runtime-provided global. The rest of the polyfills stay in registerGlobals().
9
+ */
10
+ import { installDOMException } from './DOMException';
11
+ import { installEvent } from './event';
12
+ import { installTextCoding } from './textCoding';
13
+
14
+ installDOMException();
15
+ installTextCoding();
16
+ installEvent();
@@ -0,0 +1,88 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ /**
4
+ * Minimal DOM `Event` / `EventTarget` for React Native. gravix-rtc checks
5
+ * `x instanceof Event` in its signal dial / abort handlers; without a global
6
+ * `Event` that line throws and `room.connect()` never settles (Fable M1).
7
+ */
8
+ type Listener = ((e: unknown) => void) | { handleEvent(e: unknown): void };
9
+
10
+ class GravixEvent {
11
+ static readonly NONE = 0;
12
+ static readonly AT_TARGET = 2;
13
+ readonly type: string;
14
+ readonly bubbles: boolean;
15
+ readonly cancelable: boolean;
16
+ readonly timeStamp = Date.now();
17
+ defaultPrevented = false;
18
+ target: unknown = null;
19
+ currentTarget: unknown = null;
20
+ constructor(
21
+ type: string,
22
+ init: { bubbles?: boolean; cancelable?: boolean } = {}
23
+ ) {
24
+ if (arguments.length === 0) {
25
+ throw new TypeError('Event: 1 argument required, but only 0 present.');
26
+ }
27
+ this.type = String(type);
28
+ this.bubbles = init.bubbles === true;
29
+ this.cancelable = init.cancelable === true;
30
+ }
31
+ preventDefault(): void {
32
+ if (this.cancelable) this.defaultPrevented = true;
33
+ }
34
+ stopPropagation(): void {}
35
+ stopImmediatePropagation(): void {
36
+ (this as { stopped?: boolean }).stopped = true;
37
+ }
38
+ }
39
+
40
+ class GravixEventTarget {
41
+ private readonly listeners = new Map<
42
+ string,
43
+ Array<{ fn: Listener; once: boolean }>
44
+ >();
45
+ addEventListener(
46
+ type: string,
47
+ fn: Listener | null,
48
+ options?: boolean | { once?: boolean }
49
+ ): void {
50
+ if (!fn) return;
51
+ const list = this.listeners.get(type) ?? [];
52
+ if (list.some((l) => l.fn === fn)) return;
53
+ list.push({
54
+ fn,
55
+ once: typeof options === 'object' && options.once === true,
56
+ });
57
+ this.listeners.set(type, list);
58
+ }
59
+ removeEventListener(type: string, fn: Listener | null): void {
60
+ const list = this.listeners.get(type);
61
+ if (!list || !fn) return;
62
+ this.listeners.set(
63
+ type,
64
+ list.filter((l) => l.fn !== fn)
65
+ );
66
+ }
67
+ dispatchEvent(event: GravixEvent): boolean {
68
+ const list = this.listeners.get(event.type);
69
+ event.target = this;
70
+ event.currentTarget = this;
71
+ if (list) {
72
+ for (const l of [...list]) {
73
+ if (l.once) this.removeEventListener(event.type, l.fn);
74
+ if (typeof l.fn === 'function') l.fn.call(this, event);
75
+ else l.fn.handleEvent(event);
76
+ if ((event as { stopped?: boolean }).stopped) break;
77
+ }
78
+ }
79
+ event.currentTarget = null;
80
+ return !event.defaultPrevented;
81
+ }
82
+ }
83
+
84
+ export function installEvent(): void {
85
+ const g = globalThis as { Event?: unknown; EventTarget?: unknown };
86
+ if (typeof g.Event === 'undefined') g.Event = GravixEvent;
87
+ if (typeof g.EventTarget === 'undefined') g.EventTarget = GravixEventTarget;
88
+ }
@@ -0,0 +1,112 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ /**
4
+ * Minimal SHA-256 and HMAC-SHA256 (FIPS 180-4, RFC 2104) in plain TypeScript.
5
+ *
6
+ * Only used by the `crypto.subtle` HMAC shim (see ./subtleHmac.ts) so that
7
+ * `createToken` / `GravixTokenProvider.local` from gravix-rtc can sign HS256
8
+ * join tokens on Hermes, which has no WebCrypto.
9
+ */
10
+
11
+ const K = new Uint32Array([
12
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
13
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
14
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
15
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
16
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
17
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
18
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
19
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
20
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
21
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
22
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
23
+ ]);
24
+
25
+ /* eslint-disable no-bitwise */
26
+ export function sha256(data: Uint8Array): Uint8Array {
27
+ const h = new Uint32Array([
28
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,
29
+ 0x1f83d9ab, 0x5be0cd19,
30
+ ]);
31
+ const bitLen = data.length * 8;
32
+ const padded = new Uint8Array((((data.length + 9 + 63) >> 6) << 6) >>> 0);
33
+ padded.set(data);
34
+ padded[data.length] = 0x80;
35
+ const view = new DataView(padded.buffer);
36
+ // Messages here are far below 2^32 bits; the high word stays 0.
37
+ view.setUint32(padded.length - 4, bitLen >>> 0, false);
38
+ view.setUint32(padded.length - 8, Math.floor(bitLen / 0x100000000), false);
39
+
40
+ const w = new Uint32Array(64);
41
+ for (let off = 0; off < padded.length; off += 64) {
42
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + i * 4, false);
43
+ for (let i = 16; i < 64; i++) {
44
+ const a = w[i - 15]!;
45
+ const b = w[i - 2]!;
46
+ const s0 = ((a >>> 7) | (a << 25)) ^ ((a >>> 18) | (a << 14)) ^ (a >>> 3);
47
+ const s1 =
48
+ ((b >>> 17) | (b << 15)) ^ ((b >>> 19) | (b << 13)) ^ (b >>> 10);
49
+ w[i] = (w[i - 16]! + s0 + w[i - 7]! + s1) >>> 0;
50
+ }
51
+ let a = h[0]!;
52
+ let b = h[1]!;
53
+ let c = h[2]!;
54
+ let d = h[3]!;
55
+ let e = h[4]!;
56
+ let f = h[5]!;
57
+ let g = h[6]!;
58
+ let hh = h[7]!;
59
+ for (let i = 0; i < 64; i++) {
60
+ const S1 =
61
+ ((e >>> 6) | (e << 26)) ^
62
+ ((e >>> 11) | (e << 21)) ^
63
+ ((e >>> 25) | (e << 7));
64
+ const ch = (e & f) ^ (~e & g);
65
+ const t1 = (hh + S1 + ch + K[i]! + w[i]!) >>> 0;
66
+ const S0 =
67
+ ((a >>> 2) | (a << 30)) ^
68
+ ((a >>> 13) | (a << 19)) ^
69
+ ((a >>> 22) | (a << 10));
70
+ const maj = (a & b) ^ (a & c) ^ (b & c);
71
+ const t2 = (S0 + maj) >>> 0;
72
+ hh = g;
73
+ g = f;
74
+ f = e;
75
+ e = (d + t1) >>> 0;
76
+ d = c;
77
+ c = b;
78
+ b = a;
79
+ a = (t1 + t2) >>> 0;
80
+ }
81
+ h[0] = (h[0]! + a) >>> 0;
82
+ h[1] = (h[1]! + b) >>> 0;
83
+ h[2] = (h[2]! + c) >>> 0;
84
+ h[3] = (h[3]! + d) >>> 0;
85
+ h[4] = (h[4]! + e) >>> 0;
86
+ h[5] = (h[5]! + f) >>> 0;
87
+ h[6] = (h[6]! + g) >>> 0;
88
+ h[7] = (h[7]! + hh) >>> 0;
89
+ }
90
+ const out = new Uint8Array(32);
91
+ const outView = new DataView(out.buffer);
92
+ for (let i = 0; i < 8; i++) outView.setUint32(i * 4, h[i]!, false);
93
+ return out;
94
+ }
95
+ /* eslint-enable no-bitwise */
96
+
97
+ export function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array {
98
+ const block = 64;
99
+ let k = key.length > block ? sha256(key) : key;
100
+ const padded = new Uint8Array(block);
101
+ padded.set(k);
102
+ k = padded;
103
+ const inner = new Uint8Array(block + message.length);
104
+ const outer = new Uint8Array(block + 32);
105
+ for (let i = 0; i < block; i++) {
106
+ inner[i] = k[i]! ^ 0x36; // eslint-disable-line no-bitwise
107
+ outer[i] = k[i]! ^ 0x5c; // eslint-disable-line no-bitwise
108
+ }
109
+ inner.set(message, block);
110
+ outer.set(sha256(inner), block);
111
+ return sha256(outer);
112
+ }