isomorphic-ws
Isomorphic implementation of WebSocket
Last updated 2 years ago by heineiuo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install isomorphic-ws 
SYNC missed versions from official npm registry.

isomorphic-ws

Isomorphic implementation of WebSocket.

It uses:

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

Current Tags

  • 5.0.0-beta.3                                ...           beta (2 years ago)
  • 5.0.0                                ...           latest (2 years ago)

8 Versions

  • 5.0.0                                ...           2 years ago
  • 5.0.0-beta.3                                ...           2 years ago
  • 5.0.0-beta.2 [deprecated]           ...           2 years ago
  • 5.0.0-beta.1                                ...           2 years ago
  • 4.0.1                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.2.0                                ...           7 years ago
  • 2.3.1                                ...           8 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE