Sync with Lovense Toys
Here are the methods and events you'll need when you customize the syncing feature. All layout and logic needs to be complimented by your developer.
Note: Click here to check the demo page, you will be able to see the real case code.
Workflow
Step 1: Integrate SDK
Get ctoken
See here
Initialization
Integrate pattern-sdk.js
into your website.
<script src="https://cdn.lovense-api.com/peditor-v2/pattern-sdk.js"></script>
Initialize the SDK.
Note: Call this method every time you open a media page or switch media.
const lovensePattern = new LovensePattern()
Step 2: lovensePattern.init
Note: Call this method every time you open a media page or switch media.
Parameters | Description | Type | Required |
---|---|---|---|
ctoken | See here | string | Yes |
mediaId | The media's ID from your platform.videoId can also be used here. | string | Yes |
duration | The media's total duration (in ms) | number | Yes |
videoEl | The <video> DOM element. Please make sure that VideoEl is detected on the video/audio playback page, when you calling this method. Only after detection, the toy can sync with the video/audio. | object | No |
const lovensePattern = new LovensePattern()
lovensePattern.init({
ctoken: "[ctoken]",
mediaId: "[mediaId]",
// or videoId: "[mediaId]"
videoEl: document.querySelector("video"),
// or videoEl: "document.querySelector("audio")"
duration: "[duration]",
})
Step 3: Connect to Apps
We support syncing to audio/video with Lovense Remote or VibeMate.
Connect to Lovense Remote (optional)
Get a QR Code, app URL, or Unique Code to connect to Lovense Remote. Supports connecting to Lovense Remote from both PC and mobile-based websites.
Note: If your user has already connected Lovense Remote to your platform, you don't need to call this method again when they switch to a new media. Connection persistence is supported. If you call this method again, a new QR code will be shown.
callback | Description | Type |
---|---|---|
qrCode | Suggested to display it for PC browser users. | string |
appOpenUrl | Suggested to display it for mobile browser users. | string |
code | It's a 6 digit code for use in connecting to VR videos. | string |
lovensePattern.getApp((data) => {
console.log(data) // { qrCode: "[qrCode]", appOpenUrl: "[appOpenUrl]", code: "[Unique code]" }
// If your user is on a PC, show the QR Code and have them scan it with Lovense Remote mobile app; If your user is on mobile, display a button{appOpenUrl} which can connect to the Lovense Remote app. If your user is on a VR headset, show the Unique Code and have them enter it with Lovense Remote mobile app.
})
Connect to VibeMate (optional)
Get a unique VibeMate download URL for each of your website pages. When your user downloads/opens VibeMate through this URL they will land back on that page.
Note: If your user has already connected VibeMate to your platform, you don't need to call this method again when they switch to a new media. Connection persistence is supported. If you call this method again, a new QR code will be shown.
callback | Description | Type |
---|---|---|
qrCode | Suggested to display it for PC browser users. | string |
url | The unique VibeMate download URL of each of your website pages. | string |
result | Connection state | boolean |
vibemate.getApp((data) => {
console.log(data) // { url: "[url]", result: true/false }
// If your user is on VibeMate, it will return { result: true }. In this case, please remove the syncing buttons from the video page. VibeMate will display the syncing functionality from our side.
// If your user is on other browsers, it will return { result: false, url: [url] }. When the user downloads/opens VibeMate through this URL, they will land back on this page directly.
})
Once VibeMate/Lovense Remote is connected, the event appConnected
will be triggered. Then you should display the connection status on your website, or update the status of your connection button.
lovensePattern.on("appConnected", () => {
console.log("appConnected")
// Once Lovense Remote or VibeMate is connected, your platform can control the toys.
})
Step 4: Load pattern (optional)
If you are using FunScript, this step is required every time your user connects the Lovense Remote/VibeMate app to your platform, even when the audio/video is already playing.
Note: If your user syncs with VibeMate, then VibeMate will react to scripts first. If there are no scripts, it will switch to AI Sync automatically.
Parameters | Description | Type | Required |
---|---|---|---|
type | Pattern's type, supports patterns from funScript and lovense (patterns created in Lovense software) | string | No |
data | A pattern's data. | array | No |
patternLink | Pattern file's URL | string | No |
lovensePattern.loadPattern({
type: "funScript",
patternLink: "[pattern link]"// The funscript file download link
data: [
{ pos: 50, at: 1000 },
{ pos: 80, at: 2000 },
{ pos: 20, at: 3000 },
], // FunScript data
})// If the data object is not null, this pattern data will be used first. Otherwise, pattern data is obtained from patternLink. If both are null, an error message will be returned.
When you connect to the app (Lovense Remote or VibeMate), the"lovensePattern.init" method will handle syncing the toy video/audio for most basic operations (listed below):
- Play the video/audio;
- Pause the video/audio;
- Change the progress bar of the video/audio;
- Change the speed of the video/auido;
If there are some special cases where you want to trigger the events above and you want to manually handle the operations, please call the methods here.
Optional API
lovensePattern.getPatternList
Get patterns by audio/video. If you only support one pattern per video, then there's no need to call it.
Parameters | Description | Type | Required |
---|---|---|---|
mediaId | The media's ID from your platform. videoId can also be used here. | string | Yes |
page | page | number | No |
pageSize | pageSize | number | No |
lovensePattern
.getPatternList({
mediaId: "[mediaId]",
// or videoId: "[mediaId]"
page: 1,
pageSize: 10,
})
.then((data) => {
console.log(data) // [patternList]
})
lovensePattern.exit
Call this method to disconnect Lovense Remote Or VibeMate from your platform.
lovensePattern.exit()
Events
Pattern Sync Error
Lovense Remote downloads patterns through HTTP requests. This event will be triggered when Lovense Remote or VibeMate fails to download a pattern.
lovensePattern.on("PatternSyncError", (data) => {
console.log("PatternSyncError", data.msg)
// According to the data.msg, you can check out the reasons and fix the issues.
// Missing parameter videoId or mediaId!
// Missing parameter ctoken!
// Missing parameter domId!
// Unable to read file, type: sync
// Can't Find Lovense Pattern for this media, the data can't be empty
// Unable to read file
// Can't Find Lovense Pattern for this media, Please create it from the Lovense Pattern editor page first.
// Pattern type is error!
// VibeMate Ai Sync Error
// Network error
})
App Disconnected
This event will be triggered when the server can't detect the app (Lovense Remote or VibeMate) for 85 seconds. This may happen, for example, when the app is closed or there is a network disconnection.
lovensePattern.on("appDisconnected", () => {
console.log("appDisconnected")
// You should update the Lovense Remote or VibeMate connection status on your website. We recommend showing a message to users that Lovense Remote or VibeMate is disconnected and prompting them to reconnect.
})
App Exit Pattern
This event is only triggered when there is an intentional disconnection from the app. For example, when the user clicks the "disconnect" button in the app (Lovense Remote or VibeMate), or when you call “lovensePattern.exit” on your website.
lovensePattern.on("appExitPattern", () => {
console.log("appExitPattern")
// Now you can update the App(Lovense Remote or VibeMate) connection status on your website, so the user can reconnect.
})
App Toy Status
This event will be triggered when toys connect or disconnect. It will list all the toys connected at that moment.
lovensePattern.on("appToyStatus", (data) => {
console.log("appToyStatus", data)
// [
// {
// nickName:"Dolce", //Toy nickName
// name:"dolce", //Toy name
// id:"dd83899c34d7", //Toy ID
// battery:100, //Toy battery
// version:"1", //Toy version
// status:"1" //Toy status 1:connected
// },
// {
// nickName:"Nora", //Toy nickName
// name:"nora", //Toy name
// id:"dd83899c34d7", //Toy ID
// battery:100, //Toy battery
// version:"1", //Toy version
// status:"1" //Toy status 1:connected
// }
//]
})