Изменение вебсокета
This commit is contained in:
parent
12d2d7be27
commit
f3d924a1c4
2 changed files with 6 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
||||||
|
from typing import Annotated
|
||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
from fastapi import WebSocket, WebSocketDisconnect, Depends
|
from fastapi import WebSocket, WebSocketDisconnect, Depends, Header
|
||||||
|
|
||||||
from app.exceptions import IncorrectDataException, UserDontHavePermissionException
|
from app.exceptions import IncorrectDataException, UserDontHavePermissionException
|
||||||
from app.services.message_service import MessageService
|
from app.services.message_service import MessageService
|
||||||
|
@ -133,13 +135,14 @@ manager = ConnectionManager()
|
||||||
async def websocket_endpoint(
|
async def websocket_endpoint(
|
||||||
chat_id: int,
|
chat_id: int,
|
||||||
websocket: WebSocket,
|
websocket: WebSocket,
|
||||||
|
authorization: Annotated[str | None, Header()] = None,
|
||||||
# user: SUser = Depends(get_current_user_ws),
|
# user: SUser = Depends(get_current_user_ws),
|
||||||
uow=Depends(UnitOfWork)
|
uow=Depends(UnitOfWork)
|
||||||
):
|
):
|
||||||
# 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)
|
||||||
await websocket.send_json({"headers": str(websocket.headers)})
|
await websocket.send_json({"headers": str(websocket.headers), "authorization": authorization})
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive_json()
|
data = await websocket.receive_json()
|
||||||
|
|
|
@ -50,7 +50,7 @@ async def check_verificated_user_with_exc(user: SUser = Depends(get_current_user
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def get_token_ws(websocket: WebSocket, authorization: Annotated[str | None, Header()] = None) -> str:
|
def get_token_ws(authorization: Annotated[str | None, Header()] = None) -> str:
|
||||||
if authorization is None:
|
if authorization is None:
|
||||||
raise TokenAbsentException
|
raise TokenAbsentException
|
||||||
return authorization.split()[1]
|
return authorization.split()[1]
|
||||||
|
|
Loading…
Add table
Reference in a new issue