diff --git a/resources/js/index.js b/resources/js/index.js index 1d908d1..211fca4 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -1,22 +1,43 @@ +/* global GazeClient */ + import Logger from "./utils/Logger.js"; import StarGazer from "./game/StarGazer.js"; import GazePoint from "./game/GazePoint.js"; +var gclient = new GazeClient(); + function init() { - Logger.enable(); - document.addEventListener("mousemove", onMouseMove); - StarGazer.init({ - canvas: document.querySelector("canvas"), - fps: 60, - width: 800, - height: 800, - }); + Logger.enable(); + initGazeClient(); + initStarGazer(); +} + +function initGazeClient() { + gclient.connect("ws://localhost:8001/gaze"); + gclient.addEventListener("connectionopened", onConnected); + gclient.addEventListener("dataAvailable", onGazeDataAvailable); + gclient.addEventListener("connectionclosed", onDisconnected); +} + +function initStarGazer() { + StarGazer.init({ + canvas: document.querySelector("canvas"), + fps: 60, + width: 800, + height: 800, + }); +} + +function onConnected(event) { + console.log(event); +} + +function onGazeDataAvailable(event) { + console.log(event); } -function onMouseMove(event) { - StarGazer.onGazeUpdate({ - target: new GazePoint(event.screenX, event.screenY), - }); +function onDisconnected(event) { + console.log(event); } init(); \ No newline at end of file