Gathering detailed insights and metrics for @github/stable-socket
Gathering detailed insights and metrics for @github/stable-socket
Gathering detailed insights and metrics for @github/stable-socket
Gathering detailed insights and metrics for @github/stable-socket
npm install @github/stable-socket
Typescript
Module System
Node Version
NPM Version
TypeScript (50.88%)
JavaScript (49.12%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
127 Stars
67 Commits
17 Forks
7 Watchers
3 Branches
3,898 Contributors
Updated on Jun 23, 2025
Latest Version
1.1.1
Package Id
@github/stable-socket@1.1.1
Unpacked Size
13.88 kB
Size
4.23 kB
File Count
9
NPM Version
10.8.3
Node Version
22.9.0
Published on
Oct 14, 2024
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
A web socket that reconnects.
$ npm install @github/stable-socket
1import {StableSocket} from '@github/stable-socket'
2
3const delegate = {
4 socketDidOpen(socket: Socket) {
5 // Socket is ready to write.
6 socket.send('Hello')
7 },
8 socketDidClose(socket: Socket, code?: number, reason?: string) {
9 // Socket closed and will retry the connection.
10 },
11 socketDidFinish(socket: Socket) {
12 // Socket closed for good and will not retry.
13 },
14 socketDidReceiveMessage(socket: Socket, message: string) {
15 // Socket read data from the connection.
16 },
17 socketShouldRetry(socket: Socket, code: number): boolean {
18 // Socket reconnects unless server returns the policy violation code.
19 return code !== 1008
20 }
21}
22
23const policy = {
24 timeout: 4000,
25 attempts: Infinity,
26 maxDelay: 60000
27}
28
29const url = 'wss://live.example.com'
30const socket = new StableSocket(url , delegate, policy)
31socket.open()
Writing to a StableSocket while it is in the opening or closed states discards the message data. Use a BufferedSocket to buffer writes to be sent when it opens.
1import {BufferedSocket, StableSocket} from '@github/stable-socket' 2const socket = new BufferedSocket(new StableSocket(url, delegate, policy)) 3socket.open() 4socket.send('hello') // Will be sent when the socket is open.
StableSocket and BufferedSocket are abstractions over a WebSocket that maintain an internal state machine, managing reconnects and preventing writes to closed sockets. However, sometimes we need direct access to an open WebSocket in async functions.
Asynchronously connects to a web socket port or fails after a timeout. The
socket is open, and writable with send
, when its promise is fulfilled.
Returns a Promise fulfilled with an open WebSocket or rejected with a
connection failure.
1import {connect} from '@github/stable-socket' 2 3try { 4 const socket = await connect('wss://live.example.com', 100) 5 socket.send('hi') 6} catch (e) { 7 console.log('Socket connection failed', e) 8}
Asynchronously connects to a web socket port, retrying failed connections with exponential backoff. Returns a Promise fulfilled with an open WebSocket or rejected with a connection failure.
1import {connectWithRetry} from '@github/stable-socket' 2 3try { 4 const policy = {timeout: 100, attempts: Infinity, maxDelay: 60000} 5 const socket = await connectWithRetry('wss://live.example.com', policy) 6 socket.send('hi') 7} catch (e) { 8 console.log('Socket connection failed', e) 9}
npm install
npm test
Distributed under the MIT license. See LICENSE for details.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no binaries found in the repo
Reason
all changesets reviewed
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 4
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
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
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
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