@munchi_oy/react-native-epson-printer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +223 -0
  2. package/android/build.gradle +34 -0
  3. package/android/consumer-rules.pro +0 -0
  4. package/android/libs/ePOS2.jar +0 -0
  5. package/android/src/main/AndroidManifest.xml +17 -0
  6. package/android/src/main/java/com/munchiepsonprinter/MunchiEpsonModule.java +1212 -0
  7. package/android/src/main/java/com/munchiepsonprinter/MunchiPrinterPackage.java +24 -0
  8. package/android/src/main/jniLibs/arm64-v8a/libepos2.so +0 -0
  9. package/android/src/main/jniLibs/armeabi-v7a/libepos2.so +0 -0
  10. package/android/src/main/jniLibs/x86/libepos2.so +0 -0
  11. package/android/src/main/jniLibs/x86_64/libepos2.so +0 -0
  12. package/dist/config.d.ts +14 -0
  13. package/dist/config.d.ts.map +1 -0
  14. package/dist/epson/constants.d.ts +124 -0
  15. package/dist/epson/constants.d.ts.map +1 -0
  16. package/dist/epson/discovery.d.ts +14 -0
  17. package/dist/epson/discovery.d.ts.map +1 -0
  18. package/dist/epson/driver.d.ts +26 -0
  19. package/dist/epson/driver.d.ts.map +1 -0
  20. package/dist/epson/errors.d.ts +8 -0
  21. package/dist/epson/errors.d.ts.map +1 -0
  22. package/dist/epson/eventRouter.d.ts +23 -0
  23. package/dist/epson/eventRouter.d.ts.map +1 -0
  24. package/dist/epson/mapper.d.ts +22 -0
  25. package/dist/epson/mapper.d.ts.map +1 -0
  26. package/dist/epson/modelUtils.d.ts +16 -0
  27. package/dist/epson/modelUtils.d.ts.map +1 -0
  28. package/dist/epson/native.d.ts +21 -0
  29. package/dist/epson/native.d.ts.map +1 -0
  30. package/dist/epson/payloadMapper.d.ts +7 -0
  31. package/dist/epson/payloadMapper.d.ts.map +1 -0
  32. package/dist/epson/queueController.d.ts +15 -0
  33. package/dist/epson/queueController.d.ts.map +1 -0
  34. package/dist/epson/recoveryController.d.ts +15 -0
  35. package/dist/epson/recoveryController.d.ts.map +1 -0
  36. package/dist/epson/sessionManager.d.ts +11 -0
  37. package/dist/epson/sessionManager.d.ts.map +1 -0
  38. package/dist/errorResolver.d.ts +15 -0
  39. package/dist/errorResolver.d.ts.map +1 -0
  40. package/dist/errors.d.ts +23 -0
  41. package/dist/errors.d.ts.map +1 -0
  42. package/dist/index.d.ts +15 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +11 -0
  45. package/dist/index.mjs +11 -0
  46. package/dist/react/PrinterProvider.d.ts +19 -0
  47. package/dist/react/PrinterProvider.d.ts.map +1 -0
  48. package/dist/react/usePrinterStatus.d.ts +12 -0
  49. package/dist/react/usePrinterStatus.d.ts.map +1 -0
  50. package/dist/types.d.ts +123 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/utils/errorUtils.d.ts +3 -0
  53. package/dist/utils/errorUtils.d.ts.map +1 -0
  54. package/dist/version.d.ts +2 -0
  55. package/dist/version.d.ts.map +1 -0
  56. package/ios/MunchiPrinter-Bridging-Header.h +4 -0
  57. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/Info.plist +48 -0
  58. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/_CodeSignature/CodeDirectory +0 -0
  59. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/_CodeSignature/CodeRequirements +0 -0
  60. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/_CodeSignature/CodeRequirements-1 +0 -0
  61. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/_CodeSignature/CodeResources +398 -0
  62. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/_CodeSignature/CodeSignature +0 -0
  63. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/dSYMs/libepos2.framework.dSYM/Contents/Info.plist +20 -0
  64. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/dSYMs/libepos2.framework.dSYM/Contents/Resources/DWARF/libepos2 +0 -0
  65. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/dSYMs/libepos2.framework.dSYM/Contents/Resources/Relocations/aarch64/libepos2.yml +5177 -0
  66. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/libepos2.framework/Headers/ePOS2.h +1809 -0
  67. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/libepos2.framework/Headers/libepos2.h +13 -0
  68. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/libepos2.framework/Info.plist +0 -0
  69. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/libepos2.framework/Modules/module.modulemap +6 -0
  70. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/libepos2.framework/PrivacyInfo.xcprivacy +31 -0
  71. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64/libepos2.framework/libepos2 +0 -0
  72. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/dSYMs/libepos2.framework.dSYM/Contents/Info.plist +20 -0
  73. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/dSYMs/libepos2.framework.dSYM/Contents/Resources/DWARF/libepos2 +0 -0
  74. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/dSYMs/libepos2.framework.dSYM/Contents/Resources/Relocations/aarch64/libepos2.yml +5177 -0
  75. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/dSYMs/libepos2.framework.dSYM/Contents/Resources/Relocations/x86_64/libepos2.yml +5062 -0
  76. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/Headers/ePOS2.h +1809 -0
  77. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/Headers/libepos2.h +13 -0
  78. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/Info.plist +0 -0
  79. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/Modules/module.modulemap +6 -0
  80. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/PrivacyInfo.xcprivacy +31 -0
  81. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/_CodeSignature/CodeResources +146 -0
  82. package/ios/Vendors/Epson/Frameworks/libepos2.xcframework/ios-arm64_x86_64-simulator/libepos2.framework/libepos2 +0 -0
  83. package/ios/Vendors/Epson/MunchiEpsonModule.m +35 -0
  84. package/ios/Vendors/Epson/MunchiEpsonModule.swift +455 -0
  85. package/munchi-printer.podspec +22 -0
  86. package/package.json +59 -0
  87. package/react-native.config.js +12 -0
