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
72.1
Supply Chain
98.8
Quality
83.6
Maintenance
100
Vulnerability
100
License
TypeScript (50.88%)
JavaScript (49.12%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
94,542
Last Day
93
Last Week
504
Last Month
2,361
Last Year
32,440
MIT License
125 Stars
67 Commits
17 Forks
7 Watchers
3 Branches
3,924 Contributors
Updated on Jan 09, 2025
Minified
Minified + Gzipped
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
1.1%
93
Compared to previous day
Last Week
1.8%
504
Compared to previous week
Last Month
28.7%
2,361
Compared to previous month
Last Year
-5%
32,440
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
all changesets reviewed
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
1 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-03-03
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