1.0.1 • Published 8 years ago

firefox-dgram v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

firefox-dgram npm downloads

Use the Node dgram API in Firefox Add-ons

This module lets you use the Node.js dgram (UDP) API in Firefox Packaged Add-ons.

Instead of learning the quirks of Firefox's nsIUDPSocket API for networking in Firefox Add-ons just use the higher-level node API you're familiar with. Then, compile your code with browserify and you're all set!

This module was forked from webtorrent's > chrome-dgram.

install

npm install firefox-dgram

methods

Use node's dgram API, including all parameter list shorthands and variations.

Example UDP client/bind:

var dgram = require('firefox-dgram')

var sock = dgram.createSocket('udp4')

sock.send('beep', 0, 'beep'.length, 1337, '127.0.0.1')

sock.on('message', function (data, rInfo) {
  console.log('Got data from ' + rInfo.address + ':' + rInfo.port)
  console.log(data)
})

See nodejs.org for full API documentation: dgram

browserify

Required browserify configuration for Jetpack based Firefox Add-ons:

  var b = browserify({
    insertGlobalVars: {
      setTimeout: function () {
        return 'require("sdk/timers").setTimeout'
      },
      clearTimeout: function () {
        return 'require("sdk/timers").clearTimeout'
      }
    }
  })
  
  b.exclude('sdk/timers')
  // You also need to exclude any SDK modules that browserify can't find
  // firefox-dgram needs access to XPCOM so to compile with browserify, exclude chrome
  b.exclude('chrome')

contribute

To run tests, use npm test. The tests will run TCP and UDP servers and launch a few different Firefox Packaged Add-ons with browserified client code.

You can manually specify the path to firefox by setting the environment variable:

JPM_FIREFOX_BINARY=/usr/bin/firefox npm test

license

MIT. Copyright (c) Rodney Teal, Feross Aboukhadijeh, and John Hiesey.