mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
reuse the client when sending a notification
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import http2 from "http2";
|
import http2 from "http2";
|
||||||
|
import { ClientHttp2Session } from "node:http2";
|
||||||
|
|
||||||
interface APNsUrl {
|
interface APNsUrl {
|
||||||
fullUrl: string;
|
fullUrl: string;
|
||||||
@@ -17,6 +18,8 @@ export class AppleNotificationSender {
|
|||||||
private apnsToken: string | undefined = undefined;
|
private apnsToken: string | undefined = undefined;
|
||||||
private _lastRefreshedTimeMs: number | undefined = undefined;
|
private _lastRefreshedTimeMs: number | undefined = undefined;
|
||||||
|
|
||||||
|
private client: ClientHttp2Session | undefined = undefined;
|
||||||
|
|
||||||
constructor(private shouldActuallySendNotifications = true) {
|
constructor(private shouldActuallySendNotifications = true) {
|
||||||
this.sendNotificationImmediately = this.sendNotificationImmediately.bind(this);
|
this.sendNotificationImmediately = this.sendNotificationImmediately.bind(this);
|
||||||
this.lastReloadedTimeForAPNsIsTooRecent = this.lastReloadedTimeForAPNsIsTooRecent.bind(this);
|
this.lastReloadedTimeForAPNsIsTooRecent = this.lastReloadedTimeForAPNsIsTooRecent.bind(this);
|
||||||
@@ -95,7 +98,10 @@ export class AppleNotificationSender {
|
|||||||
"apns-topic": bundleId,
|
"apns-topic": bundleId,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const client = http2.connect(host);
|
if (!this.client) {
|
||||||
|
this.client = http2.connect(host);
|
||||||
|
}
|
||||||
|
const client = this.client;
|
||||||
const req = client.request(headers);
|
const req = client.request(headers);
|
||||||
req.setEncoding('utf8');
|
req.setEncoding('utf8');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user