package/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # @munchi_oy/printer
2
+
3
+ Epson printer SDK bridge for React Native.
4
+
5
+ ## Overview
6
+
7
+ This package provides:
8
+ - Epson discovery (`discoverPrinters`)
9
+ - Epson connection lifecycle (`connect`, `disconnect`, connection events)
10
+ - Epson print queueing and hardware-recovery retries
11
+ - Receipt printing with generic `PrintJob` commands and embedded payload support
12
+
13
+ This package does not include Star or Sunmi drivers.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @munchi_oy/printer
19
+ # or
20
+ pnpm add @munchi_oy/printer
21
+ ```
22
+
23
+ ## iOS Setup
24
+
25
+ 1. Add the package.
26
+ 2. Run CocoaPods install in your iOS project:
27
+
28
+ ```bash
29
+ cd ios && pod install
30
+ ```
31
+
32
+ 3. Ensure Bluetooth/network permissions are configured in `Info.plist` for your transport mode.
33
+
34
+ ## Android Setup
35
+
36
+ 1. Add the package and sync Gradle.
37
+ 2. Ensure runtime permissions are requested in your app before discovery/connection:
38
+ - Android 12+ (`API 31+`): `BLUETOOTH_SCAN`, `BLUETOOTH_CONNECT`
39
+ - Android 11 and below: location permission for Bluetooth discovery (`ACCESS_FINE_LOCATION`)
40
+ 3. Rebuild the Android app after installation.
41
+
42
+ ## Quick Start
43
+
44
+ ```ts
45
+ import { EpsonModel, getPrinter } from '@munchi_oy/printer';
46
+
47
+ const printer = getPrinter({
48
+ target: 'BT:00:01:90:7B:5A:11',
49
+ model: EpsonModel.TM_M30III,
50
+ });
51
+
52
+ await printer.connect();
53
+ await printer.print({
54
+ commands: [
55
+ { type: 'text', text: 'Hello\n', align: 'center', bold: true },
56
+ { type: 'feed', lines: 2 },
57
+ { type: 'cut' },
58
+ ],
59
+ });
60
+ await printer.disconnect();
61
+ ```
62
+
63
+ ## Config
64
+
65
+ `getPrinter(config)` requires `EpsonPrinterConfig`.
66
+
67
+ | Field | Type | Required | Description |
68
+ | :--- | :--- | :--- | :--- |
69
+ | `model` | `EpsonModel` | Yes | Epson printer series passed to native init |
70
+ | `target` | `string` | No | Default target (for `connect()` without args) |
71
+ | `lang` | `Epos2Lang` | No | Language enum used by native printer object |
72
+ | `logger` | `PrinterLogger` | No | SDK logger hook (`error`, optional `info`) |
73
+
74
+ ## Discovery
75
+
76
+ Use discovery as a standalone API:
77
+
78
+ ```ts
79
+ import { discoverPrinters } from '@munchi_oy/printer';
80
+
81
+ const printers = await discoverPrinters({ timeout: 5000, connectionType: 'bluetooth' });
82
+ ```
83
+
84
+ `discoverPrinters` filters out Epson sub-device targets like `[local_display]`.
85
+
86
+ ## Connection Lifecycle
87
+
88
+ - `connect(target?, timeout?)`
89
+ - `disconnect()`
90
+ - `onConnectionChange(callback)`
91
+
92
+ Examples:
93
+
94
+ ```ts
95
+ await printer.connect(); // uses config.target
96
+ await printer.connect('TCP:192.168.1.50', 7000); // override target
97
+
98
+ const unsubscribe = printer.onConnectionChange((status) => {
99
+ console.log('status', status);
100
+ });
101
+ ```
102
+
103
+ ## Printing
104
+
105
+ ### PrintJob
106
+
107
+ ```ts
108
+ await printer.print({
109
+ commands: [
110
+ { type: 'align', align: 'left' },
111
+ { type: 'text', text: 'Order #123\n' },
112
+ { type: 'separator' },
113
+ { type: 'cut' },
114
+ ],
115
+ });
116
+ ```
117
+
118
+ ### Embedded Payload
119
+
120
+ ```ts
121
+ await printer.printEmbedded({
122
+ id: 'Ord-123',
123
+ ts: '12:00 PM',
124
+ lines: [{ t: '1x Burger' }],
125
+ });
126
+ ```
127
+
128
+ ### Cash Drawer
129
+
130
+ ```ts
131
+ await printer.openDrawer();
132
+ ```
133
+
134
+ ## Multi-Instance And Session Behavior
135
+
136
+ Each `getPrinter(...)` instance has its own native `sessionId`.
137
+
138
+ This ensures:
139
+ - native calls are isolated per JS instance
140
+ - native events are routed by session
141
+ - instance A does not consume instance B events
142
+
143
+ If two instances connect to the same target at the same time, native returns `TARGET_IN_USE`.
144
+
145
+ ## Logging
146
+
147
+ You can inject logger per instance or set a global logger.
148
+
149
+ ```ts
150
+ import { setGlobalLogger } from '@munchi_oy/printer';
151
+
152
+ setGlobalLogger({
153
+ info: (message) => console.log(message),
154
+ error: (message, error) => console.error(message, error),
155
+ });
156
+ ```
157
+
158
+ ## What We Support
159
+
160
+ ### Vendor Support
161
+
162
+ | Vendor | Support |
163
+ | :--- | :--- |
164
+ | Epson | Yes |
165
+ | Star | No |
166
+ | Sunmi | No |
167
+
168
+ ### Platform Focus
169
+
170
+ | Platform | Status |
171
+ | :--- | :--- |
172
+ | iOS | Supported |
173
+ | Android | Supported |
174
+
175
+ ### Connection Types
176
+
177
+ - Bluetooth (`BT:`)
178
+ - TCP (`TCP:`, `TCPS:`)
179
+ - USB (`USB:`)
180
+
181
+ ## Known Issues
182
+
183
+ - If printer hardware state is bad (cover open/paper out), jobs pause until recovery is detected.
184
+ - Discovery quality depends on OS radio/network state and Epson SDK behavior.
185
+ - Connecting to the same target from multiple active sessions returns `TARGET_IN_USE`.
186
+
187
+ ## Limitations
188
+
189
+ - Epson-only package scope.
190
+ - `model` must be known at instance creation time.
191
+ - No direct API to change model/lang after instance creation; create a new printer instance instead.
192
+ - Bridge behavior depends on Epson ePOS2 SDK constraints.
193
+
194
+ ## Troubleshooting
195
+
196
+ 1. `Native module not found`
197
+ - iOS: reinstall pods and rebuild.
198
+ - Android: clean/sync Gradle and rebuild.
199
+
200
+ 2. `Printer target is required`
201
+ - Pass `target` in config or in `connect(target)`.
202
+
203
+ 3. Frequent busy/connect retries
204
+ - Ensure only one active session per target and stable transport.
205
+
206
+ ## Migration Guide (Breaking Changes)
207
+
208
+ If you are upgrading from older versions:
209
+
210
+ 1. Epson-only
211
+ - Removed `PrinterType`, Star/Sunmi drivers, and adapter-style vendor factory.
212
+
213
+ 2. Config changes
214
+ - `model` is now required in `getPrinter({ ... })`.
215
+
216
+ 3. Connect signature changes
217
+ - Before: `connect(target, timeout, model, lang)`
218
+ - Now: `connect(target?, timeout?)`
219
+ - Model/lang come from instance config.
220
+
221
+ 4. Paths and exports
222
+ - Epson internals moved from `src/vendors/epson/*` to `src/epson/*`.
223
+ - Public imports remain from `@munchi_oy/printer`.
@@ -0,0 +1,34 @@
1
+ def safeExtGet(prop, fallback) {
2
+ return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
3
+ }
4
+
5
+ apply plugin: 'com.android.library'
6
+
7
+ android {
8
+ namespace 'com.munchiepsonprinter'
9
+ compileSdkVersion safeExtGet('compileSdkVersion', 35)
10
+
11
+ defaultConfig {
12
+ minSdkVersion safeExtGet('minSdkVersion', 24)
13
+ targetSdkVersion safeExtGet('targetSdkVersion', 35)
14
+ consumerProguardFiles 'consumer-rules.pro'
15
+ }
16
+
17
+ sourceSets {
18
+ main {
19
+ java.srcDirs = ['src/main/java']
20
+ manifest.srcFile 'src/main/AndroidManifest.xml'
21
+ jniLibs.srcDirs = ['src/main/jniLibs']
22
+ }
23
+ }
24
+ }
25
+
26
+ repositories {
27
+ google()
28
+ mavenCentral()
29
+ }
30
+
31
+ dependencies {
32
+ implementation 'com.facebook.react:react-native:+'
33
+ implementation files('libs/ePOS2.jar')
34
+ }
File without changes
Binary file
@@ -0,0 +1,17 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.munchiepsonprinter">
3
+
4
+ <uses-permission android:name="android.permission.INTERNET" />
5
+
6
+ <uses-permission
7
+ android:name="android.permission.BLUETOOTH_SCAN"
8
+ android:usesPermissionFlags="neverForLocation" />
9
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
10
+
11
+ <uses-permission
12
+ android:name="android.permission.BLUETOOTH"
13
+ android:maxSdkVersion="30" />
14
+ <uses-permission
15
+ android:name="android.permission.BLUETOOTH_ADMIN"
16
+ android:maxSdkVersion="30" />
17
+ </manifest>