Skip to content

Commit

Permalink
Filtering seekers result
Browse files Browse the repository at this point in the history
`Tessel.get` and `Tessel.list` accept additional option
`opts.authorized` for filtering seekers result.

fixes #368
  • Loading branch information
Student007 authored and rwaldron committed Oct 8, 2015
1 parent 60f1c8f commit 0023cce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Tessel.list = function(opts) {
var seekerOpts = {
timeout: opts.timeout * 1000,
usb: opts.usb,
lan: opts.lan
lan: opts.lan,
authorized: undefined
};

// Start looking for Tessels
Expand Down Expand Up @@ -113,7 +114,8 @@ Tessel.get = function(opts) {
var seekerOpts = {
timeout: (opts.timeout || 2) * 1000,
usb: opts.usb,
lan: opts.lan
lan: opts.lan,
authorized: opts.authorized || true
};

// Create a seeker object and start detecting any Tessels
Expand Down
16 changes: 15 additions & 1 deletion lib/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ util.inherits(TesselSeeker, EventEmitter);

TesselSeeker.prototype.start = function(opts) {
var self = this;
// Initialize the opts if it wasn't provided
// Initialize the opts if it wasn't provided
opts = opts || {};

// An array of pending open connections
Expand Down Expand Up @@ -49,6 +49,18 @@ TesselSeeker.prototype.start = function(opts) {
function connectionHandler(conn) {
var tessel = new Tessel(conn);
var opening = tessel.connection.open()
.then(function() {
if (tessel.lanConnection && opts.authorized !== undefined) {
if (tessel.lanConnection.authorized !== opts.authorized) {
debug('Kicking ' + conn.host.slice(0, -6) + ' due to authorized filter: ' + opts.authorized);
return Promise.reject();
} else {
return true;
}
} else {
return true;
}
})
.then(function() {
debug('Connection opened:', tessel.connection.host);
if (conn.connectionType === 'LAN' && !conn.authorized) {
Expand All @@ -66,6 +78,8 @@ TesselSeeker.prototype.start = function(opts) {
return Promise.resolve();
});
}
}).catch(function() {
return Promise.resolve();
});
// Push this Promise into the pending array
pendingOpen.push(opening);
Expand Down

0 comments on commit 0023cce

Please sign in to comment.