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

WIP: update printing architecture #139

Merged
merged 31 commits into from
Jul 25, 2024
Merged

WIP: update printing architecture #139

merged 31 commits into from
Jul 25, 2024

Conversation

tr3v3r
Copy link
Owner

@tr3v3r tr3v3r commented Mar 11, 2024

How to test:

General instructions are here.

To install npm package:

npm i [email protected]

or

yarn add [email protected]

Summary (To be updated)

Reworked the way of printing. Fixes almost all known issues.

  1. Get rid of the init and instantiate methods and introduce a new class Printer
  2. Printer is as singleton instance of the printer and can be used for single and multiple printing.
  3. Printer class provides:
    • print queue on JS side
    • print SDK methods that are now just a proxy from native SDK
    • error handling which includes description and native error code
    • proper typing

Example:

const printer = new Printer({
          target: printer.target,
          deviceName: printer.deviceName,
});

const status = await printer.queue.add(async () => {
      await printer.connect();
      
      await printer.addText('Hello world!);
      await printer.addFeedLine();
      await printer.addCut();
      await printer.sendData();

      await printer.disconnect();
})

Detailed example.

Changelog

In progress...

Migration guide

In progress...

To do

  • Remove legacy code
  • Update documentations
  • Test multiple printing (Thanks to @Waleed065. Test cases)
  • Refactoring
  • Validation for method properties on JS side

@tr3v3r tr3v3r changed the title feat(changed): updated printing architecture WIP: update printing architecture Mar 11, 2024
@tolypash
Copy link
Contributor

Still working on implementing this to local project. Looks like it works well for now. Will keep you updated when I'm done with the refactor that is needed.

@tr3v3r
Copy link
Owner Author

tr3v3r commented Mar 21, 2024

Still working on implementing this to local project. Looks like it works well for now. Will keep you updated when I'm done with the refactor that is needed.

Thanks. If any question appears don't hesitate to reach me.

BTW. @Waleed065 have already tested a lot of scenarios with single and multiple printing - so far so good.
I'm waiting for final approval from him.

@Waleed065
Copy link
Contributor

Have integrated this version in our PROD app and all use cases work for us.
We can consider it a stable version.
We're using LAN connections.

Use cases tested

  • Multi Printing ✅
  • Queue Printing ✅
  • Printing On Wifi Reconnection ✅
  • Printing On Printer Reconnection ✅
  • Warning and errors (eg: Paper Out, Open Lid) ✅

@tolypash
Copy link
Contributor

@tr3v3r Would like to clarify something. Is the intended use that I connect to all discovered printers in the beginning and stay connected, or connect to each printer to print and then disconnect each time?

@tr3v3r
Copy link
Owner Author

tr3v3r commented Mar 22, 2024

@tr3v3r Would like to clarify something. Is the intended use that I connect to all discovered printers in the beginning and stay connected, or connect to each printer to print and then disconnect each time?

@tolypash Both scenarios are valid.
But, to be honest. I don't think it's a good approach to leave the printer to be connected all the time.

you can connect and disconnect - it's cheap action.

Or if you need to do copies you can repeat commands after connection:

async function print() { // your print receipt commands
      await printer.addText('Hello world!);
      await printer.addFeedLine();
      await printer.addCut();
      await printer.sendData();
}
await printer.connect(); // connect

   await print()
   awaith printer.clearCommandBuffer();
   
   await print() // copy 1
   awaith printer.clearCommandBuffer();
   
 await printer.disconnect();  // disconnect after all copies are printed

I hope this makes sense/

@tolypash
Copy link
Contributor

Yes of course, thank you. It's just that we have many devices connecting to many printers. I will implement it by connecting and disconnecting then. Thank you!

@tr3v3r
Copy link
Owner Author

tr3v3r commented Mar 22, 2024

Yes of course, thank you. It's just that we have many devices connecting to many printers. I will implement it by connecting and disconnecting then. Thank you!

Correct. The previous implementation did the connection and disconnection under the hood by the lib, but it also added constraints because of that. So in this implementation, you can control yourself when connect and disconnect

@tr3v3r
Copy link
Owner Author

tr3v3r commented Mar 28, 2024

@Waleed065 I've released beta.2 with some small breaking changes and refactoring. Could you please try it out when you have time?
P.S. After this update, no other breaking changes are planned.

@Waleed065
Copy link
Contributor

@Waleed065 I've released beta.2 with some small breaking changes and refactoring. Could you please try it out when you have time? P.S. After this update, no other breaking changes are planned.

Sure, I'll test it and let you know

@Waleed065
Copy link
Contributor

Waleed065 commented Mar 31, 2024

@tr3v3r There are few issues with this update ( beta.2 ). Specifically releated to imports

Screenshot 2024-03-31 at 5 05 53 PM

Simulator Screenshot - iPhone 15 Pro - 2024-03-31 at 17 26 29

@tr3v3r
Copy link
Owner Author

tr3v3r commented Mar 31, 2024

@tr3v3r There are few issues with this update ( beta.2 ). Specifically releated to imports

Screenshot 2024-03-31 at 5 05 53 PM

Simulator Screenshot - iPhone 15 Pro - 2024-03-31 at 17 26 29

I see. Can I ask you why you need this enums, can't you use PrinterConstants instead? Or it's for error handling?

@Waleed065
Copy link
Contributor

@tr3v3r There are few issues with this update ( beta.2 ). Specifically releated to imports
Screenshot 2024-03-31 at 5 05 53 PM
Simulator Screenshot - iPhone 15 Pro - 2024-03-31 at 17 26 29

I see. Can I ask you why you need this enums, can't you use PrinterConstants instead? Or it's for error handling?

Yes I need them for error handling. Some PrinterConstants errorCodes have same error code that is why. But these should be available to import anyway

@mroswald
Copy link

mroswald commented Apr 5, 2024

Is there a need to bundle the queue into this library? We have our own queue around print jobs and p-queue causing strange build issues on our end. For simplicity, a more modular approach would be nice (import and use if necessary)

@tr3v3r
Copy link
Owner Author

tr3v3r commented Apr 26, 2024

Just released beta.5.

  1. Fixed thread blocking on Android
  2. Increased timeouts for Android
  3. Try to fix the issue when it's not possible to print after print error

Details: https://github.com/tr3v3r/react-native-esc-pos-printer/releases/tag/v4.0.0-beta.5
Thanks everyone for the help!
CC: @tolypash @Waleed065 @mroswald

@Waleed065
Copy link
Contributor

Waleed065 commented Apr 29, 2024

Just released beta.5.

  1. Fixed thread blocking on Android
  2. Increased timeouts for Android
  3. Try to fix the issue when it's not possible to print after print error

Details: https://github.com/tr3v3r/react-native-esc-pos-printer/releases/tag/v4.0.0-beta.5 Thanks everyone for the help! CC: @tolypash @Waleed065 @mroswald

This version Works Great, lets release it as a stable version.

Great work @tr3v3r

@tr3v3r
Copy link
Owner Author

tr3v3r commented May 8, 2024

Hello everyone.

I finally started to work on documentation. And added docs on Printer class constructor and connect method.
After all the methods covered, I'm about to release the 4.0.0 stable version.
If someone wants to speed up the release, I'd appreciate any help.

In general, what is needed:

Take any undocumented method and cover it. As a reference connect docs can be used.

Rules:

Each method must be documented by using original docs for Android and iOS

CC: @tolypash @Waleed065 @mroswald @vsnaichuk

@omarst9
Copy link

omarst9 commented May 11, 2024

I noticed that when using an older USB printer (TM-T88IV) the print times out, while it prints normally on my newer USB printer TM-T88V. Even printing “Hello World” takes around 5 seconds on the older model. Has anyone experienced that?

@tr3v3r
Copy link
Owner Author

tr3v3r commented May 11, 2024

I noticed that when using an older USB printer (TM-T88IV) the print times out, while it prints normally on my newer USB printer TM-T88V. Even printing “Hello World” takes around 5 seconds on the older model. Has anyone experienced that?

Please create separate issues for that case, probably you'll get an answer from contributors. Also, what I can suggest is that you can try to test printing using Epson official applications. If there is still an issue with a specific model - that means it's not lib issues thanks.

@softwaredev927
Copy link

softwaredev927 commented Jul 18, 2024

Hi,
Can use 4.0.0 beta.6 version to print in multi printer with multi device?
Now I'm try to print in multi printer with multi device, but is not working on 3.1.1 version.

@tr3v3r
Copy link
Owner Author

tr3v3r commented Jul 18, 2024

Hi, Can use 4.0.0 beta.6 version to print in multi printer with multi device? Now I'm try to print in multi printer with multi device, but is not working on 3.1.1 version.

Hello, @softwaredev927

Yes, you can.
#139 (comment)

@softwaredev927
Copy link

softwaredev927 commented Jul 18, 2024

Hi, Can use 4.0.0 beta.6 version to print in multi printer with multi device? Now I'm try to print in multi printer with multi device, but is not working on 3.1.1 version.

Hello, @softwaredev927

Yes, you can. #139 (comment)

Thank you. for your help.
And then now this error happened while debugging.

 BUNDLE  ./index.js

error: Error: Unable to resolve module ./constants from D:\ReactNative\olouris\node_modules\react-native-esc-pos-printer\src\index.tsx:

None of these files exist:
  * node_modules\react-native-esc-pos-printer\src\constants(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * node_modules\react-native-esc-pos-printer\src\constants\index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
> 1 | export * from './discovery';
  2 | export * from './printer';
  3 |

How can solve it?

@tr3v3r tr3v3r merged commit 9f51666 into main Jul 25, 2024
5 checks passed
@tr3v3r
Copy link
Owner Author

tr3v3r commented Jul 25, 2024

I am happy to announce that version 4.0.0 has finally been released!
Thanks to everyone for your support!

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.

7 participants