🚀 0.4.11

 更新WebSocket路径处理,确保URL以ws://或wss://开头
This commit is contained in:
hi2hi 2024-12-10 01:51:27 +00:00
parent 56959c7733
commit 444b70af47
3 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "nazhua",
"version": "0.4.10",
"version": "0.4.11",
"type": "module",
"scripts": {
"dev": "vite",

View File

@ -10,10 +10,13 @@ import WSService from './service';
* 获取不同版本的WebSocket路径
*/
function getWsApiPath() {
let url = config.nazhua.wsPath;
if (config.nazhua.nezhaVersion === 'v1') {
return config.nazhua.v1WsPath;
url = config.nazhua.v1WsPath;
}
return config.nazhua.wsPath;
const a = document.createElement('a');
a.href = url;
return a.href.replace(/^http/, 'ws');
}
const msg = new MessageSubscribe();

View File

@ -11,7 +11,10 @@ class WSService {
this.debug = options?.debug || false;
this.$wsUrl = wsUrl?.replace?.('http', 'ws');
if (!wsUrl.startsWith('ws')) {
throw new Error('WebSocket URL must start with ws:// or wss://');
}
this.$wsUrl = wsUrl;
this.$on = {
close: onClose || (() => {}),
error: onError || (() => {}),