Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tddd96-grupp1
teknikattan-scoring-system
Commits
25f9acc3
Commit
25f9acc3
authored
3 years ago
by
Victor Löfgren
Browse files
Options
Downloads
Patches
Plain Diff
Add comments to socket files
parent
dd6c9422
No related branches found
Branches containing commit
No related tags found
1 merge request
!154
Add comments to socket files
Pipeline
#45915
passed with warnings
3 years ago
Stage: setup
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/src/sockets.ts
+24
-1
24 additions, 1 deletion
client/src/sockets.ts
server/app/core/sockets.py
+15
-4
15 additions, 4 deletions
server/app/core/sockets.py
with
39 additions
and
5 deletions
client/src/sockets.ts
+
24
−
1
View file @
25f9acc3
/**
* Handles everything that has to do with syncing active competitions.
*
* @module
*/
import
io
from
'
socket.io-client
'
import
{
setCurrentSlideByOrder
,
setPresentationShowScoreboard
,
setPresentationTimer
}
from
'
./actions/presentation
'
import
{
TimerState
}
from
'
./interfaces/Timer
'
import
store
from
'
./store
'
/**
* The values that can be synced between clients connected to the same presentation.
*/
interface
SyncInterface
{
slide_order
?:
number
timer
?:
TimerState
...
...
@@ -11,9 +20,15 @@ interface SyncInterface {
let
socket
:
SocketIOClient
.
Socket
/**
* Connect to server, setup authorization header and listen to some events.
*
* @param role The role the connecting client has
*/
export
const
socketConnect
=
(
role
:
'
Judge
'
|
'
Operator
'
|
'
Team
'
|
'
Audience
'
)
=>
{
if
(
socket
)
return
// The token is the JWT returned from the login/code API call.
const
token
=
localStorage
[
`
${
role
}
Token`
]
socket
=
io
(
'
localhost:5000
'
,
{
transportOptions
:
{
...
...
@@ -26,7 +41,7 @@ export const socketConnect = (role: 'Judge' | 'Operator' | 'Team' | 'Audience')
})
socket
.
on
(
'
sync
'
,
(
data
:
SyncInterface
)
=>
{
// The order of these is important, for some reason
// The order of these is important, for some reason
, so dont change it
if
(
data
.
timer
!==
undefined
)
setPresentationTimer
(
data
.
timer
)(
store
.
dispatch
)
if
(
data
.
slide_order
!==
undefined
)
setCurrentSlideByOrder
(
data
.
slide_order
)(
store
.
dispatch
,
store
.
getState
)
if
(
data
.
show_scoreboard
!==
undefined
)
setPresentationShowScoreboard
(
data
.
show_scoreboard
)(
store
.
dispatch
)
...
...
@@ -37,10 +52,18 @@ export const socketConnect = (role: 'Judge' | 'Operator' | 'Team' | 'Audience')
})
}
/**
* Disconnect all clients.
*/
export
const
socketEndPresentation
=
()
=>
{
socket
.
emit
(
'
end_presentation
'
)
}
/**
* Sync data between all connected clients.
*
* @param syncData The data to sync between all clients connected to the same presentation
*/
export
const
socketSync
=
(
syncData
:
SyncInterface
)
=>
{
socket
.
emit
(
'
sync
'
,
syncData
)
}
This diff is collapsed.
Click to expand it.
server/app/core/sockets.py
+
15
−
4
View file @
25f9acc3
...
...
@@ -26,7 +26,7 @@ active_competitions = {}
def
_unpack_claims
():
"""
:return: A tuple containing competition_id and view
, gotten
from claim
:return: A tuple containing competition_id and view from claim
:rtype: tuple
"""
...
...
@@ -39,10 +39,19 @@ def is_active_competition(competition_id):
:return: True if competition with competition_id is currently active else False
:rtype: bool
"""
return
competition_id
in
active_competitions
def
_get_sync_variables
(
active_competition
,
sync_values
):
"""
Returns a dictionary with all values from active_competition that is to be
synced.
:return: A dicationary containg key-value pairs from active_competition
thats in sync_values
:rtype: dictionary
"""
return
{
key
:
value
for
key
,
value
in
active_competition
.
items
()
if
key
in
sync_values
}
...
...
@@ -83,7 +92,7 @@ def authorize_client(f, allowed_views=None, require_active_competition=True, *ar
def
connect
()
->
None
:
"""
Connect to a active competition. If competition with competition_id is not active,
start it if client is an operator, otherwise
ignore it
.
start it if client is an operator, otherwise
do nothing
.
"""
competition_id
,
view
=
_unpack_claims
()
...
...
@@ -133,7 +142,7 @@ def disconnect() -> None:
@authorize_client
(
allowed_views
=
[
"
Operator
"
])
def
end_presentation
()
->
None
:
"""
End a
active_competi
tion by sending end_presentation to all connected clients.
End a
presenta
tion by sending end_presentation to all connected clients.
"""
competition_id
,
_
=
_unpack_claims
()
...
...
@@ -144,7 +153,8 @@ def end_presentation() -> None:
@authorize_client
(
allowed_views
=
[
"
Operator
"
])
def
sync
(
data
)
->
None
:
"""
Sync active_competition for all clients connected to competition.
Update all values from data thats in an active_competitions. Also sync all
the updated values to all clients connected to the same competition.
"""
competition_id
,
view
=
_unpack_claims
()
...
...
@@ -153,6 +163,7 @@ def sync(data) -> None:
for
key
,
value
in
data
.
items
():
if
key
not
in
active_competition
:
logger
.
warning
(
f
"
Invalid sync data:
'
{
key
}
'
:
'
{
value
}
'"
)
continue
active_competition
[
key
]
=
value
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment