Created
July 21, 2017 18:34
-
-
Save ataraxie/451c5cf8f2bccc2687b70b5ddaf15fd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Tobii.Interaction; | |
using WebSocketSharp; | |
using WebSocketSharp.Server; | |
namespace Eyetrack.Runners.WebsocketExample | |
{ | |
class GazeService : WebSocketBehavior | |
{ | |
protected override void OnMessage(MessageEventArgs e) | |
{ | |
Console.WriteLine("Message!!"); | |
} | |
} | |
public class WebsocketRunner : Runner | |
{ | |
static WebSocketServer server; | |
static int gazeCount = 0; | |
static void onGaze(double x, double y, double timestamp) | |
{ | |
gazeCount++; | |
if (gazeCount % 50 == 0) { | |
var coordString = x + "/" + y; | |
Console.WriteLine("Broadcast: " + coordString); | |
server.WebSocketServices["/Gaze"].Sessions.Broadcast(coordString); | |
} | |
} | |
public override void run() | |
{ | |
server = new WebSocketServer("ws://localhost:4000"); | |
server.AddWebSocketService<GazeService>("/Gaze"); | |
server.Start(); | |
var host = new Host(); | |
var gazePointDataStream = host.Streams.CreateGazePointDataStream(); | |
gazePointDataStream.GazePoint(onGaze); | |
Console.ReadKey(); | |
host.DisableConnection(); | |
server.Stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment