Изменение вебсокета
This commit is contained in:
parent
f3d924a1c4
commit
b6ea1e3d72
2 changed files with 15 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
from typing import Annotated
|
||||
|
||||
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.validate_user_access_to_chat(uow=uow, user_id=user.id, chat_id=chat_id)
|
||||
await manager.connect(chat_id, websocket)
|
||||
logging.critical(authorization)
|
||||
await websocket.send_json({"headers": str(websocket.headers), "authorization": authorization})
|
||||
try:
|
||||
while True:
|
||||
|
@ -151,14 +153,15 @@ async def websocket_endpoint(
|
|||
except WebSocketDisconnect:
|
||||
manager.disconnect(chat_id, websocket)
|
||||
|
||||
#
|
||||
# @router.post(
|
||||
# "/ws/{chat_id}"
|
||||
# )
|
||||
# async def websocket_endpoint(
|
||||
# chat_id: int,
|
||||
# token: str = Depends(get_token),
|
||||
# ):
|
||||
# url = f"ws://localhost:8000/api/chat/ws/{chat_id}"
|
||||
# async with websockets.connect(url, extra_headers={"Authorization": f"Bearer {token}"}) as websocket:
|
||||
# print(await websocket.recv())
|
||||
|
||||
@router.post(
|
||||
"/ws/{chat_id}"
|
||||
)
|
||||
async def websocket_endpoint(
|
||||
chat_id: int,
|
||||
token: str = Depends(get_token),
|
||||
):
|
||||
logging.critical("Это сообщение уровня INFO")
|
||||
url = f"ws://localhost:8000/api/chat/ws/{chat_id}"
|
||||
async with websockets.connect(url, extra_headers={"Authorization": f"Bearer {token}"}) as websocket:
|
||||
print(await websocket.recv())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends, Header, WebSocket
|
||||
from fastapi import Depends, Header
|
||||
from fastapi.security import HTTPBearer
|
||||
from jose import JWTError, jwt, ExpiredSignatureError
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue