UNPKG

react-native-brother-print

Version:

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

62 lines (51 loc) 1.62 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) { 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'); } return new Promise((resolve, reject) => { ReactNativeBrotherPrint.printImageViaWifi(uri, ipAddress, modelName) .then(result => { resolve(result); }) .catch(error => { console.error('[BrotherPrint] printImageViaWifi error:', error); reject(error); }); }); } export function printImageViaBluetooth(uri, modelName) { 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'); } return new Promise((resolve, reject) => { ReactNativeBrotherPrint.printImageViaBluetooth(uri, modelName) .then(result => { resolve(result); }) .catch(error => { console.error('[BrotherPrint] printImageViaBluetooth error:', error); reject(error); }); }); }