Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Eye-Tracking Classroom
/
Live-Gaze-Analyser
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
b4578190
authored
Oct 14, 2019
by
Alexander Bazo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
9ab70573
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
15 deletions
+19
-15
lib/rooms/ImageViewerRoom.js
+19
-15
No files found.
lib/rooms/ImageViewerRoom.js
View file @
b4578190
/* eslint-env node */
/* eslint-env node */
const
TASKS
=
[{
const
MAX_GAZE_POINT_AGE
=
2000
,
imageUrl
:
"images/Brueghel-The_Dutch_Proverbs.jpg"
,
taskDescription
:
"Suchen Sie nach bildlichen Darstellungen niederländischer Sprichwörter des 16. Jahrhunderts."
,
taskSource
:
"Pieter Bruegel the Elder, Netherlandish Proverbs (Oil on oak wood, 1599), Gemäldegalerie, Berlin"
,
duration
:
30000
,
}],
MAX_GAZE_POINT_AGE
=
2000
,
GAZE_POINT_UPDATE_DELAY
=
250
;
GAZE_POINT_UPDATE_DELAY
=
250
;
const
colyseus
=
require
(
"colyseus"
),
const
colyseus
=
require
(
"colyseus"
),
...
@@ -16,7 +10,8 @@ const colyseus = require("colyseus"),
...
@@ -16,7 +10,8 @@ const colyseus = require("colyseus"),
Task
=
require
(
"../logic/Task.js"
),
Task
=
require
(
"../logic/Task.js"
),
ImageViewerState
=
require
(
"../logic/ImageViewerState.js"
);
ImageViewerState
=
require
(
"../logic/ImageViewerState.js"
);
var
availableTasks
,
var
tasks
=
Task
.
getTasks
(),
availableTasks
,
currentTask
,
currentTask
,
currentTaskIndex
,
currentTaskIndex
,
gazePoints
,
gazePoints
,
...
@@ -37,9 +32,9 @@ class ImageViewerRoom extends colyseus.Room {
...
@@ -37,9 +32,9 @@ class ImageViewerRoom extends colyseus.Room {
createTasks
()
{
createTasks
()
{
availableTasks
=
[];
availableTasks
=
[];
for
(
let
i
=
0
;
i
<
TASKS
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
tasks
.
length
;
i
++
)
{
availableTasks
.
push
(
new
Task
(
TASKS
[
i
].
imageUrl
,
TASKS
[
i
].
taskDescription
,
availableTasks
.
push
(
new
Task
(
tasks
[
i
].
imageUrl
,
tasks
[
i
].
taskDescription
,
TASKS
[
i
].
taskSource
,
TASKS
[
i
].
duration
));
tasks
[
i
].
taskSource
,
tasks
[
i
].
duration
));
}
}
currentTaskIndex
=
0
;
currentTaskIndex
=
0
;
}
}
...
@@ -76,18 +71,24 @@ class ImageViewerRoom extends colyseus.Room {
...
@@ -76,18 +71,24 @@ class ImageViewerRoom extends colyseus.Room {
this
.
setTask
();
this
.
setTask
();
}
}
// Run on each tick (~30FPS)
update
()
{
update
()
{
let
now
=
Date
.
now
();
let
now
=
Date
.
now
();
// Remove old gaze points
this
.
updateGazePoints
(
now
);
this
.
updateGazePoints
(
now
);
// Sanity check to prevent empty updates to subscribers
if
(
gazePoints
.
length
===
0
)
{
return
;
}
// Sanity check to prevent high frequency gaze updates to subscribers
if
(
now
-
lastGazePointUpdate
<
GAZE_POINT_UPDATE_DELAY
)
{
if
(
now
-
lastGazePointUpdate
<
GAZE_POINT_UPDATE_DELAY
)
{
return
;
return
;
}
}
for
(
let
i
=
0
;
i
<
gazeSubscribers
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
gazeSubscribers
.
length
;
i
++
)
{
let
client
=
gazeSubscribers
[
i
];
Logger
.
log
(
`
${
gazePoints
.
length
}
gaze points available`
);
Logger
.
log
(
`
${
gazePoints
.
length
}
gaze points available`
);
if
(
client
&&
gazePoints
.
length
>
0
)
{
if
(
gazeSubscribers
[
i
]
)
{
Logger
.
log
(
`Sending
${
gazePoints
.
length
}
gaze points to subsriber`
,
"ImageViewer Room"
);
Logger
.
log
(
`Sending
${
gazePoints
.
length
}
gaze points to subs
c
riber`
,
"ImageViewer Room"
);
this
.
send
(
client
,{
this
.
send
(
gazeSubscribers
[
i
]
,{
type
:
"gazelist"
,
type
:
"gazelist"
,
data
:
gazePoints
,
data
:
gazePoints
,
});
});
...
@@ -109,11 +110,14 @@ class ImageViewerRoom extends colyseus.Room {
...
@@ -109,11 +110,14 @@ class ImageViewerRoom extends colyseus.Room {
setTask
()
{
setTask
()
{
Logger
.
log
(
"Sending current task to state"
,
"ImageViewrRoom"
);
Logger
.
log
(
"Sending current task to state"
,
"ImageViewrRoom"
);
// Cycle through available tasks
currentTaskIndex
+=
1
;
currentTaskIndex
+=
1
;
if
(
currentTaskIndex
>=
availableTasks
.
length
)
{
if
(
currentTaskIndex
>=
availableTasks
.
length
)
{
currentTaskIndex
=
0
;
currentTaskIndex
=
0
;
}
}
currentTask
=
availableTasks
[
currentTaskIndex
];
currentTask
=
availableTasks
[
currentTaskIndex
];
// Send task to state to auto update clients
// Set listener for task change event (is based on task's duration property)
this
.
state
.
setTask
(
currentTask
,
this
.
onTaskFinished
.
bind
(
this
));
this
.
state
.
setTask
(
currentTask
,
this
.
onTaskFinished
.
bind
(
this
));
}
}
}
}
...
...
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