Multiple instance management for template node user interfaces?

This may well be a stupid question, in which case apologies for wasting peoples time . . .

I have a node-red app which offers out a dynamic web interface using a template node and websocket for dynamic interaction. Multiple users connect and use the user interface.

The user interface also has a page with a worldmap on. What I'm trying to do is default the worldmap starting location to the users lat+long when they connect. I can get their location ( successfully ) using the browsers geo location api.

So for example when a user connects, I can create and send back to the server a client generated guuid plus lat/long data. So for a particular user I know where they are - so far so good.

But presumably if I then use that info to default the start of the worldmap location, and connected user will see the map start point at the location of the latest connected user ?

What I'm confused about is how to create multiple instances of the map, one for each connected user, that defaults to their actual location. I know I can send the worldmap a payload with start lat/long, but that would simply be changed as multiple users connected wouldn't it ?

So it sent me down a mental rabbit hole where I'm unsure as to how multiple users are being 'seen' by the node-red server . . .

Does any of that actually make sense ?? Anyways, if it does, any thoughts appreciated,

Gav

1 Like

You would need to use a different Node-RED instance for each user.

I'm not entirely sure of the inner workings of Dave's Worldmap node. However, in general, nodes that have a comms channel to the front-end browser have unique identifiers on them such that, as long as you retain that information in the msg flow, a msg fed back to the comms node will only be delivered to the specific user that created the msg.

I'm most familiar with the uibuilder node (of course). This does the above process. When you send a msg to the uibuilder node (which incorporates a websocket connection courtesy of the Socket.IO library), it will be delivered to all connected clients.

However, if one of those clients sends a response message, it is tagged with a unique identifier for that client. So you can process that msg and as long as you keep hold of the id, you can send a new msg back into uibuilder and it will only be delivered to that single client.

You can easily check whether Worldmap is doing that by adding a debug node on the output set to show the whole msg.

thanks for your feedback and thoughts on this - very useful to me. I'll investigate this now.
Gav