index.js 1.1 KB
Newer Older
Alexander Bazo committed
1 2
/* global GazeClient */

Alexander Bazo committed
3 4 5 6
import Logger from "./utils/Logger.js";
import StarGazer from "./game/StarGazer.js";
import GazePoint from "./game/GazePoint.js";

Alexander Bazo committed
7 8
var gclient = new GazeClient();

Alexander Bazo committed
9
function init() {
Alexander Bazo committed
10 11 12 13 14 15 16 17
  Logger.enable();
  initGazeClient();
  initStarGazer();
}

function initGazeClient() {
  gclient.connect("ws://localhost:8001/gaze");
  gclient.addEventListener("connectionopened", onConnected);
18
  gclient.addEventListener("dataavailable", onGazeDataAvailable);
Alexander Bazo committed
19 20 21 22 23 24 25
  gclient.addEventListener("connectionclosed", onDisconnected);
}

function initStarGazer() {
  StarGazer.init({
    canvas: document.querySelector("canvas"),
    fps: 60,
Alexander Bazo committed
26
    showFPS: true,
Alexander Bazo committed
27 28 29 30 31 32 33 34 35 36
    width: 800,
    height: 800,
  });
}

function onConnected(event) {
  console.log(event);
}

function onGazeDataAvailable(event) {
37 38 39 40 41
  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);
Alexander Bazo committed
42 43
}

Alexander Bazo committed
44
function onDisconnected(event) {
Alexander Bazo committed
45
  console.log(	event);
Alexander Bazo committed
46 47 48
}

init();