diff --git a/demo/gazeclient.js b/demo/gazeclient.js deleted file mode 100644 index 01f52e0..0000000 --- a/demo/gazeclient.js +++ /dev/null @@ -1,111 +0,0 @@ -(function () { - 'use strict'; - - /* eslint-env browser */ - - class Event { - - constructor(type, data) { - this.type = type; - this.data = data; - } - - } - - class Observable { - - constructor() { - this.listeners = {}; - } - - addEventListener(type, callback) { - if (this.listeners[type] === undefined) { - this.listeners[type] = []; - } - this.listeners[type].push(callback); - } - - notifyAll(event) { - let listeners = this.listeners[event.type]; - if (listeners) { - for (let i = 0; i < listeners.length; i++) { - listeners[i](event); - } - } - } - - } - - /* eslint-env browser */ - - class GazeDataEvent extends Event { - constructor(data) { - super("gazeDataAvailable", data); - } - } - - class ConnectionEvent extends Event { - constructor() { - super("connected"); - } - } - - class WebSocketClient extends Observable { - - constructor() { - super(); - } - - connect(url) { - - this.ws = new WebSocket(url); - this.ws.onopen = onOpen.bind(this); - this.ws.onmessage = onMessage.bind(this); - } - - } - - function onOpen() { - let connectionEvent = new ConnectionEvent(); - this.notifyAll(connectionEvent); - } - - function onMessage(event) { - let gazeEvent = new GazeDataEvent(event.data); - this.notifyAll(gazeEvent); - } - - /* eslint-env browser */ - - class GazeClient extends Observable { - - constructor() { - super(); - } - - connect(url) { - this.url = url; - this.client = new WebSocketClient(); - this.client.addEventListener("connected", this.onConnected.bind(this)); - this.client.addEventListener("gazeDataAvailable", this.onGazeDataAvailable - .bind(this)); - this.client.connect(url); - } - - onOpen() { - this.client.send("hello server"); - } - - onConnected(event) { - // TODO: Implement event broadcasting - } - - onGazeDataAvailable(event) { - this.notifyAll(event); - } - - } - - window.GazeClient = GazeClient; - -}()); diff --git a/demo/gazeclient.min.js b/demo/gazeclient.min.js new file mode 100644 index 0000000..a3b182d --- /dev/null +++ b/demo/gazeclient.min.js @@ -0,0 +1 @@ +(function(){"use strict";class Observable{constructor(){this.listeners={}}addEventListener(type,callback){if(this.listeners[type]===undefined){this.listeners[type]=[]}this.listeners[type].push(callback)}notifyAll(event){let listeners=this.listeners[event.type];if(listeners){for(let i=0;i - + diff --git a/demo/resources/js/index.js b/demo/resources/js/index.js index cc57c45..15c9653 100644 --- a/demo/resources/js/index.js +++ b/demo/resources/js/index.js @@ -3,8 +3,18 @@ var gclient = new GazeClient(); gclient.connect("ws://localhost:8001/gaze"); -gclient.addEventListener("gazeDataAvailable", onGazeDataAvailable); +gclient.addEventListener("connectionopened", onConnected); +gclient.addEventListener("dataAvailable", onGazeDataAvailable); +gclient.addEventListener("connectionclosed", onDisconnected); + +function onConnected(event) { + console.log(event); +} function onGazeDataAvailable(event) { console.log(event); +} + +function onDisconnected(event) { + console.log(event); } \ No newline at end of file