https://github.com/spinda/ws-pacemaker
💗 Drop-in WebSocket ping/pong heartbeat handling for Node.js
https://github.com/spinda/ws-pacemaker
heartbeat javascript nodejs websocket
Last synced: about 2 months ago
JSON representation
💗 Drop-in WebSocket ping/pong heartbeat handling for Node.js
- Host: GitHub
- URL: https://github.com/spinda/ws-pacemaker
- Owner: spinda
- License: mpl-2.0
- Created: 2019-09-06T23:50:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:59:39.000Z (almost 3 years ago)
- Last Synced: 2025-08-09T19:33:51.709Z (2 months ago)
- Topics: heartbeat, javascript, nodejs, websocket
- Language: JavaScript
- Homepage:
- Size: 425 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ws-pacemaker
> Drop-in WebSocket ping/pong heartbeat handling for the [ws](https://github.com/websockets/ws)
> Node.js module[](https://npmjs.com/package/ws-pacemaker)
[](https://travis-ci.org/spinda/ws-pacemaker)## Overview
This module wraps around a
[`WebSocket.Server`](https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocketserver)
to send periodic heartbeat pings (via
[`WebSocket#ping`](https://github.com/websockets/ws/blob/master/doc/ws.md#websocketpingdata-mask-callback))
to all connected clients,
and closes connections when a corresponding pong is not received (via
[`WebSocket#'pong'`](https://github.com/websockets/ws/blob/master/doc/ws.md#event-pong)) within an
acceptable timeout.```js
'use strict';const WebSocket = require('ws');
const Pacemaker = require('ws-pacemaker');
const server = new WebSocket.Server({ port: 8080 });const pacemaker = new Pacemaker(server, {
pingInterval: Pacemaker.defaultPingInterval,
// ^ optional - default: send a ping every 25000 ms
pongTimeout: Pacemaker.defaultPongTimeout,
// ^ optional - default: terminate connections after 60000 ms without a pong
});pacemaker.start();
//pacemaker.stop();
// ^ automatically called when the server closes
```## Development
### Dependency Management
[Yarn](https://yarnpkg.com) is recommended for managing dependencies and development tooling.
### Code Formatting
Code formatting is handled by [prettierx](https://github.com/brodybits/prettierx), with a few
[options](.prettierrc.toml) tweaked.To check that the code is correctly formatted:
```
yarn run check
```To auto-format the code:
```
yarn run fmt
```### Testing
This project uses [Jest](https://jestjs.io/) as its test framework.
To run all tests:
```
yarn run test
```## License
Copyright (C) 2019-2020 Michael Smith <michael@spinda.net>
This program is free software: you can redistribute it and/or modify it under the terms of the
Mozilla Public License, version 2.0.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Mozilla
Public License for more details.You should have received a [copy](LICENSE) of the Mozilla Public License along with this program.
If not, see [https://www.mozilla.org/en-US/MPL/2.0/](https://www.mozilla.org/en-US/MPL/2.0/).Helpful resources:
- [Mozilla's MPL-2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/)
- [MPL-2.0 on TLDRLegal](https://tldrlegal.com/license/mozilla-public-license-2.0-\(mpl-2\))#### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in
this work by you shall be licensed as above, without any additional terms or conditions.