## IWebSocket interface

Generic interface that an implementation of `WebSocket` must satisfy to be used with `ReconnectingWebSocket`. This is a slightly modified fork of the `WebSocket` global type used in Node, narrowed to exactly the members `ReconnectingWebSocket` actually depends on.

`addEventListener`/`removeEventListener` declare a typed overload against `IWebSocketEventMap` (the global event interfaces, used here rather than the local `WebSocketEventMap` since they are generic enough to describe the events `ReconnectingWebSocket` attaches to). They also declare the permissive string overload that the real `WebSocket` types carry, which is what lets conformant implementations whose event types do not structurally match the global ones (e.g. the `ws` library, whose events are a minimal subset and use `target: WebSocket`) still satisfy this interface.

The `onopen`/`onclose`/`onmessage`/`onerror` handler properties are intentionally omitted: `ReconnectingWebSocket` never assigns to them (it uses `addEventListener`), and because they are function-valued properties their parameters are checked contravariantly, which no single precise event type can satisfy across implementations (e.g. `ws`'s events use `target: WebSocket` while the DOM's use `target: EventTarget | null`).

`binaryType` is widened to `string` and `send()` accepts the full `Message` union; a particular implementation should narrow each of these implementation-specific types.

**Signature:**

```typescript
export interface IWebSocket
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [binaryType](/content/docs/sdk/core.iwebsocket.binarytype) |  | string |  |
| [bufferedAmount](/content/docs/sdk/core.iwebsocket.bufferedamount) | `readonly` | number |  |
| [CLOSED](/content/docs/sdk/core.iwebsocket.closed) | `readonly` | number |  |
| [CLOSING](/content/docs/sdk/core.iwebsocket.closing) | `readonly` | number |  |
| [CONNECTING](/content/docs/sdk/core.iwebsocket.connecting) | `readonly` | number |  |
| [OPEN](/content/docs/sdk/core.iwebsocket.open) | `readonly` | number |  |
| [extensions](/content/docs/sdk/core.iwebsocket.extensions) | `readonly` | string |  |
| [protocol](/content/docs/sdk/core.iwebsocket.protocol) | `readonly` | string |  |
| [readyState](/content/docs/sdk/core.iwebsocket.readystate) | `readonly` | number |  |
| [url](/content/docs/sdk/core.iwebsocket.url) | `readonly` | string |  |

## Methods

| Method | Description |
| --- | --- |
| [addEventListener(type, listener, options)](/content/docs/sdk/core.iwebsocket.addeventlistener) |  |
| [addEventListener(type, listener, options)](/content/docs/sdk/core.iwebsocket.addeventlistener_1/index.html) |  |
| [close(code, reason)](/content/docs/sdk/core.iwebsocket.close) |  |
| [removeEventListener(type, listener, options)](/content/docs/sdk/core.iwebsocket.removeeventlistener) |  |
| [removeEventListener(type, listener, options)](/content/docs/sdk/core.iwebsocket.removeeventlistener_1/index.html) |  |
| [send(data)](/content/docs/sdk/core.iwebsocket.send) |  |

- [IWebSocket interface](/content/docs/sdk/core.iwebsocket#iwebsocket-interface/index.html)
- [Properties](/content/docs/sdk/core.iwebsocket#properties/index.html)
- [Methods](/content/docs/sdk/core.iwebsocket#methods/index.html)
