react-native-frame-capture 1.0.1

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 (77) hide show
  1. package/FrameCapture.podspec +21 -0
  2. package/LICENSE +20 -0
  3. package/README.md +158 -0
  4. package/android/build.gradle +77 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +20 -0
  7. package/android/src/main/java/com/framecapture/CaptureManager.kt +831 -0
  8. package/android/src/main/java/com/framecapture/Constants.kt +196 -0
  9. package/android/src/main/java/com/framecapture/ErrorHandler.kt +165 -0
  10. package/android/src/main/java/com/framecapture/FrameCaptureModule.kt +653 -0
  11. package/android/src/main/java/com/framecapture/FrameCapturePackage.kt +32 -0
  12. package/android/src/main/java/com/framecapture/OverlayRenderer.kt +423 -0
  13. package/android/src/main/java/com/framecapture/PermissionHandler.kt +150 -0
  14. package/android/src/main/java/com/framecapture/ScreenCaptureService.kt +366 -0
  15. package/android/src/main/java/com/framecapture/StorageManager.kt +221 -0
  16. package/android/src/main/java/com/framecapture/capture/BitmapProcessor.kt +157 -0
  17. package/android/src/main/java/com/framecapture/capture/CaptureEventEmitter.kt +120 -0
  18. package/android/src/main/java/com/framecapture/models/CaptureModels.kt +302 -0
  19. package/android/src/main/java/com/framecapture/models/EnumsAndExtensions.kt +60 -0
  20. package/android/src/main/java/com/framecapture/models/OverlayModels.kt +154 -0
  21. package/android/src/main/java/com/framecapture/service/CaptureNotificationManager.kt +286 -0
  22. package/android/src/main/java/com/framecapture/storage/StorageStrategies.kt +317 -0
  23. package/android/src/main/java/com/framecapture/utils/ValidationUtils.kt +379 -0
  24. package/app.plugin.js +1 -0
  25. package/ios/FrameCapture.h +5 -0
  26. package/ios/FrameCapture.mm +21 -0
  27. package/lib/module/NativeFrameCapture.js +24 -0
  28. package/lib/module/NativeFrameCapture.js.map +1 -0
  29. package/lib/module/api.js +146 -0
  30. package/lib/module/api.js.map +1 -0
  31. package/lib/module/constants.js +67 -0
  32. package/lib/module/constants.js.map +1 -0
  33. package/lib/module/errors.js +19 -0
  34. package/lib/module/errors.js.map +1 -0
  35. package/lib/module/events.js +58 -0
  36. package/lib/module/events.js.map +1 -0
  37. package/lib/module/index.js +24 -0
  38. package/lib/module/index.js.map +1 -0
  39. package/lib/module/normalize.js +51 -0
  40. package/lib/module/normalize.js.map +1 -0
  41. package/lib/module/package.json +1 -0
  42. package/lib/module/types.js +165 -0
  43. package/lib/module/types.js.map +1 -0
  44. package/lib/module/validation.js +190 -0
  45. package/lib/module/validation.js.map +1 -0
  46. package/lib/typescript/package.json +1 -0
  47. package/lib/typescript/plugin/src/index.d.ts +4 -0
  48. package/lib/typescript/plugin/src/index.d.ts.map +1 -0
  49. package/lib/typescript/src/NativeFrameCapture.d.ts +75 -0
  50. package/lib/typescript/src/NativeFrameCapture.d.ts.map +1 -0
  51. package/lib/typescript/src/api.d.ts +66 -0
  52. package/lib/typescript/src/api.d.ts.map +1 -0
  53. package/lib/typescript/src/constants.d.ts +41 -0
  54. package/lib/typescript/src/constants.d.ts.map +1 -0
  55. package/lib/typescript/src/errors.d.ts +14 -0
  56. package/lib/typescript/src/errors.d.ts.map +1 -0
  57. package/lib/typescript/src/events.d.ts +30 -0
  58. package/lib/typescript/src/events.d.ts.map +1 -0
  59. package/lib/typescript/src/index.d.ts +12 -0
  60. package/lib/typescript/src/index.d.ts.map +1 -0
  61. package/lib/typescript/src/normalize.d.ts +43 -0
  62. package/lib/typescript/src/normalize.d.ts.map +1 -0
  63. package/lib/typescript/src/types.d.ts +247 -0
  64. package/lib/typescript/src/types.d.ts.map +1 -0
  65. package/lib/typescript/src/validation.d.ts +15 -0
  66. package/lib/typescript/src/validation.d.ts.map +1 -0
  67. package/package.json +196 -0
  68. package/plugin/build/index.js +48 -0
  69. package/src/NativeFrameCapture.ts +86 -0
  70. package/src/api.ts +189 -0
  71. package/src/constants.ts +69 -0
  72. package/src/errors.ts +21 -0
  73. package/src/events.ts +61 -0
  74. package/src/index.tsx +31 -0
  75. package/src/normalize.ts +81 -0
  76. package/src/types.ts +327 -0
  77. package/src/validation.ts +321 -0
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "FrameCapture"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/nasyx-rakeeb/react-native-frame-capture.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+
20
+ install_modules_dependencies(s)
21
+ end
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Nasyx Rakeeb
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # React Native Frame Capture
2
+
3
+ [![npm version](https://img.shields.io/npm/v/react-native-frame-capture.svg)](https://www.npmjs.com/package/react-native-frame-capture)
4
+ [![npm downloads](https://img.shields.io/npm/dm/react-native-frame-capture.svg)](https://www.npmjs.com/package/react-native-frame-capture)
5
+ [![license](https://img.shields.io/npm/l/react-native-frame-capture.svg)](https://github.com/nasyx-rakeeb/react-native-frame-capture/blob/main/LICENSE)
6
+ [![platform](https://img.shields.io/badge/platform-Android-green.svg)](https://www.android.com/)
7
+
8
+ Reliable screen capture for React Native Android. Capture frames at intervals with customizable overlays and storage options.
9
+
10
+ ## Features
11
+
12
+ - 📸 **Interval-based capture** - Capture frames at configurable intervals (100ms - 60s)
13
+ - 🎨 **Customizable overlays** - Add text and image overlays with template variables
14
+ - 💾 **Flexible storage** - Save to app-specific, public, or custom directories
15
+ - 🔄 **Background capture** - Continues capturing when app is minimized (foreground service)
16
+ - ⚡ **High performance** - Built with Kotlin and TurboModule architecture
17
+ - 🎯 **Precise control** - Pause, resume, and stop capture on demand
18
+ - 📊 **Real-time events** - Get notified for every captured frame
19
+ - 🔧 **Highly configurable** - Image quality, format, resolution scaling, and more
20
+ - 📱 **Expo compatible** - Works with Expo through config plugin
21
+ - 🎭 **Custom regions** - Capture specific screen areas
22
+ - 🚫 **Status bar exclusion** - Optionally exclude status bar from captures
23
+
24
+ ## How It Works
25
+
26
+ React Native Frame Capture uses Android's **MediaProjection API** to capture screen content at regular intervals. Here's the flow:
27
+
28
+ 1. **Request Permission** - User grants screen capture permission via system dialog
29
+ 2. **Start Foreground Service** - Ensures capture continues in background
30
+ 3. **Create Virtual Display** - Mirrors screen content to an ImageReader
31
+ 4. **Capture Frames** - Grabs frames at your specified interval (e.g., every 1 second)
32
+ 5. **Process & Save** - Converts to bitmap, applies overlays, saves to storage
33
+ 6. **Emit Events** - Notifies your app with frame info (path, size, timestamp)
34
+
35
+ **Key Components:**
36
+
37
+ - **MediaProjection** - Android API for screen capture (no root required)
38
+ - **Foreground Service** - Keeps capture running when app is minimized
39
+ - **ImageReader** - Efficiently captures screen pixels
40
+ - **TurboModule** - Fast native-to-JS communication
41
+
42
+ **Why Foreground Service?** Android kills background processes aggressively. The foreground service (with notification) ensures reliable capture even when your app isn't visible.
43
+
44
+ ## Requirements
45
+
46
+ - React Native >= 0.74
47
+ - Android minSdkVersion >= 21 (Android 5.0)
48
+ - Android compileSdkVersion >= 34
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install react-native-frame-capture
54
+ ```
55
+
56
+ or
57
+
58
+ ```bash
59
+ yarn add react-native-frame-capture
60
+ ```
61
+
62
+ ### Expo
63
+
64
+ Add the config plugin to your `app.json` or `app.config.js`:
65
+
66
+ ```json
67
+ {
68
+ "expo": {
69
+ "plugins": ["react-native-frame-capture"]
70
+ }
71
+ }
72
+ ```
73
+
74
+ Then rebuild your app:
75
+
76
+ ```bash
77
+ npx expo prebuild
78
+ npx expo run:android
79
+ ```
80
+
81
+ ## Quick Start
82
+
83
+ ```typescript
84
+ import * as FrameCapture from 'react-native-frame-capture';
85
+ import { Platform, PermissionsAndroid } from 'react-native';
86
+
87
+ // 1. Request notification permission (Android 13+)
88
+ if (Platform.OS === 'android' && Platform.Version >= 33) {
89
+ await PermissionsAndroid.request(
90
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
91
+ );
92
+ }
93
+
94
+ // 2. Request screen capture permission
95
+ const permissionStatus = await FrameCapture.requestPermission();
96
+
97
+ if (permissionStatus === FrameCapture.PermissionStatus.GRANTED) {
98
+ // 3. Start capturing
99
+ await FrameCapture.startCapture({
100
+ capture: {
101
+ interval: 1000, // Capture every second
102
+ },
103
+ image: {
104
+ quality: 80,
105
+ format: 'jpeg',
106
+ },
107
+ storage: {
108
+ saveFrames: true,
109
+ location: 'private',
110
+ },
111
+ });
112
+
113
+ // 4. Listen for captured frames
114
+ const subscription = FrameCapture.addListener(
115
+ FrameCapture.CaptureEventType.FRAME_CAPTURED,
116
+ (event) => {
117
+ console.log('Frame captured:', event.filePath);
118
+ }
119
+ );
120
+
121
+ // 5. Stop capturing when done
122
+ await FrameCapture.stopCapture();
123
+ subscription.remove();
124
+ }
125
+ ```
126
+
127
+ ## Documentation
128
+
129
+ - **[API Reference](docs/api-reference.md)** - Complete API documentation
130
+ - **[Configuration](docs/configuration.md)** - Configuration options and interfaces
131
+ - **[Events](docs/events.md)** - Event types and handling
132
+ - **[Usage Examples](docs/usage-examples.md)** - Practical examples for common use cases
133
+ - **[Storage](docs/storage.md)** - Storage behavior and options
134
+ - **[Permissions](docs/permissions.md)** - Permission requirements and setup
135
+
136
+ ## Platform Support
137
+
138
+ | Platform | Supported | Version |
139
+ | -------- | --------- | ------- |
140
+ | Android | ✅ Yes | 5.0+ |
141
+ | iOS | ❌ No | N/A |
142
+
143
+ ## Architecture
144
+
145
+ - **TurboModule:** New Architecture compatible
146
+ - **Foreground Service:** Reliable background capture
147
+ - **Kotlin:** Native Android implementation
148
+ - **TypeScript:** Type-safe JavaScript API
149
+
150
+ ## Contributing
151
+
152
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
153
+
154
+ ## License
155
+
156
+ MIT © [Nasyx Rakeeb](https://github.com/nasyx-rakeeb)
157
+
158
+ Made with ❤️ using [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,77 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['FrameCapture_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["FrameCapture_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.framecapture"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ }
@@ -0,0 +1,5 @@
1
+ FrameCapture_kotlinVersion=2.0.21
2
+ FrameCapture_minSdkVersion=24
3
+ FrameCapture_targetSdkVersion=34
4
+ FrameCapture_compileSdkVersion=35
5
+ FrameCapture_ndkVersion=27.1.12297006
@@ -0,0 +1,20 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <!-- Foreground service permissions -->
3
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
4
+ <uses-permission
5
+ android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"
6
+ android:minSdkVersion="34" />
7
+
8
+ <!-- Notification permission for API 33+ -->
9
+ <uses-permission
10
+ android:name="android.permission.POST_NOTIFICATIONS"
11
+ android:minSdkVersion="33" />
12
+
13
+ <application>
14
+ <!-- Screen Capture Foreground Service -->
15
+ <service
16
+ android:name="com.framecapture.ScreenCaptureService"
17
+ android:exported="false"
18
+ android:foregroundServiceType="mediaProjection" />
19
+ </application>
20
+ </manifest>