-
Notifications
You must be signed in to change notification settings - Fork 9
/
websocket_endpoint.py
78 lines (66 loc) · 2.13 KB
/
websocket_endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from fastapi import APIRouter, Depends, Query, WebSocket
from app.dependencies.auth import AcaPyAuthVerified
from app.services.websocket import handle_websocket, websocket_auth
from shared.log_config import get_logger
logger = get_logger(__name__)
router = APIRouter()
group_id_query = Query(
default="",
description="Group ID to which the wallet belongs",
include_in_schema=False,
)
@router.websocket("/v1/ws/")
async def websocket_endpoint(
websocket: WebSocket,
group_id: str = group_id_query,
auth: AcaPyAuthVerified = Depends(websocket_auth),
):
logger.info("Received websocket request on group `{}`", group_id)
await handle_websocket(
websocket, group_id=group_id, wallet_id="", topic="", auth=auth
)
@router.websocket("/v1/ws/{wallet_id}")
async def websocket_endpoint_wallet(
websocket: WebSocket,
wallet_id: str,
group_id: str = group_id_query,
auth: AcaPyAuthVerified = Depends(websocket_auth),
):
logger.info(
"Received websocket request on group `{}` and wallet id `{}`",
group_id,
wallet_id,
)
await handle_websocket(
websocket, group_id=group_id, wallet_id=wallet_id, topic="", auth=auth
)
@router.websocket("/v1/ws/topic/{topic}")
async def websocket_endpoint_topic(
websocket: WebSocket,
topic: str,
group_id: str = group_id_query,
auth: AcaPyAuthVerified = Depends(websocket_auth),
):
logger.info(
"Received websocket request on group `{}` and topic `{}`", group_id, topic
)
await handle_websocket(
websocket, group_id=group_id, wallet_id="", topic=topic, auth=auth
)
@router.websocket("/v1/ws/{wallet_id}/{topic}")
async def websocket_endpoint_wallet_topic(
websocket: WebSocket,
wallet_id: str,
topic: str,
group_id: str = group_id_query,
auth: AcaPyAuthVerified = Depends(websocket_auth),
):
logger.info(
"Received websocket request for group `{}`, wallet id `{}`, and topic `{}`",
group_id,
wallet_id,
topic,
)
await handle_websocket(
websocket, group_id=group_id, wallet_id=wallet_id, topic=topic, auth=auth
)