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

@insertish/isomorphic-ws

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@insertish/isomorphic-ws

Isomorphic implementation of WebSocket

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
46
decreased by-41.03%
Maintainers
1
Weekly downloads
 
Created
Source

isomorphic-ws

Isomorphic implementation of WebSocket.

It uses:

  • ws on Node
  • global.WebSocket in browsers

Limitations

Before using this module you should know that ws is not perfectly API compatible with WebSocket, you should always test your code against both Node and browsers.

Some major differences:

  • no Server implementation in browsers
  • no support for the constructor options argument in browsers

Usage

You need to install both this package and ws:

> npm i isomorphic-ws ws

Then just require this package:

const WebSocket = require('isomorphic-ws');

const ws = new WebSocket('wss://echo.websocket.org/');

ws.onopen = function open() {
  console.log('connected');
  ws.send(Date.now());
};

ws.onclose = function close() {
  console.log('disconnected');
};

ws.onmessage = function incoming(data) {
  console.log(`Roundtrip time: ${Date.now() - data.data} ms`);

  setTimeout(function timeout() {
    ws.send(Date.now());
  }, 500);
};

License

MIT

Keywords

FAQs

Package last updated on 23 Dec 2021

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