-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
72 lines (67 loc) · 2.29 KB
/
server.js
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
67
68
69
70
71
72
import * as rtc from "#src/services/rtc.js";
import * as http from "#src/services/http.js";
import * as auth from "#src/services/auth.js";
import { Logger } from "#src/utils/utils.js";
import { Channel } from "#src/models/channel.js";
const logger = new Logger("SERVER", { logLevel: "all" });
async function run() {
await auth.start();
await rtc.start();
await http.start();
logger.info(`ready - PID: ${process.pid}`);
}
function cleanup() {
Channel.closeAll();
http.close();
rtc.close();
logger.info("cleanup complete");
}
const processHandlers = {
exit: cleanup,
uncaughtException: (error) => {
logger.error(`uncaught exception ${error.name}: ${error.message} ${error.stack ?? ""}`);
},
SIGINT: cleanup,
// 8, restarts the server
SIGFPE: async () => {
cleanup();
await run();
},
// 14, soft reset: only kicks all sessions, but keeps services alive
SIGALRM: () => {
Channel.closeAll();
},
// 29, prints server stats
SIGIO: async () => {
let globalIncomingBitrate = 0;
const proms = [];
for (const channel of Channel.records.values()) {
proms.push(
(async () => {
const {
sessionsStats: {
incomingBitRate: { audio, camera, screen, total },
count,
},
} = await channel.getStats();
globalIncomingBitrate += total;
logger.info(`Channel ${channel.name}: ${count} sessions`);
logger.info(`-- audio: ${audio} bps`);
logger.info(`-- camera: ${camera} bps`);
logger.info(`-- screen: ${screen} bps`);
logger.info(`-- total: ${total} bps`);
})()
);
}
await Promise.all(proms);
logger.info(`${Channel.records.size} channels total`);
logger.info(`Global incoming bitrate: ${globalIncomingBitrate} bps`);
},
};
// ==================== PROCESS ====================
process.name = "odoo_sfu";
for (const [signal, handler] of Object.entries(processHandlers)) {
process.on(signal, handler);
}
await run();
// ==================== ======= ====================