-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
66 lines (57 loc) · 2.24 KB
/
main.js
File metadata and controls
66 lines (57 loc) · 2.24 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* eufy-security-client Streaming Proxy Server
*
* Main entry point for the streaming proxy server that handles:
* - Connection to Eufy Security devices
* - Video stream transcoding
* - REST API for client communication
*/
// Import required modules
const utils = require('./server/utils');
const transcode = require('./server/transcode');
const eufy = require('./server/eufy-client');
const restServer = require('./server/rest');
// Load configuration from config file
let CONFIG = utils.loadConfig();
// Initialize server components
eufy.connect(CONFIG.EUFY_CONFIG); // Connect to Eufy Security system
transcode.initTranscode(); // Initialize video transcoding service
restServer.initRestServer(); // Start REST API server
utils.log('🚀 eufy-security-client Streaming Proxy started', 'info');
/**
* Graceful shutdown handler
* Handles SIGINT signal (Ctrl+C) to cleanly stop all services
*/
process.on('SIGINT', async () => {
utils.log('\n🛑 Shutting down...', 'warn');
transcode.stopTranscoding(); // Stop all active transcoding processes
await eufy.close(); // Close Eufy connection gracefully
process.exit(0);
});
/**
* Global exception handler
* Catches unhandled exceptions to prevent server crashes
* Some exceptions (EPIPE, ECONNRESET, EOF) are expected during normal operation
* and are safely ignored to maintain server stability
*/
process.on('uncaughtException', (err) => {
// EPIPE: Broken pipe - occurs when a client disconnects unexpectedly
if (err.code === 'EPIPE') {
utils.log('ℹ️ EPIPE uncaught exception. Ignored.', 'debug');
return;
}
// ECONNRESET: Connection reset - occurs when a connection is forcibly closed
if (err.code === 'ECONNRESET') {
utils.log('ℹ️ ECONNRESET uncaught exception. Ignored.', 'debug');
return;
}
// EOF Error: End of file - occurs during stream termination
if (err.code === 'EOF Error') {
utils.log('ℹ️ EOF Error uncaught exception. Ignored.', 'debug');
return;
}
// Log and exit for all other uncaught exceptions
utils.log(`❌ Uncaught exception: ${err.code} ${err}`, 'error');
console.error(err);
process.exit(1);
});