# @d-fischer/isomorphic-ws

> Isomorphic implementation of WebSocket

Latest version **7.0.2** (published 2024-02-20) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.0.2 |
| Published | 2024-02-20 |
| First published | 2020-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Daniel Fischer |
| Maintainers | d-fischer |
| Keywords | browser, browsers, isomorphic, node, websocket, ws |

## Links

- npm: https://www.npmjs.com/package/@d-fischer/isomorphic-ws
- Repository: https://github.com/d-fischer/isomorphic-ws
- Homepage: https://github.com/d-fischer/isomorphic-ws#readme
- Issues: https://github.com/d-fischer/isomorphic-ws/issues
- npm.io page: https://npm.io/package/@d-fischer/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

- 7.0.2 (latest) — 2024-02-20
- 7.0.1 — 2023-12-10
- 7.0.0 — 2021-09-27
- 6.0.0 — 2021-07-19
- 5.0.4 — 2021-05-31
- 5.0.3 — 2021-01-11
- 5.0.2 — 2020-04-29
- 5.0.1 — 2020-04-13
- 5.0.0 — 2020-04-13

## 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 @d-fischer/isomorphic-ws ws
```

Then just require this package:

```js
const WebSocket = require('@d-fischer/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/@d-fischer/isomorphic-ws · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
