index.js 1.63 KB
Newer Older
Alexander Bazo committed
1 2 3 4 5 6 7 8 9
/* eslint-env browser */

import Logger from "./utils/Logger.js";
import ImageViewer from "./viewer/ImageViewer.js";
import NetClient from "./com/NetClient.js";
import FakeGazeDataProvider from "./gaze/FakeGazeDataProvider.js";
import GazeDataProvider from "./gaze/GazeDataProvider.js";

const GAZE_SERVER_URL = "ws://localhost:8001/gaze",
10
VIEWER_SERVER_URL = "ws://132.199.139.204:2568";
Alexander Bazo committed
11 12 13 14 15

var starScreen = document.querySelector("#startScreen"),
  stage = document.querySelector("#stage"),
  viewerServerUrl = VIEWER_SERVER_URL,
  useMouseInput = false,
16
  showLocalGazeData = false,
Alexander Bazo committed
17 18 19 20 21 22 23 24 25
  isObserver = false,
  imageViewer;

function init() {
  document.querySelector(".startButton").addEventListener("click", initViewer);
}

function loadOptions() {
  useMouseInput = document.querySelector("#useMouseInput").checked;
26
  showLocalGazeData = document.querySelector("#showLocalGazeData").checked;
Alexander Bazo committed
27 28 29 30 31 32 33 34 35
  isObserver = document.querySelector("#isObserver").checked;
  viewerServerUrl = document.querySelector("#viewerServerUrl").value;
}

function initViewer() {
  let netClient, dataProvider;
  loadOptions();
  netClient = new NetClient(viewerServerUrl);
  dataProvider = getDataProvider();
36
  imageViewer = new ImageViewer(dataProvider, netClient, stage, isObserver, showLocalGazeData);
Alexander Bazo committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  stage.requestFullscreen().then(startViewer);
}

function startViewer() {
  starScreen.classList.add("hidden");
  stage.classList.remove("hidden");
}

function getDataProvider() {
  let provider;
  if (useMouseInput === true) {
    provider = new FakeGazeDataProvider();
  } else {
    provider = new GazeDataProvider();
  }
  provider.start(GAZE_SERVER_URL);
  return provider;
}

init();