TapSDK Web
A TypeScript/JavaScript SDK for Tap devices in the browser, using Web Bluetooth. It works with Tap Strap and TapXR. TapBand uses the same BLE API and is coming soon (waitlist). It is not for sale yet.
TapXR developer firmware supports the full gesture set: taps, thumb swipes up / down / left / right, thumb-to-finger pinches with hold, and fist with hold. This SDK delivers those raw detections (the same codes as the Python, iOS, and Android SDKs). iOS and Android also add a processed click / drag / drop layer. This Web SDK does not.
Browser Support
Call connect() from a user click. The browser blocks the Bluetooth device picker without a user gesture.
This SDK uses the Web Bluetooth API. Use Chrome or Edge. The page must use HTTPS or localhost.
Safari and Firefox do not support Web Bluetooth.
Installation
npm install @tapwithus/tapsdk
The GitHub Pages demo is unchanged. It loads the built bundle from this repository. It does not install the npm package.
Local development
Clone the repository and build the SDK:
git clone https://github.com/TapWithUs/tap-web-sdk.git
cd tap-web-sdk
npm install
npm run build
To link a local build into another project:
# In the tap-web-sdk directory
npm link
# In your project directory
npm link @tapwithus/tapsdk
Quick Start
connect() detects firmware and returns TapSDKWeb (classic) or TapSDKWeb2 (framed). Handle both. Check with isTapSDKWeb2(sdk).
import {
connect,
isTapSDKWeb2,
InputModeController,
DeviceFeatures,
ModelTypes,
VisionSensorOpModes,
UnifiedAirGestures,
} from '@tapwithus/tapsdk';
document.querySelector('#connect')!.addEventListener('click', async () => {
const sdk = await connect();
sdk.registerDisconnectionEvents((id) => console.log('Disconnected', id));
if (isTapSDKWeb2(sdk)) {
sdk.registerTapEvents((_id, tapcode) => console.log('Tap', tapcode[0]));
sdk.registerAirGestureEvents((_id, data) => {
const code = data[0];
if (code === UnifiedAirGestures.COMBINED_GESTURE_UP) {
console.log('swipe up');
}
});
await sdk.setFeature(DeviceFeatures.MODEL_DETECTION, true);
await sdk.setVisionSensorModel(ModelTypes.TAPPING);
await sdk.setVisionSensorOpMode(VisionSensorOpModes.TRIGGER);
} else {
sdk.registerTapEvents((_id, tapcode) => console.log('Tap', tapcode));
sdk.registerMouseEvents((_id, vx, vy, proximity) => {
console.log(`Mouse: vx=${vx}, vy=${vy}, proximity=${proximity}`);
});
await sdk.setInputMode(new InputModeController());
}
await sdk.sendVibrationSequence([100, 200, 100]);
});
connect() starts notifications. There is no start(). Register callbacks, then enable input. Keep the page open.
Reconnecting a Tap
After you disconnect, the Tap can stay connected to your computer, so it stops advertising and does not appear in the connect() picker. connect() therefore tries the Tap you last connected in this page session first, and opens the picker only when there is none or it does not answer within 3 s (reuseTimeout).
- Same page: works, no flag. Connect, Disconnect, Connect again reconnects without the picker.
- After a page reload: not supported for a Tap that is still connected to the computer. Chrome can list it through
getDevices() (needs a flag: Chrome chrome://flags/#enable-experimental-web-platform-features, Edge edge://flags/#enable-experimental-web-platform-features), but connecting usually fails with "Bluetooth Device is no longer in range" because the Tap is not advertising. connect() does not try these devices automatically. Disconnect the Tap in system Bluetooth settings (or reset it) so it advertises, then pick it in the picker.
import { connect, connectToDevice, getPermittedDevices } from '@tapwithus/tapsdk';
await connect(); // last Tap of this session, else the picker
await connect({ reuseKnownDevice: false }); // always the picker (add another Tap)
await connect({ device }); // a specific BluetoothDevice, no picker
const devices = await getPermittedDevices(); // session Taps first, then getDevices()
await connectToDevice(devices[0]); // same as connect({ device })