react-native-bluetooth-escpos-printer-fork 0.0.16 → 0.0.17

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.
@@ -23,7 +23,6 @@ apply plugin: 'com.android.library'
23
23
  android {
24
24
  compileSdkVersion 33
25
25
  buildToolsVersion = "33.0.0"
26
- namespace "cn.jystudio.bluetooth"
27
26
 
28
27
  defaultConfig {
29
28
  minSdkVersion 16
@@ -1,8 +1,10 @@
1
1
 
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ package="cn.jystudio.bluetooth">
3
4
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
4
5
  <uses-permission android:name="android.permission.BLUETOOTH" />
5
6
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
6
7
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
7
8
 
8
9
  </manifest>
10
+
@@ -449,7 +449,6 @@ public class RNBluetoothEscposPrinterModule extends ReactContextBaseJavaModule
449
449
  }
450
450
  }
451
451
 
452
-
453
452
  @ReactMethod
454
453
  public void cutOnePoint() {
455
454
  try{
@@ -459,7 +458,17 @@ public class RNBluetoothEscposPrinterModule extends ReactContextBaseJavaModule
459
458
  }catch (Exception e){
460
459
  Log.d(TAG, e.getMessage());
461
460
  }
462
- }
461
+ }
462
+
463
+ @ReactMethod
464
+ public void printEscPosCommands(String base64encodeStr, final Promise promise) {
465
+ byte[] bytes = Base64.decode(base64encodeStr, Base64.DEFAULT);
466
+ if (sendDataByte(bytes)) {
467
+ promise.resolve(null);
468
+ } else {
469
+ promise.reject("FAILED_TO_PRINT_ESC_POS_COMMANDS");
470
+ }
471
+ }
463
472
 
