From 822bdbbdbfc8db4c55b44c7276af23cd3b6e0727 Mon Sep 17 00:00:00 2001 From: Andrew Barba Date: Tue, 10 Nov 2020 20:42:33 -0500 Subject: [PATCH] v9.2.0 (#43) * Refactor http2-client to properly handle session errors * Rename arg * Fix ping --- CHANGELOG.md | 5 +++++ lib/http2-client.js | 17 ++++++++++++++++- package.json | 2 +- test/test.js | 3 ++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6400af..292659d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ --- +## [9.2.0](https://github.com/AndrewBarba/apns2/releases/tag/9.2.0) + +1. Allow disabling pingInterval +2. Fix issue with missing ping callback + ## [9.1.0](https://github.com/AndrewBarba/apns2/releases/tag/9.1.0) 1. Correctly handle socket error events diff --git a/lib/http2-client.js b/lib/http2-client.js index e8cfb93..424bb41 100644 --- a/lib/http2-client.js +++ b/lib/http2-client.js @@ -135,11 +135,26 @@ class HTTP2Client { client.on('error', () => this._closeAndDestroy(client)) client.on('socketError', () => this._closeAndDestroy(client)) client.on('goaway', () => this._closeAndDestroy(client)) + if (this._pingIntervalMs) { + this._createPingInterval(client) + } this._client = client - this._pingInterval = setInterval(() => client.ping(), this._pingIntervalMs).unref() return client } + /** + * Sends a ping on an interval + * + * @private + * @method _createPingInterval + */ + _createPingInterval(client) { + const sendPing = () => { + client.ping(null, () => {}) + } + this._pingInterval = setInterval(sendPing, this._pingIntervalMs).unref() + } + /** * Closes and destorys the existing client. A new client will be created on next request * diff --git a/package.json b/package.json index 502003e..227fb08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apns2", - "version": "9.1.0", + "version": "9.2.0", "description": "Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.", "author": "Andrew Barba ", "main": "lib/apns.js", diff --git a/test/test.js b/test/test.js index 9046cf8..0870223 100644 --- a/test/test.js +++ b/test/test.js @@ -33,7 +33,8 @@ describe('apns', () => { team: `TFLP87PW54`, keyId: `7U6GT5Q49J`, signingKey: process.env.APNS_SIGNING_KEY, - defaultTopic: `com.tablelist.Tablelist` + defaultTopic: `com.tablelist.Tablelist`, + pingInterval: 100 }) })