Skip to content

Commit 3058f1f

Browse files
committed
fix: nodejs push error
1 parent 578b850 commit 3058f1f

6 files changed

Lines changed: 157 additions & 56 deletions

File tree

example/node/allow_h2_for_push.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import undici from "npm:undici";
2+
import { BaseClient } from "@evex/linejs/base";
3+
4+
undici.setGlobalDispatcher(new undici.Agent({
5+
allowH2: true
6+
}));
7+
8+
//@ts-expect-error
9+
globalThis.Request = undici.Request;
10+
11+
const client = new BaseClient({
12+
//@ts-expect-error
13+
fetch: undici.fetch,
14+
});

packages/linejs/base/polling/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ export class Polling {
162162
try {
163163
cb && cb();
164164
await this.client.push.InitAndRead(this.listenTarget);
165-
await sleep(4);
165+
await sleep(4000);
166166
} catch (error) {
167167
this.client.log("LegyPusherError", { error });
168-
await sleep(4);
168+
await sleep(4000);
169169
}
170170
}
171171
this.islisten = false;

packages/linejs/base/push/conn.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class Conn {
222222
if (packet.pingType === LegyH2PingFrameType.ACK_REQUIRED) {
223223
this.writeByte(packet.ackPacket());
224224
this.manager.log(`[PUSH] send ping ack. pingId:${pingId}`, debugOnly);
225-
this.manager.OnPingCallback(pingId);
225+
this.manager.onPingCallback(pingId);
226226
} else {
227227
throw new Error(`ping type not Implemented: ${pingType}`);
228228
}
@@ -245,7 +245,7 @@ export class Conn {
245245
responsePayload = newPayload;
246246
delete this.notFinPayloads[requestId];
247247
}
248-
this.manager.OnSignOnResponse(requestId, isFin, responsePayload);
248+
this.manager.onSignOnResponse(requestId, isFin, responsePayload);
249249
} else {
250250
this.manager.log(
251251
`[PUSH] receives long data. requestId: ${requestId}, req=${req}`,
@@ -287,7 +287,7 @@ export class Conn {
287287
debugOnly,
288288
);
289289
}
290-
this.manager.OnPushResponse(packet);
290+
this.manager.onPushResponse(packet);
291291
} else {
292292
throw new Error(`push type not Implemented: ${pushType}`);
293293
}

packages/linejs/base/push/connManager.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export class ConnManager {
4343
conns: Conn[] = [];
4444
currPingId = 0;
4545
subscriptionIds: Record<number, number> = {};
46-
SignOnRequests: Record<number, LooseType[]> = {};
47-
OnPingCallback: (id: number) => void;
48-
OnSignReqResp: Record<number, LooseType> = {};
49-
OnSignOnResponse: (reqId: number, isFin: boolean, data: Uint8Array) => void;
50-
OnPushResponse: (frame: LegyH2PushFrame) => void;
46+
signOnRequests: Record<number, LooseType[]> = {};
47+
onPingCallback: (id: number) => void;
48+
onSignReqResp: Record<number, LooseType> = {};
49+
onSignOnResponse: (reqId: number, isFin: boolean, data: Uint8Array) => void;
50+
onPushResponse: (frame: LegyH2PushFrame) => void;
5151
_eventSynced = false;
5252
_pingInterval = 30;
5353
authToken: string | null = null;
@@ -58,9 +58,9 @@ export class ConnManager {
5858

5959
constructor(base: BaseClient) {
6060
this.client = base;
61-
this.OnPingCallback = this._OnPingCallback.bind(this);
62-
this.OnSignOnResponse = this._OnSignOnResponse.bind(this);
63-
this.OnPushResponse = this._OnPushResponse.bind(this);
61+
this.onPingCallback = this._OnPingCallback.bind(this);
62+
this.onSignOnResponse = this._OnSignOnResponse.bind(this);
63+
this.onPushResponse = this._OnPushResponse.bind(this);
6464
this.opStream = this.createAsyncReadableStream<Operation>();
6565
this.sqStream = this.createAsyncReadableStream<SquareEvent>();
6666
}
@@ -142,6 +142,7 @@ export class ConnManager {
142142
initServices = [3, 6, 8, 9, 10],
143143
): Promise<Conn> {
144144
const _conn = new Conn(this);
145+
this.signOnRequests = {};
145146
if (state === 1) {
146147
this.conns[0] = _conn;
147148
this.authToken = this.client.authToken!;
@@ -175,7 +176,7 @@ export class ConnManager {
175176
): Promise<{ payload: Uint8Array<ArrayBuffer>; id: number; }> {
176177
this.log("buildAndSendSignOnRequest", { serviceType, kwargs });
177178
const cl = this.client;
178-
const id = Object.keys(this.SignOnRequests).length + 1;
179+
const id = Object.keys(this.signOnRequests).length + 1;
179180
const idBuf = new Uint8Array(2);
180181
idBuf[0] = (id >> 8) & 0xff;
181182
idBuf[1] = id & 0xff;
@@ -207,7 +208,7 @@ export class ConnManager {
207208
header[4] = (req.length >> 8) & 0xff;
208209
header[5] = req.length & 0xff;
209210
header.set(req, 6);
210-
this.SignOnRequests[id] = [serviceType, methodName, null];
211+
this.signOnRequests[id] = [serviceType, methodName, null];
211212
this.log(
212213
`[H2][PUSH] send sign-on-request. requestId:${id}, service:${serviceType}`,
213214
);
@@ -222,11 +223,11 @@ export class ConnManager {
222223
): Promise<false | undefined> {
223224
// data = data.slice(5);
224225
const cl = this.client;
225-
if (!(reqId in this.SignOnRequests)) {
226+
if (!(reqId in this.signOnRequests)) {
226227
this.log(`[PUSH] unknown sign-on-response requestId:${reqId}`);
227228
return;
228229
}
229-
const entry = this.SignOnRequests[reqId];
230+
const entry = this.signOnRequests[reqId];
230231
const serviceType: number = entry[0];
231232
const methodName: string | undefined = entry[1];
232233

resources/line/line.thrift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17142,3 +17142,32 @@ struct LoginResult {
1714217142
7: string displayMessage;
1714317143
8: VerificationSessionData sessionForSMSConfirm;
1714417144
}
17145+
17146+
enum F61_EnumC10204a0 {
17147+
ALL = 0;
17148+
BLOCK = 1;
17149+
NOT_BLOCK = 2;
17150+
}
17151+
17152+
17153+
struct getUserFriendIds_args {
17154+
1: GetUserFriendIdsRequest request;
17155+
}
17156+
17157+
struct getUserFriendIds_result {
17158+
0: GetUserFriendIdsResponse success;
17159+
1: RejectedException re;
17160+
2: ServerFailureException sfe;
17161+
3: TalkException te;
17162+
}
17163+
17164+
17165+
struct GetUserFriendIdsRequest {
17166+
1: string userPageToken;
17167+
2: F61_EnumC10204a0 blockStatus;
17168+
}
17169+
17170+
struct GetUserFriendIdsResponse {
17171+
1: set<string> userFriendMids;
17172+
2: string nextUserPageToken;
17173+
}

0 commit comments

Comments
 (0)