question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onDisconnected called multiple times for a disconnected device

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vldgeorgievcommented, Apr 27, 2018

@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.

0reactions
stale[bot]commented, Apr 2, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found