reuse the client when sending a notification

This commit is contained in:
2025-04-30 17:40:17 -07:00
parent 9dcc17b687
commit 075b35e7ad

View File

@@ -1,5 +1,6 @@
import jwt from "jsonwebtoken";
import http2 from "http2";
import { ClientHttp2Session } from "node:http2";
interface APNsUrl {
fullUrl: string;
@@ -17,6 +18,8 @@ export class AppleNotificationSender {
private apnsToken: string | undefined = undefined;
private _lastRefreshedTimeMs: number | undefined = undefined;
private client: ClientHttp2Session | undefined = undefined;
constructor(private shouldActuallySendNotifications = true) {
this.sendNotificationImmediately = this.sendNotificationImmediately.bind(this);
this.lastReloadedTimeForAPNsIsTooRecent = this.lastReloadedTimeForAPNsIsTooRecent.bind(this);
@@ -95,7 +98,10 @@ export class AppleNotificationSender {
"apns-topic": bundleId,
};
try {
const client = http2.connect(host);
if (!this.client) {
this.client = http2.connect(host);
}
const client = this.client;
const req = client.request(headers);
req.setEncoding('utf8');