To use the ButtplugClient, instantiate it with an optional clientName and then call connect() passing an implementation of IButtplugClientConnector. The client is an EventEmitter and will emit events like deviceadded, deviceremoved, and disconnect as the connection state changes.
Key properties:
connected: Returns true if the client is currently connected to a server.devices: Returns a ReadonlyMap<number, ButtplugClientDevice> containing all currently discovered devices.serverInfo: Returns ButtplugClientServerInfo containing the server's name, max ping time, and protocol version.
import { ButtplugClient } from './path/to/buttplug-js';
// Note: You must provide a valid IButtplugClientConnector implementation
const client = new ButtplugClient('My App Client');
client.on('deviceadded', (device) => {
console.log('New device found:', device);
});
await client.connect(myConnector);
console.log('Connected to:', client.serverInfo?.serverName);