Commit 27325516 by Stefan Schreistetter

Intermediate version. Added functionality to broadcast gaze data to all connected sessions.

parent 82c4433d
......@@ -11,9 +11,11 @@ namespace GazeWebSocketServer
{
private IEyeTracker eyeTracker;
private GazeDataProcessor gazeDataProcessor;
private List<GazeCoordinateBehavior> gazeCoordinateBehaviors;
public EyeTrackerClient()
{
gazeCoordinateBehaviors = new List<GazeCoordinateBehavior>();
while (eyeTracker == null)
{
EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers();
......@@ -26,8 +28,9 @@ namespace GazeWebSocketServer
eyeTracker.SetGazeOutputFrequency(120f);
}
public void Start()
public void Start(GazeCoordinateBehavior gazeCoordinateBehavior)
{
gazeCoordinateBehaviors.Add(gazeCoordinateBehavior);
eyeTracker.GazeDataReceived += GazeDataReceivedHandler;
}
......@@ -38,7 +41,12 @@ namespace GazeWebSocketServer
private void GazeDataReceivedHandler(object sender, GazeDataEventArgs e)
{
Console.WriteLine(gazeDataProcessor.Extract(e).ToString());
GazeData gazeData = gazeDataProcessor.Extract(e);
foreach(GazeCoordinateBehavior behavior in gazeCoordinateBehaviors)
{
behavior.Publish(gazeData);
}
Console.WriteLine(gazeData.ToString());
}
}
}
\ No newline at end of file
......@@ -8,10 +8,29 @@ namespace GazeWebSocketServer
{
public class GazeCoordinateBehavior : WebSocketBehavior
{
protected override void OnOpen()
private EyeTrackerClient eyeTrackerClient;
public GazeCoordinateBehavior()
{
Console.WriteLine("Creating behavior...");
eyeTrackerClient = new EyeTrackerClient();
eyeTrackerClient.Start(this);
}
~GazeCoordinateBehavior()
{
eyeTrackerClient.Stop();
}
//protected override void OnOpen()
//{
// throw new NotImplementedException();
// //base.OnOpen();
//}
internal void Publish(GazeData gazeData)
{
throw new NotImplementedException();
//base.OnOpen();
Sessions.Broadcast(gazeData.ToString());
}
}
}
......@@ -10,14 +10,11 @@ namespace GazeWebSocketServer
public static void Main(string[] args)
{
var wssv = new WebSocketServer("ws://localhost:8001");
wssv.AddWebSocketService<GazeCoordinateBehavior>("/gaze");
EyeTrackerClient eyeTrackerClient = new EyeTrackerClient();
wssv.AddWebSocketService("/gaze", () => new GazeCoordinateBehavior());
eyeTrackerClient.Start();
wssv.Start();
Console.ReadKey(true);
wssv.Stop();
eyeTrackerClient.Stop();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment