J’ai commencé à travailler sur le projet, que je rejoins pour quelques temps, aux côté de David, Yohan, Aurélie et Sophie. L’idée est de travailler spécifiquement sur la collaboration temps réel sur les cartes. J’ai commencé par lire le code existant, puis par faire un état de l’art des solutions existantes. Prendre le temps de lire le code, de comparer les différents approches, et de mesurer leurs impacts.
J’ai pu échanger sur le code que j’ai fait avec Matthieu. Ses yeux sont plus avertis, et j’ai pu avoir des retours intéressants. J’ai appris entre autres l’existence d’un projet similaire, qui recouvre une partie des mêmes usages. Super ! Je n’ai pas encore pris le temps d’intégrer les changements, mais j’aime beaucoup l’idée de faire des revues de code de ce type, et je vais essayer de le faire plus souvent.
J’ai enfin choisi le statut juridique de mon activité pro : je vais être auto-entrepreneur. Ça me permet de me lancer, et de voir comment ça se passe, en limitant l’overhead administratif, et en limitant mon investissement collectif pour le moment.
+
J’ai pris le temps de mettre à jour la page Projets pour la rendre plus lisible.
+
+
Des joies
+
+
Faire de la revue de code avec Matthieu et en profiter pour se donner des nouvelles.
+
Réussir ne pas me laisser envahir par des émotions qui ne sont pas les miennes.
+
Faire un atelier d’écriture avec des ami•es, être content d’entendre les textes des autres.
+
Prendre le temps d’une après-midi pour échanger avec une amie.
+
Ressentir de la joie en écoutant de la musique. C’est simple, mais ça marche tellement bien.
+
Écouter et mesurer la dynamique existante avant de faire des propositions.
+
Me rendre compte que j’ai passé une après midi en réunion, et que je ne l’avais pas anticipé. Heureux de le mesurer…
+
Recroiser des personnes de l’ancien monde
+
+
Des peines
+
+
Mais triste de ne pas l’avoir anticipé.
+
Le rythme s’améliore, mais cette semaine était trop remplie, et je suis fatigué et en train de tomber malade en la terminant.
+
Me sentir anxieux et triste, le retour du froid ne doit pas aider.
+
+
Vu, lu, écouté
+
+
🎬 Vu The Old Oak, de Ken Loach. J’aime beaucoup la finesse du propos, j’ai fondu en larmes à la fin du film. Ça fait autant de bien que ça questionne sur mes engagements.
Adding Real-Time Collaboration to uMap, first week
+
+
+
+
+
+
Last week, I’ve been lucky to start working on uMap, an open-source map-making tool to create and share customizable maps, based on Open Street Map data.
+
My goal is to add real-time collaboration to uMap, but we first want to be sure to understand the issue correctly. There are multiple ways to solve this, so one part of the journey is to understand the problem properly (then, we’ll be able to chose the right path forward).
+
Part of the work is documenting it, so expect to see some blog posts around this in the future.
+
Also, this is made possible via the generous help of ScopyLeft, so thanks to them!
+
Installation
+
I’ve started by installing uMap on my machine, made it work and read the codebase. uMap is written in Python and Django, and using old school Javascript, specifically using the Leaflet library for SIG-related interface.
With everything working on my machine, I took some time to read the code and understand
+the current code base.
+
Here are my findings :
+
+
uMap is currently using a classical client/server architecture where :
+
The server is here mainly to handle access rights, store the data and send it over to the clients.
+
The actual rendering and modifications of the map are directly done in JavaScript, on the clients.
+
+
The data is split in multiple layers. At the time of writing, concurrent writes to the same layers are not possible, as one edit would potentially overwrite the other one. It’s possible to have concurrent edits on different layers, though.
If the data has been modified by another client, an HTTP 422 (Unprocessable Entity) status is returned, which makes it possible to detect conflicts. The users are prompted about it, and asked if they want to overwrite the changes.
+
The files are stored as geojson files on the server as {datalayer.pk}_{timestamp}.geojson. A history of the last changes is preserved (The default settings preserves the last 10 revisions).
On one side are the properties (matching the _umap_options), and on the other, the geojson data (the Features key).
+
Each feature is composed of three keys:
+
geometry: the actual geo object
+
properties: the data associated with it
+
style: just styling information which goes with it, if any.
+
+
+
+
Real-time collaboration : the different approaches
+
Behind the “real-time collaboration” name, we have :
+
+
Streaming of the changes to the clients: when you’re working with other persons on the same map, you can see their edits at the moment they happen.
+
Concurrent changes: some changes can happen on the same data concurrently. In such a case, we need to merge them together and be able to
+
Offline editing: in some cases, one needs to map data but doesn’t have access to a network. Changes happen on a local device and is then synced with other devices / the server ;
+
+
Keep in mind these notes are just food for toughs, and that other approaches might be discovered on the way
+
I’ve tried to come up with the different approaches I can follow in order to add the collaboration
+features we want.
+
+
JSON Patch and JSON Merge Patch: Two specifications by the IETF which define a format for generating and using diffs on json files. In this scenario, we could send the diffs from the clients to the server, and let it merge everything.
+
Using CRDTs: Conflict-Free Resolution Data Types are one of the other options we have lying around. The technology has been used mainly to solve concurrent editing on text documents (like etherpad-lite), but should work fine on trees.
+
+
JSON Patch and JSON Merge Patch
+
I’ve stumbled on two IETF specifications for JSON Patch and JSON Merge Patch which respectively define how JSON diffs could be defined and applied.
+
There are multiple libraries for this, and at least one for Python, Rust and JS.
If you’re making edits to the map without changing all the data all the time, it’s possible to generate diffs. For instance, let’s take this simplified data (it’s not valid geojson, but it should be enough for testing):
But… I was expecting to see only the new item to show up. Instead, we are getting two items here, because it’s replacing the “features” key with everything inside.
The “add” operation performs one of the following functions,
+ depending upon what the target location references:
+
o If the target location specifies an array index, a new value is
+ inserted into the array at the specified index.
+
o If the target location specifies an object member that does not
+ already exist, a new member is added to the object
+
o If the target location specifies an object member that does exist,
+ that member’s value is replaced.
+
+
It seems to bad for us, as in our case this will happen each time a new feature is added to the feature collection.
+
It’s not working out of the box, but we could probably hack something together by having all features defined by a unique id, and send this to the server. We wouldn’t be using vanilla geojson files though, but adding some complexity on top of it.
+
At this point, I’ve left this here and went to experiment with the other ideas. After all, the goal here is not (yet) to have something functional, but to clarify how the different options would play off.
+
Using CRDTs
+
I’ve had a look at the two main CRDTs implementation that seem to get traction these days : Automerge and Yjs.
+
I’ve first tried to make Automerge work with Python, but the Automerge-py repository is outdated now and won’t build. I realized at this point that we might not even need a python implementation:
+
In this scenario, the server could just stream the changes from one client to the other, and the CRDT will guarantee that the structures will be similar on both clients. It’s handy because it means we won’t have to implement the CRDT logic on the server side.
+
Let’s do some JavaScript, then. A simple Leaflet map would look like this:
Nothing fancy here, just a map which adds markers when you click. Now let’s add automerge:
+
We add a bunch of imports, the goal here will be to sync between tabs of the same browser. Automerge announced an automerge-repo library to help with all the wiring-up, so let’s try it out!
These were just import. Don’t bother too much. The next section does the following:
+
+
Instantiate an “automerge repo”, which helps to send the right messages to the other peers if needed ;
+
Add a mechanism to create and initialize a repository if needed,
+
or otherwise look for an existing one, based on a hash passed in the URI.
+
+
// Add an automerge repository. Sync to
+constrepo=newRepo({
+network:[newBroadcastChannelNetworkAdapter()],
+storage:newIndexedDBStorageAdapter(),
+});
+
+// Automerge-repo exposes an handle, which is mainly a wrapper around the library internals.
+lethandle:DocHandle<unknown>
+
+constrootDocUrl=`${document.location.hash.substring(1)}`
+if(isValidAutomergeUrl(rootDocUrl)){
+handle=repo.find(rootDocUrl);
+letdoc=awaithandle.doc();
+
+// Once we've found the data in the browser, let's add the features to the geojson layer.
+Object.values(doc.features).forEach(feature=>{
+geojsonLayer.addData(feature);
+});
+
+}else{
+handle=repo.create()
+awaithandle.doc();
+handle.change(doc=>doc.features={});
+}
+
+
+
Let’s change the onMapClick function:
+
functiononMapClick(e){
+constuuid=uuidv4();
+// ... What was there previously
+constnewFeature["properties"]["id"]=uuid;
+
+// Add the new feature to the geojson layer.
+// Here we use the handle to do the change.
+handle.change(doc=>{doc.features[uuid]=newFeature});
+}
+
+
+
And on the other side of the logic, let’s listen to the changes:
+
handle.on("change",({doc,patches})=>{
+// "patches" is a list of all the changes that happened to the tree.
+// Because we're sending JS objects, a lot of patches events are being sent.
+//
+// Filter to only keep first-level events (we currently don't want to reflect
+// changes down the tree — yet)
+console.log("patches",patches);
+letinserted=patches.filter(({path,action})=>{
+return(path[0]=="features"&&path.length==2&&action=="put")
+});
+
+inserted.forEach(({path})=>{
+letuuid=path[1];
+letnewFeature=doc.features[uuid];
+console.log(`Adding a new feature at position ${uuid}`)
+geojsonLayer.addData(newFeature);
+});
+});
+
+
+
And… It’s working, here is a little video capture of two tabs working together :-)
+
+
+
\ No newline at end of file
diff --git a/images/umap/umap-features.png b/images/umap/umap-features.png
new file mode 100644
index 0000000..bba6df4
Binary files /dev/null and b/images/umap/umap-features.png differ
diff --git a/images/umap/umap-options.png b/images/umap/umap-options.png
new file mode 100644
index 0000000..c5f07c3
Binary files /dev/null and b/images/umap/umap-options.png differ
diff --git a/index.html b/index.html
index 23e6b72..d11fe5c 100644
--- a/index.html
+++ b/index.html
@@ -32,7 +32,7 @@
👋 Bienvenue par ici, je suis Alexis, un développeur intéressé par les dynamiques collectives, les libertés numériques et la facilitation.
-
Vous retrouverez sur ce site mes notes hebdomadaires, quelques billets de blog, des notes de lectures et des bouts de codes que je veux garder quelque part. Bonne lecture !
Pour me contacter, envoyez-moi un email sur alexis@ ce domaine (en enlevant blog.).
🌟 Valeurs et intérets
diff --git a/projets.html b/projets.html
index 9a6fe72..531f90d 100644
--- a/projets.html
+++ b/projets.html
@@ -46,7 +46,7 @@ le Noyau Linux et
Un site web qui permet de gérer les dépenses de groupes, créé fin
2011.
Il est possible de rentrer qui à payé quoi, et pour qui, et une balance est
-gérée pour vous.
+gérée pour vous. Je maintiens une instance ouverte sur ihatemoney.org.