mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
reuse the client when sending a notification
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user