src/index.js
function createDgramServer(options = {}) {
  let isExternalSocket = false;

  if (options.socket instanceof dgram.Socket) {
    isExternalSocket = true;
  }

  const socket = isExternalSocket ? options.socket : dgram.createSocket('udp4');
  const server = new StunServer(socket);

  if (!isExternalSocket) {
    socket.on('error', error => server.emit('error', error));
    server.once('close', () => socket.close());
  }

  return server;
}
function createDgramServer(options = {}) {
  let isExternalSocket = false;

  if (options.socket instanceof dgram.Socket) {
    isExternalSocket = true;
  }

  const socket = isExternalSocket ? options.socket : dgram.createSocket('udp4');
  const server = new StunServer(socket);

  if (!isExternalSocket) {
    socket.on('error', error => server.emit('error', error));
    server.once('close', () => socket.close());
  }

  return server;
}
function createDgramServer ( options = { } ) { let isExternalSocket = false ; if ( options . socket instanceof dgram . Socket ) { isExternalSocket = true ; } const socket = isExternalSocket ? options . socket : dgram . createSocket ( 'udp4' ) ; const server = new StunServer ( socket ) ; if ( ! isExternalSocket ) { socket . on ( 'error' , error => server . emit ( 'error' , error ) ) ; server . once ( 'close' , ( ) => socket . close ( ) ) ; } return server ; }
Creates dgram STUN server.
@param {Object} [options]
@param {dgram.Socket} [options.socket] - Optional udp socket.
@returns {StunServer}
Creates dgram STUN server .