mirror of
https://github.com/open-webui/open-webui
synced 2025-01-30 14:29:55 +00:00
enh: websocket redis support
This commit is contained in:
parent
e599d5db3c
commit
ffd7d74f77
@ -2,16 +2,29 @@ import asyncio
|
|||||||
|
|
||||||
import socketio
|
import socketio
|
||||||
from open_webui.apps.webui.models.users import Users
|
from open_webui.apps.webui.models.users import Users
|
||||||
from open_webui.env import ENABLE_WEBSOCKET_SUPPORT
|
from open_webui.env import (
|
||||||
|
ENABLE_WEBSOCKET_SUPPORT,
|
||||||
|
WEBSOCKET_MANAGER,
|
||||||
|
WEBSOCKET_REDIS_URL,
|
||||||
|
)
|
||||||
from open_webui.utils.utils import decode_token
|
from open_webui.utils.utils import decode_token
|
||||||
|
|
||||||
sio = socketio.AsyncServer(
|
|
||||||
cors_allowed_origins=[],
|
if WEBSOCKET_MANAGER == "redis":
|
||||||
async_mode="asgi",
|
mgr = socketio.AsyncRedisManager(WEBSOCKET_REDIS_URL)
|
||||||
transports=(["polling", "websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]),
|
sio = socketio.AsyncServer(client_manager=mgr)
|
||||||
allow_upgrades=ENABLE_WEBSOCKET_SUPPORT,
|
else:
|
||||||
always_connect=True,
|
sio = socketio.AsyncServer(
|
||||||
)
|
cors_allowed_origins=[],
|
||||||
|
async_mode="asgi",
|
||||||
|
transports=(
|
||||||
|
["polling", "websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]
|
||||||
|
),
|
||||||
|
allow_upgrades=ENABLE_WEBSOCKET_SUPPORT,
|
||||||
|
always_connect=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")
|
app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")
|
||||||
|
|
||||||
# Dictionary to maintain the user pool
|
# Dictionary to maintain the user pool
|
||||||
|
@ -302,3 +302,7 @@ if WEBUI_AUTH and WEBUI_SECRET_KEY == "":
|
|||||||
ENABLE_WEBSOCKET_SUPPORT = (
|
ENABLE_WEBSOCKET_SUPPORT = (
|
||||||
os.environ.get("ENABLE_WEBSOCKET_SUPPORT", "True").lower() == "true"
|
os.environ.get("ENABLE_WEBSOCKET_SUPPORT", "True").lower() == "true"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
WEBSOCKET_MANAGER = os.environ.get("WEBSOCKET_MANAGER", "")
|
||||||
|
|
||||||
|
WEBSOCKET_REDIS_URL = os.environ.get("WEBSOCKET_REDIS_URL", "redis://localhost:6379/0")
|
||||||
|
Loading…
Reference in New Issue
Block a user