VridgeRemote (fire and forget layer) - RiftCat/vridge-api GitHub Wiki
Introduction
Normally, to use VRidge API you should setup connection on your own, watch for timeouts and disconnects and handle any interruptions. This is still recommended for advanced scenarios because it allows you to take full responsibility and control over the life cycle and API calls. This is described @ Control channel page.
In v3.1 we added few classes that act as an additional abstraction layer on top of the advanced API. You can use them if you just want to send data and don't care if some data is lost or connection is temporarily interrupted. This access layer works the same in both Java and C# API SDKs.
VridgeRemote class
Initialization
To start, create an instance of VridgeRemote class with following constructor arguments.
- string serverIp
- Target IP address of PC running VRidge (see: discovery)
- string appName
- Your API app name, you may connect from multiple instances of your API Client sharing the same name but only one app (distinguished by unique appName) may use data endpoint. This prevents conflicting data from interfering with each other.
- Flags capabilities
- HeadTracking and/or Controllers enum values. Select which API data endpoints you want exclusive access to.
- int reconnectFrequencyMs
- Delay between failed call and reconnection attempt. Recommended default: 2000ms.
- int timeoutThresholdMs
- Time to wait for server response before deciding to drop connection. Recommended default: 100ms.
Endpoint usage
VridgeRemote instance contains two data endpoint proxies. HeadRemote and ControllerRemote. Each time you want to interact with one of those endpoints, you query VridgeRemote getter (in C#: property) to return you selected ControllerRemote or HeadRemote.
If null is returned, it means that connection is not established - try again later. VridgeRemote will automatically handle connection and re-connection. All you need to do is check if the returned endpoint Remote is not null and execute your calls.
Keep in mind that connection may be dropped at any point, always query VridgeRemote for fresh ControllerRemote or HeadRemote as a check.
Status check
Query Status property (C#) or call getStatus() (Java) on VridgeRemote. This will let you know if other API apps are blocking you from accessing API.
Example
// Init
vridge = new VridgeRemote(
"localhost", // target IP
"Desktop-Tester", // app name
Capabilities.Controllers | Capabilities.HeadTracking);
// Status check
var currentStatus = vridge.Status;
MessageBox.Show(string.Join("\n", currentStatus.Endpoints));
// Head control
vridge.Head?.Recenter();
vridge.Head?.SetPosition(PositionX, PositionY, PositionZ);
See ControlViewModel.cs for other API calls in our visual tester app.