index.js 1.51 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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

var starScreen = document.querySelector("#startScreen"),
  stage = document.querySelector("#stage"),
  viewerServerUrl = VIEWER_SERVER_URL,
  useMouseInput = false,
  isObserver = false,
  imageViewer;

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

function loadOptions() {
  useMouseInput = document.querySelector("#useMouseInput").checked;
  isObserver = document.querySelector("#isObserver").checked;
  viewerServerUrl = document.querySelector("#viewerServerUrl").value;
}

function initViewer() {
  let netClient, dataProvider;
  loadOptions();
  netClient = new NetClient(viewerServerUrl);
  dataProvider = getDataProvider();
  imageViewer = new ImageViewer(dataProvider, netClient, stage, isObserver);
  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();