gazeclient.js 697 Bytes
Newer Older
Alexander Bazo committed
1 2 3 4 5 6 7 8 9 10 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
(function () {
	'use strict';

	/* eslint-env browser */

	function onOpen(event) {
		this.callback("Connection open");
	}

	function onMessage(event) {
		console.log(event);
	}

	class WebSocketClient {

		constructor(url, callback) {
			this.callback = callback;
			this.ws = new WebSocket(url);
			this.ws.onopen = onOpen.bind(this);
			this.ws.onmessage = onMessage.bind(this);
		}

		send(msg) {
			this.ws.send(msg);
		}

	}

	/* eslint-env browser */

	class GazeClient {

	  connect(url) {
	    this.url = url;
	    this.client = new WebSocketClient(url, this.onOpen.bind(this));
	  }

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

	}

	window.GazeClient = GazeClient;

}());