From b85597720e952140f2c291fc89fa13e760ecda98 Mon Sep 17 00:00:00 2001 From: Alexander Bazo Date: Tue, 27 Aug 2019 13:23:57 +0200 Subject: [PATCH] Add GazeData object and parsing --- lib/com/WebSocketClient.js | 7 +++++-- lib/data/GazeData.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib/data/GazeData.js diff --git a/lib/com/WebSocketClient.js b/lib/com/WebSocketClient.js index e58a60d..3691ca7 100644 --- a/lib/com/WebSocketClient.js +++ b/lib/com/WebSocketClient.js @@ -1,5 +1,7 @@ import Observable from "../utils/Observable.js"; -import { ConnectionOpenedEvent, ConnectionClosedEvent, ConnectionErrorEvent, DataEvent } from "./Events.js"; +import { ConnectionOpenedEvent, ConnectionClosedEvent, ConnectionErrorEvent, + DataEvent } from "./Events.js"; +import GazeData from "../data/GazeData.js"; class WebSocketClient extends Observable { @@ -33,7 +35,8 @@ function onError() { } function onMessage(event) { - let dataEvent = new DataEvent(event.data); + let data = GazeData.fromDataString(event.data), + dataEvent = new DataEvent(data); this.notifyAll(dataEvent); } diff --git a/lib/data/GazeData.js b/lib/data/GazeData.js new file mode 100644 index 0000000..76f8a2a --- /dev/null +++ b/lib/data/GazeData.js @@ -0,0 +1,21 @@ +const DATA_SEPERATOR = ";"; + +class GazeData { + constructor(leftEyeX, leftEyeY, rightEyeX, rightEyeY, trackerTimeStamp, + systemTimeStamp) { + this.leftEyeX = leftEyeX; + this.leftEyeY = leftEyeY; + this.rightEyeX = rightEyeX; + this.rightEyeY = rightEyeY; + this.trackerTimeStamp = trackerTimeStamp; + this.systemTimeStamp = systemTimeStamp; + } + + static fromDataString(dataString) { + let dataValues = dataString.split(DATA_SEPERATOR); + return new GazeData(dataValues[0], dataValues[1], dataValues[2], + dataValues[3], dataValues[4], dataValues[5]); + } +} + +export default GazeData; \ No newline at end of file -- libgit2 0.26.0