thalmiclabs / myo.js

Myo javascript bindings
Apache License 2.0
198 stars 63 forks source link

Fixed pairing to avoid duplicated myo on reconnect #22

Closed Ucodia closed 7 years ago

Ucodia commented 8 years ago

When connecting and disconnecting multiple times from Myo, paired Myos will be duplicated on every reconnection. Imagine a scenario where we have only one Myo paired:

Myo.on('connected', function() {
  console.log(Myo.myos.length);
};

Myo.connect();
...
// prints 1
...
Myo.disconnect();
...
Myo.connect();
...
// prints 2
...
Myo.disconnect();

Myo will be readded even if it is already registered in the list. Therefore I fixed the code on the pairing event by checking if the MAC address of the paired device is not already registered.

stolksdorf commented 7 years ago

Good catch! Thanks.