I was trying to run this in a Docker container, but got ws:// URLs with the container's internal IP address. It looks like the code walks over the server's available IP addresses and uses the last one it finds for all ws:// URLs. This won't work in a Docker, but also won't necessarily work right on any server with more than one IP address.
It seems like it would be better to have a configurable hostname to use, or default to the Host: header from the HTTP request (since that got the client here to begin with). The Host: header would work for most hosts (which only have a single A/AAAA record), and a configurable hostname would handle the rest.