This will undoubtedly break reverse proxying. WebSocket connections are established as normal HTTP connections first.

I'd suggest using the exact same path as the loaded page (window.location.href) with http replaced with ws
window.location.href.replace('http', 'ws').
^This handles https => wss as well.

I'd need to do some testing though. Gimme a few