# isomorphic-ws

> Isomorphic implementation of WebSocket

Latest version **5.0.0** (published 2022-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install isomorphic-ws
pnpm add isomorphic-ws
yarn add isomorphic-ws
bun add isomorphic-ws
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2022-06-27 |
| First published | 2017-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 417 |
| Author | @heineiuo |
| Maintainers | heineiuo |
| Keywords | browser, browsers, isomorphic, node, websocket, ws |

## Links

- npm: https://www.npmjs.com/package/isomorphic-ws
- Repository: https://github.com/heineiuo/isomorphic-ws
- Homepage: https://github.com/heineiuo/isomorphic-ws#readme
- Issues: https://github.com/heineiuo/isomorphic-ws/issues
- npm.io page: https://npm.io/package/isomorphic-ws

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2022-06-27
- 5.0.0-beta.3 (beta) — 2022-06-27
- 5.0.0-beta.2 — 2022-06-27
- 5.0.0-beta.1 — 2022-06-06
- 4.0.1 — 2018-04-27
- 4.0.0 — 2018-02-07
- 3.2.0 — 2017-10-05
- 2.3.1 — 2017-04-28

## README

# isomorphic-ws

Isomorphic implementation of WebSocket.

It uses:
- [ws](https://github.com/websockets/ws) on Node
- [global.WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) in browsers

## Limitations

Before using this module you should know that
[`ws`](https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocket)
is not perfectly API compatible with
[WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/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`](https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketaddress-protocols-options)
  argument in browsers

## Usage

You need to install both this package and [ws](https://github.com/websockets/ws):

```
> npm i isomorphic-ws ws
```

Then just require this package:

```js
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](LICENSE)

---
_Source: https://npm.io/package/isomorphic-ws · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
