Skip to content

Commit

Permalink
v9.2.0 (#43)
Browse files Browse the repository at this point in the history
* Refactor http2-client to properly handle session errors

* Rename arg

* Fix ping
  • Loading branch information
AndrewBarba authored Nov 11, 2020
1 parent 0ab1aac commit 822bdbb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion lib/http2-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"main": "lib/apns.js",
Expand Down
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})

Expand Down

0 comments on commit 822bdbb

Please sign in to comment.