Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const initComm = async (username, key) => {
const publicKey = key && key.length > 0 ? key : null;
const saga = Saga(ram, publicKey, username);
await saga.initialize();
const sw = swarm({
id: username,
stream: () => {
return saga.replicate();
}
});
const discoveryKey = saga.db.discoveryKey.toString('hex');
const signalUrls = (process.env.SIGNAL_URLS || config.SIGNAL_URLS).split(';');
sw.join(signalhub(discoveryKey, signalUrls), webrtcOpts);
sw.on('connection', async peer => {
try {
await saga.connect(peer);
} catch (err) {
console.log(err);
}