index.js 893 Bytes
Newer Older
Alexander Bazo committed
1 2
import Observable from "./utils/Observable.js";
import WebSocketClient from "./com/WebSocketClient.js";
Alexander Bazo committed
3

4 5 6 7 8
class GazeClient extends Observable {

  constructor() {
    super();
  }
Alexander Bazo committed
9 10 11

  connect(url) {
    this.url = url;
12
    this.client = new WebSocketClient();
Alexander Bazo committed
13 14
    this.client.addEventListener("connectionopened", this.onConnected.bind(this));
    this.client.addEventListener("connectionclosed", this.onDisconnected.bind(this));
Alexander Bazo committed
15
    this.client.addEventListener("erroroccurred", this.onDisconnected.bind(this));
16
    this.client.addEventListener("dataavailable", this.onDataAvailable
17 18
      .bind(this));
    this.client.connect(url);
Alexander Bazo committed
19 20
  }

Alexander Bazo committed
21 22
  onConnected(event) {
    this.notifyAll(event);
Alexander Bazo committed
23 24
  }

Alexander Bazo committed
25 26
  onDisconnected(event) {
    this.notifyAll(event);
27 28
  }

Alexander Bazo committed
29 30 31 32
  onError(event) {
    this.notifyAll(event);
  }

Alexander Bazo committed
33
  onDataAvailable(event) {
34 35 36
    this.notifyAll(event);
  }

Alexander Bazo committed
37 38 39
}

window.GazeClient = GazeClient;