Got Stuck?
Forum for Lovense Developers
Support
Document Feedback

Unity Universal Plugin For Remote

Introduction

This Unity plugin can establish communication with the Lovense Remote App available on the LAN to send toy control commands.

Note: Android and iOS Remote App requires "Game Mode" to be enabled, PC Remote App requires "Allow Control" to be enabled.

Compatibility

Unity version>= 2018.4.0

Api Compatibility Level:

  • For .Net 4.x, the import package name is remotePlugin_.Net4.x.unitypackage.
  • For .Net Framework, the import package name is remotePlugin_.NetFramework.unitypackage.
  • For .Net Standard 2.0, the import package name isremotePlugin_.NetStandard2.0.unitypackage.
  • For .Net Standard 2.1, the import package name is remotePlugin_.NetStandard2.1.unitypackage.

Import the plugin

  1. Download the plugin package from here. The latest version of the current plugin is V1.74 click to view version records

    remotePlugin_.Net4.x.unitypackage

    remotePlugin_.NetFramework.unitypackage

    remotePlugin_.NetStandard2.0.unitypackage

    remotePlugin_.NetStandard2.1.unitypackage

  2. Import the appropriate package based on your project's Api Compatibility Level.

    image

  3. Select all options and click import.

    image

  4. The file Assets/StreamingAssets/LovenseToySupportConfig.json is the configuration file for the toy support directive, and the version field represents the version of the information. The current latest version is 1.3. If it is older than this version, it is recommended to download and replace the file.

Dowload: LovenseToySupportConfig.json

The LovenseDemo folder is an example that you can refer to. Removing it won't affect the functionality.

Guide

1. Search for the local LAN Lovense Remote.

public class YourLovenseToyUI: MonoBehaviour {
	 // do search
   private void DoSearch() {
      LovenseRemote.GetInstance().SearchRemoteApp();
   }

   //callback function,parames is List<RemoteAppData>
	private void OnSearchLocalApp(List<RemoteAppData> appDatas) {
       // Show the Lovense Remote search result in the UI
	}

   private void OnGetAppsError(string errorMsg) {
       //when get apps error
   }

   void Awake(){
      // Add listener
		LovenseRemote.onGetAppsEvent.AddListener(OnSearchLocalApp);
       LovenseRemote.onGetAppsErrorEvent.AddListener(OnGetAppsError);
   }

	void OnDestory() {
		// Remove listener
		LovenseRemote.onGetAppsEvent.RemoveListener(OnSearchLocalApp);
		LovenseRemote.onGetAppsErrorEvent.RemoveListener(OnGetAppsError);
	}
}

2. List toys based on the specified IP and port

public class YourLovenseToyUI: MonoBehaviour {
   
   //do search toys
   private void DoSearchToys(string domain,int port) {
      //The default value of useHttps is true, if set value to false, http will be used for data transfer.
      LovenseRemote.GetInstance().GetToys(domin,post[,useHttps=true]);
   }

   private void OnGetToys(List<LovenseRemoteToy> toys) {
      //when get toys
   }

   private void OnGetToysError(string errorMsg) {
       //when get toys error
   }

   void Awake() {
      // Add listener
      LovenseRemote.onGotToysEvent.AddListener(OnGetToys);
      LovenseRemote.onGetToysErrorEvent.AddListener(OnGetToysError);
   } 
 
   void OnDestroy() {
       // Remove listener
      LovenseRemote.onGotToysEvent.AddListener(OnGetToys);
      LovenseRemote.onGetToysErrorEvent.AddListener(OnGetToysError);
   }
}

3. Send commands

3.1 Send functions commands

public class YourLovenseToyUI : MonoBehaviour {
   
  private void DoSendCommands(List<LovenseRemoteToy> toys, List<LovenseCommand> commands, float timeSec,  float loopRunningSec , float loopPauseSec,int stopPrevious, ) {
    LovenseRemote.GetInstance().SendFunctions(toys,commands,timeSec[,loopRunningSec,loopPauseSec,stopPrevious]); 
  }

