clean up listeners
This commit is contained in:
parent
c8dae032a9
commit
83dc9924fd
1 changed files with 10 additions and 2 deletions
12
plejd/ble.js
12
plejd/ble.js
|
|
@ -219,7 +219,11 @@ class PlejdService extends EventEmitter {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (self.state !== STATE_CONNECTED && self.state !== STATE_AUTHENTICATED) {
|
if (self.state !== STATE_CONNECTED && self.state !== STATE_AUTHENTICATED) {
|
||||||
if (self.deviceIdx < Object.keys(self.devices).length) {
|
if (self.deviceIdx < Object.keys(self.devices).length) {
|
||||||
logger('connection timed out after 10 s. trying next.');
|
logger('connection timed out after 10 s. cleaning up and trying next.');
|
||||||
|
|
||||||
|
self.device.removeAllListeners('servicesDiscover');
|
||||||
|
self.device.removeAllListeners('connect');
|
||||||
|
self.device.removeAllListeners('disconnect');
|
||||||
|
|
||||||
self.deviceIdx++;
|
self.deviceIdx++;
|
||||||
self.connect();
|
self.connect();
|
||||||
|
|
@ -240,12 +244,16 @@ class PlejdService extends EventEmitter {
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
logger('disconnect()');
|
logger('disconnect()');
|
||||||
if (this.state !== STATE_CONNECTED) {
|
if (this.state !== STATE_CONNECTED && this.state !== STATE_AUTHENTICATED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInterval(this.pingRef);
|
clearInterval(this.pingRef);
|
||||||
|
|
||||||
|
this.device.removeAllListeners('servicesDiscover');
|
||||||
|
this.device.removeAllListeners('connect');
|
||||||
|
this.device.removeAllListeners('disconnect');
|
||||||
|
|
||||||
this.unsubscribeCharacteristics();
|
this.unsubscribeCharacteristics();
|
||||||
this.device.disconnect();
|
this.device.disconnect();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue