12
12
from fastapi .responses import JSONResponse
13
13
from starlette .websockets import WebSocketDisconnect , WebSocketState
14
14
15
+ from nightwatch import __version__
15
16
from nightwatch .config import fetch_config
16
17
17
18
# Load config data
@@ -65,7 +66,7 @@ async def send(self, payload: dict) -> None:
65
66
return
66
67
67
68
try :
68
- if self ._callback is not None :
69
+ if self ._callback is not None and payload [ "type" ] != "message" :
69
70
payload ["data" ] = payload .get ("data" , {}) | {"callback" : self ._callback }
70
71
self ._callback = None
71
72
@@ -164,6 +165,8 @@ async def connect_endpoint(
164
165
continue
165
166
166
167
await app .state .broadcast ({"type" : "message" , "data" : {"user" : client .serialize (), "message" : message }})
168
+ if client ._callback is not None :
169
+ await client .send ({"type" : "response" })
167
170
168
171
case {"type" : "user-list" , "data" : _}:
169
172
await client .send ({"type" : "response" , "data" : {
@@ -180,6 +183,10 @@ async def connect_endpoint(
180
183
await app .state .broadcast ({"type" : "leave" , "data" : {"user" : client .serialize ()}})
181
184
await app .state .broadcast ({"type" : "message" , "data" : {"message" : f"{ client .username } has left the server." }})
182
185
186
+ @app .get ("/api/version" )
187
+ async def route_version () -> JSONResponse :
188
+ return JSONResponse ({"code" : 200 , "data" : {"version" : __version__ }})
189
+
183
190
# Load additional routes
184
191
from nightwatch .rics .routing import ( # noqa: E402
185
192
files , # noqa: F401
0 commit comments