Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Eye-Tracking Classroom
/
gaze-server.cs
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
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
27325516
authored
Aug 20, 2019
by
Stefan Schreistetter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Intermediate version. Added functionality to broadcast gaze data to all connected sessions.
parent
82c4433d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
GazeWebSocketServer/EyeTrackerClient.cs
+11
-2
GazeWebSocketServer/GazeCoordinateBehavior.cs
+22
-3
GazeWebSocketServer/Program.cs
+1
-5
No files found.
GazeWebSocketServer/EyeTrackerClient.cs
View file @
27325516
...
@@ -11,9 +11,11 @@ namespace GazeWebSocketServer
...
@@ -11,9 +11,11 @@ namespace GazeWebSocketServer
{
{
private
IEyeTracker
eyeTracker
;
private
IEyeTracker
eyeTracker
;
private
GazeDataProcessor
gazeDataProcessor
;
private
GazeDataProcessor
gazeDataProcessor
;
private
List
<
GazeCoordinateBehavior
>
gazeCoordinateBehaviors
;
public
EyeTrackerClient
()
public
EyeTrackerClient
()
{
{
gazeCoordinateBehaviors
=
new
List
<
GazeCoordinateBehavior
>();
while
(
eyeTracker
==
null
)
while
(
eyeTracker
==
null
)
{
{
EyeTrackerCollection
eyeTrackers
=
EyeTrackingOperations
.
FindAllEyeTrackers
();
EyeTrackerCollection
eyeTrackers
=
EyeTrackingOperations
.
FindAllEyeTrackers
();
...
@@ -26,8 +28,9 @@ namespace GazeWebSocketServer
...
@@ -26,8 +28,9 @@ namespace GazeWebSocketServer
eyeTracker
.
SetGazeOutputFrequency
(
120f
);
eyeTracker
.
SetGazeOutputFrequency
(
120f
);
}
}
public
void
Start
()
public
void
Start
(
GazeCoordinateBehavior
gazeCoordinateBehavior
)
{
{
gazeCoordinateBehaviors
.
Add
(
gazeCoordinateBehavior
);
eyeTracker
.
GazeDataReceived
+=
GazeDataReceivedHandler
;
eyeTracker
.
GazeDataReceived
+=
GazeDataReceivedHandler
;
}
}
...
@@ -38,7 +41,12 @@ namespace GazeWebSocketServer
...
@@ -38,7 +41,12 @@ namespace GazeWebSocketServer
private
void
GazeDataReceivedHandler
(
object
sender
,
GazeDataEventArgs
e
)
private
void
GazeDataReceivedHandler
(
object
sender
,
GazeDataEventArgs
e
)
{
{
Console
.
WriteLine
(
gazeDataProcessor
.
Extract
(
e
).
ToString
());
GazeData
gazeData
=
gazeDataProcessor
.
Extract
(
e
);
foreach
(
GazeCoordinateBehavior
behavior
in
gazeCoordinateBehaviors
)
{
behavior
.
Publish
(
gazeData
);
}
Console
.
WriteLine
(
gazeData
.
ToString
());
}
}
}
}
}
}
\ No newline at end of file
GazeWebSocketServer/GazeCoordinateBehavior.cs
View file @
27325516
...
@@ -8,10 +8,29 @@ namespace GazeWebSocketServer
...
@@ -8,10 +8,29 @@ namespace GazeWebSocketServer
{
{
public
class
GazeCoordinateBehavior
:
WebSocketBehavior
public
class
GazeCoordinateBehavior
:
WebSocketBehavior
{
{
protected
override
void
OnOpen
()
private
EyeTrackerClient
eyeTrackerClient
;
public
GazeCoordinateBehavior
()
{
Console
.
WriteLine
(
"Creating behavior..."
);
eyeTrackerClient
=
new
EyeTrackerClient
();
eyeTrackerClient
.
Start
(
this
);
}
~
GazeCoordinateBehavior
()
{
eyeTrackerClient
.
Stop
();
}
//protected override void OnOpen()
//{
// throw new NotImplementedException();
// //base.OnOpen();
//}
internal
void
Publish
(
GazeData
gazeData
)
{
{
throw
new
NotImplementedException
();
Sessions
.
Broadcast
(
gazeData
.
ToString
());
//base.OnOpen();
}
}
}
}
}
}
GazeWebSocketServer/Program.cs
View file @
27325516
...
@@ -10,14 +10,11 @@ namespace GazeWebSocketServer
...
@@ -10,14 +10,11 @@ namespace GazeWebSocketServer
public
static
void
Main
(
string
[]
args
)
public
static
void
Main
(
string
[]
args
)
{
{
var
wssv
=
new
WebSocketServer
(
"ws://localhost:8001"
);
var
wssv
=
new
WebSocketServer
(
"ws://localhost:8001"
);
wssv
.
AddWebSocketService
<
GazeCoordinateBehavior
>(
"/gaze"
);
wssv
.
AddWebSocketService
(
"/gaze"
,
()
=>
new
GazeCoordinateBehavior
());
EyeTrackerClient
eyeTrackerClient
=
new
EyeTrackerClient
();
eyeTrackerClient
.
Start
();
wssv
.
Start
();
wssv
.
Start
();
Console
.
ReadKey
(
true
);
Console
.
ReadKey
(
true
);
wssv
.
Stop
();
wssv
.
Stop
();
eyeTrackerClient
.
Stop
();
}
}
}
}
}
}
\ 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