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
1871d8b6
authored
Aug 22, 2019
by
Alexander Bazo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
f1ae651e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
11 deletions
+94
-11
lib/com/Events.js
+29
-0
lib/com/WebSocketClient.js
+29
-0
lib/index.js
+10
-11
lib/utils/Observable.js
+26
-0
No files found.
lib/com/Events.js
0 → 100644
View file @
1871d8b6
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
ConnectionClosedEvent
extends
Event
{
constructor
()
{
super
(
"connectionclosed"
);
}
}
export
{
DataEvent
,
ConnectionOpenedEvent
,
ConnectionClosedEvent
};
\ No newline at end of file
lib/com/WebSocketClient.js
0 → 100644
View file @
1871d8b6
import
Observable
from
"../utils/Observable.js"
;
import
{
ConnectionOpenedEvent
,
DataEvent
}
from
"./Events.js"
;
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
);
}
export
default
WebSocketClient
;
\ No newline at end of file
lib/index.js
View file @
1871d8b6
/* eslint-env browser */
import
{
Event
,
Observable
}
from
"./Observable.js"
;
import
WebSocketClient
from
"./WebSocketClient.js"
;
import
Observable
from
"./utils/Observable.js"
;
import
WebSocketClient
from
"./com/WebSocketClient.js"
;
class
GazeClient
extends
Observable
{
...
...
@@ -12,21 +10,22 @@ class GazeClient extends Observable {
connect
(
url
)
{
this
.
url
=
url
;
this
.
client
=
new
WebSocketClient
();
this
.
client
.
addEventListener
(
"connected"
,
this
.
onConnected
.
bind
(
this
));
this
.
client
.
addEventListener
(
"gazeDataAvailable"
,
this
.
onGazeDataAvailable
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
);
}
on
Open
(
)
{
this
.
client
.
send
(
"hello server"
);
on
Connected
(
event
)
{
this
.
notifyAll
(
event
);
}
on
C
onnected
(
event
)
{
// TODO: Implement event broadcasting
on
Disc
onnected
(
event
)
{
this
.
notifyAll
(
event
);
}
on
Gaze
DataAvailable
(
event
)
{
onDataAvailable
(
event
)
{
this
.
notifyAll
(
event
);
}
...
...
lib/utils/Observable.js
0 → 100644
View file @
1871d8b6
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
;
\ 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