chore: server

This commit is contained in:
手瓜一十雪 committed 2024-08-09 16:49:40 +08:00
1 parent ee38508563
commit 49fa155368
5 files changed
+508

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import { WebSocket as WebSocketClass } from 'ws';
import { OB11Response } from '../../action/OB11Response';
import { PostEventType } from '../postOB11Event';
import { log, logDebug, logError } from '@/common/utils/log';
import { isNull } from '@/common/utils/helper';
export function wsReply(wsClient: WebSocketClass, data: OB11Response | PostEventType) {
try {
const packet = Object.assign({}, data);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
if (isNull(packet['echo'])) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
delete packet['echo'];
}
wsClient.send(JSON.stringify(packet));
logDebug('ws 消息上报', wsClient.url || '', data);
} catch (e: any) {
logError('websocket 回复失败', e.stack, data);
}
}