Johannes (@JGKK) and I are creating a suite of nodes to integrate voice2json into Node-RED. These nodes allow the user to setup voice2json (entirely via Node-RED), without having to edit the voice2json configuration files manually. However this means that the properties of our nodes are stored in the external voice2json configuration files, instead of in Node-RED's flow.json file.
An extra requirement is that the voice2json configuration files can be updated by a background process, without our node knowing it ...
We got something running already, but I'm not sure whether we are heading in the right direction...
Let's first have a look at a normal situation (without external files):
- When the flow editor is started, the node configuration is transferred from the server to the client.
- When the node’s config screen is opened, the configuration is displayed.
- The user can change the configuration in the node’s config screen.
- When the user clicks the ‘Done’ button (not ‘Cancel’) in the node’s config screen, the configuration is updated (on the client side). And the ‘Deploy’ button will become active automatically (since the node is 'dirty').
- When the user clicks the ‘Deploy’ button, the node configuration is transferred from the client to the server (and stored in the flow.json file).
- The server-side configuration is now up to date.
But have a look what happens when the node's config is stored in the voice2json configuration files:
- In our case the configuration is stored in the voice2json configuration files.
- We could load those config files from the server (via a http endpoint) into the node’s config screen. This can be done automatically (when the config screen opens), but then the node suddenly becomes dirty (and Deploy button active) which seems weird behaviour since the user hasn't changed anything. So makes more sense to have a "load config" button ...
- And when the configuration is changed in the config screen, the updated configuration can be written again to the files. Automatically or via a "Save" button.
This is very straightforward, however this way we entirely circumvent the Node-RED mechanism (no undo, no redo, the node doesn’t become dirty, the deploy button doesn’t become active, nothing is deployed, there is no automatic merge, …). And in the live stream yesterday, it was mentioned that Node-RED could offer in the far future mechanisms to let users see real-time what other users are changing. This kind of cool stuff will never work together with our mechanism...
So I would like to do it the Node-RED way, but don't know how
- Suppose we store the configuration data (i.e. the files contents) in the node by adding a
- As soon as the changes have been deployed (via the Deploy button), the node can store the changes into the files (see step 12). So don't think there is a problem here. P.S. the data will be stored both in the flow.json file and in the voice2json files.
- But don’t think it is possible to load the configuration from the files (see step 13), as soon as the configuration is loaded (step 1) into the flow editor. Which we really would need, since the configuration in the flow.json file can be out of sync with the voice2json files.
- When you deploy changes and somebody else has meanwhile changed the same nodes, Node-RED will show a "Merge" dialog. However when a background process has meanwhile changed the configuration files, those changes will be overwritten by the config of the node. So the user will not be aware that there has been a conflict, and there will be no Merge dialog box .
Not an easy problem. But still hoping for some good advice...
Thanks a lot!!