Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ This method takes a hash object containing the properties as follows:
Property | Type | Requred | Description
:--------|:--------|:---------|:-----------
`wait` | Integer | Optional | Wait time of the discovery process. The unit is millisecond. The default value is `3000`.
`interfaces` | Array | Optional | An array of network interfaces which should be broadcasted to scan bulbs.

Basically you don't need to pass the `wait` property to this method. In most cases, the default value `3000` works well.

Expand Down Expand Up @@ -2156,7 +2157,7 @@ Lifx.discover().then((device_list) => {
}
```

Note that the actual number of elements in the `tiles` array equals however many are physically connected in the device chain.
Note that the actual number of elements in the `tiles` array equals however many are physically connected in the device chain.

---------------------------------------
## <a id="Release-Note">Release Note</a>
Expand Down
8 changes: 7 additions & 1 deletion lib/lifx-lan-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ const LifxLanAddress = function () {
/* ------------------------------------------------------------------
* Method: getNetworkInterfaces()
* ---------------------------------------------------------------- */
LifxLanAddress.prototype.getNetworkInterfaces = function () {
LifxLanAddress.prototype.getNetworkInterfaces = function (interfaces) {
let list = [];
let netifs = mOs.networkInterfaces();
if (interfaces == null || !Array.isArray(interfaces)) {
interfaces = [];
}
for (let dev in netifs) {
if (interfaces.length > 0 && interfaces.indexOf(dev) === -1) {
continue;
}
netifs[dev].forEach((info) => {
if (info.family !== 'IPv4' || info.internal === true) {
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/lifx-lan-udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ LifxLanUdp.prototype.destroy = function () {
/* ------------------------------------------------------------------
* Method: init()
* ---------------------------------------------------------------- */
LifxLanUdp.prototype.init = function () {
LifxLanUdp.prototype.init = function (interfaces) {
let promise = new Promise((resolve, reject) => {
this._source_id = Math.floor(Math.random() * 0xffffffff);
let netif_list = mAddress.getNetworkInterfaces();
let netif_list = mAddress.getNetworkInterfaces(interfaces);
if (!netif_list || netif_list.length === 0) {
reject(new Error('No available network interface was found.'));
return;
Expand Down
8 changes: 5 additions & 3 deletions lib/lifx-lan.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const LifxLan = function () {
/* ------------------------------------------------------------------
* Method: init()
* ---------------------------------------------------------------- */
LifxLan.prototype.init = function () {
LifxLan.prototype.init = function (interfaces) {
let promise = new Promise((resolve, reject) => {
if (this._initialized) {
resolve();
} else {
mLifxUdp.init().then(() => {
mLifxUdp.init(interfaces).then(() => {
this._initialized = true;
resolve();
}).catch((error) => {
Expand Down Expand Up @@ -72,10 +72,12 @@ LifxLan.prototype._wait = function (msec) {
* Method: discover([params])
* - params:
* - wait | Integer | Optional | The default value is 3000 (msec)
* - interfaces | Array | Optional | The default value is []
* - interface | String | Optional | The name of the network interface e.g. "eth0"
* ---------------------------------------------------------------- */
LifxLan.prototype.discover = function (params) {
let promise = new Promise((resolve, reject) => {
this.init().then(() => {
this.init(params.interfaces || []).then(() => {
return mLifxUdp.discover(params);
}).then((found_list) => {
let devices = {};
Expand Down