feat(sync): sync map properties over websocket

All keystrokes are currently sent, which is not ideal because it will
use a lot of bandwidth.
This commit is contained in:
Alexis Métaireau 2024-04-19 19:37:00 +02:00
parent 698c926997
commit c9abb15dd1
4 changed files with 9 additions and 6 deletions

View file

@ -51,7 +51,7 @@ export class MessagesDispatcher {
} }
} }
dispatch({ kind, payload }) { dispatch({ kind, ...payload }) {
console.log(kind, payload) console.log(kind, payload)
if (kind == 'operation') { if (kind == 'operation') {
let updater = this.getUpdater(payload.subject, payload.metadata) let updater = this.getUpdater(payload.subject, payload.metadata)

View file

@ -41,7 +41,7 @@ export class MapUpdater extends BaseUpdater {
update({ key, value }) { update({ key, value }) {
console.log(key, value) console.log(key, value)
this.updateObjectValue(this.map, 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) console.log(datalayer, key, value)
this.updateObjectValue(datalayer, key, value) this.updateObjectValue(datalayer, key, value)
const property = key.replace('options.', '') const property = key.replace('options.', '')
datalayer.renderProperties([property]) datalayer.render([property])
} }
} }
@ -97,7 +97,7 @@ class FeatureUpdater extends BaseUpdater {
} }
feature.datalayer.indexProperties(feature) feature.datalayer.indexProperties(feature)
feature.renderProperties([key]) feature.render([key])
} }
delete({ metadata }) { delete({ metadata }) {

View file

@ -255,7 +255,10 @@ U.Map = L.Map.extend({
initSyncEngine: async function () { initSyncEngine: async function () {
// Get the authentication token from the server // Get the authentication token from the server
// And pass it to the sync engine. // 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) { if (!error) {
this.sync = new U.SyncEngine(this, 'ws://localhost:8001', response.token) this.sync = new U.SyncEngine(this, 'ws://localhost:8001', response.token)
} }

View file

@ -38,7 +38,7 @@ class OperationMessage(BaseModel):
kind: str = "operation" kind: str = "operation"
verb: str = Literal["upsert", "update", "delete"] verb: str = Literal["upsert", "update", "delete"]
subject: str = Literal["map", "layer", "feature"] subject: str = Literal["map", "layer", "feature"]
metadata: dict metadata: Optional[dict] = None
key: str key: str
value: Optional[str] value: Optional[str]