diff --git b/.eslintrc a/.eslintrc new file mode 100644 index 0000000..45054ee --- /dev/null +++ a/.eslintrc @@ -0,0 +1,51 @@ +{ + "parserOptions": { + "sourceType": "module" + }, + "rules": + { + "block-scoped-var": "error", + "camelcase": "warn", + "comma-dangle": ["error", "always-multiline"], + "consistent-return": "error", + "curly": "error", + "default-case": "error", + "eqeqeq": "error", + "guard-for-in": "error", + "no-alert": "error", + "no-console": "warn", + "no-else-return": "error", + "no-empty-function": "error", + "no-eval": "error", + "no-eq-null": "error", + "no-extend-native": "warn", + "no-extra-bind": "error", + "no-loop-func": "error", + "no-magic-numbers": ["warn", {"ignore": [0, 1, -1], "ignoreArrayIndexes": true}], + "no-multiple-empty-lines": ["warn", {"max": 1}], + "no-multi-spaces": "warn", + "no-new": "error", + "no-new-func": "error", + "no-new-wrappers": "error", + "no-unused-expressions": "error", + "no-useless-concat": "error", + "no-undef-init": "error", + "no-underscore-dangle": "error", + "no-param-reassign": "error", + "no-self-compare": "error", + "no-void": "error", + "no-with": "error", + "one-var": "error", + "quotes": ["warn", "double"], + "semi": "error", + "strict": "error", + "vars-on-top": "error", + "yoda": "error" + }, + "env": + { + "es6": true, + "browser": true + }, + "extends": "eslint:recommended" +} \ No newline at end of file diff --git b/.gitignore a/.gitignore new file mode 100644 index 0000000..8f60004 --- /dev/null +++ a/.gitignore @@ -0,0 +1,2 @@ +# node +node_modules \ No newline at end of file diff --git b/.jsbeautifyrc a/.jsbeautifyrc new file mode 100644 index 0000000..c4e26c7 --- /dev/null +++ a/.jsbeautifyrc @@ -0,0 +1,26 @@ +{ +// Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options +"js": { + "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"], + "brace_style": "collapse-preserve-inline", + "break_chained_methods": false, + "e4x": false, + "eol": "\n", + "end_with_newline": false, + "indent_char": " ", + "indent_level": 0, + "indent_size": 2, + "indent_with_tabs": false, + "jslint_happy": false, + "keep_array_indentation": false, + "keep_function_indentation": false, + "max_preserve_newlines": 0, + "preserve_newlines": true, + "space_after_anon_function": false, + "space_before_conditional": true, + "space_in_empty_paren": false, + "space_in_paren": false, + "unescape_strings": false, + "wrap_line_length": 80 + } +} \ No newline at end of file diff --git b/Readme.md a/Readme.md new file mode 100644 index 0000000..f793455 --- /dev/null +++ a/Readme.md @@ -0,0 +1,27 @@ +# GazeClient + +A javascript library to subscribe to local gaze data streams in the OTH/UR Eyetracking Classroom. + +## Usage + +Add the library: + +``` + +``` + +Connect to a running *GazeServer*: + +``` +var gclient = new GazeClient(); +gclient.connect("ws://localhost:8001/gaze"); +``` + + +## Build + +**Prerequisite** + +- node.js + +To build a current version of this library run `npm install` and `npm run build`. The client library is packed with [rollup](https://rollupjs.org/guide/en/) and copied to `build/` and `demo/`. \ No newline at end of file diff --git b/build/gazeclient.js a/build/gazeclient.js new file mode 100644 index 0000000..70ccfc3 --- /dev/null +++ a/build/gazeclient.js @@ -0,0 +1,46 @@ +(function () { + 'use strict'; + + /* eslint-env browser */ + + function onOpen(event) { + this.callback("Connection open"); + } + + function onMessage(event) { + console.log(event); + } + + class WebSocketClient { + + constructor(url, callback) { + this.callback = callback; + this.ws = new WebSocket(url); + this.ws.onopen = onOpen.bind(this); + this.ws.onmessage = onMessage.bind(this); + } + + send(msg) { + this.ws.send(msg); + } + + } + + /* eslint-env browser */ + + class GazeClient { + + connect(url) { + this.url = url; + this.client = new WebSocketClient(url, this.onOpen.bind(this)); + } + + onOpen() { + this.client.send("hello server"); + } + + } + + window.GazeClient = GazeClient; + +}()); diff --git b/demo/gazeclient.js a/demo/gazeclient.js new file mode 100644 index 0000000..70ccfc3 --- /dev/null +++ a/demo/gazeclient.js @@ -0,0 +1,46 @@ +(function () { + 'use strict'; + + /* eslint-env browser */ + + function onOpen(event) { + this.callback("Connection open"); + } + + function onMessage(event) { + console.log(event); + } + + class WebSocketClient { + + constructor(url, callback) { + this.callback = callback; + this.ws = new WebSocket(url); + this.ws.onopen = onOpen.bind(this); + this.ws.onmessage = onMessage.bind(this); + } + + send(msg) { + this.ws.send(msg); + } + + } + + /* eslint-env browser */ + + class GazeClient { + + connect(url) { + this.url = url; + this.client = new WebSocketClient(url, this.onOpen.bind(this)); + } + + onOpen() { + this.client.send("hello server"); + } + + } + + window.GazeClient = GazeClient; + +}()); diff --git b/demo/index.html a/demo/index.html new file mode 100644 index 0000000..f7003b7 --- /dev/null +++ a/demo/index.html @@ -0,0 +1,20 @@ + + + + + + GazeClient + + + + +
+

