mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c9e91a9b94 | ||
![]() |
43fb62c5bd | ||
![]() |
cb8727d487 | ||
![]() |
a94e03e2fd |
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.5.2",
|
"version": "4.5.4",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -20,7 +20,7 @@ const WebsocketServerForm: React.FC<WebsocketServerFormProps> = ({
|
|||||||
enable: false,
|
enable: false,
|
||||||
name: '',
|
name: '',
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 3000,
|
port: 3001,
|
||||||
reportSelfMessage: false,
|
reportSelfMessage: false,
|
||||||
enableForcePushEvent: true,
|
enableForcePushEvent: true,
|
||||||
messagePostFormat: 'array',
|
messagePostFormat: 'array',
|
||||||
|
@@ -15,7 +15,7 @@ import { useWebSocketDebug } from '@/hooks/use-websocket-debug'
|
|||||||
|
|
||||||
export default function WSDebug() {
|
export default function WSDebug() {
|
||||||
const url = new URL(window.location.origin)
|
const url = new URL(window.location.origin)
|
||||||
url.port = '3000'
|
url.port = '3001'
|
||||||
url.protocol = 'ws:'
|
url.protocol = 'ws:'
|
||||||
const defaultWsUrl = url.href
|
const defaultWsUrl = url.href
|
||||||
const [socketConfig, setSocketConfig] = useLocalStorage(key.wsDebugConfig, {
|
const [socketConfig, setSocketConfig] = useLocalStorage(key.wsDebugConfig, {
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.5.2",
|
"version": "4.5.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.5.2';
|
export const napCatVersion = '4.5.4';
|
||||||
|
@@ -857,7 +857,7 @@ export class OneBotMsgApi {
|
|||||||
return parsedElement;
|
return parsedElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [];
|
return;
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@ import { IOB11NetworkAdapter } from '@/onebot/network/adapter';
|
|||||||
import json5 from 'json5';
|
import json5 from 'json5';
|
||||||
|
|
||||||
export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketServerConfig> {
|
export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketServerConfig> {
|
||||||
wsServer: WebSocketServer;
|
wsServer?: WebSocketServer;
|
||||||
wsClients: WebSocket[] = [];
|
wsClients: WebSocket[] = [];
|
||||||
wsClientsMutex = new Mutex();
|
wsClientsMutex = new Mutex();
|
||||||
private heartbeatIntervalId: NodeJS.Timeout | null = null;
|
private heartbeatIntervalId: NodeJS.Timeout | null = null;
|
||||||
@@ -30,7 +30,11 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketSer
|
|||||||
host: this.config.host === '0.0.0.0' ? '' : this.config.host,
|
host: this.config.host === '0.0.0.0' ? '' : this.config.host,
|
||||||
maxPayload: 1024 * 1024 * 1024,
|
maxPayload: 1024 * 1024 * 1024,
|
||||||
});
|
});
|
||||||
this.wsServer.on('connection', async (wsClient, wsReq) => {
|
this.createServer(this.wsServer);
|
||||||
|
|
||||||
|
}
|
||||||
|
createServer(newServer: WebSocketServer) {
|
||||||
|
newServer.on('connection', async (wsClient, wsReq) => {
|
||||||
if (!this.isEnable) {
|
if (!this.isEnable) {
|
||||||
wsClient.close();
|
wsClient.close();
|
||||||
return;
|
return;
|
||||||
@@ -40,7 +44,7 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketSer
|
|||||||
const paramUrl = wsReq.url?.indexOf('?') !== -1 ? wsReq.url?.substring(0, wsReq.url?.indexOf('?')) : wsReq.url;
|
const paramUrl = wsReq.url?.indexOf('?') !== -1 ? wsReq.url?.substring(0, wsReq.url?.indexOf('?')) : wsReq.url;
|
||||||
const isApiConnect = paramUrl === '/api' || paramUrl === '/api/';
|
const isApiConnect = paramUrl === '/api' || paramUrl === '/api/';
|
||||||
if (!isApiConnect) {
|
if (!isApiConnect) {
|
||||||
this.connectEvent(core, wsClient);
|
this.connectEvent(this.core, wsClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
wsClient.on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Client Error:', err.message));
|
wsClient.on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Client Error:', err.message));
|
||||||
@@ -74,7 +78,6 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketSer
|
|||||||
});
|
});
|
||||||
}).on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Server Error:', err.message));
|
}).on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Server Error:', err.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
connectEvent(core: NapCatCore, wsClient: WebSocket) {
|
connectEvent(core: NapCatCore, wsClient: WebSocket) {
|
||||||
try {
|
try {
|
||||||
this.checkStateAndReply<unknown>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT), wsClient);
|
this.checkStateAndReply<unknown>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT), wsClient);
|
||||||
@@ -96,7 +99,7 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketSer
|
|||||||
this.logger.logError('[OneBot] [WebSocket Server] Cannot open a opened WebSocket server');
|
this.logger.logError('[OneBot] [WebSocket Server] Cannot open a opened WebSocket server');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const addressInfo = this.wsServer.address();
|
const addressInfo = this.wsServer?.address();
|
||||||
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
||||||
|
|
||||||
this.isEnable = true;
|
this.isEnable = true;
|
||||||
@@ -108,7 +111,7 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketSer
|
|||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
this.isEnable = false;
|
this.isEnable = false;
|
||||||
this.wsServer.close((err) => {
|
this.wsServer?.close((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.logger.logError('[OneBot] [WebSocket Server] Error closing server:', err.message);
|
this.logger.logError('[OneBot] [WebSocket Server] Error closing server:', err.message);
|
||||||
} else {
|
} else {
|
||||||
@@ -205,6 +208,7 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter<WebsocketSer
|
|||||||
host: newConfig.host === '0.0.0.0' ? '' : newConfig.host,
|
host: newConfig.host === '0.0.0.0' ? '' : newConfig.host,
|
||||||
maxPayload: 1024 * 1024 * 1024,
|
maxPayload: 1024 * 1024 * 1024,
|
||||||
});
|
});
|
||||||
|
this.createServer(this.wsServer);
|
||||||
if (newConfig.enable) {
|
if (newConfig.enable) {
|
||||||
this.open();
|
this.open();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user