Skip to main content

Class: PrintersDiscovery

Controls the device discovery function.

Methods​

start​

start(params): void

Starts searching for the specified device type. An event is generated for each device detected.

By default search will be stopped after 5 seconds. To change this behavior, use the timeout parameter.

Parameters​
NameTypeDescription
paramsDiscoveryStartParamsThe search params.
Returns​

void

Example​
PrintersDiscovery.start({
timeout: 2000,
filterOption: {
deviceModel: DiscoveryFilterOption.MODEL_ALL,
},
});

stop​

stop(): void

Stops search.

Returns​

void

Example​
PrintersDiscovery.stop();

onDiscovery​

onDiscovery(listener): remove()

Adds a listener for the discovery event.

Parameters​
NameTypeDescription
listener(printers: DeviceInfo[] ) => voidThe listener function.
Returns​

remove()

Function to remove listener.

Example​
PrintersDiscovery.onDiscovery((printers) => {
console.log(printers); // will be called when every new printer is discovered
});

onStatusChange​

onStatusChange(listener): remove()

Adds a listener for the statusChange event.

Parameters​
NameTypeDescription
listener(status: 'discovering''inactive' ) => void
Returns​

remove()

Function to remove listener.

Example​

PrintersDiscovery.onStatusChange((status) => {
console.log(status); // will be called when the discovery status changes
});

onError​

onError(listener): remove()

Adds a listener for the error event.

Parameters​
NameTypeDescription
listener(error: PrinterDiscoveryError ) => voidThe listener function.
Returns​

remove()

Function to remove listener.

Example​

PrintersDiscovery.onError((error) => {
console.log(error); // will be called when an error occurs
});

pairBluetoothDevice (iOS only)​

pairBluetoothDevice(macAddress?: string): Promise<void>

Controls pairing connection with a Bluetooth device. If macAddress is not provided, a list of available devices will be shown in native dialog.

Parameters​
NameTypeDescription
macAddressstringThe BD address of the printer newly paired is returned. Format: BT:00:11:22:33:44:55
Returns​

Promise<void>

Example​

PrintersDiscovery.pairBluetoothDevice().the;