myVibe SDK Documentation
Introduction
Welcome to the myVibe SDK documentation. This SDK allows third-party developers to create micro-applications for the myVibe smart sex toy management platform.
Note: The myVibe SDK is designed to work within the myVibe app environment. Your micro-application will be loaded in iframe containers within the main app, with safe access to device control features through our secure API.
What You Can Build
The myVibe SDK enables you to build a variety of experiences:
- Custom Controls: Create unique interfaces for controlling smart devices
- Pattern Creators: Build tools for designing custom vibration patterns
- Interactive Experiences: Create games or interactive scenarios that control devices
- Media-Synchronized Actions: Connect device actions to audio, video, or other media
- Partner Apps: Create experiences for partners to control each other's devices
Key Features
- Simple, promise-based API for device control
- Pattern creation and management
- Event handling for device connection/disconnection
- Battery monitoring capabilities
- Multiple vibration motors control (where supported by hardware)
- Secure communication between your app and the device
Architecture
The myVibe SDK follows a parent-child communication model:
+------------------------+
| myVibe App |
| (Native iOS/Android) |
| |
| +----------------+ |
| | WebView | |
| | | |
| | +---------+ | |
| | | iframes | | |
| | +---------+ | |
| +----------------+ |
+------------------------+
|
| Bluetooth
v
+------------------------+
| Smart Device |
+------------------------+
Your micro-application runs in an iframe within the main application's WebView. The SDK provides a communication bridge between your micro-application and the main app, which handles the Bluetooth communication with the physical device.
Communication Flow
- Your app uses the SDK methods to request actions (e.g., changing vibration intensity)
- The SDK sends these requests to the parent application via postMessage
- The parent app processes the request and sends commands to the connected device
- The parent app sends events back to your app (e.g., device disconnection, battery status)
Security Note: This architecture ensures that micro-applications never have direct access to the Bluetooth API or device communication, maintaining security and privacy for users.
Integration Guide
Follow these steps to integrate the myVibe SDK into your micro-application:
1. Include the SDK
Add the following script tag to your HTML file:
<script src="https://app.myvibe.tech/sdk/myvibe-sdk.js"></script>
2. Initialize the SDK
Create a new instance of the SDK with your application configuration:
const myVibeApp = new MyVibeSDK.App({
name: "Your App Name", // Required
version: "1.0.0", // Optional, defaults to "1.0.0"
permissions: ["vibration", "patterns"] // Optional, defaults to ["basic"]
});
3. Set Up Event Handlers
Register callback functions for important events:
// Handle device connection
myVibeApp.onDeviceConnected(device => {
console.log(`Connected to ${device.name}`);
// Update your UI to show connected state
});
// Handle device disconnection
myVibeApp.onDeviceDisconnected(device => {
console.log(`Disconnected from ${device.name}`);
// Update your UI to show disconnected state
});
// Handle low battery warning
myVibeApp.onBatteryLow(level => {
console.log(`Battery low: ${level}%`);
// Show low battery warning
});
// Handle pattern completion
myVibeApp.onPatternComplete(pattern => {
console.log(`Pattern "${pattern.name}" completed`);
// Update UI or start next action
});
4. Control the Device
Use the SDK methods to control the connected device:
// Basic vibration control
myVibeApp.setVibration(50); // Set to 50% intensity
// Create and play a pattern
const pulsePattern = myVibeApp.createPattern({
name: "Pulse",
steps: [
{ intensity: 100, duration: 500 },
{ intensity: 0, duration: 300 },
{ intensity: 100, duration: 500 }
],
repeat: 3
});
myVibeApp.playPattern(pulsePattern);
// Stop all vibration
myVibeApp.stopVibration();
Important: Always provide a way for users to quickly stop all vibration. This is both a usability and safety consideration.
Permissions
The SDK uses a permission-based system to control what features your micro-application can access:
basic
- Basic device information and connection events (always included)vibration
- Control device vibration intensitypatterns
- Create and play vibration patternsaudio
- Access to audio input for sound-reactive featuresbluetooth
- Additional information about the Bluetooth connectionstorage
- Store pattern data and preferencesnotification
- Send notifications to the user
Specify the permissions your app needs during SDK initialization:
const myVibeApp = new MyVibeSDK.App({
name: "Your App Name",
permissions: ["vibration", "patterns", "storage"]
});
You can check if your app has a specific permission using hasPermission()
:
if (myVibeApp.hasPermission('patterns')) {
// Show pattern controls
} else {
// Hide pattern controls
}
Tip: Request only the permissions your app actually needs. This improves security and performance.
Best Practices
Follow these guidelines to create high-quality micro-applications:
User Experience
- Responsive Design: Ensure your app works well on various screen sizes
- Clear Controls: Make it obvious how to control vibration intensity
- Emergency Stop: Always include a prominent way to stop all vibration
- Battery Awareness: Monitor and display battery status
- Offline Handling: Gracefully handle device disconnections
Performance
- Efficient Updates: Don't send continuous rapid updates to the device
- Optimize Animations: Use CSS transitions instead of JavaScript for animations
- Pattern Efficiency: Use reasonable step durations (100ms minimum recommended)
- Pause Non-Essential Processes: When app is in background, pause non-essential processes
Privacy and Security
- No Personal Data: Don't collect or store unnecessary user data
- Clear Privacy Policy: Include a privacy policy explaining data usage
- Secure Communication: Use HTTPS for any external API calls
- Permission Usage: Only request permissions your app actually needs
Examples
We provide several example micro-applications to help you get started:
Remote Control Example
A simple remote control interface for basic device functions:
This example demonstrates:
- Basic SDK initialization
- Device connection handling
- Vibration intensity control
- Battery level monitoring
- Playing predefined patterns
Pattern Designer Example
A visual tool to create custom vibration patterns:
This example demonstrates:
- Creating complex patterns
- Pattern saving and loading
- Pattern playback control
- Visual pattern representation