  private void OnControlToysResult(string toyId,ControlToysResult result){
      //...
  }

  void Awake() {
    // Add listener
    LovenseRemote.onControlToysEvent.AddListener(OnControlToysResult);
  } 

  void OnDestroy() {
    // Remove listener:
    LovenseRemote.onControlToysEvent.RemoveListener(OnControlToysResult);
  }
}

3.2 Send pattern commands

public class YourLovenseToyUI : MonoBehaviour {

  private void DoSendPattern(List<LovenseRemoteToy> toys, List<LovenseCommandType> types, List<int> strengthValues,  float timeSec,int intervalsMs ) {

    LovenseRemote.GetInstance().SendPattern(toys, types,strengthValues, timeSec,intervals );
  }

  private void OnControlToysResult(string id,ControlToysResult result){
    //...
  }

  void Awake() {
    // Add listener//
    LovenseRemote.onControlToysEvent.AddListener(OnControlToysResult);
  } 

   void OnDestroy() {
    // Remove listener:
    LovenseRemote.onControlToysEvent.RemoveListener(OnControlToysResult);
  }
}

values[]: Changes in intensity

personTimeMs: Time interval for intensity switching in milliseconds

timeSec: Total running time in seconds

3.3 Send preset commands

public class YourLovenseToyUI : MonoBehaviour {

   private void DoSendPreset(List<LovenseRemoteToy> toys, string presetName, int timeSec) {

      LovenseRemote.GetInstance().SendPreset(toys, presetName, timeSec);

   }

   //callback function, parames is ControlToysResult
   private void OnControlToysResult(string id,ControlToysResult result){
      //...
   }

   void Awake() {
      // Add listener;
      LovenseRemote.onControlToysEvent.AddListener(OnControlToysResult);
   } 

   void OnDestroy() {
       // Remove listener:
      LovenseRemote.onControlToysEvent.RemoveListener(OnControlToysResult);
   }
}

Currently available preset names: "earthquake," "fireworks," "pulse," "wave"

3.4 Send stop command

public class YourLovenseToyUI : MonoBehaviour {

   private void DoSendStop(List<LovenseRemoteToy> toys) {

      LovenseRemote.GetInstance().SendStopFunction(toys);

   }

   //callback function,parames is ControlToysResult
   private void OnControlToysResult(string id,ControlToysResult result){
      //...
   }

   void Awake() {
      // Add listener//
      LovenseRemote.onControlToysEvent.AddListener(OnControlToysResult);
   } 

   void OnDestroy() {
       // Remove listener:
      LovenseRemote.onControlToysEvent.RemoveListener(OnControlToysResult);
   }
}

4. Events of toys

You need to enable the game mode in Lovense Remote and establish the connection before calling the following methods.

See How to use Toy Events API

public class YourLovenseToyUI : MonoBehaviour {

   private void DoSendStop(string ip,int port,bool isSSL) {
       LovenseRemote.GetInstance().AddEventApiListener(ip, port, isSSL);
      
   }

   //callback function,parames is ControlToysResult
   private void OnEventOfApi(string ip,EventApiType eve){
      //...
   }

   private void OnEventOfGetToys(string ip,List<EventToy> toys) {
     //...
   }

   private void OnEventOfButton(string ip,string id,int target,ButtonActionType type){
      //...
   }

   private void OnEventOfFunction(string ip,string id,FunctionValue functionValue){
      //...
   }

   private void OnEventOfFunctionWithShake(string ip,string id,float value){
      //...
   }

   private void OnEventOfToyStatus(string ip,string id,bool connected){
     //...
   }

    private void OnEveryShake(string ip,string id){
     //...
    }
    

