Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Eye-Tracking Classroom
/
gaze-client.js
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a944faf0
authored
Aug 20, 2019
by
Alexander Bazo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add observer interface to GazeClient
parent
1acd0be3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
295 additions
and
78 deletions
+295
-78
Readme.md
+10
-0
build/gazeclient.js
+95
-30
demo/gazeclient.js
+95
-30
demo/resources/js/index.js
+6
-2
lib/Events.js
+0
-0
lib/Observable.js
+38
-0
lib/WebSocketClient.js
+31
-14
lib/index.js
+20
-2
No files found.
Readme.md
View file @
a944faf0
...
...
@@ -17,6 +17,16 @@ var gclient = new GazeClient();
gclient.connect("ws://localhost:8001/gaze");
```
Subscribe to gaze events:
```
gclient.addEventListener("gazeDataAvailable", onGazeDataAvailable);
function onGazeDataAvailable(event) {
console.log(event);
}
```
## Build
...
...
build/gazeclient.js
View file @
a944faf0
(
function
()
{
'use strict'
;
'use strict'
;
/* eslint-env browser */
/* eslint-env browser */
function
onOpen
(
event
)
{
this
.
callback
(
"Connection open"
);
}
class
Event
{
function
onMessage
(
event
)
{
console
.
log
(
event
);
}
constructor
(
type
,
data
)
{
this
.
type
=
type
;
this
.
data
=
data
;
}
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
);
}
class
Observable
{
send
(
msg
)
{
this
.
ws
.
send
(
msg
)
;
}
constructor
(
)
{
this
.
listeners
=
{}
;
}
}
addEventListener
(
type
,
callback
)
{
if
(
this
.
listeners
[
type
]
===
undefined
)
{
this
.
listeners
[
type
]
=
[];
}
this
.
listeners
[
type
].
push
(
callback
);
}
/* eslint-env browser */
notifyAll
(
event
)
{
let
listeners
=
this
.
listeners
[
event
.
type
];
if
(
listeners
)
{
for
(
let
i
=
0
;
i
<
listeners
.
length
;
i
++
)
{
listeners
[
i
](
event
);
}
}
}
class
GazeClient
{
}
connect
(
url
)
{
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
(
url
,
this
.
onOpen
.
bind
(
this
));
}
/* eslint-env browser */
onOpen
()
{
this
.
client
.
send
(
"hello server"
);
}
class
GazeDataEvent
extends
Event
{
constructor
(
data
)
{
super
(
"gazeDataAvailable"
,
data
);
}
}
}
class
ConnectionEvent
extends
Event
{
constructor
()
{
super
(
"connected"
);
}
}
window
.
GazeClient
=
GazeClient
;
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
);
}
/* eslint-env browser */
class
GazeClient
extends
Observable
{
constructor
()
{
super
();
}
connect
(
url
)
{
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
();
this
.
client
.
addEventListener
(
"connected"
,
this
.
onConnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"gazeDataAvailable"
,
this
.
onGazeDataAvailable
.
bind
(
this
));
this
.
client
.
connect
(
url
);
}
onOpen
()
{
this
.
client
.
send
(
"hello server"
);
}
onConnected
(
event
)
{
// TODO: Implement event broadcasting
}
onGazeDataAvailable
(
event
)
{
this
.
notifyAll
(
event
);
}
}
window
.
GazeClient
=
GazeClient
;
}());
demo/gazeclient.js
View file @
a944faf0
(
function
()
{
'use strict'
;
'use strict'
;
/* eslint-env browser */
/* eslint-env browser */
function
onOpen
(
event
)
{
this
.
callback
(
"Connection open"
);
}
class
Event
{
function
onMessage
(
event
)
{
console
.
log
(
event
);
}
constructor
(
type
,
data
)
{
this
.
type
=
type
;
this
.
data
=
data
;
}
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
);
}
class
Observable
{
send
(
msg
)
{
this
.
ws
.
send
(
msg
)
;
}
constructor
(
)
{
this
.
listeners
=
{}
;
}
}
addEventListener
(
type
,
callback
)
{
if
(
this
.
listeners
[
type
]
===
undefined
)
{
this
.
listeners
[
type
]
=
[];
}
this
.
listeners
[
type
].
push
(
callback
);
}
/* eslint-env browser */
notifyAll
(
event
)
{
let
listeners
=
this
.
listeners
[
event
.
type
];
if
(
listeners
)
{
for
(
let
i
=
0
;
i
<
listeners
.
length
;
i
++
)
{
listeners
[
i
](
event
);
}
}
}
class
GazeClient
{
}
connect
(
url
)
{
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
(
url
,
this
.
onOpen
.
bind
(
this
));
}
/* eslint-env browser */
onOpen
()
{
this
.
client
.
send
(
"hello server"
);
}
class
GazeDataEvent
extends
Event
{
constructor
(
data
)
{
super
(
"gazeDataAvailable"
,
data
);
}
}
}
class
ConnectionEvent
extends
Event
{
constructor
()
{
super
(
"connected"
);
}
}
window
.
GazeClient
=
GazeClient
;
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
);
}
/* eslint-env browser */
class
GazeClient
extends
Observable
{
constructor
()
{
super
();
}
connect
(
url
)
{
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
();
this
.
client
.
addEventListener
(
"connected"
,
this
.
onConnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"gazeDataAvailable"
,
this
.
onGazeDataAvailable
.
bind
(
this
));
this
.
client
.
connect
(
url
);
}
onOpen
()
{
this
.
client
.
send
(
"hello server"
);
}
onConnected
(
event
)
{
// TODO: Implement event broadcasting
}
onGazeDataAvailable
(
event
)
{
this
.
notifyAll
(
event
);
}
}
window
.
GazeClient
=
GazeClient
;
}());
demo/resources/js/index.js
View file @
a944faf0
...
...
@@ -3,4 +3,8 @@
var
gclient
=
new
GazeClient
();
gclient
.
connect
(
"ws://localhost:8001/gaze"
);
// gclient.send("Hello World");
\ No newline at end of file
gclient
.
addEventListener
(
"gazeDataAvailable"
,
onGazeDataAvailable
);
function
onGazeDataAvailable
(
event
)
{
console
.
log
(
event
);
}
\ No newline at end of file
lib/Events.js
0 → 100644
View file @
a944faf0
lib/Observable.js
0 → 100644
View file @
a944faf0
/* 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
lib/WebSocketClient.js
View file @
a944faf0
/* eslint-env browser */
function
onOpen
(
event
)
{
this
.
callback
(
"Connection open"
);
import
{
Observable
,
Event
}
from
"./Observable.js"
;
class
GazeDataEvent
extends
Event
{
constructor
(
data
)
{
super
(
"gazeDataAvailable"
,
data
);
}
}
function
onMessage
(
event
)
{
console
.
log
(
event
);
class
ConnectionEvent
extends
Event
{
constructor
()
{
super
(
"connected"
);
}
}
class
WebSocketClient
{
class
WebSocketClient
extends
Observable
{
constructor
()
{
super
();
}
connect
(
url
)
{
constructor
(
url
,
callback
)
{
this
.
callback
=
callback
;
this
.
ws
=
new
WebSocket
(
url
);
this
.
ws
.
onopen
=
onOpen
.
bind
(
this
);
this
.
ws
.
onmessage
=
onMessage
.
bind
(
this
);
}
this
.
ws
=
new
WebSocket
(
url
);
this
.
ws
.
onopen
=
onOpen
.
bind
(
this
);
this
.
ws
.
onmessage
=
onMessage
.
bind
(
this
);
}
send
(
msg
)
{
this
.
ws
.
send
(
msg
);
}
}
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
lib/index.js
View file @
a944faf0
/* eslint-env browser */
import
{
Event
,
Observable
}
from
"./Observable.js"
;
import
WebSocketClient
from
"./WebSocketClient.js"
;
class
GazeClient
{
class
GazeClient
extends
Observable
{
constructor
()
{
super
();
}
connect
(
url
)
{
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
(
url
,
this
.
onOpen
.
bind
(
this
));
this
.
client
=
new
WebSocketClient
();
this
.
client
.
addEventListener
(
"connected"
,
this
.
onConnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"gazeDataAvailable"
,
this
.
onGazeDataAvailable
.
bind
(
this
));
this
.
client
.
connect
(
url
);
}
onOpen
()
{
this
.
client
.
send
(
"hello server"
);
}
onConnected
(
event
)
{
// TODO: Implement event broadcasting
}
onGazeDataAvailable
(
event
)
{
this
.
notifyAll
(
event
);
}
}
window
.
GazeClient
=
GazeClient
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment