Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anygram

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anygram - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

93

index.js
var punch = require('./punch');
var stun = require('./stun');
exports.connect = (irc, to, rinfo, punchTime) => new Promise((res, rej) =>
stun('stun.ucsb.edu').then(socket => {
var onrinfo = (rinfo) => {
socket.rinfo = rinfo;
setTimeout(
()=>punch(socket).then(res).catch(rej),
rinfo.punchTime - Date.now()
);
irc.removeListener('message', onmsg);
module.exports = (config) => {
config.stunServer = config.stunServer || 'stun.ucsb.edu';
config.timeLag = config.timeLag || 10000;
var exports = {};
exports.connect = (irc, to, rinfo) => new Promise((res, rej) =>
stun(config.stunServer).then(socket => {
var onrinfo = (rinfo) => {
socket.rinfo = rinfo;
setTimeout(
() => punch(socket).then(res).catch(rej),
rinfo.punchTime - Date.now()
);
};
var onmsg = (e) => {
if (e.from === to) {
irc.removeListener('message', onmsg);
onrinfo(JSON.parse(e.message));
}
};
if (rinfo) {
socket.linfo.punchTime = rinfo.punchTime = Date.now() + config.timeLag;
onrinfo(rinfo);
} else {
irc.on('message', onmsg);
}
irc.send(to, JSON.stringify(socket.linfo));
}).catch(rej));
exports.createServer = (irc, onconn, onerr) => {
onerr = onerr || console.error;
irc.on('message', e => {
var rinfo = JSON.parse(e.message);
exports.connect(irc, e.from, rinfo).then(onconn).catch(onerr);
});
};
var onmsg = (e) => {
if (e.from === to)
onrinfo(JSON.parse(e.message));
exports.send = (socket, msg, lport, rport) => {
var buf = new Buffer(4);
buf.writeUInt16BE(lport, 0);
buf.writeUInt16BE(rport, 2);
socket.send(Buffer.concat([buf, msg]), socket.rinfo.port, socket.rinfo.address);
};
if (rinfo) {
socket.linfo.punchTime = rinfo.punchTime = Date.now() + (punchTime || 10000);
onrinfo(rinfo);
} else {
irc.on('message', onmsg);
}
irc.send(to, JSON.stringify(socket.linfo));
}).catch(rej));
exports.createServer = (irc, cb) => {
irc.on('message', e => {
var rinfo = JSON.parse(e.message);
exports.connect(irc, e.from, rinfo).then(cb).catch(console.error);
});
};
exports.onrecv = (socket, cb) => {
socket.on('message', (msg) => {
if (msg.length <= 4) return ;
var lport = msg.readUInt16BE(2);
var rport = msg.readUInt16BE(0);
cb(msg.slice(4), lport, rport);
});
};
exports.send = (socket, msg, lport, rport) => {
var buf = new Buffer(4);
buf.writeUInt16BE(lport, 0);
buf.writeUInt16BE(rport, 2);
socket.send(Buffer.concat([buf, msg]), socket.rinfo.port, socket.rinfo.address);
return exports;
};
exports.onrecv = (socket, cb) => {
socket.on('message', (msg) => {
if (msg.length <= 4)
return ;
var rport = msg.readUInt16BE(0);
var lport = msg.readUInt16BE(2);
cb(msg.slice(4), lport, rport);
});
};

@@ -5,7 +5,8 @@ var irc = require('slate-irc');

module.exports = (e) => {
e.host = e.host || '174.143.119.91';
e.port = e.port || 6667;
e.host = e.host || '174.143.119.91';
e.pass = e.pass || '*';
var client = irc(net.connect(e));
client.pass(e.pass || '*');
client.pass(e.pass);
client.nick(e.name);

@@ -12,0 +13,0 @@ client.user(e.name, e.name);

{
"name": "anygram",
"version": "0.0.3",
"version": "0.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc