Fixed disconnect bug
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Nathan Kellenicki 2019-04-25 15:32:07 -07:00
parent 1dc583e5f2
commit 7a647da798
5 changed files with 5 additions and 6 deletions

View File

@ -180,6 +180,7 @@ class PoweredUP extends events_1.EventEmitter {
return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]).filter((hub) => hub.name === name); return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]).filter((hub) => hub.name === name);
} }
async _discoveryEventHandler(peripheral) { async _discoveryEventHandler(peripheral) {
peripheral.removeAllListeners();
const device = new nobledevice_1.NobleDevice(peripheral); const device = new nobledevice_1.NobleDevice(peripheral);
let hub; let hub;
if (await wedo2smarthub_1.WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) { if (await wedo2smarthub_1.WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) {
@ -200,7 +201,6 @@ class PoweredUP extends events_1.EventEmitter {
else { else {
return; return;
} }
peripheral.removeAllListeners();
device.on("discoverComplete", () => { device.on("discoverComplete", () => {
hub.on("connect", () => { hub.on("connect", () => {
debug(`Hub ${hub.uuid} connected`); debug(`Hub ${hub.uuid} connected`);

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "2.4.0", "version": "2.4.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "node-poweredup", "name": "node-poweredup",
"version": "2.4.0", "version": "2.4.1",
"description": "A Javascript module to interface with LEGO Powered Up components.", "description": "A Javascript module to interface with LEGO Powered Up components.",
"homepage": "https://github.com/nathankellenicki/node-poweredup/", "homepage": "https://github.com/nathankellenicki/node-poweredup/",
"main": "dist/node/index-node.js", "main": "dist/node/index-node.js",

View File

@ -126,6 +126,7 @@ export class PoweredUP extends EventEmitter {
private async _discoveryEventHandler (peripheral: Peripheral) { private async _discoveryEventHandler (peripheral: Peripheral) {
peripheral.removeAllListeners();
const device = new NobleDevice(peripheral); const device = new NobleDevice(peripheral);
let hub: Hub; let hub: Hub;
@ -144,8 +145,6 @@ export class PoweredUP extends EventEmitter {
return; return;
} }
peripheral.removeAllListeners();
device.on("discoverComplete", () => { device.on("discoverComplete", () => {
hub.on("connect", () => { hub.on("connect", () => {