mirror of
https://github.com/hi2shark/nazhua.git
synced 2026-01-16 17:20:42 +08:00
🚀 0.4.11
✨ 更新WebSocket路径处理,确保URL以ws://或wss://开头
This commit is contained in:
parent
56959c7733
commit
444b70af47
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nazhua",
|
"name": "nazhua",
|
||||||
"version": "0.4.10",
|
"version": "0.4.11",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@ -10,10 +10,13 @@ import WSService from './service';
|
|||||||
* 获取不同版本的WebSocket路径
|
* 获取不同版本的WebSocket路径
|
||||||
*/
|
*/
|
||||||
function getWsApiPath() {
|
function getWsApiPath() {
|
||||||
|
let url = config.nazhua.wsPath;
|
||||||
if (config.nazhua.nezhaVersion === 'v1') {
|
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();
|
const msg = new MessageSubscribe();
|
||||||
|
|||||||
@ -11,7 +11,10 @@ class WSService {
|
|||||||
|
|
||||||
this.debug = options?.debug || false;
|
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 = {
|
this.$on = {
|
||||||
close: onClose || (() => {}),
|
close: onClose || (() => {}),
|
||||||
error: onError || (() => {}),
|
error: onError || (() => {}),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user