Move live websocket to old url (/gj/live)
This commit is contained in:
parent
ae19ba9f27
commit
0bf74b2bba
3 changed files with 45 additions and 35 deletions
|
@ -3,7 +3,6 @@ Geographical json stores, served under /gj
|
|||
Used for displaying features on maps
|
||||
"""
|
||||
|
||||
from json import JSONDecodeError
|
||||
import logging
|
||||
from typing import Annotated
|
||||
from asyncio import CancelledError
|
||||
|
@ -15,17 +14,14 @@ from fastapi import (
|
|||
Response,
|
||||
Header,
|
||||
WebSocket,
|
||||
WebSocketDisconnect,
|
||||
status,
|
||||
)
|
||||
|
||||
from gisaf.models.authentication import User
|
||||
from gisaf.redis_tools import store as redis_store
|
||||
from gisaf.live import live_server
|
||||
from gisaf.registry import registry
|
||||
from gisaf.security import get_current_active_user
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
api = APIRouter(
|
||||
|
@ -59,37 +55,6 @@ class ConnectionManager:
|
|||
manager = ConnectionManager()
|
||||
|
||||
|
||||
@api.websocket("/live/{store}")
|
||||
async def live_layer(store: str, websocket: WebSocket):
|
||||
"""
|
||||
Websocket for live layer updates
|
||||
"""
|
||||
await websocket.accept()
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
msg_data = await websocket.receive_json()
|
||||
except JSONDecodeError:
|
||||
msg_text = await websocket.receive_text()
|
||||
if msg_text == "close":
|
||||
await websocket.close()
|
||||
continue
|
||||
# else:
|
||||
if "message" in msg_data:
|
||||
if msg_data["message"] == "subscribeLiveLayer":
|
||||
live_server.add_subscription(websocket, store)
|
||||
elif msg_data["message"] == "unsubscribeLiveLayer":
|
||||
live_server.remove_subscription(websocket, store)
|
||||
else:
|
||||
logger.warning(
|
||||
f"Got websocket message with no message field: {msg_data}"
|
||||
)
|
||||
except WebSocketDisconnect:
|
||||
logger.debug("Websocket disconnected")
|
||||
|
||||
# logger.debug('websocket connection closed')
|
||||
|
||||
|
||||
@api.get("/{store_name}")
|
||||
async def get_geojson(
|
||||
store_name,
|
||||
|
|
43
src/gisaf/api/ws.py
Normal file
43
src/gisaf/api/ws.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
from json import JSONDecodeError
|
||||
import logging
|
||||
|
||||
from fastapi import WebSocket, APIRouter, WebSocketDisconnect
|
||||
|
||||
from gisaf.live import live_server
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
api = APIRouter(
|
||||
tags=["websockets"],
|
||||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
|
||||
@api.websocket("/live/{store}")
|
||||
async def live_layer(store: str, websocket: WebSocket):
|
||||
"""
|
||||
Websocket for live layer updates
|
||||
"""
|
||||
await websocket.accept()
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
msg_data = await websocket.receive_json()
|
||||
except JSONDecodeError:
|
||||
msg_text = await websocket.receive_text()
|
||||
if msg_text == "close":
|
||||
await websocket.close()
|
||||
continue
|
||||
# else:
|
||||
if "message" in msg_data:
|
||||
if msg_data["message"] == "subscribeLiveLayer":
|
||||
live_server.add_subscription(websocket, store)
|
||||
elif msg_data["message"] == "unsubscribeLiveLayer":
|
||||
live_server.remove_subscription(websocket, store)
|
||||
else:
|
||||
logger.warning(
|
||||
f"Got websocket message with no message field: {msg_data}"
|
||||
)
|
||||
except WebSocketDisconnect:
|
||||
logger.debug("Websocket disconnected")
|
||||
# logger.debug('websocket connection closed')
|
Loading…
Add table
Add a link
Reference in a new issue