Skip to content
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

Merged
merged 2 commits into from
Jun 2, 2021
Merged

Only the first printer is reported after discovery #9

merged 2 commits into from
Jun 2, 2021

Conversation

JesperBadstue
Copy link
Contributor

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 of onDiscoveryDone 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.

@tr3v3r
Copy link
Owner

tr3v3r commented Jun 1, 2021

Hi @JesperBadstue ! Is this issue also reproduced on iOS?
Since I don't have several devices, could please try to search printers by running an example app from this repo?

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();
Copy link
Owner

@tr3v3r tr3v3r Jun 1, 2021

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);
     }

@JesperBadstue
Copy link
Contributor Author

Hi @JesperBadstue ! Is this issue also reproduced on iOS?
Since I don't have several devices, could please try to search printers by running an example app from this repo?

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

Hi @tr3v3r
Unfortunately I dont have any iOS devices so I dont know if it has the same problems:(

You are right that we should just the 5 sec delay already in the performDiscovery I'll update the PR.

@JesperBadstue JesperBadstue requested a review from tr3v3r June 2, 2021 07:18
@tr3v3r tr3v3r merged commit 47d0a1d into tr3v3r:main Jun 2, 2021
@tr3v3r
Copy link
Owner

tr3v3r commented Jun 2, 2021

@JesperBadstue merged. I'll try to prepare a new release today. Thanks for your help!

tr3v3r added a commit that referenced this pull request Jan 15, 2022
…d-printers

Only the first printer is reported after discovery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants