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
c843b11c
authored
Aug 22, 2019
by
Alexander Bazo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update demo
parent
1871d8b6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
113 deletions
+15
-113
demo/gazeclient.js
+0
-111
demo/gazeclient.min.js
+2
-0
demo/index.html
+1
-1
demo/resources/js/index.js
+12
-1
No files found.
demo/gazeclient.js
deleted
100644 → 0
View file @
1871d8b6
(
function
()
{
'use strict'
;
/* 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
);
}
}
}
}
/* eslint-env browser */
class
GazeDataEvent
extends
Event
{
constructor
(
data
)
{
super
(
"gazeDataAvailable"
,
data
);
}
}
class
ConnectionEvent
extends
Event
{
constructor
()
{
super
(
"connected"
);
}
}
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.min.js
0 → 100644
View file @
c843b11c
(
function
(){
"use strict"
;
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
)}}}}
class
Event
{
constructor
(
type
,
data
){
this
.
type
=
type
;
this
.
data
=
data
}}
class
DataEvent
extends
Event
{
constructor
(
data
){
super
(
"dataavailable"
,
data
)}}
class
ConnectionOpenedEvent
extends
Event
{
constructor
(){
super
(
"connectionopened"
)}}
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
ConnectionOpenedEvent
;
this
.
notifyAll
(
connectionEvent
)}
function
onMessage
(
event
){
let
dataEvent
=
new
DataEvent
(
event
.
data
);
this
.
notifyAll
(
dataEvent
)}
class
GazeClient
extends
Observable
{
constructor
(){
super
()}
connect
(
url
){
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
;
this
.
client
.
addEventListener
(
"connectionopened"
,
this
.
onConnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"connectionclosed"
,
this
.
onDisconnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"dataAvailable"
,
this
.
onDataAvailable
.
bind
(
this
));
this
.
client
.
connect
(
url
)}
onConnected
(
event
){
this
.
notifyAll
(
event
)}
onDisconnected
(
event
){
this
.
notifyAll
(
event
)}
onDataAvailable
(
event
){
this
.
notifyAll
(
event
)}}
window
.
GazeClient
=
GazeClient
})();
\ No newline at end of file
demo/index.html
View file @
c843b11c
...
...
@@ -13,7 +13,7 @@
</header>
<content>
</content>
<script
type=
"application/javascript"
src=
"gazeclient.js"
></script>
<script
type=
"application/javascript"
src=
"gazeclient.
min.
js"
></script>
<script
type=
"module"
src=
"resources/js/index.js"
></script>
</body>
...
...
demo/resources/js/index.js
View file @
c843b11c
...
...
@@ -3,8 +3,18 @@
var
gclient
=
new
GazeClient
();
gclient
.
connect
(
"ws://localhost:8001/gaze"
);
gclient
.
addEventListener
(
"gazeDataAvailable"
,
onGazeDataAvailable
);
gclient
.
addEventListener
(
"connectionopened"
,
onConnected
);
gclient
.
addEventListener
(
"dataAvailable"
,
onGazeDataAvailable
);
gclient
.
addEventListener
(
"connectionclosed"
,
onDisconnected
);
function
onConnected
(
event
)
{
console
.
log
(
event
);
}
function
onGazeDataAvailable
(
event
)
{
console
.
log
(
event
);
}
function
onDisconnected
(
event
)
{
console
.
log
(
event
);
}
\ 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