464
473
  private boolean sendDataByte(byte[] data) {
465
474
  if (data==null || mService.getState() != BluetoothService.STATE_CONNECTED) {
@@ -97,7 +97,7 @@ RCT_EXPORT_METHOD(printerInit:(RCTPromiseResolveBlock)resolve
97
97
  }else{
98
98
  reject(@"COMMAND_NOT_SEND",@"COMMAND_NOT_SEND",nil);
99
99
  }
100
-
100
+
101
101
  }
102
102
 
103
103
  //{GS, 'L', 0x00 , 0x00 }
@@ -111,7 +111,7 @@ RCT_EXPORT_METHOD(printerLeftSpace:(int) sp
111
111
  reject(@"COMMAND_NOT_SEND",@"INVALID_VALUE",nil);
112
112
  return;
113
113
  }
114
-
114
+
115
115
  if(RNBluetoothManager.isConnected){
116
116
  NSMutableData *data = [[NSMutableData alloc] init];
117
117
  Byte left[] = {'L'};
@@ -154,7 +154,7 @@ RCT_EXPORT_METHOD(printerUnderLine:(int)sp withResolver:(RCTPromiseResolveBlock)
154
154
  }else{
155
155
  reject(@"COMMAND_NOT_SEND",@"COMMAND_NOT_SEND",nil);
156
156
  }
157
-
157
+
158
158
  }
159
159
 
160
160
  RCT_EXPORT_METHOD(printText:(NSString *) text withOptions:(NSDictionary *) options
@@ -195,7 +195,7 @@ RCT_EXPORT_METHOD(printText:(NSString *) text withOptions:(NSDictionary *) optio
195
195
  if([@"UTF-8" isEqualToString:encoding] || [@"utf-8" isEqualToString:encoding] ){
196
196
  nsEncoding = NSUTF8StringEncoding;
197
197
  }
198
-
198
+
199
199
  return nsEncoding;
200
200
  }
201
201
  -(void) textPrint:(NSString *) text
@@ -211,9 +211,9 @@ RCT_EXPORT_METHOD(printText:(NSString *) text withOptions:(NSDictionary *) optio
211
211
  Byte *multTime[] = {intToWidth[widthTimes],intToHeight[heightTimes]};
212
212
  NSData *bytes = [text dataUsingEncoding:[self toNSEncoding:encoding]];
213
213
  NSLog(@"Got bytes length:%lu",[bytes length]);
214
-
214
+
215
215
  NSMutableData *toSend = [[NSMutableData alloc] init];
216
-
216
+
217
217
  //gsExclamationMark:{GS, '!', 0x00 };
218
218
  [toSend appendBytes:ESC_GS length:sizeof(ESC_GS)];
219
219
  [toSend appendBytes:SIGN length:sizeof(SIGN)];
@@ -240,7 +240,7 @@ RCT_EXPORT_METHOD(printText:(NSString *) text withOptions:(NSDictionary *) optio
240
240
  [toSend appendData:bytes];
241
241
  //LF
242
242
  // [toSend appendBytes:&NL length:sizeof(NL)];
243
-
243
+
244
244
  NSLog(@"Goting to write text : %@",text);
245
245
  NSLog(@"With data: %@",toSend);
246
246
  [RNBluetoothManager writeValue:toSend withDelegate:delegate];
@@ -326,7 +326,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
326
326
  *
327
327
  */
328
328
  NSMutableArray *table =[[NSMutableArray alloc] init];
329
-
329
+
330
330
  /**splits the column text to few rows and applies the alignment **/
331
331
  int padding = 1;
332
332
  for(int i=0;i< [columnWidths count];i++){
@@ -338,7 +338,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
338
338
  int shorter = 0;
339
339
  int counter = 0;
340
340
  NSMutableString *temp = [[NSMutableString alloc] init];
341
-
341
+
342
342
  for(int c=0;c<[text length];c++){
343
343
  unichar ch = [text characterAtIndex:c];
344
344
  int l = (ch>= 0x4e00 && ch <= 0x9fff)?2:1;
@@ -365,7 +365,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
365
365
  [splited addObject:css];
366
366
  }
367
367
  NSInteger align =[[columnAligns objectAtIndex:i] integerValue];
368
-
368
+
369
369
  NSMutableArray *formated = [[NSMutableArray alloc] init];
370
370
  for(ColumnSplitedString *s in splited){
371
371
  NSMutableString *empty = [[NSMutableString alloc] init];
@@ -395,7 +395,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
395
395
  }
396
396
  [table addObject:formated];
397
397
  }
398
-
398
+
399
399
  /** try to find the max row count of the table **/
400
400
  NSInteger maxRowCount = 0;
401
401
  for(int i=0;i<[table count]/*column count*/;i++){
@@ -404,7 +404,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
404
404
  maxRowCount = [rows count];// try to find the max row count;
405
405
  }
406
406
  }
407
-
407
+
408
408
  /** loop table again to fill the rows **/
409
409
  NSMutableArray<NSMutableString *> *rowsToPrint = [[NSMutableArray alloc] init];
410
410
  for(int column=0;column<[table count]/*column count*/;column++){
@@ -426,7 +426,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
426
426
  }
427
427
  }
428
428
  }
429
-
429
+
430
430
  /** loops the rows and print **/
431
431
  PrintColumnBleWriteDelegate *delegate = [[PrintColumnBleWriteDelegate alloc] init];
432
432
  delegate.now = 0;
@@ -446,7 +446,7 @@ RCT_EXPORT_METHOD(printColumn:(NSArray *)columnWidths
446
446
  NSLog(@"print text exception: %@",[e callStackSymbols]);
447
447
  reject(e.name.description,e.name.description,nil);
448
448
  }
449
-
449
+
450
450
  }
451
451
  }
452
452
 