   void Awake() {
      // Add listener
       LovenseRemote.eventOfApi.AddListener(OnEventOfApi);
       LovenseRemote.eventOfGetToys.AddListener(OnEventOfGetToys);

       LovenseRemote.eventOfButton.AddListener(OnEventOfButton);
       LovenseRemote.eventOfFunction.AddListener(OnEventOfFunction);
       LovenseRemote.eventOfShakeFrequencyChanged.AddListener(OnEventOfFunctionWithShake);
       LovenseRemote.eventOfToyStatus.AddListener(OnEventOfToyStatus);
       LovenseRemote.eventOfEveryShake.AddListener(OnEveryShake);
   } 

   void OnDestroy() {
       // Remove listener:
       LovenseRemote.eventOfApi.RemoveListener(OnEventOfApi);
       LovenseRemote.eventOfGetToys.RemoveListener(OnEventOfGetToys);

       LovenseRemote.eventOfButton.RemoveListener(OnEventOfButton);
       LovenseRemote.eventOfFunction.RemoveListener(OnEventOfFunction);
       LovenseRemote.eventOfShakeFrequencyChanged.RemoveListener(OnEventOfFunctionWithShake);
       LovenseRemote.eventOfToyStatus.RemoveListener(OnEventOfToyStatus);
       LovenseRemote.eventOfEveryShake.RemoveListener(OnEveryShake);
   }
}

Interface

LovenseRemote

Method

GetInstance
  • Description:

    Get the singleton instance of LovenseRemote

  • Parameters: None

  • Return:

    LovenseRemote instance

SearchRemoteApp
  • Description:

    Search for the Lovense Remote App and toys on the LAN, when the search is complete, the onSearchLocalAppEvent event will be triggered.

  • Parameters:

    NameTypeDefaultRequiredDescription
    timeoutint5noSet the HTTP/HTTPS timeout in seconds
  • Return: None

GetToys
  • Description:

    Get the active toy list through the Remote App domain and port, when the search is complete, the onGotToysEvent event will be triggered.

  • Parameters:

    NameTypeDefaultRequiredDescription
    domainstringyesThe Domain of the Lovense Remote App
    portint30010noThe port of the Lovense Remote App
    isUseHttpsbooltruenoWhether to use https or http to communicate with the Lovense Remote App
    timeoutint5noSet the HTTP/HTTPS timeout in seconds
  • Return: None

GetSupportCommandsByName
  • Description:

    Obtain Command types supported by toys through their names

  • Parameters:

    NameTypeDescription
    namestringthe name of toy
  • Return: List<LovenseCommandType>

SendFunctions
  • Description:

    Send function commands to the toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toysList<LovenseRemoteToy>yesThe toys you want to control
    commandsList<LovenseCommand>yesSee LovenseCommand
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length. Otherwise, the value should be greater than or equal to 1.
    loopRunningSecfloat0notime running for each command loop in second,the value should be greater than or equal to 1.
    loopPauseSecfloat0notime gap for each command loop in second ,the value should be greater than or equal to 1.
    stopPreviousint1noStop previous command, if set to 0 the previous command will not stop
    timeoutint5noSet the HTTP/HTTPS timeout in seconds
  • Return: None

SendPattern
  • Description:

    Send a series of functions to the toys, all the functions will be excecuted in types according to the order of the level in strengthValues with the interval of intervalsMs.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toysList<LovenseRemoteToy>yesThe toys you want to control
    typesList<LovenseCommandType>yesSee LovenseCommandType
    strengthValuesList<int>yesThe order of the levels
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length. Otherwise, the value should be greater than or equal to 1.
    intervalsMsfloat150noThe level interval in milliseconds ,Should be greater than 100 ,default 150
    timeoutint5noSet the HTTP/HTTPS timeout in seconds
  • Return: None

SendPreset
  • Description:

    Send a preset command to the toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toysList<LovenseRemoteToy>yesThe toys you want to control
    presetNamestringyesThe preset name to send, we provide four preset patterns in the Lovense Remote app: pulse, wave, fireworks, earthquake
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length. Otherwise, the value should be greater than or equal to 1.
    timeoutint5noSet the HTTP/HTTPS timeout in seconds
  • Return: None

