Commit 512fc907 by Alexander Bazo

Connect gaze data with game client

parent f4dd1493
class GazePoint { class GazePoint {
constructor(screenX, screenY, id) { constructor(screenX, screenY, createdAt, id) {
this.screenX = screenX; this.screenX = screenX;
this.screenY = screenY; this.screenY = screenY;
this.createdAt = Date.now(); this.createdAt = createdAt;
this.id = id || this.createdAt; this.id = id || this.createdAt;
} }
......
...@@ -15,10 +15,10 @@ class StarGazer { ...@@ -15,10 +15,10 @@ class StarGazer {
gm.start(); gm.start();
} }
onGazeUpdate(gazeUpdate) { onGazeUpdate(gazePoint) {
gazeUpdate.target.linkTo(canvas); gazePoint.linkTo(canvas);
if(gazeUpdate.target.hasLink) { if(gazePoint.hasLink) {
gm.addGazePoint(gazeUpdate.target); gm.addGazePoint(gazePoint);
} }
} }
......
...@@ -15,7 +15,7 @@ function init() { ...@@ -15,7 +15,7 @@ function init() {
function initGazeClient() { function initGazeClient() {
gclient.connect("ws://localhost:8001/gaze"); gclient.connect("ws://localhost:8001/gaze");
gclient.addEventListener("connectionopened", onConnected); gclient.addEventListener("connectionopened", onConnected);
gclient.addEventListener("dataAvailable", onGazeDataAvailable); gclient.addEventListener("dataavailable", onGazeDataAvailable);
gclient.addEventListener("connectionclosed", onDisconnected); gclient.addEventListener("connectionclosed", onDisconnected);
} }
...@@ -33,7 +33,11 @@ function onConnected(event) { ...@@ -33,7 +33,11 @@ function onConnected(event) {
} }
function onGazeDataAvailable(event) { function onGazeDataAvailable(event) {
console.log(event); let eyeX = (event.data.leftEyeX + event.data.rightEyeX) / 2,
eyeY = (event.data.leftEyeY + event.data.rightEyeY) / 2,
createdAt = event.data.trackerTimeStamp,
gazePoint = new GazePoint(eyeX, eyeY, createdAt);
StarGazer.onGazeUpdate(gazePoint);
} }
function onDisconnected(event) { function onDisconnected(event) {
......
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