# websocket-polyfill

> WebSocket class from Browser to NodeJS

Latest version **1.0.0** (published 2024-02-24) · 0 weekly downloads

## Install

```sh
npm install websocket-polyfill
pnpm add websocket-polyfill
yarn add websocket-polyfill
bun add websocket-polyfill
```

## 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 | 1.0.0 |
| Published | 2024-02-24 |
| First published | 2018-10-04 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jeongho Nam |
| Maintainers | samchon |
| Keywords | WebSocket |

## Links

- npm: https://www.npmjs.com/package/websocket-polyfill
- Repository: https://github.com/samchon/websocket-polyfill
- Homepage: https://github.com/samchon/websocket-polyfill#readme
- Issues: https://github.com/samchon/websocket-polyfill/issues
- npm.io page: https://npm.io/package/websocket-polyfill

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^8.16.0
- [tstl](https://npm.io/package/tstl.md) ^2.5.13
- [import2](https://npm.io/package/import2.md) ^1.0.3

## 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

- 1.0.0 (latest) — 2024-02-24
- 0.0.3 — 2018-10-11
- 0.0.2 — 2018-10-09
- 0.0.1 — 2018-10-09
- 0.0.0 — 2018-10-04

## README

# WebSocket-Polyfill
> ## Deprecated
> This package had been developed very long time ago.
>
> It had utilized the [`websocket`](https://github.com/theturtle32/WebSocket-Node) library, but the polyfill could be just done by only one line with [`ws`](https://github.com/websockets/ws) library. In such reason, `websocket-polyfill` no more keeps long line of codes, but just have only one line like below.
>
> I think instead of importing this `websocket-polyfill` library, it would better to write the one line code by yourself.
>
> ```typescript
> import import2 from "import2"; // JUST TO AVOID TRANSPILING
> import { is_node } from "tstl"; // YOU CAN REPLACE IT LIKE BELOW
>
> // let is_node_: boolean | null = null;
> // const is_node = (): boolean =>
> //   (is_node_ ??=
> //     typeof global === "object" &&
> //     typeof global.process === "object" &&
> //     typeof global.process.versions === "object" &&
> //     typeof global.process.versions.node !== "undefined");
>
> if (is_node()) (global as any).WebSocket ??= import2("ws");
> ```

## Outline
WebSocket class for NodeJS.

## Installation
### NPM Module
```bash
npm install --save websocket-polyfill
```

### Usage
```typescript
import "websocket-polyfill";

const main = (): void => {
  const ws: WebSocket = new WebSocket("ws://127.0.0.1:38000/main");
  ws.onmessage = (msg: MessageEvent) => {
    console.log("Data from ws-server", msg.data);
  };
}
main();
```

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