@rdlabo/capacitor-brotherprint 6.2.0 → 6.3.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/README.md +60 -20
- package/android/src/main/AndroidManifest.xml +2 -17
- package/android/src/main/java/jp/rdlabo/capacitor/plugin/brotherprint/BrotherPrint.kt +118 -86
- package/android/src/main/java/jp/rdlabo/capacitor/plugin/brotherprint/models/BrotherPrintSettings.kt +72 -28
- package/dist/docs.json +116 -46
- package/dist/esm/brother-printer.enum.d.ts +10 -1
- package/dist/esm/brother-printer.enum.js +12 -1
- package/dist/esm/brother-printer.enum.js.map +1 -1
- package/dist/esm/definitions.d.ts +66 -9
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +12 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +12 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Model/PrintErrorModel.swift +19 -0
- package/ios/Plugin/Model/PrinterModel.swift +38 -2
- package/ios/Plugin/Model/PrinterSettingsModel.swift +54 -19
- package/ios/Plugin/Plugin.swift +59 -26
- package/ios/Plugin.xcworkspace/xcuserdata/sakakibara.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Capacitor Brother Print is a native Brother Print SDK implementation for iOS & Android. Support These models.
|
|
4
4
|
|
|
5
|
+
**This plugin is still in the RC (release candidate) phase.**
|
|
6
|
+
|
|
5
7
|
## Supported models
|
|
6
8
|
|
|
7
9
|
Each product link is an Amazon affiliate link. If you choose to make a purchase through these links, it would be greatly appreciated and **would help** support development costs. Thank you!
|
|
8
10
|
|
|
9
11
|
| Product | Model | iOS/WiFi | iOS/BT | iOS/BLE | Android/USB | Android/WiFi | Android/BT | Android/BLE |
|
|
10
12
|
| ------------------------------------- | ------------ | -------- | ------ | ------- | ----------- | ------------ | ---------- | ----------- |
|
|
11
|
-
| QL-810W | QL_810W | ✗ | ✗ | ✗ |
|
|
12
|
-
| [QL-820NWB](https://amzn.to/3BXQ1aj) | QL_820NWB | ◯ | ※1 | ✗ |
|
|
13
|
+
| QL-810W | QL_810W | ✗ | ✗ | ✗ | - | ✗ | ✗ | ✗ |
|
|
14
|
+
| [QL-820NWB](https://amzn.to/3BXQ1aj) | QL_820NWB | ◯ | ※1 | ✗ | - | ◯ | △ | ✗ |
|
|
13
15
|
| [QL-820NWBc](https://amzn.to/4fjhUIe) | QL_820NWB | ◯ | ※2 | ✗ | ✗ | ◯ | ◯ | ✗ |
|
|
14
16
|
| [TD-2320D](https://amzn.to/48EFCN3) | TD_2320D_203 | ✗ | ✗ | ✗ | △ | ✗ | ✗ | ✗ |
|
|
15
|
-
| [TD-2350D](https://amzn.to/48ma6TK) |
|
|
17
|
+
| [TD-2350D](https://amzn.to/48ma6TK) | TD_2350D_300 | ◯ | △ | △ | - | ◯ | ◯ | △ |
|
|
16
18
|
|
|
17
19
|
Amazon Affiliate Links: **https://amzn.to/3AiiOFT**
|
|
18
20
|
|
|
@@ -22,17 +24,19 @@ Amazon Affiliate Links: **https://amzn.to/3AiiOFT**
|
|
|
22
24
|
| --- | -------------------------- |
|
|
23
25
|
| ◯ | Supported and tested |
|
|
24
26
|
| △ | Implemented but not tested |
|
|
25
|
-
|
|
|
27
|
+
| - | Plugin is not supported |
|
|
28
|
+
| ✗ | Device is not supported |
|
|
26
29
|
| BT | Bluetooth |
|
|
27
30
|
| BLE | Bluetooth Low Energy |
|
|
28
31
|
|
|
29
32
|
※1 Due to low Bluetooth version, connection is not possible with iOS. Ref: https://okbizcs.okwave.jp/brother/qa/q9932082.html
|
|
33
|
+
|
|
30
34
|
※2 The iOS/BT implementation for the QL-820NWBc is in place, but it’s uncertain if it functions correctly. It’s unclear whether this is an implementation issue, as Brother’s official app also doesn’t work well.
|
|
31
35
|
|
|
32
36
|
## How to install
|
|
33
37
|
|
|
34
38
|
```
|
|
35
|
-
% npm install @rdlabo/capacitor-brotherprint
|
|
39
|
+
% npm install @rdlabo/capacitor-brotherprint
|
|
36
40
|
```
|
|
37
41
|
|
|
38
42
|
## Initialize the Brother SDK
|
|
@@ -297,6 +301,8 @@ Basically, it times out, so there is no need to use it. Use it when you want to
|
|
|
297
301
|
addListener(eventName: BrotherPrintEventsEnum.onPrinterAvailable, listenerFunc: (printers: BRLMChannelResult) => void) => Promise<PluginListenerHandle>
|
|
298
302
|
```
|
|
299
303
|
|
|
304
|
+
Find the printer that can connected to the device.
|
|
305
|
+
|
|
300
306
|
| Param | Type |
|
|
301
307
|
| ------------------ | -------------------------------------------------------------------------------------------- |
|
|
302
308
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrinterAvailable</a></code> |
|
|
@@ -313,6 +319,8 @@ addListener(eventName: BrotherPrintEventsEnum.onPrinterAvailable, listenerFunc:
|
|
|
313
319
|
addListener(eventName: BrotherPrintEventsEnum.onPrint, listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
314
320
|
```
|
|
315
321
|
|
|
322
|
+
Success Print Event
|
|
323
|
+
|
|
316
324
|
| Param | Type |
|
|
317
325
|
| ------------------ | --------------------------------------------------------------------------------- |
|
|
318
326
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrint</a></code> |
|
|
@@ -329,6 +337,9 @@ addListener(eventName: BrotherPrintEventsEnum.onPrint, listenerFunc: () => void)
|
|
|
329
337
|
addListener(eventName: BrotherPrintEventsEnum.onPrintFailedCommunication, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>
|
|
330
338
|
```
|
|
331
339
|
|
|
340
|
+
Failed to connect to the printer.
|
|
341
|
+
ex: Bluetooth is off, Printer is off, etc.
|
|
342
|
+
|
|
332
343
|
| Param | Type |
|
|
333
344
|
| ------------------ | ---------------------------------------------------------------------------------------------------- |
|
|
334
345
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrintFailedCommunication</a></code> |
|
|
@@ -345,6 +356,8 @@ addListener(eventName: BrotherPrintEventsEnum.onPrintFailedCommunication, listen
|
|
|
345
356
|
addListener(eventName: BrotherPrintEventsEnum.onPrintError, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>
|
|
346
357
|
```
|
|
347
358
|
|
|
359
|
+
Failed to print.
|
|
360
|
+
|
|
348
361
|
| Param | Type |
|
|
349
362
|
| ------------------ | -------------------------------------------------------------------------------------- |
|
|
350
363
|
| **`eventName`** | <code><a href="#brotherprinteventsenum">BrotherPrintEventsEnum.onPrintError</a></code> |
|
|
@@ -370,7 +383,7 @@ addListener(eventName: BrotherPrintEventsEnum.onPrintError, listenerFunc: (info:
|
|
|
370
383
|
|
|
371
384
|
#### BRLMPrintOptions
|
|
372
385
|
|
|
373
|
-
<code>{ encodedImage: string; /** * Should use enum <a href="#
|
|
386
|
+
<code>{ encodedImage: string; /** * Should use enum <a href="#brlmprintermodelname">BRLMPrinterModelName</a> */ modelName: <a href="#brlmprintermodelname">BRLMPrinterModelName</a>; } & <a href="#partial">Partial</a><<a href="#brlmchannelresult">BRLMChannelResult</a>> & (<a href="#brlmprinterqlmodelsettings">BRLMPrinterQLModelSettings</a> | <a href="#brlmprintertdmodelsettings">BRLMPrinterTDModelSettings</a>)</code>
|
|
374
387
|
|
|
375
388
|
|
|
376
389
|
#### Partial
|
|
@@ -382,14 +395,19 @@ Make all properties in T optional
|
|
|
382
395
|
|
|
383
396
|
#### BRLMChannelResult
|
|
384
397
|
|
|
385
|
-
<code>{ port: 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; modelName: string; serialNumber: string; macAddress: string; nodeName: string; location: string;
|
|
398
|
+
<code>{ port: 'usb' | 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; modelName: string; serialNumber: string; macAddress: string; nodeName: string; location: string; /** * This need to connect to the printer. * wifi: IP Address * bluetooth: macAddress * bluetoothLowEnergy: modelName for bluetoothLowEnergy */ channelInfo: string; }</code>
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
#### BRLMPrinterQLModelSettings
|
|
402
|
+
|
|
403
|
+
<code>{ /** * Should use enum <a href="#brlmprinterlabelname">BRLMPrinterLabelName</a> */ labelName: <a href="#brlmprinterlabelname">BRLMPrinterLabelName</a>; } & <a href="#brlmprintersettings">BRLMPrinterSettings</a></code>
|
|
386
404
|
|
|
387
405
|
|
|
388
406
|
#### BRLMPrinterSettings
|
|
389
407
|
|
|
390
408
|
These are optional. If these are not set, default values are assigned by the printer.
|
|
391
409
|
|
|
392
|
-
<code>{ /** * The number of copies you print. */ numberOfCopies?: <a href="#brlmprinternumberofcopies">BRLMPrinterNumberOfCopies</a>; /** * Whether the auto-cut is enabled or not. If true, your printer cut the paper each page. */ autoCut?: <a href="#brlmprinterautocuttype">BRLMPrinterAutoCutType</a>; /** * A scale mode that specifies how your data is scaled in a print area of your printer. */ scaleMode?: <a href="#brlmprinterscalemode">BRLMPrinterScaleMode</a>; /** * A scale value. This is effective when ScaleMode is ScaleValue. */ scaleValue?: <a href="#brlmprinterscalevaluetype">BRLMPrinterScaleValueType</a>; /** * A way to rasterize your data. */ halftone?: <a href="#brlmprinterhalftone">BRLMPrinterHalftone</a>; /** * A threshold value. This is effective when the Halftone is Threshold. */ halftoneThreshold?: <a href="#brlmprinterhalftonethresholdtype">BRLMPrinterHalftoneThresholdType</a>; /** * An image rotation that specifies the angle in which your data is placed in the print area. Rotation direction is clockwise. */ imageRotation?: <a href="#brlmprinterimagerotation">BRLMPrinterImageRotation</a>; /** * A vertical alignment that specifies how your data is placed in the printable area. */ verticalAlignment?: <a href="#brlmprinterverticalalignment">BRLMPrinterVerticalAlignment</a>; /** * A horizontal alignment that specifies how your data is placed in the printable area. */ horizontalAlignment?: <a href="#brlmprinterhorizontalalignment">BRLMPrinterHorizontalAlignment</a>; /** * A compress mode that specifies how to compress your data. * note: This is ios only. */ compressMode?: <a href="#brlmprintercompressmode">BRLMPrinterCompressMode</a>; /** * A priority that is print speed or print quality. Whether or not this has an effect is depend on your printer. */ printQuality?: <a href="#brlmprinterprintquality">BRLMPrinterPrintQuality</a>;
|
|
410
|
+
<code>{ /** * The number of copies you print. */ numberOfCopies?: <a href="#brlmprinternumberofcopies">BRLMPrinterNumberOfCopies</a>; /** * Whether the auto-cut is enabled or not. If true, your printer cut the paper each page. */ autoCut?: <a href="#brlmprinterautocuttype">BRLMPrinterAutoCutType</a>; /** * A scale mode that specifies how your data is scaled in a print area of your printer. */ scaleMode?: <a href="#brlmprinterscalemode">BRLMPrinterScaleMode</a>; /** * A scale value. This is effective when ScaleMode is ScaleValue. */ scaleValue?: <a href="#brlmprinterscalevaluetype">BRLMPrinterScaleValueType</a>; /** * A way to rasterize your data. */ halftone?: <a href="#brlmprinterhalftone">BRLMPrinterHalftone</a>; /** * A threshold value. This is effective when the Halftone is Threshold. */ halftoneThreshold?: <a href="#brlmprinterhalftonethresholdtype">BRLMPrinterHalftoneThresholdType</a>; /** * An image rotation that specifies the angle in which your data is placed in the print area. Rotation direction is clockwise. */ imageRotation?: <a href="#brlmprinterimagerotation">BRLMPrinterImageRotation</a>; /** * A vertical alignment that specifies how your data is placed in the printable area. */ verticalAlignment?: <a href="#brlmprinterverticalalignment">BRLMPrinterVerticalAlignment</a>; /** * A horizontal alignment that specifies how your data is placed in the printable area. */ horizontalAlignment?: <a href="#brlmprinterhorizontalalignment">BRLMPrinterHorizontalAlignment</a>; /** * A compress mode that specifies how to compress your data. * note: This is ios only. */ compressMode?: <a href="#brlmprintercompressmode">BRLMPrinterCompressMode</a>; /** * A priority that is print speed or print quality. Whether or not this has an effect is depend on your printer. */ printQuality?: <a href="#brlmprinterprintquality">BRLMPrinterPrintQuality</a>; }</code>
|
|
393
411
|
|
|
394
412
|
|
|
395
413
|
#### BRLMPrinterNumberOfCopies
|
|
@@ -412,9 +430,14 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
412
430
|
<code>number</code>
|
|
413
431
|
|
|
414
432
|
|
|
433
|
+
#### BRLMPrinterTDModelSettings
|
|
434
|
+
|
|
435
|
+
<code>{ /** * Should use enum <a href="#brkmprintercustompapertype">BRKMPrinterCustomPaperType</a> */ paperType: <a href="#brkmprintercustompapertype">BRKMPrinterCustomPaperType</a>; /** * The width of the label. For example, the RD-U04J1 is 60.0 wide. */ tapeWidth: number; /** * The length of the label. For example, the RD-U04J1 is 60.0 wide. */ tapeLength: number; /** * It is the difference between a sticker and a mount. * For example, the RD-U04J1 is `1.0, 2.0, 1.0, 2.0` */ marginTop: number; marginRight: number; marginBottom: number; marginLeft: number; /** * The spacing between seals. For example, the RD-U04J1 is 0.2. */ gapLength: number; paperMarkPosition: number; paperMarkLength: number; /** * Should use enum <a href="#brkmprintercustompaperunit">BRKMPrinterCustomPaperUnit</a>. * For example, the RD-U04J1 is mm. */ paperUnit: <a href="#brkmprintercustompaperunit">BRKMPrinterCustomPaperUnit</a>; }</code>
|
|
436
|
+
|
|
437
|
+
|
|
415
438
|
#### BRLMSearchOption
|
|
416
439
|
|
|
417
|
-
<code>{ port: 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; /** * searchDuration is the time to end search for devices. * default is 15 seconds. * use only port is 'wifi' or 'bluetoothLowEnergy'. */ searchDuration: number; }</code>
|
|
440
|
+
<code>{ /** * 'usb' is android only, and now developing. */ port: 'usb' | 'wifi' | 'bluetooth' | 'bluetoothLowEnergy'; /** * searchDuration is the time to end search for devices. * default is 15 seconds. * use only port is 'wifi' or 'bluetoothLowEnergy'. */ searchDuration: number; }</code>
|
|
418
441
|
|
|
419
442
|
|
|
420
443
|
#### ErrorInfo
|
|
@@ -425,6 +448,17 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
425
448
|
### Enums
|
|
426
449
|
|
|
427
450
|
|
|
451
|
+
#### BRLMPrinterModelName
|
|
452
|
+
|
|
453
|
+
| Members | Value |
|
|
454
|
+
| ------------------ | --------------------------- |
|
|
455
|
+
| **`QL_810W`** | <code>'QL_810W'</code> |
|
|
456
|
+
| **`QL_820NWB`** | <code>'QL_820NWB'</code> |
|
|
457
|
+
| **`TD_2320D_203`** | <code>'TD_2320D_203'</code> |
|
|
458
|
+
| **`TD_2030AD`** | <code>'TD_2030AD'</code> |
|
|
459
|
+
| **`TD_2350D_300`** | <code>'TD_2350D_300'</code> |
|
|
460
|
+
|
|
461
|
+
|
|
428
462
|
#### BRLMPrinterLabelName
|
|
429
463
|
|
|
430
464
|
| Members | Value |
|
|
@@ -455,17 +489,6 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
455
489
|
| **`W62H75`** | <code>'W62H75'</code> |
|
|
456
490
|
|
|
457
491
|
|
|
458
|
-
#### BRLMPrinterModelName
|
|
459
|
-
|
|
460
|
-
| Members | Value |
|
|
461
|
-
| ------------------ | --------------------------- |
|
|
462
|
-
| **`QL_810W`** | <code>'QL_810W'</code> |
|
|
463
|
-
| **`QL_820NWB`** | <code>'QL_820NWB'</code> |
|
|
464
|
-
| **`TD_2320D_203`** | <code>'TD_2320D_203'</code> |
|
|
465
|
-
| **`TD_2030AD`** | <code>'TD_2030AD'</code> |
|
|
466
|
-
| **`TD_2350D_203`** | <code>'TD_2350D_203'</code> |
|
|
467
|
-
|
|
468
|
-
|
|
469
492
|
#### BRLMPrinterScaleMode
|
|
470
493
|
|
|
471
494
|
| Members | Value |
|
|
@@ -530,6 +553,23 @@ These are optional. If these are not set, default values are assigned by the pri
|
|
|
530
553
|
| **`Fast`** | <code>'Fast'</code> |
|
|
531
554
|
|
|
532
555
|
|
|
556
|
+
#### BRKMPrinterCustomPaperType
|
|
557
|
+
|
|
558
|
+
| Members | Value |
|
|
559
|
+
| ------------------- | ---------------------------- |
|
|
560
|
+
| **`rollPaper`** | <code>'rollPaper'</code> |
|
|
561
|
+
| **`dieCutPaper`** | <code>'dieCutPaper'</code> |
|
|
562
|
+
| **`markRollPaper`** | <code>'markRollPaper'</code> |
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
#### BRKMPrinterCustomPaperUnit
|
|
566
|
+
|
|
567
|
+
| Members | Value |
|
|
568
|
+
| ---------- | ------------------- |
|
|
569
|
+
| **`mm`** | <code>'mm'</code> |
|
|
570
|
+
| **`inch`** | <code>'inch'</code> |
|
|
571
|
+
|
|
572
|
+
|
|
533
573
|
#### BrotherPrintEventsEnum
|
|
534
574
|
|
|
535
575
|
| Members | Value |
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
6
|
-
|
|
7
|
-
<!-- For Wi-Fi -->
|
|
8
|
-
<uses-permission android:name="android.permission.INTERNET" />
|
|
9
|
-
|
|
10
|
-
<!-- For Bluetooth -->
|
|
11
|
-
<uses-permission android:name="android.permission.BLUETOOTH" />
|
|
12
|
-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
|
13
|
-
|
|
14
|
-
<!-- For Bluetooth Low Energy -->
|
|
15
|
-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
16
|
-
</manifest>
|
|
17
|
-
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
</manifest>
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
package jp.rdlabo.capacitor.plugin.brotherprint
|
|
2
2
|
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.bluetooth.BluetoothAdapter
|
|
3
5
|
import android.bluetooth.BluetoothManager
|
|
4
6
|
import android.content.Context
|
|
5
7
|
import android.graphics.BitmapFactory
|
|
8
|
+
import android.hardware.usb.UsbManager
|
|
6
9
|
import android.util.Base64
|
|
7
10
|
import android.util.Log
|
|
8
|
-
import com.brother.ptouch.sdk.LabelInfo
|
|
9
|
-
import com.brother.ptouch.sdk.Printer
|
|
10
|
-
import com.brother.ptouch.sdk.PrinterInfo
|
|
11
11
|
import com.brother.sdk.lmprinter.BLESearchOption
|
|
12
12
|
import com.brother.sdk.lmprinter.Channel
|
|
13
13
|
import com.brother.sdk.lmprinter.NetworkSearchOption
|
|
14
|
+
import com.brother.sdk.lmprinter.OpenChannelError
|
|
15
|
+
import com.brother.sdk.lmprinter.PrintError
|
|
16
|
+
import com.brother.sdk.lmprinter.PrinterDriverGenerator
|
|
17
|
+
import com.brother.sdk.lmprinter.PrinterModel
|
|
14
18
|
import com.brother.sdk.lmprinter.PrinterSearcher
|
|
15
19
|
import com.brother.sdk.lmprinter.PrinterSearcher.cancelNetworkSearch
|
|
20
|
+
import com.brother.sdk.lmprinter.setting.PrintSettings
|
|
21
|
+
import com.brother.sdk.lmprinter.setting.QLPrintSettings
|
|
22
|
+
import com.brother.sdk.lmprinter.setting.TDPrintSettings
|
|
16
23
|
import com.getcapacitor.JSObject
|
|
17
|
-
import com.getcapacitor.Plugin
|
|
18
|
-
import android.Manifest;
|
|
19
24
|
import com.getcapacitor.PermissionState
|
|
25
|
+
import com.getcapacitor.Plugin
|
|
20
26
|
import com.getcapacitor.PluginCall
|
|
21
27
|
import com.getcapacitor.PluginMethod
|
|
22
28
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
@@ -25,6 +31,7 @@ import com.getcapacitor.annotation.PermissionCallback
|
|
|
25
31
|
import jp.rdlabo.capacitor.plugin.brotherprint.models.BrotherPrintEvent
|
|
26
32
|
import jp.rdlabo.capacitor.plugin.brotherprint.models.BrotherPrintSettings
|
|
27
33
|
|
|
34
|
+
|
|
28
35
|
@CapacitorPlugin(
|
|
29
36
|
name = "BrotherPrint",
|
|
30
37
|
permissions = [
|
|
@@ -64,96 +71,86 @@ class BrotherPrint : Plugin() {
|
|
|
64
71
|
val decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
|
|
65
72
|
|
|
66
73
|
val port: String? = call.getString("port", "wifi")
|
|
67
|
-
val
|
|
68
|
-
val
|
|
69
|
-
val serialNumber: String? = call.getString("serialNumber", "")
|
|
70
|
-
val macAddress: String? = call.getString("macAddress", "")
|
|
74
|
+
val channelInfo: String? = call.getString("channelInfo", "")
|
|
75
|
+
// val localName: String? = call.getString("localName", "")
|
|
76
|
+
// val serialNumber: String? = call.getString("serialNumber", "")
|
|
77
|
+
// val macAddress: String? = call.getString("macAddress", "")
|
|
71
78
|
|
|
72
|
-
|
|
73
|
-
val
|
|
79
|
+
lateinit var settings: PrintSettings;
|
|
80
|
+
val modelName = call.getString("modelName", "QL_820NWB")!!
|
|
81
|
+
val printerModel = PrinterModel.entries.find { it.name == modelName }
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
settings
|
|
82
|
-
|
|
83
|
-
settings.port = PrinterInfo.Port.NET
|
|
84
|
-
} else if (port == "bluetooth") {
|
|
85
|
-
val manager =
|
|
86
|
-
bridge.context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
|
87
|
-
printer.setBluetooth(manager.adapter)
|
|
88
|
-
settings.port = PrinterInfo.Port.BLUETOOTH
|
|
89
|
-
settings.macAddress = serialNumber
|
|
83
|
+
if (printerModel != null && modelName.startsWith("QL")) {
|
|
84
|
+
settings = QLPrintSettings(printerModel);
|
|
85
|
+
settings = BrotherPrintSettings().modelQLSettings(call, settings)
|
|
86
|
+
settings.workPath = bridge.context.cacheDir.path;
|
|
87
|
+
} else if (printerModel != null && modelName.startsWith("TD")) {
|
|
88
|
+
settings = TDPrintSettings(printerModel)
|
|
89
|
+
settings = BrotherPrintSettings().modelTDSettings(call, settings)
|
|
90
|
+
settings.workPath = bridge.context.cacheDir.path;
|
|
90
91
|
} else {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
printer.setBluetooth(manager.adapter)
|
|
94
|
-
settings.port = PrinterInfo.Port.BLE
|
|
92
|
+
call.reject("Error - modelName:$modelName is not supported")
|
|
93
|
+
return;
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
Thread {
|
|
97
|
+
val channel: Channel = when (port) {
|
|
98
|
+
"usb" -> Channel.newUsbChannel(bridge.context.getSystemService(Context.USB_SERVICE) as UsbManager)
|
|
99
|
+
"wifi" -> Channel.newWifiChannel(channelInfo)
|
|
100
|
+
"bluetooth" -> Channel.newBluetoothChannel(channelInfo, getBluetoothAdapter(bridge.context))
|
|
101
|
+
"bluetoothLowEnergy" -> Channel.newBluetoothLowEnergyChannel(
|
|
102
|
+
channelInfo, bridge.context, getBluetoothAdapter(bridge.context)
|
|
103
|
+
)
|
|
104
|
+
else -> {
|
|
105
|
+
call.reject("Error - port:$port is not supported")
|
|
106
|
+
return@Thread
|
|
107
|
+
}
|
|
108
|
+
}
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
val result = PrinterDriverGenerator.openChannel(channel)
|
|
111
|
+
if (result.error.code != OpenChannelError.ErrorCode.NoError) {
|
|
112
|
+
this.notifyListeners(BrotherPrintEvent.onPrintFailedCommunication.webEventName,
|
|
113
|
+
JSObject().put("code", result.error.code)
|
|
114
|
+
.put("message", result.error.code.toString())
|
|
115
|
+
)
|
|
116
|
+
call.reject("Error - openChannel: " + result.error.code.toString())
|
|
117
|
+
return@Thread
|
|
118
|
+
}
|
|
105
119
|
|
|
106
|
-
|
|
107
|
-
val setResult = Printer.getResult()
|
|
108
|
-
notifyListeners(
|
|
109
|
-
BrotherPrintEvent.onPrintError.webEventName,
|
|
110
|
-
JSObject().put("code", setResult.errorCode)
|
|
111
|
-
.put("message", setResult.toString())
|
|
112
|
-
)
|
|
113
|
-
}
|
|
120
|
+
val printerDriver = result.driver
|
|
114
121
|
|
|
115
|
-
|
|
116
|
-
Log.d(logTag, "Start Printer Thread")
|
|
117
|
-
Thread {
|
|
118
|
-
if (printer.startCommunication()) {
|
|
119
|
-
val result = printer.printImage(decodedByte)
|
|
120
|
-
if (result.errorCode == PrinterInfo.ErrorCode.ERROR_NONE) {
|
|
121
|
-
notifyListeners(
|
|
122
|
-
BrotherPrintEvent.onPrint.webEventName,
|
|
123
|
-
JSObject().put("code", result.errorCode)
|
|
124
|
-
.put("message", result.toString())
|
|
125
|
-
)
|
|
126
|
-
} else {
|
|
127
|
-
Log.d("TAG", "ERROR - " + result.errorCode)
|
|
128
|
-
notifyListeners(
|
|
129
|
-
BrotherPrintEvent.onPrintError.webEventName,
|
|
130
|
-
JSObject().put("code", result.errorCode)
|
|
131
|
-
.put("message", result.toString())
|
|
132
|
-
)
|
|
133
|
-
}
|
|
122
|
+
val printError: PrintError = printerDriver.printImage(decodedByte, settings)
|
|
134
123
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
124
|
+
if (printError.code != PrintError.ErrorCode.NoError) {
|
|
125
|
+
printerDriver.closeChannel()
|
|
126
|
+
notifyListeners(
|
|
127
|
+
BrotherPrintEvent.onPrintError.webEventName,
|
|
128
|
+
JSObject().put("code", printError.code)
|
|
129
|
+
.put("message", result.error.code.toString())
|
|
130
|
+
)
|
|
131
|
+
call.reject("Error - Print Image: " + result.error.code.toString())
|
|
132
|
+
return@Thread
|
|
142
133
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
|
|
135
|
+
printerDriver.closeChannel()
|
|
136
|
+
|
|
146
137
|
notifyListeners(
|
|
147
|
-
BrotherPrintEvent.
|
|
148
|
-
|
|
138
|
+
BrotherPrintEvent.onPrint.webEventName,
|
|
139
|
+
JSObject()
|
|
149
140
|
)
|
|
150
|
-
call.
|
|
151
|
-
}
|
|
141
|
+
call.resolve()
|
|
142
|
+
}.start()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private fun getBluetoothAdapter(context: Context): BluetoothAdapter? {
|
|
146
|
+
val manager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
|
147
|
+
return manager.adapter
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
@PluginMethod
|
|
155
151
|
fun search(call: PluginCall) {
|
|
156
152
|
when(call.getString("port", "wifi")) {
|
|
153
|
+
"usb" -> this.searchUsbPrinter(call)
|
|
157
154
|
"wifi" -> this.searchWiFiPrinter(call)
|
|
158
155
|
"bluetooth" -> this.checkBLEChannel(call)
|
|
159
156
|
"bluetoothLowEnergy" -> this.searchBLEPrinter(call)
|
|
@@ -161,6 +158,36 @@ class BrotherPrint : Plugin() {
|
|
|
161
158
|
}
|
|
162
159
|
}
|
|
163
160
|
|
|
161
|
+
private fun searchUsbPrinter(call: PluginCall) {
|
|
162
|
+
Log.d("brother", "searchUsbPrinter")
|
|
163
|
+
Thread {
|
|
164
|
+
val result = PrinterSearcher.startUSBSearch(bridge.context)
|
|
165
|
+
|
|
166
|
+
when (result.error.code) {
|
|
167
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.NoError -> {
|
|
168
|
+
}
|
|
169
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.NotPermitted -> {
|
|
170
|
+
// TODO: has error
|
|
171
|
+
}
|
|
172
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.Canceled,
|
|
173
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.InterfaceInactive,
|
|
174
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.InterfaceUnsupported,
|
|
175
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.AlreadySearching,
|
|
176
|
+
com.brother.sdk.lmprinter.PrinterSearchError.ErrorCode.UnknownError -> {
|
|
177
|
+
}
|
|
178
|
+
null -> {}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (channel in result.channels){
|
|
182
|
+
this.notifyListeners(
|
|
183
|
+
BrotherPrintEvent.onPrinterAvailable.webEventName,
|
|
184
|
+
this.chanelToPrinter("usb", channel)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}.start()
|
|
188
|
+
call.resolve();
|
|
189
|
+
}
|
|
190
|
+
|
|
164
191
|
private fun searchWiFiPrinter(call: PluginCall) {
|
|
165
192
|
Log.d("brother", "searchWiFiPrinter")
|
|
166
193
|
Thread {
|
|
@@ -185,7 +212,7 @@ class BrotherPrint : Plugin() {
|
|
|
185
212
|
|
|
186
213
|
private fun checkBLEChannel(call: PluginCall) {
|
|
187
214
|
if (!isBluetoothPermissionGranted()) {
|
|
188
|
-
|
|
215
|
+
requestPermissionForAlias("bluetooth", call, "permissionCallback");
|
|
189
216
|
} else {
|
|
190
217
|
Log.d("brother", "checkBLEChannel")
|
|
191
218
|
Thread {
|
|
@@ -200,7 +227,10 @@ class BrotherPrint : Plugin() {
|
|
|
200
227
|
|
|
201
228
|
private fun searchBLEPrinter(call: PluginCall) {
|
|
202
229
|
if (!isBluetoothPermissionGranted()) {
|
|
203
|
-
|
|
230
|
+
requestPermissionForAlias("bluetooth", call, "permissionCallback");
|
|
231
|
+
return;
|
|
232
|
+
} else if (!isLocationPermissionGranted()) {
|
|
233
|
+
requestPermissionForAlias("location", call, "permissionCallback");
|
|
204
234
|
return;
|
|
205
235
|
} else {
|
|
206
236
|
Log.d("brother", "searchBLEPrinter")
|
|
@@ -226,12 +256,13 @@ class BrotherPrint : Plugin() {
|
|
|
226
256
|
}
|
|
227
257
|
|
|
228
258
|
private fun chanelToPrinter(port: String, channel: Channel): JSObject? {
|
|
259
|
+
Log.d("brother", channel.toString());
|
|
229
260
|
val modelName = channel.extraInfo[Channel.ExtraInfoKey.ModelName] ?: ""
|
|
230
261
|
val serialNumber = channel.extraInfo[Channel.ExtraInfoKey.SerialNubmer] ?: ""
|
|
231
262
|
val macAddress = channel.extraInfo[Channel.ExtraInfoKey.MACAddress] ?: ""
|
|
232
263
|
val nodeName = channel.extraInfo[Channel.ExtraInfoKey.NodeName] ?: ""
|
|
233
264
|
val location = channel.extraInfo[Channel.ExtraInfoKey.Location] ?: ""
|
|
234
|
-
val
|
|
265
|
+
val channelInfo = channel.channelInfo
|
|
235
266
|
|
|
236
267
|
return JSObject()
|
|
237
268
|
.put("port", port)
|
|
@@ -240,22 +271,24 @@ class BrotherPrint : Plugin() {
|
|
|
240
271
|
.put("macAddress", macAddress)
|
|
241
272
|
.put("nodeName", nodeName)
|
|
242
273
|
.put("location", location)
|
|
243
|
-
.put("
|
|
274
|
+
.put("channelInfo", channelInfo)
|
|
244
275
|
}
|
|
245
276
|
|
|
246
277
|
@PluginMethod
|
|
247
|
-
fun cancelSearchWiFiPrinter(call: PluginCall
|
|
278
|
+
fun cancelSearchWiFiPrinter(call: PluginCall) {
|
|
248
279
|
Thread {
|
|
249
280
|
this.cancelRoutineWiFi?.invoke()
|
|
250
281
|
this.cancelRoutineWiFi = null
|
|
282
|
+
call.resolve()
|
|
251
283
|
}.start()
|
|
252
284
|
}
|
|
253
285
|
|
|
254
286
|
@PluginMethod
|
|
255
|
-
fun cancelSearchBluetoothPrinter(call: PluginCall
|
|
287
|
+
fun cancelSearchBluetoothPrinter(call: PluginCall) {
|
|
256
288
|
Thread {
|
|
257
289
|
this.cancelRoutineBluetooth?.invoke()
|
|
258
290
|
this.cancelRoutineBluetooth = null
|
|
291
|
+
call.resolve()
|
|
259
292
|
}.start()
|
|
260
293
|
}
|
|
261
294
|
|
|
@@ -272,8 +305,7 @@ class BrotherPrint : Plugin() {
|
|
|
272
305
|
return
|
|
273
306
|
}
|
|
274
307
|
when (call.methodName) {
|
|
275
|
-
"
|
|
276
|
-
"searchBLEPrinter" -> searchBLEPrinter(call)
|
|
308
|
+
"search" -> this.search(call)
|
|
277
309
|
}
|
|
278
310
|
}
|
|
279
311
|
|