Commit 51bd5294 by Alexander Bazo

Add new library version

parent bc52d6c7
// GazeClient Version 1.0 - [https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-client.js]
(function () {
'use strict';
/* eslint-env browser */
class Event {
constructor(type, data) {
this.type = type;
this.data = data;
}
}
class Observable {
constructor() {
......@@ -36,17 +26,24 @@
}
/* eslint-env browser */
class Event {
constructor(type, data) {
this.type = type;
this.data = data;
}
}
class GazeDataEvent extends Event {
class DataEvent extends Event {
constructor(data) {
super("gazeDataAvailable", data);
super("dataavailable", data);
}
}
class ConnectionEvent extends Event {
class ConnectionOpenedEvent extends Event {
constructor() {
super("connected");
super("connectionopened");
}
}
......@@ -57,7 +54,6 @@
}
connect(url) {
this.ws = new WebSocket(url);
this.ws.onopen = onOpen.bind(this);
this.ws.onmessage = onMessage.bind(this);
......@@ -66,17 +62,15 @@
}
function onOpen() {
let connectionEvent = new ConnectionEvent();
let connectionEvent = new ConnectionOpenedEvent();
this.notifyAll(connectionEvent);
}
function onMessage(event) {
let gazeEvent = new GazeDataEvent(event.data);
this.notifyAll(gazeEvent);
let dataEvent = new DataEvent(event.data);
this.notifyAll(dataEvent);
}
/* eslint-env browser */
class GazeClient extends Observable {
constructor() {
......@@ -86,21 +80,22 @@
connect(url) {
this.url = url;
this.client = new WebSocketClient();
this.client.addEventListener("connected", this.onConnected.bind(this));
this.client.addEventListener("gazeDataAvailable", this.onGazeDataAvailable
this.client.addEventListener("connectionopened", this.onConnected.bind(this));
this.client.addEventListener("connectionclosed", this.onDisconnected.bind(this));
this.client.addEventListener("dataAvailable", this.onDataAvailable
.bind(this));
this.client.connect(url);
}
onOpen() {
this.client.send("hello server");
onConnected(event) {
this.notifyAll(event);
}
onConnected(event) {
// TODO: Implement event broadcasting
onDisconnected(event) {
this.notifyAll(event);
}
onGazeDataAvailable(event) {
onDataAvailable(event) {
this.notifyAll(event);
}
......@@ -109,3 +104,4 @@
window.GazeClient = GazeClient;
}());
//# sourceMappingURL=gazeclient.js.map
{"version":3,"file":"gazeclient.js","sources":["../lib/utils/Observable.js","../lib/com/Events.js","../lib/com/WebSocketClient.js","../lib/index.js"],"sourcesContent":["class Observable {\r\n\r\n constructor() {\r\n this.listeners = {};\r\n }\r\n\r\n addEventListener(type, callback) {\r\n if (this.listeners[type] === undefined) {\r\n this.listeners[type] = [];\r\n }\r\n this.listeners[type].push(callback);\r\n }\r\n\r\n notifyAll(event) {\r\n let listeners = this.listeners[event.type];\r\n if (listeners) {\r\n for (let i = 0; i < listeners.length; i++) {\r\n listeners[i](event);\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\nexport default Observable;","class Event {\r\n\r\n constructor(type, data) {\r\n this.type = type;\r\n this.data = data;\r\n }\r\n\r\n}\r\n\r\nclass DataEvent extends Event {\r\n constructor(data) {\r\n super(\"dataavailable\", data);\r\n }\r\n}\r\n\r\nclass ConnectionOpenedEvent extends Event {\r\n constructor() {\r\n super(\"connectionopened\");\r\n }\r\n}\r\n\r\nclass ConnectionClosedEvent extends Event {\r\n constructor() {\r\n super(\"connectionclosed\");\r\n }\r\n}\r\n\r\nexport {DataEvent, ConnectionOpenedEvent, ConnectionClosedEvent};","import Observable from \"../utils/Observable.js\";\r\nimport { ConnectionOpenedEvent, DataEvent } from \"./Events.js\";\r\n\r\nclass WebSocketClient extends Observable {\r\n\r\n constructor() {\r\n super();\r\n }\r\n\r\n connect(url) {\r\n this.ws = new WebSocket(url);\r\n this.ws.onopen = onOpen.bind(this);\r\n this.ws.onmessage = onMessage.bind(this);\r\n }\r\n\r\n}\r\n\r\nfunction onOpen() {\r\n let connectionEvent = new ConnectionOpenedEvent();\r\n this.notifyAll(connectionEvent);\r\n}\r\n\r\nfunction onMessage(event) {\r\n let dataEvent = new DataEvent(event.data);\r\n this.notifyAll(dataEvent);\r\n}\r\n\r\nexport default WebSocketClient;","import Observable from \"./utils/Observable.js\";\r\nimport WebSocketClient from \"./com/WebSocketClient.js\";\r\n\r\nclass GazeClient extends Observable {\r\n\r\n constructor() {\r\n super();\r\n }\r\n\r\n connect(url) {\r\n this.url = url;\r\n this.client = new WebSocketClient();\r\n this.client.addEventListener(\"connectionopened\", this.onConnected.bind(this));\r\n this.client.addEventListener(\"connectionclosed\", this.onDisconnected.bind(this));\r\n this.client.addEventListener(\"dataAvailable\", this.onDataAvailable\r\n .bind(this));\r\n this.client.connect(url);\r\n }\r\n\r\n onConnected(event) {\r\n this.notifyAll(event);\r\n }\r\n\r\n onDisconnected(event) {\r\n this.notifyAll(event);\r\n }\r\n\r\n onDataAvailable(event) {\r\n this.notifyAll(event);\r\n }\r\n\r\n}\r\n\r\nwindow.GazeClient = GazeClient;"],"names":[],"mappings":";;;;EAAA,MAAM,UAAU,CAAC;;EAEjB,EAAE,WAAW,GAAG;EAChB,IAAI,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;EACxB,GAAG;;EAEH,EAAE,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE;EACnC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE;EAC5C,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;EAChC,KAAK;EACL,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;EACxC,GAAG;;EAEH,EAAE,SAAS,CAAC,KAAK,EAAE;EACnB,IAAI,IAAI,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;EAC/C,IAAI,IAAI,SAAS,EAAE;EACnB,MAAM,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;EACjD,QAAQ,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;EAC5B,OAAO;EACP,KAAK;EACL,GAAG;;EAEH,CAAC;;ECtBD,MAAM,KAAK,CAAC;;EAEZ,EAAE,WAAW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pC,EAAE,WAAW,GAAG;EAChB,IAAI,KAAK,EAAE,CAAC;EACZ,GAAG;;EAEH,EAAE,OAAO,CAAC,GAAG,EAAE;EACf,IAAI,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;EACnB,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;EACxC,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;EAClF,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;EACrF,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,eAAe,EAAE,IAAI,CAAC,eAAe;EACtE,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;EACnB,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;EAC7B,GAAG;;EAEH,EAAE,WAAW,CAAC,KAAK,EAAE;EACrB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;EAC1B,GAAG;;EAEH,EAAE,cAAc,CAAC,KAAK,EAAE;EACxB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;EAC1B,GAAG;;EAEH,EAAE,eAAe,CAAC,KAAK,EAAE;EACzB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;EAC1B,GAAG;;EAEH,CAAC;;EAED,MAAM,CAAC,UAAU,GAAG,UAAU;;;;"}
\ No newline at end of file
(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<listeners.length;i++){listeners[i](event)}}}}class Event{constructor(type,data){this.type=type;this.data=data}}class DataEvent extends Event{constructor(data){super("dataavailable",data)}}class ConnectionOpenedEvent extends Event{constructor(){super("connectionopened")}}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 ConnectionOpenedEvent;this.notifyAll(connectionEvent)}function onMessage(event){let dataEvent=new DataEvent(event.data);this.notifyAll(dataEvent)}class GazeClient extends Observable{constructor(){super()}connect(url){this.url=url;this.client=new WebSocketClient;this.client.addEventListener("connectionopened",this.onConnected.bind(this));this.client.addEventListener("connectionclosed",this.onDisconnected.bind(this));this.client.addEventListener("dataAvailable",this.onDataAvailable.bind(this));this.client.connect(url)}onConnected(event){this.notifyAll(event)}onDisconnected(event){this.notifyAll(event)}onDataAvailable(event){this.notifyAll(event)}}window.GazeClient=GazeClient})();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment