From c9abb15dd11004bfacb221e76b6271a5ea652d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 19 Apr 2024 19:37:00 +0200 Subject: [PATCH] feat(sync): sync map properties over websocket All keystrokes are currently sent, which is not ideal because it will use a lot of bandwidth. --- umap/static/umap/js/modules/sync/engine.js | 2 +- umap/static/umap/js/modules/sync/updaters.js | 6 +++--- umap/static/umap/js/umap.js | 5 ++++- umap/ws.py | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 7337906e..ed971c6a 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -51,7 +51,7 @@ export class MessagesDispatcher { } } - dispatch({ kind, payload }) { + dispatch({ kind, ...payload }) { console.log(kind, payload) if (kind == 'operation') { let updater = this.getUpdater(payload.subject, payload.metadata) diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 62a13f6a..a37ee0b9 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -41,7 +41,7 @@ export class MapUpdater extends BaseUpdater { update({ key, value }) { console.log(key, value) this.updateObjectValue(this.map, key, value) - this.map.renderProperties([key.replace('options.', '')]) + this.map.render([key.replace('options.', '')]) } } @@ -51,7 +51,7 @@ export class DatalayerUpdater extends BaseUpdater { console.log(datalayer, key, value) this.updateObjectValue(datalayer, key, value) const property = key.replace('options.', '') - datalayer.renderProperties([property]) + datalayer.render([property]) } } @@ -97,7 +97,7 @@ class FeatureUpdater extends BaseUpdater { } feature.datalayer.indexProperties(feature) - feature.renderProperties([key]) + feature.render([key]) } delete({ metadata }) { diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 6da30a2a..fbd98a58 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -255,7 +255,10 @@ U.Map = L.Map.extend({ initSyncEngine: async function () { // Get the authentication token from the server // And pass it to the sync engine. - const [response, _, error] = await this.server.get('/map/2/ws-token/') + // FIXME: use `this.urls` + const [response, _, error] = await this.server.get( + `/map/${this.options.umap_id}/ws-token/` + ) if (!error) { this.sync = new U.SyncEngine(this, 'ws://localhost:8001', response.token) } diff --git a/umap/ws.py b/umap/ws.py index 86839cdd..41601f4c 100644 --- a/umap/ws.py +++ b/umap/ws.py @@ -38,7 +38,7 @@ class OperationMessage(BaseModel): kind: str = "operation" verb: str = Literal["upsert", "update", "delete"] subject: str = Literal["map", "layer", "feature"] - metadata: dict + metadata: Optional[dict] = None key: str value: Optional[str]