@yesprasoon/capacitor-bluetooth-communication
Version:
A Capacitor plugin for client-to-server communication over Bluetooth Classic on Android.
61 lines (60 loc) • 1.84 kB
TypeScript
import { PluginListenerHandle } from '@capacitor/core';
export interface BluetoothDevice {
name: string | null;
address: string;
}
/**
* Interface for the BluetoothCommunicationPlugin, providing methods for bluetooth communications.
*/
export interface BluetoothCommunicationPlugin {
/**
* Initializes the Bluetooth adapter.
* Resolves if Bluetooth is supported, rejects otherwise.
*/
initialize(): Promise<void>;
/**
* Enables Bluetooth on the device.
* If Bluetooth is already enabled, resolves without any action.
*/
enableBluetooth(): Promise<void>;
/**
* Scans for paired Bluetooth devices.
* @returns A list of paired devices.
*/
scanDevices(): Promise<{
devices: BluetoothDevice[];
}>;
/**
* Starts the Bluetooth server and listens for incoming connections.
*/
startServer(): Promise<void>;
/**
* Stops the Bluetooth server and disconnects any active connections.
*/
stopServer(): Promise<void>;
/**
* Connects to a Bluetooth device using its MAC address.
* @param options The connection options, including the device address.
*/
connect(options: {
address: string;
}): Promise<void>;
/**
* Disconnects the current Bluetooth connection.
*/
disconnect(): Promise<void>;
/**
* Sends data to the connected Bluetooth device.
* @param options The data to be sent as a string.
*/
sendData(options: {
data: string;
}): Promise<void>;
/**
* Listens for incoming data from the connected Bluetooth device.
* The plugin emits a `dataReceived` event when new data is received.
*/
addListener(eventName: 'dataReceived', listenerFunc: (data: {
data: string;
}) => void): PluginListenerHandle;
}