thatguydan/hue.js — pull request #2 by bahamas10 (2013-04-01 01:12:49+00:00)
Title: Fixing discovery for node v0.10.2

`dgram` stuff is now asynchronous. I don't know the finer details, but you can read the discussion here https://github.com/joyent/node/issues/4981 for more information.

If you run discovery on node v0.10 you are greeted with:

```
dgram.js:322
throw errnoException(process._errno, 'getsockname');
^
Error: getsockname EINVAL
at errnoException (dgram.js:439:11)
at Socket.address (dgram.js:322:11)
at Object.module.exports [as discover] (/usr/local/lib/node_modules/hue-cli/node_modules/hue.js/lib/Discoverer.js:20:23)
at Object. (/usr/local/lib/node_modules/hue-cli/hue-cli.js:191:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
```

With the patch i've supplied (I couldn't think of a better way to shim this than to check the node version :( ) it will work on node v0.8 and node v0.10.

```
dave @ [ lifeforce :: (Linux) ] ~/dev/hue.js $ node -v
v0.8.20
dave @ [ lifeforce :: (Linux) ] ~/dev/hue.js $ node example/discover.js
[ '10.0.1.218' ]
dave @ [ lifeforce :: (Linux) ] ~/dev/hue.js $ sudo ~/dev/scripts/install-node v0.10.2 &>/dev/null
dave @ [ lifeforce :: (Linux) ] ~/dev/hue.js $ node -v
v0.10.2
dave @ [ lifeforce :: (Linux) ] ~/dev/hue.js $ node example/discover.js
[ '10.0.1.218' ]
```