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 ...@@ -11,9 +11,11 @@ namespace GazeWebSocketServer
{ {
private IEyeTracker eyeTracker; private IEyeTracker eyeTracker;
private GazeDataProcessor gazeDataProcessor; private GazeDataProcessor gazeDataProcessor;
private List<GazeCoordinateBehavior> gazeCoordinateBehaviors;
public EyeTrackerClient() public EyeTrackerClient()
{ {
gazeCoordinateBehaviors = new List<GazeCoordinateBehavior>();
while (eyeTracker == null) while (eyeTracker == null)
{ {
EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers(); EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers();
...@@ -26,8 +28,9 @@ namespace GazeWebSocketServer ...@@ -26,8 +28,9 @@ namespace GazeWebSocketServer
eyeTracker.SetGazeOutputFrequency(120f); eyeTracker.SetGazeOutputFrequency(120f);
} }
public void Start() public void Start(GazeCoordinateBehavior gazeCoordinateBehavior)
{ {
gazeCoordinateBehaviors.Add(gazeCoordinateBehavior);
eyeTracker.GazeDataReceived += GazeDataReceivedHandler; eyeTracker.GazeDataReceived += GazeDataReceivedHandler;
} }
...@@ -38,7 +41,12 @@ namespace GazeWebSocketServer ...@@ -38,7 +41,12 @@ namespace GazeWebSocketServer
private void GazeDataReceivedHandler(object sender, GazeDataEventArgs e) 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 ...@@ -8,10 +8,29 @@ namespace GazeWebSocketServer
{ {
public class GazeCoordinateBehavior : WebSocketBehavior 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(); Sessions.Broadcast(gazeData.ToString());
//base.OnOpen();
} }
} }
} }
...@@ -10,14 +10,11 @@ namespace GazeWebSocketServer ...@@ -10,14 +10,11 @@ namespace GazeWebSocketServer
public static void Main(string[] args) public static void Main(string[] args)
{ {
var wssv = new WebSocketServer("ws://localhost:8001"); var wssv = new WebSocketServer("ws://localhost:8001");
wssv.AddWebSocketService<GazeCoordinateBehavior>("/gaze"); wssv.AddWebSocketService("/gaze", () => new GazeCoordinateBehavior());
EyeTrackerClient eyeTrackerClient = new EyeTrackerClient();
eyeTrackerClient.Start();
wssv.Start(); wssv.Start();
Console.ReadKey(true); Console.ReadKey(true);
wssv.Stop(); 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