index.js 759 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 15
    this.client.addEventListener("connectionopened", this.onConnected.bind(this));
    this.client.addEventListener("connectionclosed", this.onDisconnected.bind(this));
    this.client.addEventListener("dataAvailable", this.onDataAvailable
16 17
      .bind(this));
    this.client.connect(url);
Alexander Bazo committed
18 19
  }

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

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

Alexander Bazo committed
28
  onDataAvailable(event) {
29 30 31
    this.notifyAll(event);
  }

Alexander Bazo committed
32 33 34
}

window.GazeClient = GazeClient;