Some code to use the Leap Motion remotely in Unity based on Websockets
For example, you can use it with VirtualHere on your Standalone Virtual Reality Headset as the Oculus Quest or the Pico Neo, connect your Leap Motion on the headset directly and let a remote pc compute hands data for you and access it remotely in your Unity Android app on your headset.
-
- add two Plugins to your Unity Project (so under a Plugins folder in your Assets):
-
- add the Leap Motion Unity Core Plugin
-
- add the scripts of this repository to your project, replace the
IController.cs
code by the one in this repository and fix the Leap Motion code:
- replace the Controller type by IController in the LeapServiceProvider :
protected IController _leapController;
(the LeapServiceProvider file is given as an example, but warning, that's maybe not the same version as yours) - propagate the change everywhere to remove errors (change
Controller
toIController
) - add in
LeapServiceController.cs
const int _port = 6437; [SerializeField] protected bool _remoteConnection; [SerializeField] protected string _ip = "127.0.0.1"; [SerializeField] protected int _jsonVersion = 6;
- replace the
_leapController = new Controller();
inLeapServiceController
by
if (!_remoteConnection) { _leapController = new Controller(); } else { _leapController = new RemoteController($"ws://{_ip}:{_port}/v{_jsonVersion}.json"); }
- add the scripts of this repository to your project, replace the
-
- unsure in the Leap Control Panel that you give access to web applications
-
- use the Leap Motion SDK as normal, and just check the
Remote Connection
box in theLeapServiceProvider
orLeapXRServiceProvider
in the Unity inspector
- use the Leap Motion SDK as normal, and just check the
-
- by default, the Leap Motion software is configured to allow only local connection on the hidden webserver, so don't forget to enable the "websocket_allow_remote" in the config file (like explained here https://forums.leapmotion.com/t/read-leap-data-from-guest-vm-on-host-machine-using-websockets/1523/10 and there https://developer.leapmotion.com/documentation/v4/configuration.html) and restart the leap software. Also, don't forget to set the ip in the inspector of
LeapServiceProvider
orLeapXRServiceProvider
- by default, the Leap Motion software is configured to allow only local connection on the hidden webserver, so don't forget to enable the "websocket_allow_remote" in the config file (like explained here https://forums.leapmotion.com/t/read-leap-data-from-guest-vm-on-host-machine-using-websockets/1523/10 and there https://developer.leapmotion.com/documentation/v4/configuration.html) and restart the leap software. Also, don't forget to set the ip in the inspector of
-
- if that don't work, check your anti-virus or firewall on your pc