SendStopFunction
  • Description:

    Send a stop command to the toys.

  • Parameters:

    NameTypeDescription
    toysList<LovenseRemoteToy>The toys you want to stop
    timeoutintSet the HTTP/HTTPS timeout in seconds,default is 5
  • Return: None

AddEventApiListener
  • Description:  Add events API listener, will trigger eventOfApi and eventOfGetToys if any toy under the local network supports Events API.

  • Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's ip
    portintThe Lovense Remote App's port
    isSSLboolDetermine whether to use SSL protocol, default value is false
  • Return: None

RemoveEventApiListener
  • Description:

    Remove the event API listener under the specified local IP and port.

  • Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's ip
    portintThe Lovense Remote App's port
  • Return: None

CloseAllEventApi
  • Description:

    Remove all event API connection.

  • Parameters:None

  • Return: None

Event

onGetAppsEvent
  • Description:

    Triggered when the search for the Lovense Remote App is complete.

  • Callback Parameters:

    NameTypeDescription
    appDatasList<RemoteAppData>The search result
onGetAppsErrorEvent
  • Description:

    Triggered when getting Lovense Remote App is on error.

  • Callback Parameters:

    NameTypeDescription
    errorMsgstringError message
onGotToysEvent
  • Description:

    Triggered when getting toy list is complete.

  • Callback Parameters:

    NameTypeDescription
    toysList<LovenseRemoteToy>The toys of getting
onGetToysErrorEvent
  • Description:

    Triggered when getting toy list is on error.

  • Callback Parameters:

    NameTypeDescription
    errorMsgstringError message
onControlToysEvent
  • Description:

    Triggered when sending commands is complete.

  • Callback Parameters:

    NameTypeDescription
    resultControlToysResultThe result
eventOfApi
  • Description:

    Triggered when the events API status has changed.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    eveEventApiTypeSee EventApiType
eventOfGetToys
  • Description:

    Triggered when the events API has been enabled and the toys under local network support Events API.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    toysList<EventToy>the toys which support events api, See EventToy
eventOfToyStatus
  • Description:

    Triggered when the connection status of the toy changes.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    idstringThe toy's id
    connectedboolThe toy's connection status
eventOfButton
  • Description:

    Triggered when the toy's button is pressed.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    idstringThe toy's id
    indexboolThe index of the corresponding button.
    0 represents button controls the vibration and 1 represents button controls the inflation/rotation.
    typeButtonActionTypeSee ButtonActionType
eventOfFunction
  • Description:

    Triggered when the parameter functionValue of the toy changed.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    idstringThe toy's id
    valueFunctionValueSee FunctionValue
eventOfShakeFrequencyChanged
  • Description:

    Triggered when the shake value of the toy changed.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    idstringThe toy's id
    valuefloatThe value of shake
eventOfEveryShake
  • Description:

    Trigger when user shakes the toy every time.

  • Callback Parameters:

    NameTypeDescription
    ipstringThe Lovense Remote App's IP
    idstringThe toy's id

RemoteAppData

  • Description:

    The connection information and status of the Lovense Remote App.

  • Properties:

    NameTypeDescription
    onlineboolThe status of the Lovense Remote App, true represents online, false represents offline
    domainstringThe domain of the Lovense Remote App
    httpsPortintThe https port of the Lovense Remote App
    wssPortintThe wss port of the Lovense Remote App

LovenseRemoteToy

  • Description:

    The information of the Lovense toy.

  • Properties:

    NameTypeDescription
    domainstringThe domain of the Lovense Remote App that the toy is connected to
    portintThe port of the Lovense Remote App that the toy is connected to
    isHttpsboolWhether to use https or http to communicate with the Lovense Remote App
    idstringThe toy's id
    statusstringThe toy's status, 1 represents connected, 0 represents disconnected
    namestringThe toy's name, such as "nora"
    nickNamestringThe toy's nickname, such as "My Nora"
    batteryintThe toy's battery level, from 0 to 100

