From c843b11c13469e77926872a24c29155ec4bf47cc Mon Sep 17 00:00:00 2001 From: Alexander Bazo Date: Thu, 22 Aug 2019 20:27:11 +0200 Subject: [PATCH] Update demo --- demo/gazeclient.js | 111 --------------------------------------------------------------------------------------------------------------- demo/gazeclient.min.js | 1 + demo/index.html | 2 +- demo/resources/js/index.js | 12 +++++++++++- 4 files changed, 13 insertions(+), 113 deletions(-) delete mode 100644 demo/gazeclient.js create mode 100644 demo/gazeclient.min.js 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 -- libgit2 0.26.0