nicojanssens / turn-js

TURN (Traversal Using Relay NAT) library written entirely in JavaScript
MIT License
28 stars 4 forks source link

Usage help #11

Open missinglink opened 3 weeks ago

missinglink commented 3 weeks ago

Hi, I'm trying to use this lib to access the Cloudflare TURN Service but hitting errors for both TCP and UDP:

grep version node_modules/turn-js/package.json
  "version": "0.5.4",

node --version
v22.9.0

Is it possible that it's not compatible with recent node versions?

UDP

const client = turn(
  'turn.cloudflare.com',
  3478,
  username,
  credential,
  new turn.transports.UDP()
)

client.allocate((address) => {
  console.error('address', address)
}, (e) => {
  console.error('error', e)
})
node:dgram:633
    port = validatePort(port, 'Port', false);
           ^

RangeError [ERR_SOCKET_BAD_PORT]: Port should be > 0 and < 65536. Received type number (0).
    at Socket.send (node:dgram:633:12)
    at UdpWrapper.send (/code/node_modules/stun-js/lib/transports/udp.js:64:16)
    at StunComm.sendStunRequest (/code/node_modules/stun-js/lib/stun_comm.js:101:19)
    at StunComm.sendStunRequestP (/code/node_modules/stun-js/lib/stun_comm.js:139:8)
    at TurnClient.sendAllocateP (/code/node_modules/turn-js/lib/turn_client.js:355:15)
    at TurnClient.allocateP (/code/node_modules/turn-js/lib/turn_client.js:58:15)
    at TurnClient.allocate (/code/node_modules/turn-js/lib/turn_client.js:134:8)
    at <anonymous> (/code/example.ts:16:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  code: 'ERR_SOCKET_BAD_PORT'
}

Node.js v22.9.0

TCP

const client = turn(
  'turn.cloudflare.com',
  3478,
  username,
  credential,
  new turn.transports.TCP()
)

client.allocate((address) => {
  console.error('address', address)
}, (e) => {
  console.error('error', e)
})
/code/node_modules/stun-js/lib/transports/tcp.js:88
  var flushed = this._client.write(bytes, 'binary', function () {
                             ^

TypeError: Cannot read properties of undefined (reading 'write')
    at TcpWrapper.send (/code/node_modules/stun-js/lib/transports/tcp.js:88:30)
    at StunComm.sendStunRequest (/code/node_modules/stun-js/lib/stun_comm.js:101:19)
    at StunComm.sendStunRequestP (/code/node_modules/stun-js/lib/stun_comm.js:139:8)
    at TurnClient.sendAllocateP (/code/node_modules/turn-js/lib/turn_client.js:355:15)
    at TurnClient.allocateP (/code/node_modules/turn-js/lib/turn_client.js:58:15)
    at TurnClient.allocate (/code/node_modules/turn-js/lib/turn_client.js:134:8)
    at <anonymous> (/code/example.ts:16:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v22.9.0
nicojanssens commented 3 weeks ago

Tx for the heads-up. Will have a look at this soon.

nicojanssens commented 1 week ago

@missinglink Could u try again? All tests ($npm run test-node) now pass when using node.js v22.11.0.