How to ctx.state with socket io

I would suggest you check out: strapi-plugin-socket-io - npm

And likewise the forum thread for it by the maintainer: StrapIO the ez to use socket.io configurator