# @monsterbitar/isomorphic-ws

> Isomorphic implementation of WebSocket with ESM support

Latest version **5.3.1** (published 2024-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @monsterbitar/isomorphic-ws
pnpm add @monsterbitar/isomorphic-ws
yarn add @monsterbitar/isomorphic-ws
bun add @monsterbitar/isomorphic-ws
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.3.1 |
| Published | 2024-01-08 |
| First published | 2023-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | @heineiuo |
| Maintainers | monsterbitar |
| Keywords | browser, browsers, isomorphic, node, websocket, ws |

## Links

- npm: https://www.npmjs.com/package/@monsterbitar/isomorphic-ws
- Repository: https://gitlab.com/GeneralProtocols/electrum-cash/isomorphic-ws
- Homepage: https://gitlab.com/GeneralProtocols/electrum-cash/isomorphic-ws#readme
- Issues: https://gitlab.com/GeneralProtocols/electrum-cash/isomorphic-ws/issues
- npm.io page: https://npm.io/package/@monsterbitar/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.3.1 (latest) — 2024-01-08
- 5.3.0 — 2023-10-05
- 5.2.0 — 2023-07-11
- 5.1.5 — 2023-06-22
- 5.1.4 — 2023-06-20
- 5.1.3 — 2023-06-20
- 5.1.2 — 2023-06-19
- 5.1.1 — 2023-06-19
- 5.1.0 — 2023-06-19

## README

# isomorphic-ws

Isomorphic implementation of WebSocket.

NOTE: This is a fork that simply exports the package as an ESM support version in addition to the existing packages.

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://websocket-echo.com/');

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/@monsterbitar/isomorphic-ws · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
