Detect 127.0.0.1 as localhost as well
I think the actual point is that if the website is served over https,
the websocket must be wss. I'm not sure why a wss socket wouldn't work
ws:// socket works for me on https:// page. I use ws:// because I couldn't get wss:// socket to work in my setup, some certificate issue not related to the hostname.