diff --git a/manifest.json b/manifest.json index d1684cb7..7d24b713 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "NapCatQQ", "slug": "NapCat.Framework", "description": "高性能的 OneBot 11 协议实现", - "version": "2.4.3", + "version": "2.4.4", "icon": "./logo.png", "authors": [ { diff --git a/package.json b/package.json index 201882b1..f8a0c1a5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "napcat", "private": true, "type": "module", - "version": "2.4.3", + "version": "2.4.4", "scripts": { "build:framework": "vite build --mode framework", "build:shell": "vite build --mode shell", diff --git a/src/common/version.ts b/src/common/version.ts index 73f14927..e612013f 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1 +1 @@ -export const napCatVersion = '2.4.3'; +export const napCatVersion = '2.4.4'; diff --git a/src/onebot/network/passive-websocket.ts b/src/onebot/network/passive-websocket.ts index 70b2f371..0f4e5c61 100644 --- a/src/onebot/network/passive-websocket.ts +++ b/src/onebot/network/passive-websocket.ts @@ -21,6 +21,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { core: NapCatCore; logger: LogWrapper; private heartbeatIntervalId: NodeJS.Timeout | null = null; + wsClientWithEvent: WebSocket[] = []; constructor( ip: string, @@ -46,7 +47,12 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { } //鉴权 this.authorize(token, wsClient, wsReq); - this.connectEvent(core, wsClient); + let paramUrl = wsReq.url?.indexOf('?') !== -1 ? wsReq.url?.substring(0, wsReq.url?.indexOf('?')) : wsReq.url; + const isEventConnect = paramUrl === '/event' || paramUrl === '' || paramUrl === '/'; + if (isEventConnect) { + this.connectEvent(core, wsClient); + } + wsClient.on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Client Error:', err.message)); wsClient.on('message', (message) => { this.handleMessage(wsClient, message).then().catch(this.logger.logError); @@ -59,13 +65,21 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { }); wsClient.once('close', () => { this.wsClientsMutex.runExclusive(async () => { - const index = this.wsClients.indexOf(wsClient); - if (index !== -1) { - this.wsClients.splice(index, 1); + const NormolIndex = this.wsClients.indexOf(wsClient); + if (NormolIndex !== -1) { + this.wsClients.splice(NormolIndex, 1); } + const EventIndex = this.wsClientWithEvent.indexOf(wsClient); + if (EventIndex !== -1) { + this.wsClientWithEvent.splice(EventIndex, 1); + } + }); }); await this.wsClientsMutex.runExclusive(async () => { + if(isEventConnect){ + this.wsClientWithEvent.push(wsClient); + } this.wsClients.push(wsClient); }); }).on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Server Error:', err.message)); @@ -81,7 +95,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { onEvent(event: T) { this.wsClientsMutex.runExclusive(async () => { - this.wsClients.forEach((wsClient) => { + this.wsClientWithEvent.forEach((wsClient) => { wsClient.send(JSON.stringify(event)); }); }); diff --git a/src/webui/ui/NapCat.ts b/src/webui/ui/NapCat.ts index f6e6c02c..9d33f560 100644 --- a/src/webui/ui/NapCat.ts +++ b/src/webui/ui/NapCat.ts @@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) { SettingItem( 'Napcat', undefined, - SettingButton('V2.4.3', 'napcat-update-button', 'secondary'), + SettingButton('V2.4.4', 'napcat-update-button', 'secondary'), ), ]), SettingList([ diff --git a/static/assets/renderer.js b/static/assets/renderer.js index a17485a9..3fc06e5f 100644 --- a/static/assets/renderer.js +++ b/static/assets/renderer.js @@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) { SettingItem( 'Napcat', void 0, - SettingButton("V2.4.3", "napcat-update-button", "secondary") + SettingButton("V2.4.4", "napcat-update-button", "secondary") ) ]), SettingList([