feat: 添加query WS的功能

This commit is contained in:
2024-09-28 18:35:50 +08:00
parent 632d164087
commit ed178ee4c6
11 changed files with 239 additions and 13 deletions

24
src/utils.ts Normal file
View File

@@ -0,0 +1,24 @@
export const parseUrl = (url: string) => {
try {
new URL(url);
} catch (e) {
const _url = new URL(url, location.origin);
return _url.href;
}
};
export const parseWsUrl = (url: string) => {
try {
new URL(url);
return url;
} catch (e) {
const _url = new URL(url, location.origin);
if (_url.protocol === 'http:') {
_url.protocol = 'ws:';
}
if (_url.protocol === 'https:') {
_url.protocol = 'wss:';
}
return _url.href;
}
};