DEV Community

loading...

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

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.