index.js 718 Bytes
Newer Older
Alexander Bazo committed
1 2
/* eslint-env browser */

3
import { Event, Observable } from "./Observable.js";
Alexander Bazo committed
4 5
import WebSocketClient from "./WebSocketClient.js";

6 7 8 9 10
class GazeClient extends Observable {

  constructor() {
    super();
  }
Alexander Bazo committed
11 12 13

  connect(url) {
    this.url = url;
14 15 16 17 18
    this.client = new WebSocketClient();
    this.client.addEventListener("connected", this.onConnected.bind(this));
    this.client.addEventListener("gazeDataAvailable", this.onGazeDataAvailable
      .bind(this));
    this.client.connect(url);
Alexander Bazo committed
19 20 21 22 23 24
  }

  onOpen() {
    this.client.send("hello server");
  }

25 26 27 28 29 30 31 32
  onConnected(event) {
    // TODO: Implement event broadcasting
  }

  onGazeDataAvailable(event) {
    this.notifyAll(event);
  }

Alexander Bazo committed
33 34 35
}

window.GazeClient = GazeClient;