Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
da47c2df
Commit
da47c2df
authored
Jun 07, 2024
by
Timothy J. Baek
Browse files
refac: active users
parent
694d1708
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
backend/apps/socket/main.py
backend/apps/socket/main.py
+19
-4
No files found.
backend/apps/socket/main.py
View file @
da47c2df
...
@@ -10,7 +10,7 @@ app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")
...
@@ -10,7 +10,7 @@ app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")
# Dictionary to maintain the user pool
# Dictionary to maintain the user pool
SESSION_POOL
=
{}
USER_POOL
=
{}
USER_POOL
=
{}
USAGE_POOL
=
{}
USAGE_POOL
=
{}
# Timeout duration in seconds
# Timeout duration in seconds
...
@@ -29,7 +29,12 @@ async def connect(sid, environ, auth):
...
@@ -29,7 +29,12 @@ async def connect(sid, environ, auth):
user
=
Users
.
get_user_by_id
(
data
[
"id"
])
user
=
Users
.
get_user_by_id
(
data
[
"id"
])
if
user
:
if
user
:
USER_POOL
[
sid
]
=
user
.
id
SESSION_POOL
[
sid
]
=
user
.
id
if
user
.
id
in
USER_POOL
:
USER_POOL
[
user
.
id
].
append
(
sid
)
else
:
USER_POOL
[
user
.
id
]
=
[
sid
]
print
(
f
"user
{
user
.
name
}
(
{
user
.
id
}
) connected with session ID
{
sid
}
"
)
print
(
f
"user
{
user
.
name
}
(
{
user
.
id
}
) connected with session ID
{
sid
}
"
)
print
(
len
(
set
(
USER_POOL
)))
print
(
len
(
set
(
USER_POOL
)))
...
@@ -50,7 +55,13 @@ async def user_join(sid, data):
...
@@ -50,7 +55,13 @@ async def user_join(sid, data):
user
=
Users
.
get_user_by_id
(
data
[
"id"
])
user
=
Users
.
get_user_by_id
(
data
[
"id"
])
if
user
:
if
user
:
USER_POOL
[
sid
]
=
user
.
id
SESSION_POOL
[
sid
]
=
user
.
id
if
user
.
id
in
USER_POOL
:
USER_POOL
[
user
.
id
].
append
(
sid
)
else
:
USER_POOL
[
user
.
id
]
=
[
sid
]
print
(
f
"user
{
user
.
name
}
(
{
user
.
id
}
) connected with session ID
{
sid
}
"
)
print
(
f
"user
{
user
.
name
}
(
{
user
.
id
}
) connected with session ID
{
sid
}
"
)
print
(
len
(
set
(
USER_POOL
)))
print
(
len
(
set
(
USER_POOL
)))
...
@@ -124,7 +135,11 @@ async def remove_after_timeout(sid, model_id):
...
@@ -124,7 +135,11 @@ async def remove_after_timeout(sid, model_id):
@
sio
.
event
@
sio
.
event
async
def
disconnect
(
sid
):
async
def
disconnect
(
sid
):
if
sid
in
USER_POOL
:
if
sid
in
USER_POOL
:
disconnected_user
=
USER_POOL
.
pop
(
sid
)
disconnected_user
=
SESSION_POOL
.
pop
(
sid
)
USER_POOL
[
disconnected_user
].
remove
(
sid
)
if
len
(
USER_POOL
[
disconnected_user
])
==
0
:
del
USER_POOL
[
disconnected_user
]
print
(
f
"user
{
disconnected_user
}
disconnected with session ID
{
sid
}
"
)
print
(
f
"user
{
disconnected_user
}
disconnected with session ID
{
sid
}
"
)
await
sio
.
emit
(
"user-count"
,
{
"count"
:
len
(
USER_POOL
)})
await
sio
.
emit
(
"user-count"
,
{
"count"
:
len
(
USER_POOL
)})
...
...
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