-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only the first printer is reported after discovery #9
Only the first printer is reported after discovery #9
Conversation
Hi @JesperBadstue ! Is this issue also reproduced on iOS? Actually, I suppose it's not an ideal solution for this issue, since we are already waiting for 5 seconds after running Discovery.start(). So possibly better to shift sending an event into performDiscovery method? Please look through my notes in the code |
if (mOnDiscoveryReporter == null) { | ||
mOnDiscoveryReporter = new Runnable() { | ||
public synchronized void run() { | ||
WritableArray stringArray = Arguments.createArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's extract this forming and sending data into separate method like:
public void sendDiscoveredDataToJS() {
WritableArray stringArray = Arguments.createArray();
for (int counter = 0; counter < mPrinterList.size(); counter++) {
final DeviceInfo info = mPrinterList.get(counter);
WritableMap printerData = Arguments.createMap();
........
sendEvent(reactContext, "onDiscoveryDone", stringArray);
}
And try to send it right after the discovery done (after 5 sec) here:
private void performDiscovery(MyCallbackInterface callback) {
final Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
if(mPrinterList.size() > 0) {
sendDiscoveredDataToJS() // will be invoked after 5 sec with acc. results
}
stopDiscovery();
callback.onDone("Search completed");
}
};
handler.postDelayed(r, 5000);
}
Hi @tr3v3r You are right that we should just the 5 sec delay already in the |
@JesperBadstue merged. I'll try to prepare a new release today. Thanks for your help! |
…d-printers Only the first printer is reported after discovery
I noticed that when discovering printers the
DiscoveryListener
was first called with one printer, and shortly thereafter with two printers etc by the Eposon lib.The problem is then that as soon at we get a printer in the listener we send the event
onDiscoveryDone
and the react part of the lib stops listening to any more events. This means that the second discovered printer was never reported.I have added a
mOnDiscoveryReporter
that delays the emitting ofonDiscoveryDone
for 3 seconds to allow us to discover more than one printer. The 3 seconds is more or less arbitrarily chosen and I guess it could be made configurable if needed.