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 @@ + + + +
+ +