-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhsync.js
More file actions
36 lines (28 loc) · 1016 Bytes
/
hsync.js
File metadata and controls
36 lines (28 loc) · 1016 Bytes
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
import net from 'net';
import mqtt from 'mqtt';
import createDebug from 'debug';
import { createHsync, setNet, setMqtt } from './connection.js';
import config from './config.js';
import { setRTC } from './lib/peers.js';
import rtc from './lib/rtc-node.js';
const debugError = createDebug('errors');
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 };
fullConfig.dynamicHost = fullConfig.dynamicHost || fullConfig.defaultDynamicHost;
const con = await createHsync(fullConfig);
return con;
}
function createConnection(configObj = {}) {
const fullConfig = { ...config, ...configObj };
return createHsync(fullConfig);
}
export { createConnection, dynamicConnect, config };