Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 619131c

Browse files
authored
Merge pull request #4 from Earthmark/main
Migrated to using ALVR v20
2 parents 10fb0fb + 9e1b9bc commit 619131c

File tree

14 files changed

+919
-1023
lines changed

14 files changed

+919
-1023
lines changed

Interface/ALXR/ALXRModule.cs

Lines changed: 0 additions & 600 deletions
This file was deleted.

Interface/AlvrConnection.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using BaseX;
2+
using System;
3+
using System.Net.Sockets;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using OscCore;
7+
8+
namespace QuestProModule;
9+
10+
public class AlvrConnection : IDisposable
11+
{
12+
private readonly SyncCell<FbMessage> _messageTarget;
13+
14+
/// <summary>
15+
/// A message owned by this reader that is currently being mutated.
16+
/// </summary>
17+
private FbMessage _workingMessage = new();
18+
19+
private readonly UdpClient _client;
20+
private readonly CancellationTokenSource _stopToken = new();
21+
private readonly Task _listenTask;
22+
23+
public AlvrConnection(int port, SyncCell<FbMessage> target)
24+
{
25+
_messageTarget = target;
26+
_client = new UdpClient(port);
27+
_listenTask = Task.Run(ListenAsync);
28+
UniLog.Log($"Opening Alvr connection on {port}");
29+
}
30+
31+
private async Task ListenAsync()
32+
{
33+
while (!_stopToken.IsCancellationRequested)
34+
{
35+
try
36+
{
37+
var got = await _client.ReceiveAsync();
38+
var message = new OscMessageRaw(new ArraySegment<byte>(got.Buffer));
39+
switch (message.Address)
40+
{
41+
case "/tracking/eye/left/Quat":
42+
case "/tracking/eye/left/Active":
43+
case "/tracking/eye/right/Quat":
44+
case "/tracking/eye/right/Active":
45+
// Ignore these, we do this ourselves.
46+
break;
47+
case "/tracking/eye_htc":
48+
case "/tracking/lip_htc":
49+
UniLog.Error("Unexpected ALVR message in loading area, please use facebook eye tracking.");
50+
break;
51+
case "/tracking/face_fb":
52+
_workingMessage.ParseOsc(message);
53+
if (!_stopToken.IsCancellationRequested)
54+
{
55+
_messageTarget.Swap(ref _workingMessage);
56+
}
57+
break;
58+
}
59+
}
60+
catch (Exception ex)
61+
{
62+
UniLog.Error(ex.Message);
63+
}
64+
}
65+
}
66+
67+
public void Dispose()
68+
{
69+
UniLog.Log("Alvr connection closing.");
70+
_stopToken.Cancel();
71+
_client.Dispose();
72+
}
73+
}

Interface/AlvrMonitor.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using BaseX;
2+
using System;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Timers;
6+
7+
namespace QuestProModule;
8+
9+
internal class AlvrMonitor : IDisposable
10+
{
11+
public string ClientName { get; set; }
12+
public string ClientPath { get; set; }
13+
public string Arguments { get; set; }
14+
15+
private readonly Timer _timer;
16+
17+
private Process _foundProcess;
18+
19+
public AlvrMonitor()
20+
{
21+
_timer = new(1000);
22+
_timer.Elapsed += (o, e) => CheckProcess();
23+
}
24+
25+
void CheckProcess()
26+
{
27+
if (!CheckIfRunning())
28+
{
29+
StartClient();
30+
}
31+
}
32+
33+
private bool CheckIfRunning()
34+
{
35+
Process[] alvrClients = Process.GetProcessesByName("alxr-client");
36+
foreach (Process client in alvrClients)
37+
{
38+
if (_foundProcess is { HasExited: false })
39+
{
40+
client.Dispose();
41+
continue;
42+
}
43+
44+
WatchProcess(client);
45+
}
46+
47+
return !(_foundProcess?.HasExited ?? true);
48+
}
49+
50+
private void WatchProcess(Process process)
51+
{
52+
_foundProcess?.Dispose();
53+
_foundProcess = null;
54+
55+
if (process.HasExited)
56+
{
57+
return;
58+
}
59+
60+
_foundProcess = process;
61+
62+
_foundProcess.Exited += (o, e) => _timer.Start();
63+
}
64+
65+
private void StartClient()
66+
{
67+
try
68+
{
69+
string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
70+
string clientPath = Path.Combine(directory, ClientPath);
71+
var process = Process.Start(clientPath, Arguments);
72+
73+
UniLog.Log($"Starting ALXR at: {process.StartInfo.FileName}");
74+
WatchProcess(process);
75+
}
76+
catch
77+
{
78+
UniLog.Log($"Failed to start process at {ClientPath}");
79+
}
80+
}
81+
82+
public void Dispose()
83+
{
84+
_timer.Dispose();
85+
_foundProcess?.Dispose();
86+
}
87+
}

Interface/EyeDevice.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)