Skip to content

Commit

Permalink
chore: 使用 ReconnectingWebSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Dec 29, 2024
1 parent 897d3e3 commit 9e9c1a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"nodejs-base64": "^2.0.0",
"posthog-node": "^4.3.1",
"prompts": "^2.4.2",
"reconnecting-websocket": "^4.4.0",
"telegram": "^2.26.8",
"tmp-promise": "^3.0.3",
"tsx": "^4.19.2",
Expand Down
5 changes: 3 additions & 2 deletions main/src/client/NapCatClient/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NapCatFriend, NapCatGroup } from './entity';
import { napCatReceiveToMessageElem } from './convert';
import { NapCatFriendRequestEvent, NapCatGroupEvent, NapCatGroupInviteEvent } from './event';
import type { ImageElem } from '@icqqjs/icqq';
import ReconnectingWebSocket from 'reconnecting-websocket';

export interface CreateNapCatParams extends CreateQQClientParamsBase {
type: 'napcat';
Expand All @@ -17,11 +18,11 @@ export class NapCatClient extends QQClient {
private constructor(id: number, private readonly wsUrl: string) {
super(id);
this.logger = getLogger(`NapCatClient - ${id}`);
this.ws = new WebSocket(wsUrl);
this.ws = new ReconnectingWebSocket(wsUrl);
this.ws.onmessage = (e) => this.handleWebSocketMessage(e.data);
}

private readonly ws: WebSocket;
private readonly ws: ReconnectingWebSocket;
private readonly logger: Logger;

public static async create(params: CreateNapCatParams) {
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e9c1a3

Please sign in to comment.