Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose service IP and port as variables in service providers #1498

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions Packages/Tracking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- (Pose Detector) Add a new rule type to match rotation of a joint to a target
- Help Menu that links out to docs, a place to report bugs & places to get support
- (Service Provider) Expose service IP and port as user settable variables

### Changed
- Changed from using obsolete FindObjectOfType to using newer implementations
Expand Down
20 changes: 20 additions & 0 deletions Packages/Tracking/Core/Editor/Scripts/LeapServiceProviderEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ protected override void OnEnable()

specifyCustomDrawer("_specificSerialNumber", drawSerialNumberToggle);

deferProperty("_serviceConnectionInput");
deferProperty("_serverNameSpace");
deferProperty("_servicePort");
deferProperty("_serviceIP");
deferProperty("_useInterpolation");

deferProperty("_reconnectionAttempts");
Expand All @@ -78,7 +81,24 @@ protected override void OnEnable()
hideField("_trackingOptimization");
}
addPropertyToFoldout("_useInterpolation", "Advanced Options");

addPropertyToFoldout("_serviceConnectionInput", "Advanced Options");

specifyConditionalDrawing("_serviceConnectionInput",
(int)LeapServiceProvider.ServiceConnectionInput.NAME,
"_serverNameSpace");

specifyConditionalDrawing("_serviceConnectionInput",
(int)LeapServiceProvider.ServiceConnectionInput.IP_PORT,
"_serviceIP");

specifyConditionalDrawing("_serviceConnectionInput",
(int)LeapServiceProvider.ServiceConnectionInput.IP_PORT,
"_servicePort");

addPropertyToFoldout("_serverNameSpace", "Advanced Options");
addPropertyToFoldout("_serviceIP", "Advanced Options");
addPropertyToFoldout("_servicePort", "Advanced Options");

addPropertyToFoldout("_reconnectionAttempts", "Advanced Options");
addPropertyToFoldout("_reconnectionInterval", "Advanced Options");
Expand Down
48 changes: 47 additions & 1 deletion Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,34 @@ public enum TrackingOptimizationMode
[SerializeField]
protected bool _preventInitializingTrackingMode;

/// <summary>
/// The type of input to use for connection to the service
/// </summary>
public enum ServiceConnectionInput
{
NAME,
IP_PORT
}
[Tooltip("Which input to use for the service connection")]
[SerializeField]
[EditTimeOnly]
protected ServiceConnectionInput _serviceConnectionInput = ServiceConnectionInput.NAME;

[Tooltip("Which Leap Service API Endpoint to connect to. This is configured on the service with the 'api_namespace' argument.")]
[SerializeField]
[EditTimeOnly]
protected string _serverNameSpace = "Leap Service";

[Tooltip("The IP address on which the Tracking service listens to. This is configured on the service with 'ip_address' in the 'leap_server_config' session of 'ServerConfig.json'")]
[SerializeField]
[EditTimeOnly]
protected string _serviceIP = "127.0.0.1";

[Tooltip("The port on which the Tracking service listens to. This is configured on the service with 'port' in the 'leap_server_config' session of 'ServerConfig.json'")]
[SerializeField]
[EditTimeOnly]
protected string _servicePort = "12345";

public override TrackingSource TrackingDataSource { get { return CheckLeapServiceAvailable(); } }

/// <summary>
Expand Down Expand Up @@ -845,6 +868,20 @@ public TrackingOptimizationMode GetTrackingMode()
throw new Exception("Unknown tracking optimization mode");
}

/// <summary>
/// Set the _serviceConnectionInput mode to IP_PORT, set the target IP and port of the service to the parameters and connect to the new service address
/// </summary>
public void SetTargetServiceIPPortToConnectTo(string IP, string port)
{
_serviceConnectionInput = ServiceConnectionInput.IP_PORT;

_serviceIP = IP;
_servicePort = port;

destroyController();
createController();
}

#endregion

#region Internal Methods
Expand Down Expand Up @@ -888,6 +925,11 @@ protected void createController()

string serialNumber = _multipleDeviceMode != MultipleDeviceMode.Disabled ? SpecificSerialNumber : "";

if(_serviceConnectionInput == ServiceConnectionInput.IP_PORT)
{
_serverNameSpace = $"{{\"tracking_server_ip\": \"{_serviceIP}\", \"tracking_server_port\": {_servicePort}}}";
}

_leapController = new Controller(serialNumber.GetHashCode(), _serverNameSpace, _multipleDeviceMode != MultipleDeviceMode.Disabled);

_leapController.Device += (s, e) =>
Expand Down Expand Up @@ -1066,6 +1108,10 @@ private TrackingSource CheckLeapServiceAvailable()
return _trackingSource;
}
#endif
if (_serviceConnectionInput == ServiceConnectionInput.IP_PORT)
{
_serverNameSpace = $"{{\"tracking_server_ip\": \"{_serviceIP}\", \"tracking_server_port\": {_servicePort}}}";
}

if (LeapInternal.Connection.IsConnectionAvailable(_serverNameSpace))
{
Expand Down Expand Up @@ -1289,4 +1335,4 @@ public class LeapFOVInfo

#endregion
}
}
}