Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
e0219e84
Commit
e0219e84
authored
3 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Preliminary work for better socket.io event handling.
parent
d2919090
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/events/socketio.py
+10
-12
10 additions, 12 deletions
app/events/socketio.py
with
10 additions
and
12 deletions
app/events/socketio.py
+
10
−
12
View file @
e0219e84
...
...
@@ -7,7 +7,7 @@ from ..models import User
'''
'
A list containing session ids of
connected
Socket.IO sessions, to keep track
'
A list containing session ids of Socket.IO sessions, to keep track
'
of all connected sessions, which can be used to determine the runtimes of
'
associated background tasks.
'''
...
...
@@ -22,21 +22,22 @@ sessions = []
def
socketio_connect
():
'''
'
The Socket.IO module creates a session id (sid) for each request.
'
On connect the sid is saved in the
connected
sessions list.
'
On connect the sid is saved in the sessions list.
'''
sessions
.
append
(
request
.
sid
)
return
{
'
code
'
:
200
,
'
msg
'
:
'
OK
'
}
@socketio.on
(
'
disconnect
'
)
def
socketio_disconnect
():
'''
'
On disconnect the session id gets removed from the connected sessions
'
list.
'
On disconnect the session id gets removed from the sessions list.
'''
try
:
sessions
.
remove
(
request
.
sid
)
except
ValueError
:
pass
return
{
'
code
'
:
200
,
'
msg
'
:
'
OK
'
}
@socketio.on
(
'
start_user_session
'
)
...
...
@@ -58,18 +59,15 @@ def socketio_start_user_session(user_id):
join_room
(
room
)
@socketio.on
(
'
stop_user_session
'
)
@socketio.on
(
'
users.request
'
)
@socketio_login_required
def
socketio_st
op_user
_session
(
user_id
):
def
socketio_st
art
_session
(
user_id
):
user
=
User
.
query
.
get
(
user_id
)
if
user
is
None
:
response
=
{
'
code
'
:
404
,
'
msg
'
:
'
Not found
'
}
socketio
.
emit
(
'
stop_user_session
'
,
response
,
room
=
request
.
sid
)
elif
not
(
user
==
current_user
or
current_user
.
is_administrator
):
response
=
{
'
code
'
:
403
,
'
msg
'
:
'
Forbidden
'
}
socketio
.
emit
(
'
stop_user_session
'
,
response
,
room
=
request
.
sid
)
else
:
response
=
{
'
code
'
:
200
,
'
msg
'
:
'
OK
'
}
socketio
.
emit
(
'
stop_user_session
'
,
response
,
room
=
request
.
sid
)
room
=
'
user_{}
'
.
format
(
user
.
id
)
leave_room
(
room
)
response
=
{
'
code
'
:
200
,
'
msg
'
:
'
OK
'
,
'
payload
'
:
user
.
to_dict
()}
join_room
(
'
users.{}
'
.
format
(
user
.
id
))
return
response
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