Installations
npm install websocket-promise-lite
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.16.0
NPM Version
8.11.0
Score
71
Supply Chain
94.1
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (94.52%)
JavaScript (5.48%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
pdwrl
Download Statistics
Total Downloads
2,297
Last Day
2
Last Week
7
Last Month
38
Last Year
326
GitHub Statistics
10 Stars
22 Commits
2 Forks
1 Watching
2 Branches
1 Contributors
Package Meta Information
Latest Version
2.1.1
Package Id
websocket-promise-lite@2.1.1
Unpacked Size
15.75 kB
Size
5.11 kB
File Count
8
NPM Version
8.11.0
Node Version
16.16.0
Publised On
16 Jun 2023
Total Downloads
Cumulative downloads
Total Downloads
2,297
Last day
0%
2
Compared to previous day
Last week
-65%
7
Compared to previous week
Last month
15.2%
38
Compared to previous month
Last year
-50.6%
326
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
What is it?
This is an Axios for WebSockets :-)
For what?
To easily work with sockets in async / await style.
Installation
npm i websocket-promise-lite
How to use?
1import WebsocketPromiseLiteClient from 'websocket-promise-lite' 2 3const demoFunc = async () => { 4 const WS = new WebsocketPromiseLiteClient({ 5 url: 'wss://ws.postman-echo.com/raw' 6 }) 7 await WS.connectionEstablished() 8 const answer = await WS.send({ 9 myMessage: 'hello websocket!' 10 }) 11 console.log(answer) 12 13 // next actions ... 14 15 WS.close() 16} 17 18demoFunc()
Important!
Back-end (websocket server) have to answer with the same "messageId" parameter!
API
methods
- connectionEstablished: waits for the connection to be established. If fails it reconnects automatically
- send: sends any unserialized object by WS
- close: closes WS at normal way (code 1000)
- destroy: destructor. Removes all event listeners, closes WS connection and clears the list of operations
1const WS = new WebsocketPromiseLiteClient(config)
where config is an object with a possible properties:
Config parameters
url: WebSocket URL. Must start with "ws://" or "wss://". The only required param
maxNumberOfReconnects: maximum number of reconnections, after which there will be no more reconnections. If -1 then will be no reconnections. Default Infinity
.
pauseBetweenReconnects: pause between reconnections (in ms). If 0 then reconnections will become after randomized pause. Pauses are stored in array [xyz, 3xyz, 5xyz, 8xyz, 12xyz, 17xyz ... 17xyz], where xyz is random number. This is so that all clients reconnects at different time for stable back-end. Default 0
.
connectTimeout: time in ms after which connection is considered unsuccessful (and then reconnects again). Default 5000
.
serializer: serializer function. For example, CBOR.encode
. Default JSON.stringify
.
deserializer: deserializer function. For example, CBOR.decode
. Default JSON.parse
.
binaryType: type of data to be transmitted. In most cases it's "arraybuffer". But You may specify it as blob
. Default arraybuffer
.
urlAdditionalGenerator: use it when second url part have to be generated by some algorythm. Pass a function.
onConnectionOpen: function (async or not) which is called when a connection is opened successfully for a 1st time
onConnectionClose: function (async or not) which is called when a connection is closed.
onConnectionReOpen: function (async or not) which is called when a connection is before reopen.
onBeforeReOpen: function (async or not) which is called when a connection is before reopen.
onNotPromisedData: function (async or not) which is called when server sends not promised data (simple WS data from back-end)
Tips
- Don't serialize data before sending via websocket-promise-lite. All the data is serialized by lib before sending.
- Library adds "messageId" field to object You are sending. Make sure Your data object has no field with the same name.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: license.txt:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.1
/10
Last Scanned on 2025-01-27
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