Изменение вебсокета
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
|
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())
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue