This commit is contained in:
Marcus Westin 2019-12-15 17:42:57 +01:00
parent 9a84afada0
commit 8ed90c1668

View file

@ -1,4 +1,4 @@
const noble = require('@abandonware/noble');
const noble = require('@icanos/noble');
const crypto = require('crypto');
const xor = require('buffer-xor');
const _ = require('lodash');
@ -57,7 +57,7 @@ class PlejdService extends EventEmitter {
ping: null
};
this._wireEvents();
this.wireEvents();
}
scan() {
@ -81,6 +81,11 @@ class PlejdService extends EventEmitter {
}
connect(uuid = null) {
if (this.state === STATE_CONNECTING) {
console.log('warning: currently connecting to a device, please wait...');
return;
}
if (!uuid) {
this.device = Object.values(this.devices)[0];
}
@ -92,9 +97,21 @@ class PlejdService extends EventEmitter {
}
}
logger('connecting to ' + this.device.id + ' with addr ' + this.device.address + ' and rssi ' + this.device.rssi);
this.state = STATE_CONNECTING;
this.device.connect(this.onDeviceConnected);
}
disconnect() {
logger('disconnect()');
if (this.state !== STATE_CONNECTED) {
return;
}
this.device.disconnect();
}
authenticate() {
logger('authenticate()');
const self = this;
@ -336,4 +353,6 @@ class PlejdService extends EventEmitter {
return buffer
}
}
}
module.exports = PlejdService;