@connexup/react-native-xprinter 0.1.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.
- package/LICENSE +20 -0
- package/NativeXPrinter.podspec +23 -0
- package/README.md +24 -0
- package/android/build.gradle +73 -0
- package/android/gradle.properties +5 -0
- package/android/libs/printer-lib-3.4.7.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/connexup/xprinter/Errors.kt +11 -0
- package/android/src/main/java/com/connexup/xprinter/Util.kt +106 -0
- package/android/src/main/java/com/connexup/xprinter/XPrinterPackage.kt +77 -0
- package/android/src/main/java/com/connexup/xprinter/esc/Convert.kt +211 -0
- package/android/src/main/java/com/connexup/xprinter/esc/XPrinterESCModule.kt +1995 -0
- package/android/src/main/java/com/connexup/xprinter/printer/Convert.kt +46 -0
- package/android/src/main/java/com/connexup/xprinter/printer/DeviceConnection.kt +14 -0
- package/android/src/main/java/com/connexup/xprinter/printer/Printers.kt +153 -0
- package/android/src/main/java/com/connexup/xprinter/printer/XPrinterPrinterModule.kt +295 -0
- package/android/src/main/java/com/connexup/xprinter/tspl/Convert.kt +151 -0
- package/android/src/main/java/com/connexup/xprinter/tspl/XPrinterTSPLModule.kt +1408 -0
- package/android/src/main/java/com/connexup/xprinter/utils/XPrinterUtilsModule.kt +54 -0
- package/ios/ESC/ESCConvert.swift +283 -0
- package/ios/ESC/Models/RCTESCPrintBarCodeRequest.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintBitmapRequest.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintPDF417Request.swift +27 -0
- package/ios/ESC/Models/RCTESCPrintQRCodeRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTableBarcode.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintTableRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTableRow.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTextRequest.swift +21 -0
- package/ios/ESC/Models/RCTESCPrintTextSizeRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCSelectBitmapModelRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCSetNetAllRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCSetPrintAreaRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCSetTextStyleRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCWifiConfigRequest.swift +23 -0
- package/ios/ESC/NativeXPrinterESC.swift +1339 -0
- package/ios/ESC/RCTNativeXPrinterESC.h +10 -0
- package/ios/ESC/RCTNativeXPrinterESC.mm +541 -0
- package/ios/Errors.swift +11 -0
- package/ios/NativeErrorInfo.swift +21 -0
- package/ios/Printer/Connecter.swift +214 -0
- package/ios/Printer/Models/RCTDeviceConnectStatusChangeEvent.swift +19 -0
- package/ios/Printer/Models/RCTNetDevice.swift +21 -0
- package/ios/Printer/Models/RCTUSBDevice.swift +17 -0
- package/ios/Printer/Models/RCTUpdateUdpNetConfigRequest.swift +21 -0
- package/ios/Printer/NativeXPrinterPrinter.swift +209 -0
- package/ios/Printer/Printers.swift +59 -0
- package/ios/Printer/RCTNativeXPrinterPrinter.h +12 -0
- package/ios/Printer/RCTNativeXPrinterPrinter.mm +123 -0
- package/ios/PrinterSDK/Headers/CPCLCommand.h +324 -0
- package/ios/PrinterSDK/Headers/KDS_Log.h +47 -0
- package/ios/PrinterSDK/Headers/LabelDocument.h +32 -0
- package/ios/PrinterSDK/Headers/LabelImageTranster.h +19 -0
- package/ios/PrinterSDK/Headers/POSBLEManager.h +164 -0
- package/ios/PrinterSDK/Headers/POSCommand.h +760 -0
- package/ios/PrinterSDK/Headers/POSImageTranster.h +34 -0
- package/ios/PrinterSDK/Headers/POSPrinter.h +47 -0
- package/ios/PrinterSDK/Headers/POSPrinterSDK.h +13 -0
- package/ios/PrinterSDK/Headers/POSWIFIManager.h +162 -0
- package/ios/PrinterSDK/Headers/PTable.h +50 -0
- package/ios/PrinterSDK/Headers/PrinterProfile.h +28 -0
- package/ios/PrinterSDK/Headers/TSCBLEManager.h +142 -0
- package/ios/PrinterSDK/Headers/TSCCommand.h +701 -0
- package/ios/PrinterSDK/Headers/TSCPrinterSDK.h +15 -0
- package/ios/PrinterSDK/Headers/TSCWIFIManager.h +99 -0
- package/ios/PrinterSDK/Headers/WIFIConnecter.h +131 -0
- package/ios/PrinterSDK/Headers/ZPLCommand.h +372 -0
- package/ios/PrinterSDK/libPrinterSDK.a +0 -0
- package/ios/TSPL/Models/RCTTSPLBarRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLBarcodeRequest.swift +29 -0
- package/ios/TSPL/Models/RCTTSPLBitmapCompressionRequest.swift +25 -0
- package/ios/TSPL/Models/RCTTSPLBitmapRequest.swift +25 -0
- package/ios/TSPL/Models/RCTTSPLBoxRequest.swift +21 -0
- package/ios/TSPL/Models/RCTTSPLEraseRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLPDFBase64Request.swift +21 -0
- package/ios/TSPL/Models/RCTTSPLPutBMPRequest.swift +17 -0
- package/ios/TSPL/Models/RCTTSPLQRCodeRequest.swift +29 -0
- package/ios/TSPL/Models/RCTTSPLReverseRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLTextRequest.swift +25 -0
- package/ios/TSPL/NativeXPrinterTSPL.swift +831 -0
- package/ios/TSPL/RCTNativeXPrinterTSPL.h +10 -0
- package/ios/TSPL/RCTNativeXPrinterTSPL.mm +445 -0
- package/ios/TSPL/TSPLConvert.swift +140 -0
- package/ios/Utils/Models/RCTCheckIsPureWhiteImageRequest.swift +16 -0
- package/ios/Utils/NativeXPrinterUtils.swift +17 -0
- package/ios/Utils/RCTNativeXPrinterUtils.h +10 -0
- package/ios/Utils/RCTNativeXPrinterUtils.mm +38 -0
- package/ios/Utils.swift +126 -0
- package/lib/module/esc/NativeXPrinterESC.js +218 -0
- package/lib/module/esc/NativeXPrinterESC.js.map +1 -0
- package/lib/module/esc/index.js +324 -0
- package/lib/module/esc/index.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/printer/NativeXPrinterPrinter.js +30 -0
- package/lib/module/printer/NativeXPrinterPrinter.js.map +1 -0
- package/lib/module/printer/index.js +110 -0
- package/lib/module/printer/index.js.map +1 -0
- package/lib/module/tspl/NativeXPrinterTSPL.js +143 -0
- package/lib/module/tspl/NativeXPrinterTSPL.js.map +1 -0
- package/lib/module/tspl/index.js +347 -0
- package/lib/module/tspl/index.js.map +1 -0
- package/lib/module/type.js +12 -0
- package/lib/module/type.js.map +1 -0
- package/lib/module/util.js +4 -0
- package/lib/module/util.js.map +1 -0
- package/lib/module/utils/NativeXPrinterUtils.js +5 -0
- package/lib/module/utils/NativeXPrinterUtils.js.map +1 -0
- package/lib/module/utils/index.js +17 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/esc/NativeXPrinterESC.d.ts +343 -0
- package/lib/typescript/src/esc/NativeXPrinterESC.d.ts.map +1 -0
- package/lib/typescript/src/esc/index.d.ts +122 -0
- package/lib/typescript/src/esc/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts +61 -0
- package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts.map +1 -0
- package/lib/typescript/src/printer/index.d.ts +32 -0
- package/lib/typescript/src/printer/index.d.ts.map +1 -0
- package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts +261 -0
- package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts.map +1 -0
- package/lib/typescript/src/tspl/index.d.ts +128 -0
- package/lib/typescript/src/tspl/index.d.ts.map +1 -0
- package/lib/typescript/src/type.d.ts +9 -0
- package/lib/typescript/src/type.d.ts.map +1 -0
- package/lib/typescript/src/util.d.ts +2 -0
- package/lib/typescript/src/util.d.ts.map +1 -0
- package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts +10 -0
- package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +9 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/esc/NativeXPrinterESC.ts +516 -0
- package/src/esc/index.ts +489 -0
- package/src/index.ts +5 -0
- package/src/printer/NativeXPrinterPrinter.ts +84 -0
- package/src/printer/index.ts +160 -0
- package/src/tspl/NativeXPrinterTSPL.ts +388 -0
- package/src/tspl/index.ts +535 -0
- package/src/type.ts +11 -0
- package/src/util.ts +1 -0
- package/src/utils/NativeXPrinterUtils.ts +14 -0
- package/src/utils/index.ts +27 -0
|
@@ -0,0 +1,1408 @@
|
|
|
1
|
+
package com.connexup.xprinter.tspl
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import com.connexup.xprinter.COMMON_ERROR
|
|
5
|
+
import com.connexup.xprinter.NativeXPrinterTSPLSpec
|
|
6
|
+
import com.connexup.xprinter.PARAMS_ERROR
|
|
7
|
+
import com.connexup.xprinter.PRINTER_NOT_FOUND_ERROR
|
|
8
|
+
import com.connexup.xprinter.loadAndScaleBitmap
|
|
9
|
+
import com.connexup.xprinter.printer.Printers
|
|
10
|
+
import com.facebook.react.bridge.Promise
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap
|
|
13
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
14
|
+
import kotlinx.coroutines.CoroutineScope
|
|
15
|
+
import kotlinx.coroutines.Dispatchers
|
|
16
|
+
import kotlinx.coroutines.SupervisorJob
|
|
17
|
+
import kotlinx.coroutines.launch
|
|
18
|
+
import kotlinx.coroutines.withContext
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Description:
|
|
22
|
+
* @author lukechen@chancetop.com
|
|
23
|
+
* @date 2026/2/9
|
|
24
|
+
*/
|
|
25
|
+
class XPrinterTSPLModule(reactContext: ReactApplicationContext) :
|
|
26
|
+
NativeXPrinterTSPLSpec(reactContext) {
|
|
27
|
+
|
|
28
|
+
private val scope: CoroutineScope by lazy {
|
|
29
|
+
CoroutineScope(
|
|
30
|
+
SupervisorJob() + Dispatchers.Main
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private val printers = Printers.tsplPrinters
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
override fun sizeInch(connectInfo: String, width: Double, height: Double, promise: Promise) {
|
|
38
|
+
scope.launch {
|
|
39
|
+
val printer = printers[connectInfo]
|
|
40
|
+
if (printer == null) {
|
|
41
|
+
promise.reject(
|
|
42
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
43
|
+
"not found printer:${connectInfo}"
|
|
44
|
+
)
|
|
45
|
+
return@launch
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
withContext(Dispatchers.IO) {
|
|
50
|
+
printer.sizeInch(width, height)
|
|
51
|
+
}
|
|
52
|
+
promise.resolve(null)
|
|
53
|
+
} catch (e: Exception) {
|
|
54
|
+
promise.reject(
|
|
55
|
+
COMMON_ERROR,
|
|
56
|
+
e.message,
|
|
57
|
+
e
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun sizeMm(connectInfo: String, width: Double, height: Double, promise: Promise) {
|
|
64
|
+
scope.launch {
|
|
65
|
+
val printer = printers[connectInfo]
|
|
66
|
+
if (printer == null) {
|
|
67
|
+
promise.reject(
|
|
68
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
69
|
+
"not found printer:${connectInfo}"
|
|
70
|
+
)
|
|
71
|
+
return@launch
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
withContext(Dispatchers.IO) {
|
|
76
|
+
printer.sizeMm(width, height)
|
|
77
|
+
}
|
|
78
|
+
promise.resolve(null)
|
|
79
|
+
} catch (e: Exception) {
|
|
80
|
+
promise.reject(
|
|
81
|
+
COMMON_ERROR,
|
|
82
|
+
e.message,
|
|
83
|
+
e
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
override fun gapInch(connectInfo: String, m: Double, n: Double, promise: Promise) {
|
|
90
|
+
scope.launch {
|
|
91
|
+
val printer = printers[connectInfo]
|
|
92
|
+
if (printer == null) {
|
|
93
|
+
promise.reject(
|
|
94
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
95
|
+
"not found printer:${connectInfo}"
|
|
96
|
+
)
|
|
97
|
+
return@launch
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
withContext(Dispatchers.IO) {
|
|
102
|
+
printer.gapInch(m, n)
|
|
103
|
+
}
|
|
104
|
+
promise.resolve(null)
|
|
105
|
+
} catch (e: Exception) {
|
|
106
|
+
promise.reject(
|
|
107
|
+
COMMON_ERROR,
|
|
108
|
+
e.message,
|
|
109
|
+
e
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override fun gapMm(connectInfo: String, m: Double, n: Double, promise: Promise) {
|
|
116
|
+
scope.launch {
|
|
117
|
+
val printer = printers[connectInfo]
|
|
118
|
+
if (printer == null) {
|
|
119
|
+
promise.reject(
|
|
120
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
121
|
+
"not found printer:${connectInfo}"
|
|
122
|
+
)
|
|
123
|
+
return@launch
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
withContext(Dispatchers.IO) {
|
|
128
|
+
printer.gapMm(m, n)
|
|
129
|
+
}
|
|
130
|
+
promise.resolve(null)
|
|
131
|
+
} catch (e: Exception) {
|
|
132
|
+
promise.reject(
|
|
133
|
+
COMMON_ERROR,
|
|
134
|
+
e.message,
|
|
135
|
+
e
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
override fun speed(connectInfo: String, speed: Double, promise: Promise) {
|
|
142
|
+
scope.launch {
|
|
143
|
+
val printer = printers[connectInfo]
|
|
144
|
+
if (printer == null) {
|
|
145
|
+
promise.reject(
|
|
146
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
147
|
+
"not found printer:${connectInfo}"
|
|
148
|
+
)
|
|
149
|
+
return@launch
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
withContext(Dispatchers.IO) {
|
|
154
|
+
printer.speed(speed)
|
|
155
|
+
}
|
|
156
|
+
promise.resolve(null)
|
|
157
|
+
} catch (e: Exception) {
|
|
158
|
+
promise.reject(
|
|
159
|
+
COMMON_ERROR,
|
|
160
|
+
e.message,
|
|
161
|
+
e
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
override fun density(connectInfo: String, density: Double, promise: Promise) {
|
|
168
|
+
scope.launch {
|
|
169
|
+
val printer = printers[connectInfo]
|
|
170
|
+
if (printer == null) {
|
|
171
|
+
promise.reject(
|
|
172
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
173
|
+
"not found printer:${connectInfo}"
|
|
174
|
+
)
|
|
175
|
+
return@launch
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
withContext(Dispatchers.IO) {
|
|
180
|
+
printer.density(density.toInt())
|
|
181
|
+
}
|
|
182
|
+
promise.resolve(null)
|
|
183
|
+
} catch (e: Exception) {
|
|
184
|
+
promise.reject(
|
|
185
|
+
COMMON_ERROR,
|
|
186
|
+
e.message,
|
|
187
|
+
e
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
override fun direction(
|
|
194
|
+
connectInfo: String,
|
|
195
|
+
direction: String,
|
|
196
|
+
isMirror: Boolean,
|
|
197
|
+
promise: Promise
|
|
198
|
+
) {
|
|
199
|
+
scope.launch {
|
|
200
|
+
val printer = printers[connectInfo]
|
|
201
|
+
if (printer == null) {
|
|
202
|
+
promise.reject(
|
|
203
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
204
|
+
"not found printer:${connectInfo}"
|
|
205
|
+
)
|
|
206
|
+
return@launch
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
val direction = direction.toTSPLDirection()
|
|
210
|
+
if (direction == null) {
|
|
211
|
+
promise.reject(
|
|
212
|
+
PARAMS_ERROR,
|
|
213
|
+
"direction is error"
|
|
214
|
+
)
|
|
215
|
+
return@launch
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
withContext(Dispatchers.IO) {
|
|
220
|
+
printer.direction(direction, isMirror)
|
|
221
|
+
}
|
|
222
|
+
promise.resolve(null)
|
|
223
|
+
} catch (e: Exception) {
|
|
224
|
+
promise.reject(
|
|
225
|
+
COMMON_ERROR,
|
|
226
|
+
e.message,
|
|
227
|
+
e
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
override fun cls(connectInfo: String, promise: Promise) {
|
|
234
|
+
scope.launch {
|
|
235
|
+
val printer = printers[connectInfo]
|
|
236
|
+
if (printer == null) {
|
|
237
|
+
promise.reject(
|
|
238
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
239
|
+
"not found printer:${connectInfo}"
|
|
240
|
+
)
|
|
241
|
+
return@launch
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
withContext(Dispatchers.IO) {
|
|
246
|
+
printer.cls()
|
|
247
|
+
}
|
|
248
|
+
promise.resolve(null)
|
|
249
|
+
} catch (e: Exception) {
|
|
250
|
+
promise.reject(
|
|
251
|
+
COMMON_ERROR,
|
|
252
|
+
e.message,
|
|
253
|
+
e
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
override fun box(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
260
|
+
scope.launch {
|
|
261
|
+
val printer = printers[connectInfo]
|
|
262
|
+
if (printer == null) {
|
|
263
|
+
promise.reject(
|
|
264
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
265
|
+
"not found printer:${connectInfo}"
|
|
266
|
+
)
|
|
267
|
+
return@launch
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
val x = payload.getInt("x")
|
|
272
|
+
val y = payload.getInt("y")
|
|
273
|
+
val width = payload.getInt("width")
|
|
274
|
+
val height = payload.getInt("height")
|
|
275
|
+
val thickness = payload.getInt("thickness")
|
|
276
|
+
withContext(Dispatchers.IO) {
|
|
277
|
+
printer.box(x, y, width, height, thickness)
|
|
278
|
+
}
|
|
279
|
+
promise.resolve(null)
|
|
280
|
+
} catch (e: Exception) {
|
|
281
|
+
promise.reject(
|
|
282
|
+
COMMON_ERROR,
|
|
283
|
+
e.message,
|
|
284
|
+
e
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
override fun bar(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
291
|
+
scope.launch {
|
|
292
|
+
val printer = printers[connectInfo]
|
|
293
|
+
if (printer == null) {
|
|
294
|
+
promise.reject(
|
|
295
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
296
|
+
"not found printer:${connectInfo}"
|
|
297
|
+
)
|
|
298
|
+
return@launch
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
val x = payload.getInt("x")
|
|
303
|
+
val y = payload.getInt("y")
|
|
304
|
+
val width = payload.getInt("width")
|
|
305
|
+
val height = payload.getInt("height")
|
|
306
|
+
withContext(Dispatchers.IO) {
|
|
307
|
+
printer.bar(x, y, width, height)
|
|
308
|
+
}
|
|
309
|
+
promise.resolve(null)
|
|
310
|
+
} catch (e: Exception) {
|
|
311
|
+
promise.reject(
|
|
312
|
+
COMMON_ERROR,
|
|
313
|
+
e.message,
|
|
314
|
+
e
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
override fun barcode(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
321
|
+
scope.launch {
|
|
322
|
+
val printer = printers[connectInfo]
|
|
323
|
+
if (printer == null) {
|
|
324
|
+
promise.reject(
|
|
325
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
326
|
+
"not found printer:${connectInfo}"
|
|
327
|
+
)
|
|
328
|
+
return@launch
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
val x = payload.getInt("x")
|
|
333
|
+
val y = payload.getInt("y")
|
|
334
|
+
val codeType = payload.getString("codeType")?.toTSPLBarcodeType()
|
|
335
|
+
if (codeType == null) {
|
|
336
|
+
promise.reject(
|
|
337
|
+
PARAMS_ERROR,
|
|
338
|
+
"codeType is error"
|
|
339
|
+
)
|
|
340
|
+
return@launch
|
|
341
|
+
}
|
|
342
|
+
val height = payload.getInt("height")
|
|
343
|
+
val readable = payload.getString("readable")?.toTSPLReadable()
|
|
344
|
+
if (readable == null) {
|
|
345
|
+
promise.reject(
|
|
346
|
+
PARAMS_ERROR,
|
|
347
|
+
"readable is error"
|
|
348
|
+
)
|
|
349
|
+
return@launch
|
|
350
|
+
}
|
|
351
|
+
val rotation = payload.getString("rotation")?.toTSPLRotation()
|
|
352
|
+
if (rotation == null) {
|
|
353
|
+
promise.reject(
|
|
354
|
+
PARAMS_ERROR,
|
|
355
|
+
"rotation is error"
|
|
356
|
+
)
|
|
357
|
+
return@launch
|
|
358
|
+
}
|
|
359
|
+
val narrow = payload.getInt("narrow")
|
|
360
|
+
val wide = payload.getInt("wide")
|
|
361
|
+
val content = payload.getString("content")
|
|
362
|
+
if (content == null) {
|
|
363
|
+
promise.reject(
|
|
364
|
+
PARAMS_ERROR,
|
|
365
|
+
"content is error"
|
|
366
|
+
)
|
|
367
|
+
return@launch
|
|
368
|
+
}
|
|
369
|
+
withContext(Dispatchers.IO) {
|
|
370
|
+
printer.barcode(
|
|
371
|
+
x,
|
|
372
|
+
y,
|
|
373
|
+
codeType,
|
|
374
|
+
height,
|
|
375
|
+
readable,
|
|
376
|
+
rotation,
|
|
377
|
+
narrow,
|
|
378
|
+
wide,
|
|
379
|
+
content
|
|
380
|
+
)
|
|
381
|
+
}
|
|
382
|
+
promise.resolve(null)
|
|
383
|
+
} catch (e: Exception) {
|
|
384
|
+
promise.reject(
|
|
385
|
+
COMMON_ERROR,
|
|
386
|
+
e.message,
|
|
387
|
+
e
|
|
388
|
+
)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
override fun text(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
394
|
+
scope.launch {
|
|
395
|
+
val printer = printers[connectInfo]
|
|
396
|
+
if (printer == null) {
|
|
397
|
+
promise.reject(
|
|
398
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
399
|
+
"not found printer:${connectInfo}"
|
|
400
|
+
)
|
|
401
|
+
return@launch
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
val x = payload.getInt("x")
|
|
406
|
+
val y = payload.getInt("y")
|
|
407
|
+
val font = payload.getString("font")?.toTSPLFont()
|
|
408
|
+
if (font == null) {
|
|
409
|
+
promise.reject(
|
|
410
|
+
PARAMS_ERROR,
|
|
411
|
+
"font is error"
|
|
412
|
+
)
|
|
413
|
+
return@launch
|
|
414
|
+
}
|
|
415
|
+
val rotation = payload.getString("rotation")?.toTSPLRotation()
|
|
416
|
+
if (rotation == null) {
|
|
417
|
+
promise.reject(
|
|
418
|
+
PARAMS_ERROR,
|
|
419
|
+
"rotation is error"
|
|
420
|
+
)
|
|
421
|
+
return@launch
|
|
422
|
+
}
|
|
423
|
+
val xRatio = payload.getInt("xRatio")
|
|
424
|
+
val yRatio = payload.getInt("yRatio")
|
|
425
|
+
val content = payload.getString("content")
|
|
426
|
+
if (content == null) {
|
|
427
|
+
promise.reject(
|
|
428
|
+
PARAMS_ERROR,
|
|
429
|
+
"content is error"
|
|
430
|
+
)
|
|
431
|
+
return@launch
|
|
432
|
+
}
|
|
433
|
+
withContext(Dispatchers.IO) {
|
|
434
|
+
printer.text(x, y, font, rotation, xRatio, yRatio, content)
|
|
435
|
+
}
|
|
436
|
+
promise.resolve(null)
|
|
437
|
+
} catch (e: Exception) {
|
|
438
|
+
promise.reject(
|
|
439
|
+
COMMON_ERROR,
|
|
440
|
+
e.message,
|
|
441
|
+
e
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
override fun offsetInch(connectInfo: String, offset: Double, promise: Promise) {
|
|
448
|
+
scope.launch {
|
|
449
|
+
val printer = printers[connectInfo]
|
|
450
|
+
if (printer == null) {
|
|
451
|
+
promise.reject(
|
|
452
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
453
|
+
"not found printer:${connectInfo}"
|
|
454
|
+
)
|
|
455
|
+
return@launch
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
try {
|
|
459
|
+
withContext(Dispatchers.IO) {
|
|
460
|
+
printer.offsetInch(offset)
|
|
461
|
+
}
|
|
462
|
+
promise.resolve(null)
|
|
463
|
+
} catch (e: Exception) {
|
|
464
|
+
promise.reject(
|
|
465
|
+
COMMON_ERROR,
|
|
466
|
+
e.message,
|
|
467
|
+
e
|
|
468
|
+
)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
override fun offsetMm(connectInfo: String, offset: Double, promise: Promise) {
|
|
474
|
+
scope.launch {
|
|
475
|
+
val printer = printers[connectInfo]
|
|
476
|
+
if (printer == null) {
|
|
477
|
+
promise.reject(
|
|
478
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
479
|
+
"not found printer:${connectInfo}"
|
|
480
|
+
)
|
|
481
|
+
return@launch
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
try {
|
|
485
|
+
withContext(Dispatchers.IO) {
|
|
486
|
+
printer.offsetMm(offset)
|
|
487
|
+
}
|
|
488
|
+
promise.resolve(null)
|
|
489
|
+
} catch (e: Exception) {
|
|
490
|
+
promise.reject(
|
|
491
|
+
COMMON_ERROR,
|
|
492
|
+
e.message,
|
|
493
|
+
e
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
override fun reference(connectInfo: String, x: Double, y: Double, promise: Promise) {
|
|
500
|
+
scope.launch {
|
|
501
|
+
val printer = printers[connectInfo]
|
|
502
|
+
if (printer == null) {
|
|
503
|
+
promise.reject(
|
|
504
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
505
|
+
"not found printer:${connectInfo}"
|
|
506
|
+
)
|
|
507
|
+
return@launch
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
try {
|
|
511
|
+
withContext(Dispatchers.IO) {
|
|
512
|
+
printer.reference(x.toInt(), y.toInt())
|
|
513
|
+
}
|
|
514
|
+
promise.resolve(null)
|
|
515
|
+
} catch (e: Exception) {
|
|
516
|
+
promise.reject(
|
|
517
|
+
COMMON_ERROR,
|
|
518
|
+
e.message,
|
|
519
|
+
e
|
|
520
|
+
)
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
override fun qrcode(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
526
|
+
scope.launch {
|
|
527
|
+
val printer = printers[connectInfo]
|
|
528
|
+
if (printer == null) {
|
|
529
|
+
promise.reject(
|
|
530
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
531
|
+
"not found printer:${connectInfo}"
|
|
532
|
+
)
|
|
533
|
+
return@launch
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
try {
|
|
537
|
+
val x = payload.getInt("x")
|
|
538
|
+
val y = payload.getInt("y")
|
|
539
|
+
val ecLevel = payload.getString("ecLevel")?.toTSPLECLevel()
|
|
540
|
+
if (ecLevel == null) {
|
|
541
|
+
promise.reject(
|
|
542
|
+
PARAMS_ERROR,
|
|
543
|
+
"ecLevel is error"
|
|
544
|
+
)
|
|
545
|
+
return@launch
|
|
546
|
+
}
|
|
547
|
+
val cellWidth = payload.getInt("cellWidth")
|
|
548
|
+
val mode = payload.getString("mode")?.toTSPLQrcodeMode()
|
|
549
|
+
if (mode == null) {
|
|
550
|
+
promise.reject(
|
|
551
|
+
PARAMS_ERROR,
|
|
552
|
+
"mode is error"
|
|
553
|
+
)
|
|
554
|
+
return@launch
|
|
555
|
+
}
|
|
556
|
+
val rotation = payload.getString("rotation")?.toTSPLRotation()
|
|
557
|
+
if (rotation == null) {
|
|
558
|
+
promise.reject(
|
|
559
|
+
PARAMS_ERROR,
|
|
560
|
+
"rotation is error"
|
|
561
|
+
)
|
|
562
|
+
return@launch
|
|
563
|
+
}
|
|
564
|
+
val model = payload.getString("model")?.toTSPLQrcodeModel()
|
|
565
|
+
if (model == null) {
|
|
566
|
+
promise.reject(
|
|
567
|
+
PARAMS_ERROR,
|
|
568
|
+
"model is error"
|
|
569
|
+
)
|
|
570
|
+
return@launch
|
|
571
|
+
}
|
|
572
|
+
val mask = payload.getString("mask")
|
|
573
|
+
if (mask == null) {
|
|
574
|
+
promise.reject(
|
|
575
|
+
PARAMS_ERROR,
|
|
576
|
+
"mask is error"
|
|
577
|
+
)
|
|
578
|
+
return@launch
|
|
579
|
+
}
|
|
580
|
+
val data = payload.getString("data")
|
|
581
|
+
if (data == null) {
|
|
582
|
+
promise.reject(
|
|
583
|
+
PARAMS_ERROR,
|
|
584
|
+
"data is error"
|
|
585
|
+
)
|
|
586
|
+
return@launch
|
|
587
|
+
}
|
|
588
|
+
withContext(Dispatchers.IO) {
|
|
589
|
+
printer.qrcode(x, y, ecLevel, cellWidth, mode, rotation, model, mask, data)
|
|
590
|
+
}
|
|
591
|
+
promise.resolve(null)
|
|
592
|
+
} catch (e: Exception) {
|
|
593
|
+
promise.reject(
|
|
594
|
+
COMMON_ERROR,
|
|
595
|
+
e.message,
|
|
596
|
+
e
|
|
597
|
+
)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
override fun print(connectInfo: String, count: Double, promise: Promise) {
|
|
603
|
+
scope.launch {
|
|
604
|
+
val printer = printers[connectInfo]
|
|
605
|
+
if (printer == null) {
|
|
606
|
+
promise.reject(
|
|
607
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
608
|
+
"not found printer:${connectInfo}"
|
|
609
|
+
)
|
|
610
|
+
return@launch
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
try {
|
|
614
|
+
withContext(Dispatchers.IO) {
|
|
615
|
+
printer.print(count.toInt())
|
|
616
|
+
}
|
|
617
|
+
promise.resolve(null)
|
|
618
|
+
} catch (e: Exception) {
|
|
619
|
+
promise.reject(
|
|
620
|
+
COMMON_ERROR,
|
|
621
|
+
e.message,
|
|
622
|
+
e
|
|
623
|
+
)
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
override fun printWithResponse(
|
|
629
|
+
connectInfo: String,
|
|
630
|
+
count: Double,
|
|
631
|
+
timeout: Double,
|
|
632
|
+
promise: Promise
|
|
633
|
+
) {
|
|
634
|
+
scope.launch {
|
|
635
|
+
val printer = printers[connectInfo]
|
|
636
|
+
if (printer == null) {
|
|
637
|
+
promise.reject(
|
|
638
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
639
|
+
"not found printer:${connectInfo}"
|
|
640
|
+
)
|
|
641
|
+
return@launch
|
|
642
|
+
}
|
|
643
|
+
try {
|
|
644
|
+
withContext(Dispatchers.IO) {
|
|
645
|
+
printer.printWithResponse(count.toInt(), timeout.toInt()) {
|
|
646
|
+
scope.launch {
|
|
647
|
+
val result = WritableNativeMap()
|
|
648
|
+
result.putInt("status", it)
|
|
649
|
+
promise.resolve(result)
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
} catch (e: Exception) {
|
|
654
|
+
promise.reject(
|
|
655
|
+
COMMON_ERROR,
|
|
656
|
+
e.message,
|
|
657
|
+
e
|
|
658
|
+
)
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
override fun feed(connectInfo: String, length: Double, promise: Promise) {
|
|
664
|
+
scope.launch {
|
|
665
|
+
val printer = printers[connectInfo]
|
|
666
|
+
if (printer == null) {
|
|
667
|
+
promise.reject(
|
|
668
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
669
|
+
"not found printer:${connectInfo}"
|
|
670
|
+
)
|
|
671
|
+
return@launch
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
try {
|
|
675
|
+
withContext(Dispatchers.IO) {
|
|
676
|
+
printer.feed(length.toInt())
|
|
677
|
+
}
|
|
678
|
+
promise.resolve(null)
|
|
679
|
+
} catch (e: Exception) {
|
|
680
|
+
promise.reject(
|
|
681
|
+
COMMON_ERROR,
|
|
682
|
+
e.message,
|
|
683
|
+
e
|
|
684
|
+
)
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
override fun backFeed(connectInfo: String, length: Double, promise: Promise) {
|
|
690
|
+
scope.launch {
|
|
691
|
+
val printer = printers[connectInfo]
|
|
692
|
+
if (printer == null) {
|
|
693
|
+
promise.reject(
|
|
694
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
695
|
+
"not found printer:${connectInfo}"
|
|
696
|
+
)
|
|
697
|
+
return@launch
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
try {
|
|
701
|
+
withContext(Dispatchers.IO) {
|
|
702
|
+
printer.backFeed(length.toInt())
|
|
703
|
+
}
|
|
704
|
+
promise.resolve(null)
|
|
705
|
+
} catch (e: Exception) {
|
|
706
|
+
promise.reject(
|
|
707
|
+
COMMON_ERROR,
|
|
708
|
+
e.message,
|
|
709
|
+
e
|
|
710
|
+
)
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
override fun formFeed(connectInfo: String, promise: Promise) {
|
|
716
|
+
scope.launch {
|
|
717
|
+
val printer = printers[connectInfo]
|
|
718
|
+
if (printer == null) {
|
|
719
|
+
promise.reject(
|
|
720
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
721
|
+
"not found printer:${connectInfo}"
|
|
722
|
+
)
|
|
723
|
+
return@launch
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
try {
|
|
727
|
+
withContext(Dispatchers.IO) {
|
|
728
|
+
printer.formFeed()
|
|
729
|
+
}
|
|
730
|
+
promise.resolve(null)
|
|
731
|
+
} catch (e: Exception) {
|
|
732
|
+
promise.reject(
|
|
733
|
+
COMMON_ERROR,
|
|
734
|
+
e.message,
|
|
735
|
+
e
|
|
736
|
+
)
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
override fun limitFeedMm(connectInfo: String, length: Double, promise: Promise) {
|
|
742
|
+
scope.launch {
|
|
743
|
+
val printer = printers[connectInfo]
|
|
744
|
+
if (printer == null) {
|
|
745
|
+
promise.reject(
|
|
746
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
747
|
+
"not found printer:${connectInfo}"
|
|
748
|
+
)
|
|
749
|
+
return@launch
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
try {
|
|
753
|
+
withContext(Dispatchers.IO) {
|
|
754
|
+
printer.limitFeedMm(length.toInt())
|
|
755
|
+
}
|
|
756
|
+
promise.resolve(null)
|
|
757
|
+
} catch (e: Exception) {
|
|
758
|
+
promise.reject(
|
|
759
|
+
COMMON_ERROR,
|
|
760
|
+
e.message,
|
|
761
|
+
e
|
|
762
|
+
)
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
override fun limitFeedInch(connectInfo: String, length: Double, promise: Promise) {
|
|
768
|
+
scope.launch {
|
|
769
|
+
val printer = printers[connectInfo]
|
|
770
|
+
if (printer == null) {
|
|
771
|
+
promise.reject(
|
|
772
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
773
|
+
"not found printer:${connectInfo}"
|
|
774
|
+
)
|
|
775
|
+
return@launch
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
try {
|
|
779
|
+
withContext(Dispatchers.IO) {
|
|
780
|
+
printer.limitFeedInch(length.toInt())
|
|
781
|
+
}
|
|
782
|
+
promise.resolve(null)
|
|
783
|
+
} catch (e: Exception) {
|
|
784
|
+
promise.reject(
|
|
785
|
+
COMMON_ERROR,
|
|
786
|
+
e.message,
|
|
787
|
+
e
|
|
788
|
+
)
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
override fun home(connectInfo: String, promise: Promise) {
|
|
794
|
+
scope.launch {
|
|
795
|
+
val printer = printers[connectInfo]
|
|
796
|
+
if (printer == null) {
|
|
797
|
+
promise.reject(
|
|
798
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
799
|
+
"not found printer:${connectInfo}"
|
|
800
|
+
)
|
|
801
|
+
return@launch
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
try {
|
|
805
|
+
withContext(Dispatchers.IO) {
|
|
806
|
+
printer.home()
|
|
807
|
+
}
|
|
808
|
+
promise.resolve(null)
|
|
809
|
+
} catch (e: Exception) {
|
|
810
|
+
promise.reject(
|
|
811
|
+
COMMON_ERROR,
|
|
812
|
+
e.message,
|
|
813
|
+
e
|
|
814
|
+
)
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
override fun codePage(connectInfo: String, page: String, promise: Promise) {
|
|
820
|
+
scope.launch {
|
|
821
|
+
val printer = printers[connectInfo]
|
|
822
|
+
if (printer == null) {
|
|
823
|
+
promise.reject(
|
|
824
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
825
|
+
"not found printer:${connectInfo}"
|
|
826
|
+
)
|
|
827
|
+
return@launch
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
try {
|
|
831
|
+
withContext(Dispatchers.IO) {
|
|
832
|
+
printer.codePage(page)
|
|
833
|
+
}
|
|
834
|
+
promise.resolve(null)
|
|
835
|
+
} catch (e: Exception) {
|
|
836
|
+
promise.reject(
|
|
837
|
+
COMMON_ERROR,
|
|
838
|
+
e.message,
|
|
839
|
+
e
|
|
840
|
+
)
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
override fun sound(connectInfo: String, level: Double, interval: Double, promise: Promise) {
|
|
846
|
+
scope.launch {
|
|
847
|
+
val printer = printers[connectInfo]
|
|
848
|
+
if (printer == null) {
|
|
849
|
+
promise.reject(
|
|
850
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
851
|
+
"not found printer:${connectInfo}"
|
|
852
|
+
)
|
|
853
|
+
return@launch
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
try {
|
|
857
|
+
withContext(Dispatchers.IO) {
|
|
858
|
+
printer.sound(level.toInt(), interval.toInt())
|
|
859
|
+
}
|
|
860
|
+
promise.resolve(null)
|
|
861
|
+
} catch (e: Exception) {
|
|
862
|
+
promise.reject(
|
|
863
|
+
COMMON_ERROR,
|
|
864
|
+
e.message,
|
|
865
|
+
e
|
|
866
|
+
)
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
override fun bitmap(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
872
|
+
scope.launch {
|
|
873
|
+
val printer = printers[connectInfo]
|
|
874
|
+
if (printer == null) {
|
|
875
|
+
promise.reject(
|
|
876
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
877
|
+
"not found printer:${connectInfo}"
|
|
878
|
+
)
|
|
879
|
+
return@launch
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
val x = payload.getInt("x")
|
|
883
|
+
val y = payload.getInt("y")
|
|
884
|
+
val mode = payload.getString("mode")?.toTSPLBitmapMode()
|
|
885
|
+
if (mode == null) {
|
|
886
|
+
promise.reject(
|
|
887
|
+
PARAMS_ERROR,
|
|
888
|
+
"mode is error"
|
|
889
|
+
)
|
|
890
|
+
return@launch
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
val bitmapPath = payload.getString("bitmapPath")
|
|
894
|
+
val bitmapContent = payload.getString("bitmapContent")
|
|
895
|
+
if (bitmapPath == null && bitmapContent == null) {
|
|
896
|
+
promise.reject(
|
|
897
|
+
PARAMS_ERROR,
|
|
898
|
+
"bitmapPath is null and bitmapContent is null"
|
|
899
|
+
)
|
|
900
|
+
return@launch
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
val width = payload.getInt("width")
|
|
904
|
+
|
|
905
|
+
val algorithmType = payload.getString("algorithmType")?.toTSPLBitmapAlgorithmType()
|
|
906
|
+
if (algorithmType == null) {
|
|
907
|
+
promise.reject(
|
|
908
|
+
PARAMS_ERROR,
|
|
909
|
+
"algorithmType is error"
|
|
910
|
+
)
|
|
911
|
+
return@launch
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
var bitmap: Bitmap? = null
|
|
916
|
+
try {
|
|
917
|
+
withContext(Dispatchers.IO) {
|
|
918
|
+
bitmap = loadAndScaleBitmap(
|
|
919
|
+
bitmapContent = bitmapContent,
|
|
920
|
+
bitmapPath = bitmapPath,
|
|
921
|
+
width = width
|
|
922
|
+
)
|
|
923
|
+
printer.bitmap(x, y, mode, width, bitmap, algorithmType)
|
|
924
|
+
}
|
|
925
|
+
promise.resolve(null)
|
|
926
|
+
} catch (e: Exception) {
|
|
927
|
+
promise.reject(
|
|
928
|
+
COMMON_ERROR,
|
|
929
|
+
e.message,
|
|
930
|
+
e
|
|
931
|
+
)
|
|
932
|
+
}
|
|
933
|
+
scope.launch(Dispatchers.IO) {
|
|
934
|
+
try {
|
|
935
|
+
if (bitmap !== null && !bitmap.isRecycled) {
|
|
936
|
+
bitmap.recycle()
|
|
937
|
+
}
|
|
938
|
+
} catch (_: Exception) {
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
override fun bitmapCompression(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
945
|
+
scope.launch {
|
|
946
|
+
val printer = printers[connectInfo]
|
|
947
|
+
if (printer == null) {
|
|
948
|
+
promise.reject(
|
|
949
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
950
|
+
"not found printer:${connectInfo}"
|
|
951
|
+
)
|
|
952
|
+
return@launch
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
val x = payload.getInt("x")
|
|
956
|
+
val y = payload.getInt("y")
|
|
957
|
+
val mode = payload.getString("mode")?.toTSPLBitmapCompressionMode()
|
|
958
|
+
if (mode == null) {
|
|
959
|
+
promise.reject(
|
|
960
|
+
PARAMS_ERROR,
|
|
961
|
+
"mode is error"
|
|
962
|
+
)
|
|
963
|
+
return@launch
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
val bitmapPath = payload.getString("bitmapPath")
|
|
967
|
+
val bitmapContent = payload.getString("bitmapContent")
|
|
968
|
+
if (bitmapPath == null && bitmapContent == null) {
|
|
969
|
+
promise.reject(
|
|
970
|
+
PARAMS_ERROR,
|
|
971
|
+
"bitmapPath is null and bitmapContent is null"
|
|
972
|
+
)
|
|
973
|
+
return@launch
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
val width = payload.getInt("width")
|
|
977
|
+
|
|
978
|
+
val algorithmType = payload.getString("algorithmType")?.toTSPLBitmapAlgorithmType()
|
|
979
|
+
if (algorithmType == null) {
|
|
980
|
+
promise.reject(
|
|
981
|
+
PARAMS_ERROR,
|
|
982
|
+
"algorithmType is error"
|
|
983
|
+
)
|
|
984
|
+
return@launch
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
var bitmap: Bitmap? = null
|
|
988
|
+
try {
|
|
989
|
+
withContext(Dispatchers.IO) {
|
|
990
|
+
bitmap = loadAndScaleBitmap(
|
|
991
|
+
bitmapContent = bitmapContent,
|
|
992
|
+
bitmapPath = bitmapPath,
|
|
993
|
+
width = width
|
|
994
|
+
)
|
|
995
|
+
printer.bitmapCompression(x, y, mode, width, bitmap, algorithmType)
|
|
996
|
+
}
|
|
997
|
+
promise.resolve(null)
|
|
998
|
+
} catch (e: Exception) {
|
|
999
|
+
promise.reject(
|
|
1000
|
+
COMMON_ERROR,
|
|
1001
|
+
e.message,
|
|
1002
|
+
e
|
|
1003
|
+
)
|
|
1004
|
+
}
|
|
1005
|
+
scope.launch(Dispatchers.IO) {
|
|
1006
|
+
try {
|
|
1007
|
+
if (bitmap !== null && !bitmap.isRecycled) {
|
|
1008
|
+
bitmap.recycle()
|
|
1009
|
+
}
|
|
1010
|
+
} catch (_: Exception) {
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
override fun pdfBase64(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
1017
|
+
scope.launch {
|
|
1018
|
+
val printer = printers[connectInfo]
|
|
1019
|
+
if (printer == null) {
|
|
1020
|
+
promise.reject(
|
|
1021
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1022
|
+
"not found printer:${connectInfo}"
|
|
1023
|
+
)
|
|
1024
|
+
return@launch
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
val x = payload.getInt("x")
|
|
1028
|
+
val y = payload.getInt("y")
|
|
1029
|
+
val pageWidth = payload.getInt("pageWidth")
|
|
1030
|
+
val base64String = payload.getString("base64String")
|
|
1031
|
+
if (base64String == null) {
|
|
1032
|
+
promise.reject(
|
|
1033
|
+
PARAMS_ERROR,
|
|
1034
|
+
"base64String is null"
|
|
1035
|
+
)
|
|
1036
|
+
return@launch
|
|
1037
|
+
}
|
|
1038
|
+
val algorithmType = payload.getString("algorithmType")?.toTSPLBitmapAlgorithmType()
|
|
1039
|
+
if (algorithmType == null) {
|
|
1040
|
+
promise.reject(
|
|
1041
|
+
PARAMS_ERROR,
|
|
1042
|
+
"algorithmType is error"
|
|
1043
|
+
)
|
|
1044
|
+
return@launch
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
try {
|
|
1048
|
+
withContext(Dispatchers.IO) {
|
|
1049
|
+
printer.pdfBase64(x, y, pageWidth, base64String, algorithmType)
|
|
1050
|
+
}
|
|
1051
|
+
promise.resolve(null)
|
|
1052
|
+
} catch (e: Exception) {
|
|
1053
|
+
promise.reject(
|
|
1054
|
+
COMMON_ERROR,
|
|
1055
|
+
e.message,
|
|
1056
|
+
e
|
|
1057
|
+
)
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
override fun erase(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
1063
|
+
scope.launch {
|
|
1064
|
+
val printer = printers[connectInfo]
|
|
1065
|
+
if (printer == null) {
|
|
1066
|
+
promise.reject(
|
|
1067
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1068
|
+
"not found printer:${connectInfo}"
|
|
1069
|
+
)
|
|
1070
|
+
return@launch
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
val x = payload.getInt("x")
|
|
1074
|
+
val y = payload.getInt("y")
|
|
1075
|
+
val width = payload.getInt("width")
|
|
1076
|
+
val height = payload.getInt("height")
|
|
1077
|
+
try {
|
|
1078
|
+
withContext(Dispatchers.IO) {
|
|
1079
|
+
printer.erase(x, y, width, height)
|
|
1080
|
+
}
|
|
1081
|
+
promise.resolve(null)
|
|
1082
|
+
} catch (e: Exception) {
|
|
1083
|
+
promise.reject(
|
|
1084
|
+
COMMON_ERROR,
|
|
1085
|
+
e.message,
|
|
1086
|
+
e
|
|
1087
|
+
)
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
override fun reverse(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
1093
|
+
scope.launch {
|
|
1094
|
+
val printer = printers[connectInfo]
|
|
1095
|
+
if (printer == null) {
|
|
1096
|
+
promise.reject(
|
|
1097
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1098
|
+
"not found printer:${connectInfo}"
|
|
1099
|
+
)
|
|
1100
|
+
return@launch
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
val x = payload.getInt("x")
|
|
1104
|
+
val y = payload.getInt("y")
|
|
1105
|
+
val width = payload.getInt("width")
|
|
1106
|
+
val height = payload.getInt("height")
|
|
1107
|
+
try {
|
|
1108
|
+
withContext(Dispatchers.IO) {
|
|
1109
|
+
printer.reverse(x, y, width, height)
|
|
1110
|
+
}
|
|
1111
|
+
promise.resolve(null)
|
|
1112
|
+
} catch (e: Exception) {
|
|
1113
|
+
promise.reject(
|
|
1114
|
+
COMMON_ERROR,
|
|
1115
|
+
e.message,
|
|
1116
|
+
e
|
|
1117
|
+
)
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
override fun cut(connectInfo: String, promise: Promise) {
|
|
1124
|
+
scope.launch {
|
|
1125
|
+
val printer = printers[connectInfo]
|
|
1126
|
+
if (printer == null) {
|
|
1127
|
+
promise.reject(
|
|
1128
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1129
|
+
"not found printer:${connectInfo}"
|
|
1130
|
+
)
|
|
1131
|
+
return@launch
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
try {
|
|
1135
|
+
withContext(Dispatchers.IO) {
|
|
1136
|
+
printer.cut()
|
|
1137
|
+
}
|
|
1138
|
+
promise.resolve(null)
|
|
1139
|
+
} catch (e: Exception) {
|
|
1140
|
+
promise.reject(
|
|
1141
|
+
COMMON_ERROR,
|
|
1142
|
+
e.message,
|
|
1143
|
+
e
|
|
1144
|
+
)
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
override fun setPeel(connectInfo: String, isOpen: Boolean, promise: Promise) {
|
|
1150
|
+
scope.launch {
|
|
1151
|
+
val printer = printers[connectInfo]
|
|
1152
|
+
if (printer == null) {
|
|
1153
|
+
promise.reject(
|
|
1154
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1155
|
+
"not found printer:${connectInfo}"
|
|
1156
|
+
)
|
|
1157
|
+
return@launch
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
try {
|
|
1161
|
+
withContext(Dispatchers.IO) {
|
|
1162
|
+
printer.setPeel(isOpen)
|
|
1163
|
+
}
|
|
1164
|
+
promise.resolve(null)
|
|
1165
|
+
} catch (e: Exception) {
|
|
1166
|
+
promise.reject(
|
|
1167
|
+
COMMON_ERROR,
|
|
1168
|
+
e.message,
|
|
1169
|
+
e
|
|
1170
|
+
)
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
override fun setTear(connectInfo: String, isOpen: Boolean, promise: Promise) {
|
|
1176
|
+
scope.launch {
|
|
1177
|
+
val printer = printers[connectInfo]
|
|
1178
|
+
if (printer == null) {
|
|
1179
|
+
promise.reject(
|
|
1180
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1181
|
+
"not found printer:${connectInfo}"
|
|
1182
|
+
)
|
|
1183
|
+
return@launch
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
try {
|
|
1187
|
+
withContext(Dispatchers.IO) {
|
|
1188
|
+
printer.setTear(isOpen)
|
|
1189
|
+
}
|
|
1190
|
+
promise.resolve(null)
|
|
1191
|
+
} catch (e: Exception) {
|
|
1192
|
+
promise.reject(
|
|
1193
|
+
COMMON_ERROR,
|
|
1194
|
+
e.message,
|
|
1195
|
+
e
|
|
1196
|
+
)
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
override fun setCutter(connectInfo: String, pieces: Double, promise: Promise) {
|
|
1202
|
+
scope.launch {
|
|
1203
|
+
val printer = printers[connectInfo]
|
|
1204
|
+
if (printer == null) {
|
|
1205
|
+
promise.reject(
|
|
1206
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1207
|
+
"not found printer:${connectInfo}"
|
|
1208
|
+
)
|
|
1209
|
+
return@launch
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
try {
|
|
1213
|
+
withContext(Dispatchers.IO) {
|
|
1214
|
+
printer.setCutter(pieces.toInt())
|
|
1215
|
+
}
|
|
1216
|
+
promise.resolve(null)
|
|
1217
|
+
} catch (e: Exception) {
|
|
1218
|
+
promise.reject(
|
|
1219
|
+
COMMON_ERROR,
|
|
1220
|
+
e.message,
|
|
1221
|
+
e
|
|
1222
|
+
)
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
override fun putBMP(connectInfo: String, payload: ReadableMap, promise: Promise) {
|
|
1228
|
+
scope.launch {
|
|
1229
|
+
val printer = printers[connectInfo]
|
|
1230
|
+
if (printer == null) {
|
|
1231
|
+
promise.reject(
|
|
1232
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1233
|
+
"not found printer:${connectInfo}"
|
|
1234
|
+
)
|
|
1235
|
+
return@launch
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
val x = payload.getInt("x")
|
|
1239
|
+
val y = payload.getInt("y")
|
|
1240
|
+
val fileName = payload.getString("fileName")
|
|
1241
|
+
if (fileName == null) {
|
|
1242
|
+
promise.reject(
|
|
1243
|
+
PARAMS_ERROR,
|
|
1244
|
+
"fileName is error"
|
|
1245
|
+
)
|
|
1246
|
+
return@launch
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
try {
|
|
1250
|
+
withContext(Dispatchers.IO) {
|
|
1251
|
+
printer.putBmp(x, y, fileName)
|
|
1252
|
+
}
|
|
1253
|
+
promise.resolve(null)
|
|
1254
|
+
} catch (e: Exception) {
|
|
1255
|
+
promise.reject(
|
|
1256
|
+
COMMON_ERROR,
|
|
1257
|
+
e.message,
|
|
1258
|
+
e
|
|
1259
|
+
)
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
override fun blineInch(connectInfo: String, m: Double, n: Double, promise: Promise) {
|
|
1265
|
+
scope.launch {
|
|
1266
|
+
val printer = printers[connectInfo]
|
|
1267
|
+
if (printer == null) {
|
|
1268
|
+
promise.reject(
|
|
1269
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1270
|
+
"not found printer:${connectInfo}"
|
|
1271
|
+
)
|
|
1272
|
+
return@launch
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
try {
|
|
1276
|
+
withContext(Dispatchers.IO) {
|
|
1277
|
+
printer.blineInch(m, n)
|
|
1278
|
+
}
|
|
1279
|
+
promise.resolve(null)
|
|
1280
|
+
} catch (e: Exception) {
|
|
1281
|
+
promise.reject(
|
|
1282
|
+
COMMON_ERROR,
|
|
1283
|
+
e.message,
|
|
1284
|
+
e
|
|
1285
|
+
)
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
override fun blineMm(connectInfo: String, m: Double, n: Double, promise: Promise) {
|
|
1291
|
+
scope.launch {
|
|
1292
|
+
val printer = printers[connectInfo]
|
|
1293
|
+
if (printer == null) {
|
|
1294
|
+
promise.reject(
|
|
1295
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1296
|
+
"not found printer:${connectInfo}"
|
|
1297
|
+
)
|
|
1298
|
+
return@launch
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
try {
|
|
1302
|
+
withContext(Dispatchers.IO) {
|
|
1303
|
+
printer.blineMm(m, n)
|
|
1304
|
+
}
|
|
1305
|
+
promise.resolve(null)
|
|
1306
|
+
} catch (e: Exception) {
|
|
1307
|
+
promise.reject(
|
|
1308
|
+
COMMON_ERROR,
|
|
1309
|
+
e.message,
|
|
1310
|
+
e
|
|
1311
|
+
)
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
override fun setPrinterModel(connectInfo: String, model: String, promise: Promise) {
|
|
1317
|
+
scope.launch {
|
|
1318
|
+
val printer = printers[connectInfo]
|
|
1319
|
+
if (printer == null) {
|
|
1320
|
+
promise.reject(
|
|
1321
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1322
|
+
"not found printer:${connectInfo}"
|
|
1323
|
+
)
|
|
1324
|
+
return@launch
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
try {
|
|
1328
|
+
withContext(Dispatchers.IO) {
|
|
1329
|
+
printer.setPrinterModel(model)
|
|
1330
|
+
}
|
|
1331
|
+
promise.resolve(null)
|
|
1332
|
+
} catch (e: Exception) {
|
|
1333
|
+
promise.reject(
|
|
1334
|
+
COMMON_ERROR,
|
|
1335
|
+
e.message,
|
|
1336
|
+
e
|
|
1337
|
+
)
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
override fun getPrinterModel(connectInfo: String, promise: Promise) {
|
|
1343
|
+
scope.launch {
|
|
1344
|
+
val printer = printers[connectInfo]
|
|
1345
|
+
if (printer == null) {
|
|
1346
|
+
promise.reject(
|
|
1347
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1348
|
+
"not found printer:${connectInfo}"
|
|
1349
|
+
)
|
|
1350
|
+
return@launch
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
try {
|
|
1354
|
+
withContext(Dispatchers.IO) {
|
|
1355
|
+
printer.getPrinterModel {
|
|
1356
|
+
scope.launch {
|
|
1357
|
+
val result = WritableNativeMap()
|
|
1358
|
+
result.putString("model", it)
|
|
1359
|
+
promise.resolve(result)
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
} catch (e: Exception) {
|
|
1364
|
+
promise.reject(
|
|
1365
|
+
COMMON_ERROR,
|
|
1366
|
+
e.message,
|
|
1367
|
+
e
|
|
1368
|
+
)
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
override fun printerStatus(connectInfo: String, timeout: Double, promise: Promise) {
|
|
1375
|
+
scope.launch {
|
|
1376
|
+
val printer = printers[connectInfo]
|
|
1377
|
+
if (printer == null) {
|
|
1378
|
+
promise.reject(
|
|
1379
|
+
PRINTER_NOT_FOUND_ERROR,
|
|
1380
|
+
"not found printer:${connectInfo}"
|
|
1381
|
+
)
|
|
1382
|
+
return@launch
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
try {
|
|
1386
|
+
withContext(Dispatchers.IO) {
|
|
1387
|
+
printer.printerStatus(timeout.toInt()) {
|
|
1388
|
+
scope.launch {
|
|
1389
|
+
val result = WritableNativeMap()
|
|
1390
|
+
result.putInt("status", it)
|
|
1391
|
+
promise.resolve(result)
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
} catch (e: Exception) {
|
|
1396
|
+
promise.reject(
|
|
1397
|
+
COMMON_ERROR,
|
|
1398
|
+
e.message,
|
|
1399
|
+
e
|
|
1400
|
+
)
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
companion object {
|
|
1406
|
+
const val NAME = NativeXPrinterTSPLSpec.NAME
|
|
1407
|
+
}
|
|
1408
|
+
}
|