-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiaxServer.js
executable file
·49 lines (41 loc) · 1.29 KB
/
iaxServer.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
#!/usr/bin/env node
/**
* IAX2 Server for Registrations
*
* @author Rob Vella, KK9ROB <[email protected]>
* @copyright Copyright (c) 2020 AllStarLink, Inc
* @license AGPL-3.0-or-later
*/
require('dotenv').config({ path: __dirname + '/.env' });
const cluster = require('cluster');
const colors = require('colors');
const numCPUs = require('os').cpus().length * process.env.CPU_MULTIPLIER;
if (cluster.isMaster) {
console.log('Starting ' + numCPUs + ' forks');
// Fork workers.
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
const asyncRedis = require("async-redis");
const redis = asyncRedis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
// password: process.env.REDIS_PASSWORD || undefined
});
const Server = require('./lib/Server.js');
const Iax = new (require('./lib/Iax'));
redis.on('ready', async () => {
Iax.Call.setRedis(redis);
Server.init((msg, info) => {
try {
Iax.receiveMessage(msg, info);
} catch (e) {
console.error(e);
}
}, process.env.LISTEN_PORT);
})
}