ssb-mobile-bluetooth-manager
Advanced tools
Comparing version
50
index.js
@@ -263,2 +263,51 @@ const net = require('net'); | ||
function getValidAddresses(devices, cb) { | ||
var results = []; | ||
var count = 0; | ||
devices.forEach( (device, num) => { | ||
// Leave some grace seconds so it's not complete spam.. | ||
setTimeout( () => { | ||
getMetadataForDevice(device.remoteAddress, (err, res) => { | ||
count = count + 1; | ||
console.log("getValidAddresses count: " + count) | ||
if (!err) { | ||
console.log(device.remoteAddress + " is available for scuttlebutt bluetooth connections"); | ||
device.id = res.id; | ||
results.push(device); | ||
} | ||
if (count === devices.length) { | ||
console.log("Calling back (get valid addresses)..."); | ||
console.log("Valid addresses:"); | ||
console.log(device); | ||
cb(null, { | ||
"discovered": results, | ||
"lastUpdate": Date.now() | ||
}); | ||
} | ||
}); | ||
}, num * 2000); | ||
}) | ||
} | ||
function nearbyScuttlebuttDevices(refreshInterval) { | ||
return pull( | ||
nearbyDevices(refreshInterval), | ||
pull.asyncMap( (result, cb) => { | ||
console.log("Result is? "); | ||
console.log(result); | ||
getValidAddresses(result.discovered, cb) | ||
}) | ||
) | ||
} | ||
function nearbyDevices(refreshInterval) { | ||
@@ -382,2 +431,3 @@ | ||
nearbyDevices, | ||
nearbyScuttlebuttDevices, | ||
makeDeviceDiscoverable, | ||
@@ -384,0 +434,0 @@ getMetadataForDevice, |
{ | ||
"name": "ssb-mobile-bluetooth-manager", | ||
"version": "2.0.11", | ||
"version": "2.0.12", | ||
"description": "A module for managing bluetooth connections over a react native bridge.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
13318
10.61%333
12.88%