tact-js
v2.0.4
Published
    ![npm d
Keywords
Readme
bHaptics Web SDK
Web-based haptic control library for bHaptics devices. A variety of haptic events can be played in your browser.
- Written in TypeScript
- Supports ESM
✨ Features
🎮 Play events
Play haptic event exported from bHaptics developer portal
🔵 Dot mode
Play single-frame feedback with intensity-mapped dot values
🧭 Path mode
Play directional feedback across the surface of a device
📦 Installation
npm install tact-js
# or
yarn add tact-js
# or
pnpm add tact-js🚀 Quick Start
Prerequisite
- Download and install the bHaptics Player
- Make sure the Player is running
- Connect your bHaptics Device to the Player
- Ensure the Player version is vX.Y.Z or later
Usage
Initialize the library
import Tact from 'tact-js';
// Initialize the library
Tact.init({
appId: '<APP_ID>',
apiKey: '<API_KEY>',
});Play an event
import Tact, { PositionType } from 'tact-js';
// Play an event
Tact.play({ eventKey: key });Play dot mode
import Tact, { PositionType } from 'tact-js';
// Play a dot
Tact.playDot({
position: PositionType.Vest, // e.g., Vest, Head, ForearmL, ForearmR etc.
motorValues: [100, 0, ... , 0], // 0 ~ 100
});Play path mode
import Tact, { PositionType } from 'tact-js';
// Play a path
Tact.playPath({
position: PositionType.Vest, // e.g., Vest, Head, ForearmL, ForearmR etc.
x: [0.4, 0.42, ... , 1], // 0 ~ 1
y: [0.5, 0.52, ... , 1], // 0 ~ 1
intensity: [100, 89, ... , 49], // 0 ~ 100
});📚 API
Tact.init(params: InitParams): void
- Initialize the library
params:appId: string - Your application IDapiKey: string - Your API keyremote?: string - (Optional) Remote IP address and Port number of the bHaptics Player (ex. "192.168.0.123:15881")
Tact.play(params: PlayParams): void
- Play an event
params:eventKey: string - Event keystartTime?: number - Start time in millisecondsintensityRatio?: number - Intensity ratiodurationRatio?: number - Duration ratiooffsetX?: number - Offset XoffsetY?: number - Offset Y
Tact.playDot(params: PlayDotParams): void
- Play a dot
params:position: PositionType - Position typemotorValues: number[] - Motor valuesduration?: number - Duration in milliseconds
Tact.playPath(params: PlayPathParams): void
- Play a path
params:position: PositionType - Position typex: number[] - X valuesy: number[] - Y valuesintensity: number[] - Intensity valuesduration?: number - Duration in milliseconds
🛠 Troubleshooting
Vite
If you are using Vite, you may need to add the following to your vite.config.js file:
export default defineConfig({
// ...
optimizeDeps: {
exclude: ['tact-js'],
},
// ...
});Demo
- Online demo: tact-js
- Local demo: Check the
demo/directory for a minimal setup example
🪪 License
bHaptics License