LovenseCommand

  • Description:

    The toy control command.

  • Properties:

    NameTypeDescription
    typeLovenseCommandTypeSee below
    valueintFunction level

Function Level:

TypeRange
VIBRATE0 - 20
VIBRATE10 - 20
VIBRATE20 - 20
VIBRATE30 - 20
ROTATE0 - 20
PUMP0 - 3
SUCTION0 - 20
FINGERING0 - 20
THRUSTRING0 - 20
DEPTH0 - 3

LovenseCommandType

  • Description:

    The enum of the toy function type.

  • Enum:

    Value
    VIBRATE
    VIBRATE1
    VIBRATE2
    VIBRATE3
    ROTATE
    PUMP
    THRUSTRING
    FINGERING
    SUCTION
    DEPTH

The DEPTH command is a setting command that requires the THRUSTRING command to take effect.

ControlToysResult

  • Description:

    The result of the toy control command.

  • Properties:

    NameTypeDescription
    codeintThe result code
    typestringThe result type

Result Code:

CodeDescription
0The request has an HTTP error or a network error
200Success
400Invalid Command
401Toy Not Found
402Toy Not Connected
403Toy Doesn't Support This Command
404Invalid Parameter
500HTTP server not started or disabled
506Server Error.Restart Lovense Connect

EventApiType

  • Description:

    The enum of the events API type.

  • Enum:

    ValueDescription
    EVENT_OPENthe events api has opened
    EVENT_ERRORthe events api is on error
    EVENT_GRANTEDthe events open and granted the app name
    EVENT_CLOSEthe events api has closed

EventToy

  • Description:

    The toys that support events API.

  • Properties:

    Nametype
    idstring
    namestring
    typestring
    hVersionstring
    fVersionint
    nicknamestring
    batteryint
    connectedbool

ButtonActionType

  • Description:

    The enum of the button action type.

  • Enum:

    Value
    BUTTON_DOWN
    BUTTON_UP
    BUTTON_PRESSED

FunctionValue

  • Description:

    The events API's action values.

  • Properties:

    Nametype
    typeSee FunctionType
    indexint
    valueint

FunctionType

  • Description:

The enum of the function type.

  • Enum:

    Value
    VIBRATE
    ROTATE
    INFLATION
    THRUSTING
    DEPTH
    BATTERY

Version Records

[Version1.74] - 2024-04-10

  • 1.Fix error code 601.

[Version1.73] - 2023-12-15

  • 1.Bug fixing for Android platform.

[Version1.72] - 2023-11-30

  • 1.Adapting compatibility for the IL2CPP scripting backend.

[Version1.71] - 2023-11-24

  • 1.Fixed MissingMethodException.

[Version1.7] - 2023-11-15

  • 1.Add Depth command.

  • 2.Update the configuration file to version1.3.

[Version1.6] - 2023-11-07

  • 1.Add capability with WebGL.

[Version1.5] - 2023-11-01

  • 1.Add Vibrate1 Vibrate2 Vibrate3 commands.

[Version1.4] - 2023-10-24

  • Added timeout parameter to the following functions using http/https:

    SearchRemoteApp

    GetToys

    SendFunctions

    SendPattern

    SendPreset

    SendStopFunction

  • The callback is triggered when the HTTP/HTTPS connection times out.

[Version1.3] - 2023-09-27

  • 1.Add events API of Lovense Remote App.

[Version1.2] - 2023-09-12

  • 1.Add a function that can query toy support instructions

  • 2.Finding an empty Remote App or empty toy also triggers an event.

  • 3.Change type of 'strengthValues' int[] to List<int> in pattern function

  • 4.Change time type int to float.

  • 5.Event [onControlToysEvent] add parames 'toyId'

[Version1.1] - 2023-08-25

  • 1.Add onGetAppsErrorEvent and onGetAppsErrorEvent when the request has an HTTP error or a network error.

  • 2.Add a error code when control toys has occus an HTTP error or a network error.

[Version1.0] - 2023-08-20

  • 1.Functions

  • 2.Pattern

  • 3.Preset