GazeClient

+
+ + + + + + + diff --git b/demo/resources/css/default.css a/demo/resources/css/default.css new file mode 100644 index 0000000..e69de29 --- /dev/null +++ a/demo/resources/css/default.css diff --git b/demo/resources/js/index.js a/demo/resources/js/index.js new file mode 100644 index 0000000..6b8554c --- /dev/null +++ a/demo/resources/js/index.js @@ -0,0 +1,6 @@ +/* eslint-env browser */ +/* global GazeClient */ + +var gclient = new GazeClient(); +gclient.connect("ws://localhost:8001/gaze"); +// gclient.send("Hello World"); \ No newline at end of file diff --git b/lib/WebSocketClient.js a/lib/WebSocketClient.js new file mode 100644 index 0000000..3735116 --- /dev/null +++ a/lib/WebSocketClient.js @@ -0,0 +1,26 @@ +/* eslint-env browser */ + +function onOpen(event) { + this.callback("Connection open"); +} + +function onMessage(event) { + console.log(event); +} + +class WebSocketClient { + + constructor(url, callback) { + this.callback = callback; + this.ws = new WebSocket(url); + this.ws.onopen = onOpen.bind(this); + this.ws.onmessage = onMessage.bind(this); + } + + send(msg) { + this.ws.send(msg); + } + +} + +export default WebSocketClient; \ No newline at end of file diff --git b/lib/index.js a/lib/index.js new file mode 100644 index 0000000..b43a9db --- /dev/null +++ a/lib/index.js @@ -0,0 +1,18 @@ +/* eslint-env browser */ + +import WebSocketClient from "./WebSocketClient.js"; + +class GazeClient { + + connect(url) { + this.url = url; + this.client = new WebSocketClient(url, this.onOpen.bind(this)); + } + + onOpen() { + this.client.send("hello server"); + } + +} + +window.GazeClient = GazeClient; \ No newline at end of file diff --git b/package-lock.json a/package-lock.json new file mode 100644 index 0000000..e3ce404 --- /dev/null +++ a/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "gazeclient", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, + "@types/node": { + "version": "12.7.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.2.tgz", + "integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==", + "dev": true + }, + "acorn": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", + "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", + "dev": true + }, + "rollup": { + "version": "1.19.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.19.4.tgz", + "integrity": "sha512-G24w409GNj7i/Yam2cQla6qV2k6Nug8bD2DZg9v63QX/cH/dEdbNJg8H4lUm5M1bRpPKRUC465Rm9H51JTKOfQ==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "@types/node": "^12.6.9", + "acorn": "^6.2.1" + } + } + } +} diff --git b/package.json a/package.json new file mode 100644 index 0000000..3d7feb5 --- /dev/null +++ a/package.json @@ -0,0 +1,16 @@ +{ + "name": "gazeclient", + "version": "1.0.0", + "description": "A javascript client to subscribe to gaze data streams over websocket", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "rollup lib/index.js --format iife --name \"gazeclient\" --file build/gazeclient.js", + "postbuild": "cp build/gazeclient.js demo/gazeclient.js" + }, + "author": "Alexander Bazo ", + "license": "MIT", + "devDependencies": { + "rollup": "^1.19.4" + } +}