onDisconnected called multiple times for a disconnected device
See original GitHub issueI noticed some behavior that seems strange with the onDisconnected listener. If a device is connected and then disconnected, the listener is called once, as it should. But if the same device connects and disconnects again in a short period, the listener is called twice. Then on the next disconnect three times and so on. This is on Android with ble-plx 0.8.0.
My simplified code is something like this:
bleManagerPlx.startDeviceScan([SERVICE], { allowDuplicates: false }, (error, device) => {
if (device.name.startsWith('......')) {
if ('a check that the device is not already connected') {
connectDevice(device.id);
}
}
})
bleManagerPlx.connectToDevice(deviceId)
.then((device) => {
device.onDisconnected((error, disconnectedDevice) => {
console.log('Disconnected ', disconnectedDevice.name);
});
});
Now, I could store the subscription that is returned by onDisconnected() and call remove on it to stop listening, but I think that the subscription should have been removed by the manager when the connection is cancelled. Is that by design?
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
onDisconnected called multiple times for a disconnected device
If a device is connected and then disconnected, the listener is called once, as it should. But if the same device connects and...
Read more >Signalr firing multiple OnDisconnect calls and the connection ...
Almost a Chat scenario. We're seeing multiple OnDisconnected calls for some connections although the connections are alive.
Read more >OnDisconnect | Firebase JavaScript API reference
If you want an operation to occur each time a disconnect occurs, you'll need to re-establish the onDisconnect operations each time you reconnect....
Read more >Getting recorded message on disconnected phone
my phone was disconnected due to a move. I want a recorded message on the old phone number so that when someone calls...
Read more >SignalR Troubleshooting | Microsoft Learn
The syntax for calling these two communication models is different in the client code. ... at which time the OnDisconnected event will fire....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dariuszseweryn Well, yes, I register a new listener once a device is connected. I think it doesn’t matter if it is a new device, or a reconnect of an old one after a minute, an hour or a day. At least to me it seems better to automatically unsubscribe from the old listener once a device disconnects. This device may never reconnect, so why should the listener stay active.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.