I’m developing an application in which I use ReactJS, Redux and Websockets. In this application I’m implementing live rendering feature. (User will get notification on the screen without refreshing the page).
Let’s say I have 2 components which I need to render.
- Notification
- Chat
I was thinking of opening 2 separate sockets with accessing 2 separate end points to get data for these 2 components.
Notification Component
componentDidMount() {
io("sample.data/endpoint/notification").on("data", data => this.setState({notificationData: data}));
}
Chat Component
componentDidMount() {
io("sample.data/endpoint/chat").on("data", data => this.setState({chatData: data}));
}
Instead of using 2 separate sockets, is there a way which i can do both these functions using 1 socket? In other words, there is an endpoint which retrieves both Notification and Chat data and and after getting that data, is there a way for me to filter and then feed those separate data in to 2 components?
In other words, is there a way to keep a centralized class to handle all the Websocket requests and feed the response to different components?
Let me know your comments regarding this and suggest me a way to approach this.