Gathering detailed insights and metrics for simple-websocket
Gathering detailed insights and metrics for simple-websocket
Gathering detailed insights and metrics for simple-websocket
Gathering detailed insights and metrics for simple-websocket
websocket13
Simple WebSocket protocol 13 client with no native or heavy dependencies
@types/simple-websocket
TypeScript definitions for simple-websocket
socket-signal-websocket
socket-signal through simple-websocket
jquery-simple-websocket
jQuery Simple WebSocket - a fluent, gracefull websocket
npm install simple-websocket
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
184 Stars
295 Commits
32 Forks
6 Watching
4 Branches
9 Contributors
Updated on 25 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-1.6%
76,372
Compared to previous day
Last week
3.1%
404,122
Compared to previous week
Last month
6%
1,754,385
Compared to previous month
Last year
107.6%
17,576,820
Compared to previous year
This package is used by WebTorrent.
npm install simple-websocket
This package works in the browser with browserify. If
you do not use a bundler, you can use the simplewebsocket.min.js
standalone script
directly in a <script>
tag. This exports a SimpleWebsocket
constructor on
window
. Wherever you see Socket
in the examples below, substitute that with
SimpleWebsocket
.
1var Socket = require('simple-websocket') 2 3var socket = new Socket('wss://echo.websocket.org') 4socket.on('connect', function () { 5 // socket is connected! 6 socket.send('sup!') 7}) 8 9socket.on('data', function (data) { 10 console.log('got message: ' + data) 11})
socket = new Socket(url)
Create a new WebSocket connection to the server at url
. This usage is a shorthand
for socket = new Socket({ url: url })
socket = new Socket(opts)
If opts.url
is specified as a string, then a WebSocket connection will be created
to the server at opts.url
.
If opts.socket
is specified as an instance of a raw WebSocket object, then the
given WebSocket object will be used and one will not be automatically be created
internally. (This is for advanced users.)
Other properties on opts
will be passed through to the underlying superclass,
stream.Duplex
.
socket.send(data)
Send text/binary data to the WebSocket server. data
can be any of several types:
String
, Buffer
(see buffer), TypedArrayView
(Uint8Array
, etc.), ArrayBuffer
, or Blob
(in browsers that support it).
Note: If this method is called before the socket.on('connect')
event has fired, then
data will be buffered.
socket.destroy([err])
Destroy and cleanup this websocket connection.
If the optional err
parameter is passed, then it will be emitted as an 'error'
event on the stream.
Socket.WEBSOCKET_SUPPORT
Detect WebSocket support in the javascript environment.
1var Socket = require('simple-websocket') 2 3if (Socket.WEBSOCKET_SUPPORT) { 4 // websocket support! 5} else { 6 // fallback 7}
socket.on('connect', function () {})
Fired when the websocket connection is ready to use.
socket.on('data', function (data) {})
Received a message from the websocket server.
data
will be either a String
or a Buffer/Uint8Array
(see buffer).
JSON strings will be parsed and the resulting Object
emitted.
socket.on('close', function () {})
Called when the websocket connection has closed.
socket.on('error', function (err) {})
err
is an Error
object.
Fired when a fatal error occurs.
The server implementation is basically ws
but the 'connection'
event provides
sockets that are instances of simple-websocket
, i.e. they are duplex streams.
1var Server = require('simple-websocket/server') 2 3var server = new Server({ port: port }) // see `ws` docs for other options 4 5server.on('connection', function (socket) { 6 socket.write('pong') 7 socket.on('data', function (data) {}) 8 socket.on('close', function () {}) 9 socket.on('error', function (err) {}) 10}) 11 12server.close()
MIT. Copyright (c) Feross Aboukhadijeh.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
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 2024-11-25
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