DEV Community

Discussion on: Nuxt-Socket.IO: How Namespaces Config May Make Your Life Insanely Easier

richardeschloss profile image
Richard Schloss Author • Edited on

I've been wondering the same thing. I have a "dynamic" and "evolving" API feature I've been thinking about and wanting to implement! Currently the namespace config works for namespaces known ahead of time, but I would like to get dynamic namespaces working somehow. I hope I can help in the future! (I'm sorry the feature isn't there yet :/ )

ahereandnow profile image

It's okay. This seems like a great tool. And frankly, it turned out that it would be better to source handling of namespaces and rooms on the server side, so your current implementation is arranged perfectly for me. Thank you for writing this! It does make it simpler to manage reactivity by a lot, in my opinion.

Thread Thread
richardeschloss profile image
Richard Schloss Author

I fully agree. I was thinking that maybe the server would already have an API it supports, perhaps like:

const api = Object.freeze({
  version: 1.14,
  addUser() { ... },
  sendMsg() { ... }

And then maybe a specific set of events can be reserved for the dynamic api use, so that the client listen for "serverApi" event, and the server may handle it like:

io.on('connection', (socket) => {
  socket.emit('serverApi', { api: Object.keys(api), version: api.version })

And then maybe when the client receives that api, dynamically configure the namespace emitters. And that might be pretty cool, because that could be a lot less manual config for the developer to do.