Изменение вебсокета

This commit is contained in:
urec56 2024-06-05 17:40:37 +05:00
parent f3d924a1c4
commit b6ea1e3d72
2 changed files with 15 additions and 12 deletions

View file

@ -1,3 +1,4 @@
import logging
from typing import Annotated from typing import Annotated
import websockets import websockets
@ -142,6 +143,7 @@ async def websocket_endpoint(
# await AuthService.check_verificated_user_with_exc(uow=uow, user_id=user.id) # await AuthService.check_verificated_user_with_exc(uow=uow, user_id=user.id)
# await AuthService.validate_user_access_to_chat(uow=uow, user_id=user.id, chat_id=chat_id) # await AuthService.validate_user_access_to_chat(uow=uow, user_id=user.id, chat_id=chat_id)
await manager.connect(chat_id, websocket) await manager.connect(chat_id, websocket)
logging.critical(authorization)
await websocket.send_json({"headers": str(websocket.headers), "authorization": authorization}) await websocket.send_json({"headers": str(websocket.headers), "authorization": authorization})
try: try:
while True: while True:
@ -151,14 +153,15 @@ async def websocket_endpoint(
except WebSocketDisconnect: except WebSocketDisconnect:
manager.disconnect(chat_id, websocket) manager.disconnect(chat_id, websocket)
#
# @router.post( @router.post(
# "/ws/{chat_id}" "/ws/{chat_id}"
# ) )
# async def websocket_endpoint( async def websocket_endpoint(
# chat_id: int, chat_id: int,
# token: str = Depends(get_token), token: str = Depends(get_token),
# ): ):
# url = f"ws://localhost:8000/api/chat/ws/{chat_id}" logging.critical("Это сообщение уровня INFO")
# async with websockets.connect(url, extra_headers={"Authorization": f"Bearer {token}"}) as websocket: url = f"ws://localhost:8000/api/chat/ws/{chat_id}"
# print(await websocket.recv()) async with websockets.connect(url, extra_headers={"Authorization": f"Bearer {token}"}) as websocket:
print(await websocket.recv())

View file

@ -1,6 +1,6 @@
from typing import Annotated from typing import Annotated
from fastapi import Depends, Header, WebSocket from fastapi import Depends, Header
from fastapi.security import HTTPBearer from fastapi.security import HTTPBearer
from jose import JWTError, jwt, ExpiredSignatureError from jose import JWTError, jwt, ExpiredSignatureError