Gathering detailed insights and metrics for robust-websocket
Gathering detailed insights and metrics for robust-websocket
Gathering detailed insights and metrics for robust-websocket
Gathering detailed insights and metrics for robust-websocket
altamoon-robust-websocket
A robust reconnecting WebSocket client for the browser
@jknott/typescript-robust-websocket
A robust reconnecting WebSocket client for the browser with ts compatability based on robust-websocket
react-native-use-websocket
React Native Hook designed to provide robust WebSocket integrations to your Components.
ws-robust
A wrapper around the browser's WebSocket to make it easier to work with
npm install robust-websocket
Typescript
Module System
Node Version
NPM Version
JavaScript (92.06%)
HTML (7.94%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
165 Stars
59 Commits
25 Forks
2 Watchers
4 Branches
9 Contributors
Updated on Jul 02, 2025
Latest Version
1.0.0
Package Id
robust-websocket@1.0.0
Size
9.44 kB
NPM Version
5.6.0
Node Version
8.11.3
Published on
Nov 12, 2018
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
robust-websocket
is a wrapper around the standard WebSocket class that implements the same interface, but can reconnect when disconnected or the user's computer comes back online.
It is error-code aware and will not reconnect on 1008 (HTTP 400 equivalent) and 1011 (HTTP 500 equivalent) by default. This behavior is fully configurable via the shouldConnect
(see Usage).
Use it as you would a normal websocket:
1var ws = new RobustWebSocket('ws://echo.websocket.org/') 2 3ws.addEventListener('open', function(event) { 4 ws.send('Hello!') 5}) 6 7ws.addEventListener('message', function(event) { 8 console.log('we got: ' + event.data) 9})
But with an optional set of options you can specify as a 3rd parameter
1var ws = new RobustWebSocket('ws://echo.websocket.org/', null { 2 // The number of milliseconds to wait before a connection is considered to have timed out. Defaults to 4 seconds. 3 timeout: 4000, 4 // A function that given a CloseEvent or an online event (https://developer.mozilla.org/en-US/docs/Online_and_offline_events) and the `RobustWebSocket`, 5 // will return the number of milliseconds to wait to reconnect, or a non-Number to not reconnect. 6 // see below for more examples; below is the default functionality. 7 shouldReconnect: function(event, ws) { 8 if (event.code === 1008 || event.code === 1011) return 9 return [0, 3000, 10000][ws.attempts] 10 }, 11 // A boolean indicating whether or not to open the connection automatically. Defaults to true, matching native [WebSocket] behavior. 12 // You can open the websocket by calling `open()` when you are ready. You can close and re-open the RobustWebSocket instance as much as you wish. 13 automaticOpen: true, 14 // A boolean indicating whether to disable subscribing to the connectivity events provided by the browser. 15 // By default RobustWebSocket instances use connectivity events to avoid triggering reconnection when the browser is offline. This flag is provided in the unlikely event of cases where this may not be desired. 16 ignoreConnectivityEvents: false 17})
The URL parameter can either be a string, or a function which returns a string. This can be useful if you need the WebSocket to reconnect to a different URL than it connected to initially:
1var ws = new RobustWebSocket((ws) => { 2 return ws.reconnects > 0 ? `ws://echo.websocket.org/?reconnect=${ws.reconnects}` : `ws://echo.websocket.org/` 3});
shouldReconnect
ExamplesReconnect with an exponetial backoff on all errors
1function shouldReconnect(event, ws) { 2 return Math.pow(1.5, ws.attempts) * 500 3}
Reconnect immediately but only 20 times per RobustWebSocket instance
1function shouldReconnect(event, ws) { 2 return ws.reconnects <= 20 && 0 3}
Reconnect only on some whitelisted codes, and only 3 attempts, except on online events, then connect immediately
1function shouldReconnect(event, ws) { 2 if (event.type === 'online') return 0 3 return [1006,1011,1012].indexOf(event.code) && [1000,5000,10000][ws.attempt] 4}
See documentation for CloseEvent and online event, the two types of events that shouldReconnect
will receive.
Typically, websockets closed with code 1000
indicate that the socket
closed normally. In these cases, robust-websocket
won't call
shouldReconnect
(and will not attempt to reconnect), unless you set
shouldReconnect.handle1000
to true
.
You may need these polyfills to support older browsers
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More