HeligPfleigh / react-native-thermal-receipt-printer

A RN library for thermal printer
163 stars 103 forks source link

Android: if there is no printer available on the defined host and port the application hangs #30

Closed harshmaur closed 3 years ago

harshmaur commented 3 years ago
useEffect(() => {
    NetPrinter.init().then(() => {
      NetPrinter.connectPrinter('192.168.1.105', 9100).then(
        (printer) => console.log(printer),
        (error) => console.warn(error)
      )
    })
  }, [])

If there is no printer on 192.168.1.105 the whole application hangs up.

CaioSilveira63 commented 3 years ago

i had to use React-native-ping to verify the adress before trying to connect.

`
import Ping from 'react-native-ping';

NetPrinter.init();

const ms = await Ping.start(IPADRESS, { timeout: 1000, }).then( async () => { await NetPrinter.connectPrinter( IPADRESS, PORT, ), await NetPrinter.printBill(TEXT); }, err => { console.log(err); }, `

harshmaur commented 3 years ago

Thanks! That should help!