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 }) })