Skip to content

Commit

Permalink
[fix] Fixed WebSocket routes and JS
Browse files Browse the repository at this point in the history
WebSocket routes should start with "/ws/".
Fixed real-time update bug in JS.
  • Loading branch information
pandafy authored May 16, 2023
1 parent 012b27b commit e5f70b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
6 changes: 3 additions & 3 deletions openwisp_network_topology/routing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.urls import re_path
from django.urls import path

from . import consumers

websocket_urlpatterns = [
# This route is used by both
# the admin and non-admin topology view
re_path(
r'^network-topology/topology/(?P<pk>[^/]+)/$',
path(
'ws/network-topology/topology/<uuid:pk>/',
consumers.TopologyConsumer.as_asgi(),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
loadNetJsonGraph = (el='body', url='{{ graph_url }}') => {
const history_url = '{{ history_url }}';
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${wsProtocol}//${window.location.host}/network-topology/topology/${getTopologyIdFromUrl()}/`;
const wsUrl = `${wsProtocol}//${window.location.host}/ws/network-topology/topology/${getTopologyIdFromUrl()}/`;
const socket = new WebSocket(wsUrl);

const getDataParseOptions = (data) => {
Expand Down Expand Up @@ -190,7 +190,7 @@
const data=JSON.parse(e.data);
if(data.type==="broadcast_topology"){
const topology=JSON.parse(data.topology);
window.__njg_graph__.utils.JSONDataUpdate.call(window.__njg_graph__, topology);
window.graph.utils.JSONDataUpdate.call(window.graph, topology);
}
}

Expand Down
12 changes: 1 addition & 11 deletions openwisp_network_topology/tests/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def _get_communicator(self, admin_client, topology_id):
session_id = admin_client.cookies['sessionid'].value
communicator = WebsocketCommunicator(
self.application,
path=f'network-topology/topology/{topology_id}/',
path=f'ws/network-topology/topology/{topology_id}/',
headers=[
(
b'cookie',
Expand Down Expand Up @@ -104,16 +104,6 @@ async def test_consumer_connection_auth_disabled_org_manager(self, client):
async def test_consumer_connection_auth_disabled_unauth_user(self, client):
await self._assert_connection_unauth_user(client)

async def test_consumer_connection_invalid_topology_pk(
self, admin_user, admin_client
):
org = await database_sync_to_async(self._create_org)()
await database_sync_to_async(self._create_topology)(organization=org)
communicator = await self._get_communicator(admin_client, 'invalid_topology_pk')
connected, _ = await communicator.connect()
assert connected is False
await communicator.disconnect()

async def test_consumer_connection_unexisting_topology(
self, admin_user, admin_client
):
Expand Down

0 comments on commit e5f70b6

Please sign in to comment.