Basic JS SDK Demo

Step 1: Application for authorization token

✔️

Warning: ⚠️ For security reasons, the developer token should be always used on the server side. You should never use it in your JS code from the client side.

AuthToken: 👉 {{ authToken }}

Code Example:

const { data: resData } = await axios.post(
  "https://api.lovense-api.com/api/basicApi/getToken",
  {
    token: “{{token}}”,
    uid: “{{uid}}”,
    uname: “{{uname}}”
  }
)
if (resData.code === 0) {
  this.authToken = resData.data && resData.data.authToken
} else {
  throw new Error(resData.message)
}
            
Step 2: Initialize

✔️

Code Example:

const basicSdkInstance = new LovenseBasicSdk({
  platform: "{{ platform }}",
  authToken: "{{ authToken }}",
  uid: "{{ uid }}",
  uname: "{{ uname }}"
})
basicSdkInstance.on("ready", (instance) => {
  this.readyStatus = true
})
basicSdkInstance.on("sdkError", (data) => {
  console.error('sdk error:', data.code, data.message)
})
            
Step 3: Get QR code

✔️

Code Example:

const codeRes = await this.basicSdkInstance.getQrcode()
this.qrcode = codeRes.qrcodeUrl
            
Step 4: Control toys

Connected ✔️ DisConnected

Device 👇

domain: {{ `https://${deviceInfo.domain}:${deviceInfo.httpsPort}` }}

App: {{ `${deviceInfo.appType} - ${deviceInfo.appVersion}` }}

platform: {{ deviceInfo.platform }}

Toys 👇

{{item.name}}