-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera_sim.js
More file actions
48 lines (36 loc) · 1.33 KB
/
camera_sim.js
File metadata and controls
48 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const fs = require('node:fs');
const testFileName = 'stream_frame.jpg';
async function uploadFrame() {
try {
const fileBuffer = fs.readFileSync(testFileName);
const blob = new Blob([fileBuffer], { type: 'image/jpeg' });
const formData = new FormData();
formData.append('frame', blob, testFileName);
const response = await fetch('http://localhost:3000/api/camera/upload', {
method: 'POST',
body: formData
});
if (response.ok) {
const data = await response.json();
process.stdout.write(`\r✅ Upload Success | FPS: ${data.fps} `);
} else {
const text = await response.text();
console.error('\n❌ Upload Failed:', response.status, text);
}
} catch (error) {
if (error.code === 'ECONNREFUSED' || error.cause?.code === 'ECONNREFUSED') {
process.stdout.write(`\r❌ Connection Refused - Is Server Running? `);
} else {
console.error('\n❌ Error testing upload:', error);
}
}
}
console.log("🚀 Starting Camera Simulation...");
console.log("Press Ctrl+C to stop");
// Upload every 200ms (approx 5 FPS)
setInterval(uploadFrame, 200);
// Cleanup on exit
process.on('SIGINT', () => {
console.log('\nStopping simulation...');
process.exit();
});