Events
Listen for discovered printers and print results. Register listeners before Search and Print so the first events are not missed.
import type { PluginListenerHandle } from '@capacitor/core';
import { BrotherPrint, BrotherPrintEventsEnum } from '@rdlabo/capacitor-brotherprint';
const handles: PluginListenerHandle[] = [];
const registerPrintListeners = async () => {
handles.push(
await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrinterAvailable, (printer) => {
console.log('printer', printer.channelInfo);
}),
);
handles.push(
await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrint, () => {
console.log('onPrint');
}),
);
handles.push(
await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrintFailedCommunication, (info) => {
console.log('onPrintFailedCommunication', info);
}),
);
handles.push(
await BrotherPrint.addListener(BrotherPrintEventsEnum.onPrintError, (info) => {
console.log('onPrintError', info);
}),
);
};
const removePrintListeners = async () => {
await Promise.all(handles.map((handle) => handle.remove()));
};
| Event | When it fires |
|---|---|
onPrinterAvailable |
A printer that can connect was found |
onPrint |
Print succeeded |
onPrintFailedCommunication |
The printer could not be reached |
onPrintError |
Print failed |
See the demo for a complete page:
https://github.com/rdlabo-dev/capacitor-brotherprint/blob/v8.1.1/demo/src/app/home/home.page.ts
method addListener(BrotherPrintEventsEnum.onPrinterAvailable, ...)
Find the printer that can connected to the device.
addListener(eventName: BrotherPrintEventsEnum.onPrinterAvailable, listenerFunc: (printers: BRLMChannelResult) => void) => Promise<PluginListenerHandle>
method addListener(BrotherPrintEventsEnum.onPrint, ...)
Success Print Event
addListener(eventName: BrotherPrintEventsEnum.onPrint, listenerFunc: () => void) => Promise<PluginListenerHandle>
method addListener(BrotherPrintEventsEnum.onPrintFailedCommunication, ...)
Failed to connect to the printer.
ex: Bluetooth is off, Printer is off, etc.
addListener(eventName: BrotherPrintEventsEnum.onPrintFailedCommunication, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>
method addListener(BrotherPrintEventsEnum.onPrintError, ...)
Failed to print.
addListener(eventName: BrotherPrintEventsEnum.onPrintError, listenerFunc: (info: ErrorInfo) => void) => Promise<PluginListenerHandle>
enum BrotherPrintEventsEnum
| Member | Value |
|---|---|
onPrinterAvailable |
'onPrinterAvailable' |
onPrint |
'onPrint' |
onPrintFailedCommunication |
'onPrintFailedCommunication' |
onPrintError |
'onPrintError' |
interface PluginListenerHandle
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
type alias ErrorInfo
{ message: string; code: number; }