diff --git a/src/notifications/senders/AppleNotificationSender.ts b/src/notifications/senders/AppleNotificationSender.ts index 4aac769..61c0b73 100644 --- a/src/notifications/senders/AppleNotificationSender.ts +++ b/src/notifications/senders/AppleNotificationSender.ts @@ -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');