feat(core): 当页面为http时,自动使用ws协议连接web-socket

This commit is contained in:
王立帮
2025-05-22 22:10:25 +08:00
parent 99d4ce9d2d
commit c3e7039ffa
2 changed files with 8 additions and 6 deletions

View File

@@ -27,12 +27,13 @@ Loader.init = function () {
let url = ''; let url = '';
if (SOFTWARE.webCompiler?.url) { if (SOFTWARE.webCompiler?.url) {
const info = new window.URL(SOFTWARE.webCompiler.url); const info = new window.URL(SOFTWARE.webCompiler.url);
if (window.location.protocol === 'http:') {
info.protocol = 'ws:';
}
if (info.hostname === 'default') { if (info.hostname === 'default') {
info.hostname = window.location.hostname; info.hostname = window.location.hostname;
url = info.origin;
} else {
url = SOFTWARE.webCompiler.url;
} }
url = info.origin;
} else { } else {
url = `wss://${window.location.host}`; url = `wss://${window.location.host}`;
} }

View File

@@ -33,12 +33,13 @@ Loader.init = function () {
let url = ''; let url = '';
if (SOFTWARE.webSocket?.url) { if (SOFTWARE.webSocket?.url) {
const info = new window.URL(SOFTWARE.webSocket.url); const info = new window.URL(SOFTWARE.webSocket.url);
if (window.location.protocol === 'http:') {
info.protocol = 'ws:';
}
if (info.hostname === 'default') { if (info.hostname === 'default') {
info.hostname = window.location.hostname; info.hostname = window.location.hostname;
url = info.origin;
} else {
url = SOFTWARE.webSocket.url;
} }
url = info.origin;
} else { } else {
url = `wss://${window.location.host}`; url = `wss://${window.location.host}`;
} }