Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nanosocket

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanosocket

tiny modern websocket client

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Nanosocket

  • Tiny: ~20 lines, ~1 kb bundled
  • Handles reconnection with exponential backoff
  • Receive responses via callback/promise/stream (checkout emitterify)
example.html:
const socket = nanosocket('wss://echo.websocket.org')
// to connect to the same origin:
// const socket = nanosocket()

// log stream of incoming messages
socket.on('recv').map(d => console.log("recv", d))

// log all connection events
socket.on('connected').map(d => console.log("connected", d))

// log all disconnection events
socket.on('disconnected').map(d => console.log("disconnected", d))

// send a message
// note that this returns a promsie for when the message is actually sent
// since you can send when disconnected, and it will send after reconnecting etc
socket.send('boo').then(d => console.log("sent", d))

Keywords

FAQs

Package last updated on 03 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc