我想在浏览器端构建一个相对于页面URI的WebSocket URI.比方说,在我的情况下转换HTTP URI就像
http://example.com:8000/path
https://example.com:8000/path
Run Code Online (Sandbox Code Playgroud)
至
ws://example.com:8000/path/to/ws
wss://example.com:8000/path/to/ws
Run Code Online (Sandbox Code Playgroud)
我目前正在做的是用"ws"替换前4个字母"http",并将"/ to/ws"附加到它上面.那有更好的方法吗?