I have this sample C#
code that connects to the EyeX engine of the Tobii EyeX eye tracking device, subscribes to a gaze data stream and writes the result to the console.
var eyeXHost = new EyeXHost();
var stream = eyeXHost.CreateGazePointDataStream(GazePointDataMode.LightlyFiltered);
eyeXHost.Start();
stream.Next += (s, e) => Console.WriteLine("Gaze point at ({0:0.0}, {1:0.0}) @{2:0}", e.X, e.Y, e.Timestamp);
Console.In.Read();
I'm calling this code from a Node.js script with the help of Edge.js. I was able to get it to work but I found that I had to modify the code in ways that I don't fully understand.
var eyeXHost = new EyeXHost();
var stream = eyeXHost.CreateGazePointDataStream(GazePointDataMode.LightlyFiltered);
await Task.Run(() => eyeXHost.Start());
stream.Next += async (s, e) => {
await onGazePoint(new GazePoint(e.X, e.Y, e.Timestamp));
};
Namely, I had to wrap eyeXHost.Start()
in an await Task.Run()
call. Otherwise, the thread seems to block and no gaze data is received. I also had to add async await
to the stream event handler.
Why was it necessary to do this?