iidrak-analytics-react 1.2.4 → 1.2.5
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { strf } from "./string.format.js";
|
|
4
|
-
import
|
|
4
|
+
import { captureRef } from "react-native-view-shot";
|
|
5
5
|
import { Platform, Dimensions } from "react-native";
|
|
6
6
|
|
|
7
7
|
strf();
|
|
@@ -24,6 +24,8 @@ class MetaStreamIORecorder {
|
|
|
24
24
|
// Use lower quality by default to save bandwidth
|
|
25
25
|
this.quality = config.quality || 0.5;
|
|
26
26
|
this.fps = config.fps || 2; // Frames per second (0.5s interval)
|
|
27
|
+
this.app_id = config.app_id || "default"; // Default to 'default' app if not specified
|
|
28
|
+
this.lastBase64 = null;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
setSessionId(id) {
|
|
@@ -41,7 +43,7 @@ class MetaStreamIORecorder {
|
|
|
41
43
|
|
|
42
44
|
// 1. Initialize Session on Python Server
|
|
43
45
|
// Note: We use a separate fetch here because the payload format is different from standard analytics
|
|
44
|
-
await fetch(`${this.endpoint}/sessions`, {
|
|
46
|
+
await fetch(`${this.endpoint}/apps/${this.app_id}/sessions`, {
|
|
45
47
|
method: 'POST',
|
|
46
48
|
headers: { 'Content-Type': 'application/json' },
|
|
47
49
|
body: JSON.stringify({
|
|
@@ -84,25 +86,55 @@ class MetaStreamIORecorder {
|
|
|
84
86
|
|
|
85
87
|
startLoop(viewRef) {
|
|
86
88
|
const intervalMs = 1000 / this.fps;
|
|
87
|
-
|
|
89
|
+
this.lastUploadTime = 0;
|
|
90
|
+
console.log("Starting loop");
|
|
88
91
|
this.intervalId = setInterval(async () => {
|
|
89
92
|
if (!viewRef.current) return;
|
|
90
93
|
|
|
91
94
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
// Capture as base64 for comparison and direct upload
|
|
96
|
+
// Resize to width 400px (height maintained automatically) to reduce size
|
|
97
|
+
// Use PNG to ensure deterministic output for diffing
|
|
98
|
+
const base64 = await captureRef(viewRef, {
|
|
99
|
+
format: "png",
|
|
94
100
|
quality: this.quality,
|
|
95
|
-
|
|
101
|
+
width: 400,
|
|
102
|
+
result: "base64"
|
|
96
103
|
});
|
|
97
104
|
|
|
98
|
-
|
|
105
|
+
let isDuplicate = false;
|
|
106
|
+
if(this.lastBase64){
|
|
107
|
+
if (this.lastBase64 === base64) {
|
|
108
|
+
isDuplicate = true;
|
|
109
|
+
console.log("DBG:: Duplicate frame");
|
|
110
|
+
}else{
|
|
111
|
+
console.log("DBG:: New frame");
|
|
112
|
+
this.lastBase64 = base64;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const now = Date.now();
|
|
117
|
+
// Logic:
|
|
118
|
+
// If NEW frame: Upload immediately.
|
|
119
|
+
// If DUPLICATE frame:
|
|
120
|
+
// Only upload if it's been > 5 seconds since last upload (Keepalive)
|
|
121
|
+
// This reduces chatter significantly.
|
|
122
|
+
|
|
123
|
+
const timeSinceLastUpload = (now - this.lastUploadTime) / 1000;
|
|
124
|
+
|
|
125
|
+
if (!isDuplicate || timeSinceLastUpload > 5.0) {
|
|
126
|
+
console.log("DBG:: Uploading frame");
|
|
127
|
+
this.uploadFrame(base64, isDuplicate);
|
|
128
|
+
this.lastUploadTime = now;
|
|
129
|
+
this.lastBase64 = base64;
|
|
130
|
+
}
|
|
99
131
|
} catch (e) {
|
|
100
132
|
// Silent fail on capture error to avoid log spam
|
|
101
133
|
}
|
|
102
134
|
}, intervalMs);
|
|
103
135
|
}
|
|
104
136
|
|
|
105
|
-
async uploadFrame(
|
|
137
|
+
async uploadFrame(data, isDuplicate) {
|
|
106
138
|
if (!this.recorderSessionId) return;
|
|
107
139
|
|
|
108
140
|
const formData = new FormData();
|
|
@@ -111,14 +143,19 @@ class MetaStreamIORecorder {
|
|
|
111
143
|
|
|
112
144
|
formData.append('timestamp', String(timestamp));
|
|
113
145
|
formData.append('duration', String(duration));
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
146
|
+
|
|
147
|
+
if (isDuplicate) {
|
|
148
|
+
formData.append('is_duplicate', 'true');
|
|
149
|
+
} else {
|
|
150
|
+
formData.append('file', {
|
|
151
|
+
uri: 'data:image/png;base64,' + data,
|
|
152
|
+
type: 'image/png',
|
|
153
|
+
name: 'screenshot.png',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
119
156
|
|
|
120
157
|
try {
|
|
121
|
-
await fetch(`${this.endpoint}/sessions/${this.recorderSessionId}/screenshot`, {
|
|
158
|
+
await fetch(`${this.endpoint}/apps/${this.app_id}/sessions/${this.recorderSessionId}/screenshot`, {
|
|
122
159
|
method: 'POST',
|
|
123
160
|
body: formData,
|
|
124
161
|
headers: {
|
|
@@ -145,7 +182,7 @@ class MetaStreamIORecorder {
|
|
|
145
182
|
};
|
|
146
183
|
|
|
147
184
|
try {
|
|
148
|
-
fetch(`${this.endpoint}/sessions/${this.recorderSessionId}/events`, {
|
|
185
|
+
fetch(`${this.endpoint}/apps/${this.app_id}/sessions/${this.recorderSessionId}/events`, {
|
|
149
186
|
method: 'POST',
|
|
150
187
|
headers: { 'Content-Type': 'application/json' },
|
|
151
188
|
body: JSON.stringify([event])
|