mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-25 18:10:07 +08:00
chore: network 初步完成
This commit is contained in:
parent
1cbfccc4eb
commit
44a8c8e35d
@ -26,7 +26,6 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
}
|
||||
|
||||
registerHeartBeat() {
|
||||
// WS反向心跳
|
||||
if (this.connection) {
|
||||
this.heartbeatTimer = setInterval(() => {
|
||||
if (this.connection && this.connection.readyState === NodeWebSocket.OPEN) {
|
||||
@ -42,8 +41,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
|
||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
if (this.connection) {
|
||||
const wrappedEvent = this.wrapEvent(event);
|
||||
this.connection.send(JSON.stringify(wrappedEvent));
|
||||
this.connection.send(JSON.stringify(event));
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +68,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
}
|
||||
|
||||
private async tryConnect() {
|
||||
while (!this.connection) {
|
||||
while (!this.connection && !this.isClosed) {
|
||||
try {
|
||||
this.connection = new NodeWebSocket(this.url);
|
||||
this.connection.on('message', (data) => {
|
||||
@ -102,12 +100,4 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
console.error('Failed to handle message:', e);
|
||||
}
|
||||
}
|
||||
|
||||
private wrapEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
// Wrap the event as needed
|
||||
return {
|
||||
type: 'event',
|
||||
data: event
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user