Skip to content

Commit 24d287e

Browse files
author
Daisuke Baba
committed
Fix an issue where unsubscribe() was invoked even when the peripheral state wasn't 'connected'
1 parent 23dde13 commit 24d287e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/generic-ble.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ export default function(RED) {
244244
},
245245
unsubscribe: () => {
246246
return new Promise((resolve) => {
247-
if (obj.notifiable) {
247+
let peripheral = noble._peripherals[obj._peripheralId];
248+
if (obj.notifiable && peripheral && peripheral.state === 'connected') {
248249
delete obj.dataListener;
249250
obj.object.unsubscribe(resolve);
250251
} else {

0 commit comments

Comments
 (0)