@repliqo/sdk-react-native 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INTEGRATION_GUIDE.md +1384 -1312
- package/android/src/main/java/com/repliqo/screencapture/MultiWindowCapture.java +242 -230
- package/android/src/main/java/com/repliqo/screencapture/ScreenCaptureModule.java +94 -170
- package/dist/components/RepliqoFlatList.d.ts +5 -0
- package/dist/components/RepliqoFlatList.js +39 -0
- package/dist/components/RepliqoScrollView.d.ts +3 -0
- package/dist/components/RepliqoScrollView.js +16 -265
- package/dist/components/useRepliqoScrollTracking.d.ts +33 -0
- package/dist/components/useRepliqoScrollTracking.js +304 -0
- package/dist/core/client.d.ts +52 -5
- package/dist/core/client.js +310 -48
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.js +5 -1
- package/dist/core/storage.d.ts +29 -0
- package/dist/core/storage.js +33 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/snapshot/NativeScreenCapture.d.ts +6 -44
- package/dist/snapshot/NativeScreenCapture.js +6 -64
- package/dist/snapshot/capture.d.ts +7 -0
- package/dist/snapshot/capture.js +17 -5
- package/dist/trackers/error.tracker.d.ts +25 -0
- package/dist/trackers/error.tracker.js +114 -37
- package/dist/trackers/navigation.tracker.js +11 -0
- package/dist/transport/api.client.d.ts +34 -1
- package/dist/transport/api.client.js +102 -19
- package/dist/transport/batch-queue.d.ts +53 -1
- package/dist/transport/batch-queue.js +126 -19
- package/dist/types/events.d.ts +12 -0
- package/package.json +68 -64
- package/src/components/RepliqoFlatList.tsx +64 -0
- package/src/components/RepliqoScrollView.tsx +53 -302
- package/src/components/useRepliqoScrollTracking.ts +366 -0
- package/src/core/client.ts +953 -672
- package/src/core/config.ts +38 -30
- package/src/core/storage.ts +51 -0
- package/src/index.ts +54 -52
- package/src/snapshot/NativeScreenCapture.ts +62 -157
- package/src/snapshot/capture.ts +154 -142
- package/src/trackers/error.tracker.ts +211 -136
- package/src/trackers/navigation.tracker.ts +107 -98
- package/src/transport/api.client.ts +430 -327
- package/src/transport/batch-queue.ts +212 -95
- package/src/types/events.ts +72 -60
- package/android/src/main/java/com/repliqo/screencapture/FullContentCapture.java +0 -273
- package/android/src/main/java/com/repliqo/screencapture/PixelCopyScan.java +0 -279
- package/android/src/main/java/com/repliqo/screencapture/ScrollScanCapture.java +0 -248
- package/src/snapshot/ScreenCaptureManager.ts +0 -156
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
package com.repliqo.screencapture;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.graphics.Bitmap;
|
|
5
|
-
import android.graphics.Canvas;
|
|
6
|
-
import android.util.Base64;
|
|
7
|
-
import android.util.Log;
|
|
8
|
-
import android.view.View;
|
|
9
|
-
import android.view.ViewGroup;
|
|
10
|
-
import android.widget.ScrollView;
|
|
11
|
-
|
|
12
|
-
import com.facebook.react.bridge.Arguments;
|
|
13
|
-
import com.facebook.react.bridge.WritableArray;
|
|
14
|
-
import com.facebook.react.bridge.WritableMap;
|
|
15
|
-
|
|
16
|
-
import java.io.ByteArrayOutputStream;
|
|
17
|
-
import java.lang.reflect.Field;
|
|
18
|
-
import java.util.ArrayList;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Performs a fast programmatic scroll-scan of the main ScrollView to
|
|
22
|
-
* capture the ENTIRE content as a series of viewport tiles.
|
|
23
|
-
*
|
|
24
|
-
* The scan is invisible to the user:
|
|
25
|
-
* 1. Save current scroll position
|
|
26
|
-
* 2. scrollTo(0, 0) — instant, no animation
|
|
27
|
-
* 3. Capture viewport at Y=0
|
|
28
|
-
* 4. scrollTo(0, viewportHeight) — instant
|
|
29
|
-
* 5. Capture viewport at Y=viewportHeight
|
|
30
|
-
* 6. ... repeat until end of content
|
|
31
|
-
* 7. scrollTo(0, originalY) — restore position
|
|
32
|
-
*
|
|
33
|
-
* Total time: ~300-500ms for a typical screen. The user sees a brief
|
|
34
|
-
* flicker at most (usually nothing because it happens within one frame).
|
|
35
|
-
*
|
|
36
|
-
* Must run on the UI thread.
|
|
37
|
-
*/
|
|
38
|
-
public class ScrollScanCapture {
|
|
39
|
-
private static final String TAG = "RepliqoCapture";
|
|
40
|
-
private static final int TARGET_WIDTH = 390;
|
|
41
|
-
private static final int JPEG_QUALITY = 40;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Scan the ScrollView and return all viewport tiles.
|
|
45
|
-
*
|
|
46
|
-
* @return WritableArray of tile objects, or null on failure
|
|
47
|
-
*/
|
|
48
|
-
public static WritableArray scan(Activity activity) {
|
|
49
|
-
if (activity == null || activity.isFinishing()) return null;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
View scrollView = findVerticalScrollView(activity);
|
|
53
|
-
if (scrollView == null) {
|
|
54
|
-
Log.d(TAG, "No ScrollView found for scan");
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
View contentView = getContentChild(scrollView);
|
|
59
|
-
if (contentView == null) return null;
|
|
60
|
-
|
|
61
|
-
int viewportWidth = scrollView.getWidth();
|
|
62
|
-
int viewportHeight = scrollView.getHeight();
|
|
63
|
-
int contentHeight = contentView.getHeight();
|
|
64
|
-
|
|
65
|
-
if (viewportWidth <= 0 || viewportHeight <= 0 || contentHeight <= 0) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// If content fits in viewport, just capture once
|
|
70
|
-
if (contentHeight <= viewportHeight) {
|
|
71
|
-
WritableArray tiles = Arguments.createArray();
|
|
72
|
-
WritableMap tile = captureSingleTile(
|
|
73
|
-
scrollView, 0, viewportWidth, viewportHeight, contentHeight
|
|
74
|
-
);
|
|
75
|
-
if (tile != null) tiles.pushMap(tile);
|
|
76
|
-
return tiles;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Save original scroll position
|
|
80
|
-
int originalScrollY = scrollView.getScrollY();
|
|
81
|
-
|
|
82
|
-
WritableArray tiles = Arguments.createArray();
|
|
83
|
-
|
|
84
|
-
// Scan from top to bottom in viewport-sized steps
|
|
85
|
-
// Use 80% overlap to avoid gaps from scroll imprecision
|
|
86
|
-
int step = (int) (viewportHeight * 0.8);
|
|
87
|
-
int y = 0;
|
|
88
|
-
|
|
89
|
-
while (y < contentHeight) {
|
|
90
|
-
// Scroll to position — instant, no animation
|
|
91
|
-
scrollView.scrollTo(0, y);
|
|
92
|
-
|
|
93
|
-
// Force a layout pass so the views at this position render
|
|
94
|
-
scrollView.invalidate();
|
|
95
|
-
contentView.invalidate();
|
|
96
|
-
|
|
97
|
-
// Capture the viewport at this position
|
|
98
|
-
WritableMap tile = captureSingleTile(
|
|
99
|
-
scrollView, y, viewportWidth, viewportHeight, contentHeight
|
|
100
|
-
);
|
|
101
|
-
if (tile != null) {
|
|
102
|
-
tiles.pushMap(tile);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
y += step;
|
|
106
|
-
|
|
107
|
-
// Last step: capture the very bottom
|
|
108
|
-
if (y >= contentHeight && y - step < contentHeight - viewportHeight) {
|
|
109
|
-
y = contentHeight - viewportHeight;
|
|
110
|
-
scrollView.scrollTo(0, y);
|
|
111
|
-
scrollView.invalidate();
|
|
112
|
-
contentView.invalidate();
|
|
113
|
-
|
|
114
|
-
WritableMap lastTile = captureSingleTile(
|
|
115
|
-
scrollView, y, viewportWidth, viewportHeight, contentHeight
|
|
116
|
-
);
|
|
117
|
-
if (lastTile != null) {
|
|
118
|
-
tiles.pushMap(lastTile);
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Restore original scroll position — instant
|
|
125
|
-
scrollView.scrollTo(0, originalScrollY);
|
|
126
|
-
|
|
127
|
-
Log.d(TAG, "Scroll scan complete: " + tiles.size() +
|
|
128
|
-
" tiles, content=" + contentHeight + "px");
|
|
129
|
-
|
|
130
|
-
return tiles;
|
|
131
|
-
|
|
132
|
-
} catch (Exception e) {
|
|
133
|
-
Log.w(TAG, "ScrollScanCapture failed: " + e.getMessage());
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private static WritableMap captureSingleTile(
|
|
139
|
-
View scrollView, int scrollY,
|
|
140
|
-
int viewportWidth, int viewportHeight, int contentHeight) {
|
|
141
|
-
try {
|
|
142
|
-
// Scale to target width
|
|
143
|
-
float scale = (float) TARGET_WIDTH / viewportWidth;
|
|
144
|
-
int outWidth = TARGET_WIDTH;
|
|
145
|
-
int outHeight = Math.round(viewportHeight * scale);
|
|
146
|
-
|
|
147
|
-
if (outWidth <= 0 || outHeight <= 0) return null;
|
|
148
|
-
|
|
149
|
-
Bitmap bitmap = Bitmap.createBitmap(outWidth, outHeight,
|
|
150
|
-
Bitmap.Config.ARGB_8888);
|
|
151
|
-
Canvas canvas = new Canvas(bitmap);
|
|
152
|
-
canvas.scale(scale, scale);
|
|
153
|
-
|
|
154
|
-
// Translate canvas to account for scroll position within the view
|
|
155
|
-
canvas.translate(0, -scrollView.getScrollY());
|
|
156
|
-
|
|
157
|
-
// Draw the scrollview's content
|
|
158
|
-
View content = getContentChild(scrollView);
|
|
159
|
-
if (content != null) {
|
|
160
|
-
content.draw(canvas);
|
|
161
|
-
} else {
|
|
162
|
-
scrollView.draw(canvas);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Compress to JPEG
|
|
166
|
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
167
|
-
bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_QUALITY, baos);
|
|
168
|
-
String base64 = Base64.encodeToString(baos.toByteArray(), Base64.NO_WRAP);
|
|
169
|
-
bitmap.recycle();
|
|
170
|
-
|
|
171
|
-
WritableMap tile = Arguments.createMap();
|
|
172
|
-
tile.putString("image", base64);
|
|
173
|
-
tile.putInt("width", outWidth);
|
|
174
|
-
tile.putInt("height", outHeight);
|
|
175
|
-
tile.putInt("scrollOffsetY", scrollY);
|
|
176
|
-
tile.putInt("viewportHeight", viewportHeight);
|
|
177
|
-
tile.putInt("contentHeight", contentHeight);
|
|
178
|
-
tile.putString("format", "jpeg");
|
|
179
|
-
return tile;
|
|
180
|
-
|
|
181
|
-
} catch (Exception e) {
|
|
182
|
-
Log.w(TAG, "Tile capture at Y=" + scrollY + " failed: " + e.getMessage());
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
@SuppressWarnings("unchecked")
|
|
188
|
-
private static View findVerticalScrollView(Activity activity) {
|
|
189
|
-
View decorView = activity.getWindow().getDecorView();
|
|
190
|
-
View found = findInTree(decorView);
|
|
191
|
-
if (found != null) return found;
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
Class<?> wmgClass = Class.forName("android.view.WindowManagerGlobal");
|
|
195
|
-
Object wmg = wmgClass.getMethod("getInstance").invoke(null);
|
|
196
|
-
Field viewsField = wmgClass.getDeclaredField("mViews");
|
|
197
|
-
viewsField.setAccessible(true);
|
|
198
|
-
ArrayList<View> views = (ArrayList<View>) viewsField.get(wmg);
|
|
199
|
-
if (views != null) {
|
|
200
|
-
for (View root : views) {
|
|
201
|
-
if (root == decorView) continue;
|
|
202
|
-
found = findInTree(root);
|
|
203
|
-
if (found != null) return found;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
} catch (Exception e) { }
|
|
207
|
-
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
private static View findInTree(View view) {
|
|
212
|
-
if (view == null) return null;
|
|
213
|
-
if (isVerticalScroll(view) && view instanceof ViewGroup
|
|
214
|
-
&& ((ViewGroup) view).getChildCount() > 0) {
|
|
215
|
-
return view;
|
|
216
|
-
}
|
|
217
|
-
if (view instanceof ViewGroup) {
|
|
218
|
-
ViewGroup group = (ViewGroup) view;
|
|
219
|
-
for (int i = 0; i < group.getChildCount(); i++) {
|
|
220
|
-
View found = findInTree(group.getChildAt(i));
|
|
221
|
-
if (found != null) return found;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private static boolean isVerticalScroll(View view) {
|
|
228
|
-
if (view instanceof ScrollView) return true;
|
|
229
|
-
Class<?> clazz = view.getClass();
|
|
230
|
-
while (clazz != null && clazz != View.class) {
|
|
231
|
-
String name = clazz.getName();
|
|
232
|
-
if (name.contains("Horizontal")) return false;
|
|
233
|
-
if (name.contains("NestedScrollView") ||
|
|
234
|
-
name.contains("ReactScrollView") ||
|
|
235
|
-
name.endsWith("ScrollView")) return true;
|
|
236
|
-
clazz = clazz.getSuperclass();
|
|
237
|
-
}
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
private static View getContentChild(View scrollView) {
|
|
242
|
-
if (scrollView instanceof ViewGroup) {
|
|
243
|
-
ViewGroup group = (ViewGroup) scrollView;
|
|
244
|
-
if (group.getChildCount() > 0) return group.getChildAt(0);
|
|
245
|
-
}
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { captureFullContent } from './NativeScreenCapture';
|
|
2
|
-
|
|
3
|
-
/** 24 hours in milliseconds. */
|
|
4
|
-
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
5
|
-
|
|
6
|
-
/** Wait for screen to render before capturing. */
|
|
7
|
-
const RENDER_DELAY_MS = 800;
|
|
8
|
-
|
|
9
|
-
/** Max base64 size to upload (3MB base64 ≈ ~2.2MB binary). */
|
|
10
|
-
const MAX_IMAGE_SIZE = 3 * 1024 * 1024;
|
|
11
|
-
|
|
12
|
-
export type UploadFn = (
|
|
13
|
-
screenName: string,
|
|
14
|
-
image: string,
|
|
15
|
-
width: number,
|
|
16
|
-
height: number,
|
|
17
|
-
isFullContent: boolean,
|
|
18
|
-
) => Promise<void>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Manages full-content screen captures for heatmap backgrounds.
|
|
22
|
-
*
|
|
23
|
-
* - Captures the full ScrollView content on screen enter
|
|
24
|
-
* - Local cache with 24h TTL to avoid redundant captures
|
|
25
|
-
* - Cancels pending captures when navigating away (prevents cross-screen bugs)
|
|
26
|
-
* - Async and non-blocking: never delays navigation or crashes the app
|
|
27
|
-
*/
|
|
28
|
-
export class ScreenCaptureManager {
|
|
29
|
-
private cache = new Map<string, number>();
|
|
30
|
-
private pending = new Set<string>();
|
|
31
|
-
private pendingTimer: ReturnType<typeof setTimeout> | null = null;
|
|
32
|
-
private currentScreen: string | null = null;
|
|
33
|
-
private uploadFn: UploadFn;
|
|
34
|
-
private debug: boolean;
|
|
35
|
-
|
|
36
|
-
constructor(uploadFn: UploadFn, debug = false) {
|
|
37
|
-
this.uploadFn = uploadFn;
|
|
38
|
-
this.debug = debug;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Called when the user enters a screen. Schedules a full-content
|
|
43
|
-
* capture after a delay if no recent capture exists.
|
|
44
|
-
*
|
|
45
|
-
* Cancels any pending capture from a previous screen to prevent
|
|
46
|
-
* cross-screen data corruption (capturing screen B but labeling as A).
|
|
47
|
-
*/
|
|
48
|
-
onScreenEnter(screenName: string): void {
|
|
49
|
-
// Cancel any pending capture from the previous screen
|
|
50
|
-
this.cancelPending();
|
|
51
|
-
this.currentScreen = screenName;
|
|
52
|
-
|
|
53
|
-
if (!this.shouldCapture(screenName)) return;
|
|
54
|
-
|
|
55
|
-
this.pending.add(screenName);
|
|
56
|
-
|
|
57
|
-
this.pendingTimer = setTimeout(() => {
|
|
58
|
-
this.pendingTimer = null;
|
|
59
|
-
// Verify the user is STILL on this screen before capturing
|
|
60
|
-
if (this.currentScreen !== screenName) {
|
|
61
|
-
this.pending.delete(screenName);
|
|
62
|
-
if (this.debug) {
|
|
63
|
-
console.log(
|
|
64
|
-
`[Repliqo] Screen capture skipped: navigated away from "${screenName}"`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
this.captureAndUpload(screenName).catch(() => {});
|
|
70
|
-
}, RENDER_DELAY_MS);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private shouldCapture(screenName: string): boolean {
|
|
74
|
-
if (this.pending.has(screenName)) return false;
|
|
75
|
-
|
|
76
|
-
const lastCapture = this.cache.get(screenName);
|
|
77
|
-
if (lastCapture && Date.now() - lastCapture < CACHE_TTL_MS) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private async captureAndUpload(screenName: string): Promise<void> {
|
|
85
|
-
try {
|
|
86
|
-
const result = await captureFullContent();
|
|
87
|
-
if (!result) {
|
|
88
|
-
if (this.debug) {
|
|
89
|
-
console.log(`[Repliqo] Screen capture returned null for "${screenName}"`);
|
|
90
|
-
}
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Guard: check we're still on the same screen after the async capture
|
|
95
|
-
if (this.currentScreen !== screenName) {
|
|
96
|
-
if (this.debug) {
|
|
97
|
-
console.log(
|
|
98
|
-
`[Repliqo] Screen capture discarded: user left "${screenName}" during capture`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Guard: reject oversized images to prevent OOM during upload
|
|
105
|
-
if (result.image.length > MAX_IMAGE_SIZE) {
|
|
106
|
-
if (this.debug) {
|
|
107
|
-
console.warn(
|
|
108
|
-
`[Repliqo] Screen capture too large (${Math.round(result.image.length / 1024)}KB), skipping "${screenName}"`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (this.debug) {
|
|
115
|
-
console.log(
|
|
116
|
-
`[Repliqo] Screen captured: "${screenName}" ${result.width}x${result.height} ` +
|
|
117
|
-
`(full=${result.isFullContent}, ${Math.round(result.image.length / 1024)}KB)`,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
await this.uploadFn(
|
|
122
|
-
screenName,
|
|
123
|
-
result.image,
|
|
124
|
-
result.width,
|
|
125
|
-
result.height,
|
|
126
|
-
result.isFullContent,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
this.cache.set(screenName, Date.now());
|
|
130
|
-
|
|
131
|
-
if (this.debug) {
|
|
132
|
-
console.log(`[Repliqo] Screen capture uploaded: "${screenName}"`);
|
|
133
|
-
}
|
|
134
|
-
} catch (err) {
|
|
135
|
-
if (this.debug) {
|
|
136
|
-
console.warn(`[Repliqo] Screen capture failed for "${screenName}":`, err);
|
|
137
|
-
}
|
|
138
|
-
} finally {
|
|
139
|
-
this.pending.delete(screenName);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private cancelPending(): void {
|
|
144
|
-
if (this.pendingTimer !== null) {
|
|
145
|
-
clearTimeout(this.pendingTimer);
|
|
146
|
-
this.pendingTimer = null;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
reset(): void {
|
|
151
|
-
this.cancelPending();
|
|
152
|
-
this.cache.clear();
|
|
153
|
-
this.pending.clear();
|
|
154
|
-
this.currentScreen = null;
|
|
155
|
-
}
|
|
156
|
-
}
|