SMU-SIS / ecology

Lightweight library to easily build cross-device applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leaving devices are not being recorded

QuentinRoy opened this issue · comments

It seems that ecology.getAvailableDevices does not update the devices that have left. Once a device has been connected, it is always returned by this method.
Experienced when using cordova-ecology-plugin and reacology-model-sync.

Just to understand more about this issue. Do you call disconnect method when the device leaves ecology? In Android, we call disconnect method in onDestroy() method.

Well. For a client, disconnect means that you lost access to the server. I am not sure what is the relationship with onDestroy(). When working on the reacology boilerplate, if I have device A (server) and B connected, then close the app on B, A keeps thinking that B is here.

For a native app, onDestroy() method is called when you close the app. so ecology is notified about the disconnection if we call disconnect method in onDestroy().

Similarly, we should implement it in cordova to notify ecology. Otherwise how will ecology know. In my demo apps, I used document.addEventListener("backbutton", yourCallbackFunction, false); to implement disconnect method.

OK, I think we have a spec problem here. Notifying the client that he disconnected himself is not very useful (though it does count as a disconnection). Again, the point of the disconnect event is to be informed on the status of your connection with the ecology (that is currently centralized on the server, so this is really about connection to the server). It might be because you disconnected manually, but more often than not, that is because the connection has been interrupted. Maybe because the server app has been closed, or because the server device is not in range, or because the network channel got broken for whatever reason. This is what we need to detect..

This is true in the other direction of course. The server needs to know if a client has been disconnected even if that client did not call disconnect. Of course using disconnect is good because this means we can warn the server quicker. But sometimes, the device just got out of range and the server should still be able to detect that device is not available anymore. getAvailableDevices is supposed to return the devices that are available, not just the device that were here and haven't called disconnect yet...

A very simple way to test it is to launch the reacology-boilerplate.
With only one device you should see "Waiting for my friend" on the server and "Not connected" on the other device.
Once the second device is here the interface appear.
Turn off the bluetooth, close one of the app, or bring a device out of range and we should be back on the initial configuration. This is currently not the case. :(