-
Notifications
You must be signed in to change notification settings - Fork 2
/
hsync.js
40 lines (32 loc) · 1022 Bytes
/
hsync.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
const net = require('net');
const mqtt = require('mqtt');
const debugError = require('debug')('errors');
const { createHsync, setNet, setMqtt } = require('./connection');
const config = require('./config');
const { setRTC } = require('./lib/peers');
const rtc = require('./lib/rtc-node');
setRTC(rtc);
setNet(net);
setMqtt(mqtt);
process.on('unhandledRejection', (reason, p) => {
debugError(reason, 'Unhandled Rejection at Promise', p, reason.stack, p.stack);
});
process.on('uncaughtException', err => {
debugError(err, 'Uncaught Exception thrown', err.stack);
});
async function dynamicConnect(configObj = {}) {
const fullConfig = {...config, ...configObj};
let con;
fullConfig.dynamicHost = fullConfig.dynamicHost || fullConfig.defaultDynamicHost;
con = await createHsync(fullConfig);
return con;
}
function createConnection(configObj = {}) {
const fullConfig = {...config, ...configObj};
return createHsync(fullConfig);
}
module.exports = {
createConnection,
dynamicConnect,
config,
};