I'm building an app with some realtime features (notifications, real-time comments, ..., and of course the classic chatroom). It's structured as a single page app. I'm using page.js to handle routes, require.js, and, for now, a simple custom mvc framework. Backend with node and socket.io for the realtime support.
The thing is, I have different sections, like home, posts, chat. Each section is dynamically rendered based on the routes. Now, how should I bind specific socket events for each section? I don't want to listen to events that are unrelated to the current viewing section. Should I create a new connection everytime the user changes the section, targeting a different namespace? Or should I remove all the event listeners in the socket, and attach a new set of events? I don't know what's the best approach, or if socket.io is the best choice for this.
Thanks.