other means
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios from "axios";
|
||||
import {blue100} from "react-native-paper/lib/typescript/styles/themes/v2/colors";
|
||||
|
||||
class PrintingService {
|
||||
private static instance: PrintingService | null = null;
|
||||
@@ -17,9 +18,24 @@ class PrintingService {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
private newAbortSignal(timeoutMs: number) {
|
||||
const abortController = new AbortController();
|
||||
setTimeout(() => abortController.abort(), timeoutMs || 0);
|
||||
|
||||
return abortController.signal;
|
||||
}
|
||||
|
||||
private async print(printer: string, type: string, bytes: Uint8Array): Promise<boolean> {
|
||||
let response = await axios.post(`http://${this.apiUrl}:${this.port}/print/${printer}/${type}`, bytes.buffer);
|
||||
return response.data.ok;
|
||||
try {
|
||||
let response = await axios.post(`http://${this.apiUrl}:${this.port}/print/${printer}/${type}`, bytes.buffer, {
|
||||
timeout: 20 * 1000,
|
||||
signal: this.newAbortSignal(20 * 1000)
|
||||
});
|
||||
return response.data.ok;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async printPdf(printer: string, pdfBytes: Uint8Array): Promise<boolean> {
|
||||
@@ -29,6 +45,11 @@ class PrintingService {
|
||||
public async printImage(printer: string, imageBytes: Uint8Array): Promise<boolean> {
|
||||
return this.print(printer, "image", imageBytes);
|
||||
}
|
||||
|
||||
public getPrinter(baseMarketplace: number): string {
|
||||
if (baseMarketplace == 0) return "wildberries";
|
||||
return "ozon";
|
||||
}
|
||||
}
|
||||
|
||||
export default PrintingService;
|
||||
Reference in New Issue
Block a user