WebRTC for Node.js
Current stage: working prototype. Send your feedback and usage ideas to speed up development.
git clone
andnpm i
- type
npm start
to run demo - open
localhost:7007
in your browser (Chrome).
Low-level Session Traversal Utilities for NAT (STUN) client and server
License: MIT License
const server = stun.createServer({ type: 'tcp' });
server.on(STUN_EVENT_BINDING_REQUEST, (req, socket) => {
// ...
});
// OR
server.on(STUN_EVENT_BINDING_REQUEST, (req, res) => {
const msg = stun.createMessage();
res.send(msg);
});
It appears stun has implemented a subset of the specs compared to coturn (https://github.com/coturn/coturn), so I was wondering if you could comment on the specs which stun has yet to implement and what that means for production (ie. will some networks not work, etc).
Thanks for the help!
Hi everyone, i faced with unable to get external port for connection to my localhost from the outside.
I tried const response = await stun.request('stun.l.google.com:19302'); let xorAddress = response.getXorAddress(); //console.log(xorAddress.address + xorAddress.port)
but data from method getXorAddress() is wrong.
Help me please get ip and port for able to connect to my localhost from the outside.
according to nodejs Buffer.concat(list[, totalLength])
it seems seems that
function xorIPv6(address, transactionId) {
return xor(address, Buffer.concat(constants.kStunMagicCookieBuffer, transactionId))
}
should rather be written as
function xorIPv6(address, transactionId) {
return xor(address, Buffer.concat([constants.kStunMagicCookieBuffer, transactionId]))
}
const client = stun.connect({ type: 'tcp', host: 'stun.l.google.com', port: 19302 });
const request = stun.createMessage(STUN_BINDING_REQUEST);
client.on('error', (err) => {
// ...
});
client.on(STUN_BINDING_RESPONSE, (response) => {
// ...
});
client.send(request);
/// or
client.request(request, (err, response) => {
// ...
});
https://github.com/serverless-stack/serverless-stack started using the package, however, this indirect dependency breaks our product. I have created a patch that solves the issue temporarily (using relative references in requires) - I suggest moving the sources out of that node_modules and use relative references when requiring project sources.
Any attribute type MAY appear more than once in a STUN message.
Unless specified otherwise, the order of appearance is significant:
only the first occurrence needs to be processed by a receiver, and
any duplicates MAY be ignored by a receiver.
https://tools.ietf.org/html/rfc5389#section-15
[[readonly]]
flag for any arrived messages?Hi, I am trying to use this library in an Electron + React project I am developing.
For some reason everything works nicely as long as I run the application in debug mode, if I try to run the production ready compiled binary of the app I get and empty blank window.
Do you have any clue on why this might be happening? I am at a loss here, can't really find a solution.
Thanks
const client = stun.request('stun://stun.l.google.com:19302');
udp.on('message', (message, rinfo) => {
// add rinfo to StunResponse
})
or ability to get remote info from stun.request
createServer({ type: 'udp' });
createServer({ type: 'tcp' });
createServer({ type: 'tls' });
createServer({ type: 'dtls' });
example:
message.addUsername(username);
message.addAddress(ip, port)
I did a test with 3 different node.js stun servers: stun
, node-stun
, and ministun
. All had the same properties on the cases I tested on. The case they all failed was when I tried to connect a phone on its mobile network to a desktop client (which was also the machine hosting the stun server and coordination server). This case worked fine when I used stun:stun.l.google.com:19302
however, so I'm not sure if there's some functionality these modules aren't implementing, if they all have similar bugs, or if something else is going on. In any case, it feels like a rather large hole in the abilities of all of these stun server modules and finding a way to support that case would be a great way to differentiate this module vs the rest.
Here's the code I was testing with, and a readme that detailed the cases and the restults for each module:
I created similar issues on the other repos as well:
See #2
There are a few new attributes in this RFC that would be useful to support:
Comprehension-required range (0x0000-0x7FFF):
0x0003: CHANGE-REQUEST
0x0026: PADDING
0x0027: RESPONSE-PORT
Comprehension-optional range (0x8000-0xFFFF):
0x802b: RESPONSE-ORIGIN
0x802c: OTHER-ADDRESS
Emit error
event for brocken messages.
InvalidMessageError
class for brocken messages?packet
for this type error?packet
for for this type error?CVE-2022-2218 requires updating parse-url to 6.0.1 or higher.
Using the supplied example code, with my STUN server from https://github.com/jselbie/stunserver I get an exception on the Send() method.
My code is:
var stun = require('stun')
const { STUN_BINDING_REQUEST, STUN_ATTR_XOR_MAPPED_ADDRESS } = stun.constants
const server = stun.createServer()
const request = stun.createMessage(STUN_BINDING_REQUEST)
server.once('bindingResponse', stunMsg => {
console.log('your ip:', stunMsg.getAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS).value.address)
server.close()
})
server.send(request, 3478, 'stun.mitel.io')
And the stack trace I get out is
Exception has occurred: Error Error: Unsupported attribute type "32811". at parseAttribute (c:\github\devops-udp-healthcheck\node_modules\stun\lib\message.js:289:9) at stunMsg._attrs.packet.attributes.map.attrPacket (c:\github\devops-udp-healthcheck\node_modules\stun\lib\message.js:69:7) at Array.map (native) at Function.from (c:\github\devops-udp-healthcheck\node_modules\stun\lib\message.js:68:40) at StunServer.process (c:\github\devops-udp-healthcheck\node_modules\stun\lib\server.js:31:33) at StunServer.handleMessage (c:\github\devops-udp-healthcheck\node_modules\stun\lib\server.js:61:10) at emitTwo (events.js:125:13) at Socket.emit (events.js:213:7) at UDP.onMessage [as onmessage] (dgram.js:619:8)
I'm at a bit of a loss. This seems to work fine with the supplied Google STUN servers, and in theory the STUNTMAN STUN server should be following all the appropriate RFC's.
Any guidance would be much appreciated.
Due to the way JavaScript handles bitwise operands, I think the result of xor can be "negative".
This is causing the addFingerprint method to fail intermittently since the value is expected to be a positive integer. Here's the problematic line: https://github.com/reklatsmasters/stun/blob/cb84b7361d651742041f72f1ea247eb808c499e7/lib/message.js#L159
Take a look to
stun/src/node_modules/lib/validate.js
Line 53 in 3db7f5d
fingerprintLength
value becomes NaN
; should be change to
fingerprintLength = 8 // 4 bytes of attribute header + 4 bytes of CRC32
Description: Address in some responses is undefined.
OS: 10.15.6 (19G73)
Node.js: v14.4.0
Stun: 2.1.0
const stun = require('stun');
const freeStunServers = [
// google
"stun1.l.google.com:19302",
"stun2.l.google.com:19302",
"stun3.l.google.com:19302",
"stun4.l.google.com:19302",
// others
"stun.ekiga.net:3478",
"stun.schlund.de:3478",
"stun.xten.com:3478",
]
freeStunServers.forEach( stunURL => {
stun.request(stunURL, (err, res) => {
if (err) {
console.error(err);
} else {
let add = res.getXorAddress();
if (add) {
const { address, port } = res.getXorAddress();
console.log(`Res from ${stunURL} : Your IP is ${address} PORT is ${port}.`);
}else{
console.log(`Res from ${stunURL} : address is undefined.`);
}
}
});
})
Output:
Res from stun1.l.google.com:19302 : Your IP is 120.236.163.98 PORT is 12422.
Res from stun2.l.google.com:19302 : Your IP is 120.236.163.98 PORT is 8165.
Res from stun.ekiga.net:3478 : address is undefined.
Res from stun.xten.com:3478 : address is undefined.
Res from stun4.l.google.com:19302 : Your IP is 202.116.36.83 PORT is 12715.
Res from stun3.l.google.com:19302 : Your IP is 120.236.163.98 PORT is 8166.
Res from stun.schlund.de:3478 : Your IP is 120.236.163.98 PORT is 5170.
Hi Dmitriy, you are doing really great job
I was wondering how to add this package to firebase functions, because i want to implement STUN functionality inside firebase, so can this package achieve that or is it beyond it's limitation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.