UNPKG

react-native-brother-print

Version:

React Native module for printing with Brother printers via WiFi and Bluetooth

68 lines (55 loc) 1.92 kB
// main index.js import { NativeModules } from 'react-native'; const { ReactNativeBrotherPrint } = NativeModules; if (!ReactNativeBrotherPrint) { console.error('[BrotherPrint] Native module not found!'); throw new Error('ReactNativeBrotherPrint module is not available'); } export function printImageViaWifi(uri, ipAddress, modelName, options = {}) { if (!uri) { console.error('[BrotherPrint] uri missing'); throw new Error('image uri missing'); } if (!ipAddress) { console.error('[BrotherPrint] ipAddress missing'); throw new Error('ip address missing'); } if (!modelName) { console.error('[BrotherPrint] modelName missing'); throw new Error('model name missing'); } // Extract halftone and thresholdingValue from options const { halftone, thresholdingValue } = options; return new Promise((resolve, reject) => { ReactNativeBrotherPrint.printImageViaWifi(uri, ipAddress, modelName, halftone, thresholdingValue) .then(result => { resolve(result); }) .catch(error => { console.error('[BrotherPrint] printImageViaWifi error:', error); reject(error); }); }); } export function printImageViaBluetooth(uri, modelName, options = {}) { if (!uri) { console.error('[BrotherPrint] uri missing'); throw new Error('image uri missing'); } if (!modelName) { console.error('[BrotherPrint] modelName missing'); throw new Error('modelName missing'); } // Extract halftone and thresholdingValue from options const { halftone, thresholdingValue } = options; return new Promise((resolve, reject) => { ReactNativeBrotherPrint.printImageViaBluetooth(uri, modelName, halftone, thresholdingValue) .then(result => { resolve(result); }) .catch(error => { console.error('[BrotherPrint] printImageViaBluetooth error:', error); reject(error); }); }); }