@nosmai/moderation-react-native
v0.1.0
Published
On-device content and text moderation for React Native (image NSFW, object detection, chat toxicity), powered by the native Nosmai SDK.
Downloads
185
Readme
@nosmai/moderation-react-native
On-device content and text moderation for React Native, wrapping the native Nosmai SDK (CoreML/ANE on iOS, NCNN/Vulkan on Android). Image NSFW, object detection (weapon / drug / cigarette / alcohol) and chat toxicity. Everything runs offline; no frame or message leaves the device.
Image, video, text moderation and a live-camera preview are all supported.
Requirements
- iOS 15.1+, Android API 24+ (arm64-v8a only), New Architecture enabled.
- Android host app on Kotlin 2.2.0+ (the native AAR ships Kotlin 2.2.0 metadata).
- A Nosmai license key registered for your app's bundle id (iOS) / package name (Android) at https://nosmai.com/.
Install
npm install @nosmai/moderation-react-nativeiOS
No extra step. The pod depends on NosmaiModerationSDK, so pod install pulls
the native SDK and its encrypted models. Set the Podfile platform to 15.1 and,
because the SDK is a static xcframework, keep ENABLE_USER_SCRIPT_SANDBOXING = NO
(a Podfile post_install can force it). Add NSCameraUsageDescription and
ITSAppUsesNonExemptEncryption = NO to Info.plist.
Android
The native SDK ships as a large AAR that the host app must provide (the plugin references it at compile time only):
- Download
nosmai-detection.aarfrom the Android releases intoandroid/app/libs/nosmai-detection.aar. - In
android/app/build.gradle:android { defaultConfig { minSdkVersion 24; ndk { abiFilters "arm64-v8a" } } } dependencies { implementation files("libs/nosmai-detection.aar") } - Ensure the project uses Kotlin 2.2.0+.
Usage
import { NosmaiModeration } from '@nosmai/moderation-react-native';
// Initialize once. Load only the models you use.
const init = await NosmaiModeration.initialize('NOSMAI-XXXX', [
'objectDetection',
'nsfw',
]);
if (!init.success) {
console.warn('Moderation unavailable:', init.error);
}
// Image (objects + NSFW).
const r = await NosmaiModeration.analyzeImage(filePath);
if (r.isUnsafe) {
// r.detections, r.nsfw ('safe' | 'warn' | 'block')
}
// Recorded video.
const v = await NosmaiModeration.analyzeVideo(filePath, 500);
// Chat text (optional model).
await NosmaiModeration.initializeText();
const t = await NosmaiModeration.moderateText('a message to check');
if (t.blocked) {
console.log('blocked:', t.category);
}
// Tune thresholds at runtime.
NosmaiModeration.setThreshold('weapon', 0.85);
NosmaiModeration.setNsfwThreshold('explicit', 0.45);
// Free native resources.
NosmaiModeration.shutdown();Live camera
Render <NosmaiCameraPreview /> to open the camera and moderate every frame. The
native view owns the camera lifecycle: it starts on mount and stops on unmount.
Request camera permission before mounting it.
import { NosmaiCameraPreview } from '@nosmai/moderation-react-native';
<NosmaiCameraPreview
style={{ width: '100%', height: 320 }}
facing="back" // or "front"
onResult={(r) => {
if (r.isUnsafe) {
// r.nsfw ('safe' | 'warn' | 'block'), r.detections
}
}}
/>Add NSCameraUsageDescription (iOS) and the CAMERA permission (Android). The
live path also requires a license with the live feature enabled.
All async methods run native inference off the JS thread. analyzeImage,
analyzeVideo and moderateText return the typed result shapes exported from
this package (NosmaiResult, NosmaiVideoResult, NosmaiTextResult).
How it works
The Turbo Module bridges to the native SDK: iOS calls the NosmaiModerationSDK
pod, Android calls the AAR. Results cross the bridge as JSON and are parsed into
typed objects with string enums, so the API matches the native and web SDKs.
Models are encrypted and decrypted in native memory, keyed by the license.
License
Proprietary. Register your app at https://nosmai.com/ to get a license key.
