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
1f751395
authored
Aug 27, 2019
by
Alexander Bazo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error events
parent
403ba4e4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
3 deletions
+27
-3
Readme.md
+1
-0
lib/com/Events.js
+8
-2
lib/com/WebSocketClient.js
+13
-1
lib/index.js
+5
-0
No files found.
Readme.md
View file @
1f751395
...
...
@@ -33,6 +33,7 @@ gclient.connect("ws://localhost:8001/gaze");
|---|---|---|---|
| ConnectionOpenedEvent | connectionclosed | Invoked when client successfully connected to server. | - |
| ConnectionClosedEvent | connectionclosed | Invoked when client lost connection to server. | - |
| ConnectionErrorEvent | erroroccurred | Invoked when an error occurred during server client communication. | - |
| DataEvent | dataavailable | Invoked when new gaze data from eye-tracker is available. | On-display (x,y) coordinates for both eyes |
## Build
...
...
lib/com/Events.js
View file @
1f751395
...
...
@@ -25,4 +25,10 @@ class ConnectionClosedEvent extends Event {
}
}
export
{
DataEvent
,
ConnectionOpenedEvent
,
ConnectionClosedEvent
};
\ No newline at end of file
class
ConnectionErrorEvent
extends
Event
{
constructor
()
{
super
(
"erroroccurred"
);
}
}
export
{
DataEvent
,
ConnectionOpenedEvent
,
ConnectionClosedEvent
,
ConnectionErrorEvent
};
\ No newline at end of file
lib/com/WebSocketClient.js
View file @
1f751395
import
Observable
from
"../utils/Observable.js"
;
import
{
ConnectionOpenedEvent
,
DataEvent
}
from
"./Events.js"
;
import
{
ConnectionOpenedEvent
,
ConnectionClosedEvent
,
ConnectionErrorEvent
,
DataEvent
}
from
"./Events.js"
;
class
WebSocketClient
extends
Observable
{
...
...
@@ -10,6 +10,8 @@ class WebSocketClient extends Observable {
connect
(
url
)
{
this
.
ws
=
new
WebSocket
(
url
);
this
.
ws
.
onopen
=
onOpen
.
bind
(
this
);
this
.
ws
.
onclose
=
onClose
.
bind
(
this
);
this
.
ws
.
onerror
=
onError
.
bind
(
this
);
this
.
ws
.
onmessage
=
onMessage
.
bind
(
this
);
}
...
...
@@ -20,6 +22,16 @@ function onOpen() {
this
.
notifyAll
(
connectionEvent
);
}
function
onClose
()
{
let
connectionEvent
=
new
ConnectionClosedEvent
();
this
.
notifyAll
(
connectionEvent
);
}
function
onError
()
{
let
connectionEvent
=
new
ConnectionErrorEvent
();
this
.
notifyAll
(
connectionEvent
);
}
function
onMessage
(
event
)
{
let
dataEvent
=
new
DataEvent
(
event
.
data
);
this
.
notifyAll
(
dataEvent
);
...
...
lib/index.js
View file @
1f751395
...
...
@@ -12,6 +12,7 @@ class GazeClient extends Observable {
this
.
client
=
new
WebSocketClient
();
this
.
client
.
addEventListener
(
"connectionopened"
,
this
.
onConnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"connectionclosed"
,
this
.
onDisconnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"erroroccurred"
,
this
.
onDisconnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"dataAvailable"
,
this
.
onDataAvailable
.
bind
(
this
));
this
.
client
.
connect
(
url
);
...
...
@@ -25,6 +26,10 @@ class GazeClient extends Observable {
this
.
notifyAll
(
event
);
}
onError
(
event
)
{
this
.
notifyAll
(
event
);
}
onDataAvailable
(
event
)
{
this
.
notifyAll
(
event
);
}
...
...
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