Reputation: 131
i am making a Web app using Socket.io with express.
I want to emit data to all the clients and all the clients can edit/update that data and that updated data will be updated in realtime(for all the clients).
Is this possible, without removing and updating whole data? And what if a new user joins the room and i want to show the data same as on the other clients
Upvotes: 1
Views: 74
Reputation: 707148
Is this possible, without removing and updating whole data?
Yes, it is possible.
Socket.io is just a transport that lets you send data between client and server. With code such as:
io.emit('someMsg', someData)
You can broadcast data to all clients connected to the default namespace.
If you want to send incremental updates to each of your connected clients, then you have to manufacture that incremental data on your server, put it into an object or array and then broadcast that to your clients.
It will then be up to the clients themselves to receive that data, process it and update their own client display - presumably by changing the DOM to insert, delete or modify data on screen.
Neither node.js, socket.io or express have any built-in mechanisms for creating the incremental packets of data or updating the display. That would be up to you to do.
And what if a new user joins the room and i want to show the data same as on the other clients
Generally, it is the server's responsibility to know how to generate the current data set for any new user that enters. It may be able to do that from scratch with some set of queries or it may have to accumulate the data that has been built over time so it can send that to any new users (or even any existing user that just hits refresh).
Upvotes: 1