# extra-native-websocket

> ```sh npm install --save extra-native-websocket # or yarn add extra-native-websocket ```

Latest version **0.5.3** (published 2026-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install extra-native-websocket
pnpm add extra-native-websocket
yarn add extra-native-websocket
bun add extra-native-websocket
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.3 |
| Published | 2026-06-19 |
| First published | 2022-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 8 |
| Unpacked size | 33.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

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

## Dependencies (8)

- [extra-abort](https://npm.io/package/extra-abort.md) ^0.4.0
- [extra-defer](https://npm.io/package/extra-defer.md) ^0.3.1
- [assert-never](https://npm.io/package/assert-never.md) ^1.4.0
- [extra-promise](https://npm.io/package/extra-promise.md) ^7.0.0
- [@blackglory/errors](https://npm.io/package/@blackglory/errors.md) ^3.0.3
- [@blackglory/prelude](https://npm.io/package/@blackglory/prelude.md) ^0.4.0
- [@blackglory/wait-for](https://npm.io/package/@blackglory/wait-for.md) ^0.8.1
- [@blackglory/structures](https://npm.io/package/@blackglory/structures.md) ^0.14.10

## Recent versions

- 0.5.3 (latest) — 2026-06-19
- 0.5.2 — 2026-05-24
- 0.5.1 — 2026-02-27
- 0.5.0 — 2025-07-21
- 0.4.1 — 2024-08-01
- 0.4.0 — 2023-12-08
- 0.3.2 — 2023-06-10
- 0.3.1 — 2022-06-08
- 0.3.0 — 2022-06-08
- 0.2.2 — 2022-06-03
- 0.2.1 — 2022-06-02
- 0.2.0 — 2022-05-31
- 0.1.0 — 2022-05-30

## README

# extra-native-websocket
## Install
```sh
npm install --save extra-native-websocket
# or
yarn add extra-native-websocket
```

## API
### WebSocketError
```ts
class WebSocketError extends CustomError {
  readonly code: number
  readonly reason: string
}
```

### ExtraNativeWebSocket
```ts
import { Emitter } from '@blackglory/structures'

enum BinaryType {
  Blob
, ArrayBuffer
}

enum State {
  Closed
, Connecting
, Connected
, Closing
}

class ExtraNativeWebSocket extends Emitter<{
  open: [event: Event]
  message: [event: MessageEvent]
  error: [event: Event]
  close: [event: CloseEvent]
}> {
  constructor(createWebSocket: () => WebSocket)

  getState(): State
  getBinaryType(): BinaryType
  setBinaryType(val: BinaryType): void

  /**
   * @throws {WebSocketError}
   */
  connect(signal?: AbortSignal): Promise<void>
  close(code?: number, reason?: string): Promise<void>
  send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void
}
```

### autoReconnect
```ts
function autoReconnect(
  ws: ExtraNativeWebSocket
, reconnectInterval?: number = 0
, connectTimeout?: number
): () => void
```

### autoReconnectWithExponentialBackOff
```ts
function autoReonnectWithExponentialBackOff(
  ws: ExtraWebSocket
, reconnectInterval: {
    baseInterval: number
    maxInterval?: number = Infinity
    factor?: number = 2
    jitter?: boolean = true
  }
, connectTimeout?: number
): () => void
```

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