Commit 403ba4e4 by Alexander Bazo

Remove old file versions

parent 51c3f50f
/* 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);
}
}
}
}
export default Observable;
export { Event, Observable };
\ No newline at end of file
/* eslint-env browser */
import { Observable, Event } from "./Observable.js";
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);
}
export default WebSocketClient;
\ 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