@@ -495,7 +495,7 @@ RCT_EXPORT_METHOD(printPic:(NSString *) base64encodeStr withOptions:(NSDictionar
495
495
  scaled = [ImageUtils imagePadLeft:paddingLeft withSource:scaled];
496
496
  size =[scaled size];
497
497
  }
498
-
498
+
499
499
  unsigned char * graImage = [ImageUtils imageToGreyImage:scaled];
500
500
  unsigned char * formatedData = [ImageUtils format_K_threshold:graImage width:size.width height:size.height];
501
501
  NSData *dataToPrint = [ImageUtils eachLinePixToCmd:formatedData nWidth:size.width nHeight:size.height nMode:0];
@@ -528,7 +528,7 @@ RCT_EXPORT_METHOD(printQRCode:(NSString *)content
528
528
  hints.encoding=NSUTF8StringEncoding;
529
529
  hints.margin=0;
530
530
  hints.errorCorrectionLevel = [self findCorrectionLevel:correctionLevel];
531
-
531
+
532
532
  ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
533
533
  ZXBitMatrix *result = [writer encode:content
534
534
  format:kBarcodeFormatQRCode
@@ -553,6 +553,26 @@ RCT_EXPORT_METHOD(printQRCode:(NSString *)content
553
553
  }
554
554
  }
555
555
 
556
+ RCT_EXPORT_METHOD(printEscPosCommands:(NSString *)base64encodeStr
557
+ resolver:(RCTPromiseResolveBlock)resolve
558
+ rejecter:(RCTPromiseRejectBlock)reject)
559
+ {
560
+ if(RNBluetoothManager.isConnected){
561
+ @try{
562
+ NSData *decoded = [[NSData alloc] initWithBase64EncodedString:base64encodeStr options:0];
563
+ pendingResolve = resolve;
564
+ pendingReject = reject;
565
+ [RNBluetoothManager writeValue:decoded withDelegate:self];
566
+ }
567
+ @catch(NSException *e){
568
+ NSLog(@"ERROR IN PRINTING ESC/POS COMMANDS: %@",[e callStackSymbols]);
569
+ reject(@"FAILED_TO_PRINT_ESC_POS_COMMANDS",@"FAILED_TO_PRINT_ESC_POS_COMMANDS",nil);
570
+ }
571
+ }else{
572
+ reject(@"BLUETOOTH_NOT_CONNECTED",@"Bluetooth device is not connected",nil);
573
+ }
574
+ }
575
+
556
576
  RCT_EXPORT_METHOD(printBarCode:(NSString *) str withType:(NSInteger)
557
577
  nType width:(NSInteger) nWidth heigth:(NSInteger) nHeight
558
578
  hriFontType:(NSInteger) nHriFontType hriFontPosition:(NSInteger) nHriFontPosition
@@ -565,7 +585,7 @@ RCT_EXPORT_METHOD(printBarCode:(NSString *) str withType:(NSInteger)
565
585
  reject(@"INVALID_PARAMETER",@"INVALID_PARAMETER",nil);
566
586
  return;
567
587
  }
568
-
588
+
569
589
  NSData *conentData = [str dataUsingEncoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)];
570
590
  NSMutableData *toPrint = [[NSMutableData alloc] init];
571
591
  int8_t * command = malloc(16);
@@ -587,7 +607,7 @@ RCT_EXPORT_METHOD(printBarCode:(NSString *) str withType:(NSInteger)
587
607
  command[15] = [conentData length];
588
608
  [toPrint appendBytes:command length:16];
589
609
  [toPrint appendData:conentData];
590
-
610
+
591
611
  pendingReject = reject;
592
612
  pendingResolve = resolve;
593
613
  [RNBluetoothManager writeValue:toPrint withDelegate:self];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bluetooth-escpos-printer-fork",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "React-Native plugin for the bluetooth ESC/POS printers.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package-lock.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "name": "react-native-bluetooth-escpos-printer-fork",
3
- "version": "0.0.6",
4
- "lockfileVersion": 1,
5
- "requires": true,
6
- "dependencies": {
7
- "jetifier": {
8
- "version": "1.6.6",
9
- "resolved": "https://registry.npmjs.org/jetifier/-/jetifier-1.6.6.tgz",
10
- "integrity": "sha512-JNAkmPeB/GS2tCRqUzRPsTOHpGDah7xP18vGJfIjZC+W2sxEHbxgJxetIjIqhjQ3yYbYNEELkM/spKLtwoOSUQ=="
11
- },
12
- "jetify": {
13
- "version": "1.0.2",
14
- "resolved": "https://registry.npmjs.org/jetify/-/jetify-1.0.2.tgz",
15
- "integrity": "sha512-LmeaeeM5l37oZRs6O0O0jMafEw7ra1++YJN2tnbCPnfjulnXryMlQKRib/4e64fJ2rzOWomyDsSFjD+7ZSXyKg=="
16
- }
17
- }
18
- }