Skip to content

Commit

Permalink
Add ApnsClient keepAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Feb 20, 2024
1 parent a7e86c6 commit faa7603
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 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 @@

---

## [11.5.0](https://github.com/AndrewBarba/apns2/releases/tag/11.5.0)

1. Add `ApnsClient.keepAlive`
2. Deprecate `ApnsClient.pingInterval`

## [11.4.0](https://github.com/AndrewBarba/apns2/releases/tag/11.4.0)

1. Add `location` push type
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const client = new ApnsClient({
signingKey: fs.readFileSync(`${__dirname}/path/to/auth.p8`),
defaultTopic: `com.tablelist.Tablelist`,
requestTimeout: 0, // optional, Default: 0 (without timeout)
pingInterval: 5000, // optional, Default: 5000
keepAlive: true, // optional, Default: 5000
})
```

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apns2",
"version": "11.4.0",
"version": "11.5.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": "dist/index.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
"watchos"
],
"dependencies": {
"fetch-http2": "^1.3.0",
"fetch-http2": "^1.4.0",
"fast-jwt": "^3.3.2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/apns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export interface ApnsOptions {
defaultTopic?: string
host?: Host | string
requestTimeout?: number
keepAlive?: boolean | number

// @deprecated Use keepAlive instead
pingInterval?: number
}

Expand All @@ -40,6 +43,9 @@ export class ApnsClient extends EventEmitter {
readonly signingKey: string | Buffer | PrivateKey
readonly defaultTopic?: string
readonly requestTimeout?: number
readonly keepAlive?: boolean | number

// @deprecated Use keepAlive instead
readonly pingInterval?: number

private _token: SigningToken | null
Expand All @@ -52,6 +58,7 @@ export class ApnsClient extends EventEmitter {
this.defaultTopic = options.defaultTopic
this.host = options.host ?? Host.production
this.requestTimeout = options.requestTimeout
this.keepAlive = options.keepAlive
this.pingInterval = options.pingInterval
this._token = null
this.on(Errors.expiredProviderToken, () => this._resetSigningToken())
Expand Down Expand Up @@ -80,7 +87,7 @@ export class ApnsClient extends EventEmitter {
},
body: JSON.stringify(notification.buildApnsOptions()),
timeout: this.requestTimeout,
keepAlive: this.pingInterval ?? 5000
keepAlive: this.keepAlive ?? this.pingInterval ?? 5000
}

if (notification.priority !== Priority.immediate) {
Expand Down
2 changes: 1 addition & 1 deletion test/apns2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('apns', () => {
keyId: '7U6GT5Q49J',
signingKey: process.env.APNS_SIGNING_KEY ?? '',
defaultTopic: 'com.tablelist.Tablelist',
pingInterval: 100
keepAlive: 100
})
})

Expand Down

0 comments on commit faa7603

Please sign in to comment.