---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk/interfaces/WebSocketLikeInstance.md
---
[Reference](../../../index.md) / [@getenginex/sdk](../index.md) / WebSocketLikeInstance

# WebSocketLikeInstance

Socket opened by a [WebSocketLike](../type-aliases/WebSocketLike.md): the subset of the browser `WebSocket` that
realtime uses. The browser `WebSocket`, the Node 22+ global and the one from the `ws` package are compatible
(outside the browser, with the `Origin` header: see [WebSocketLike](../type-aliases/WebSocketLike.md)).

## Extended by

* [`MockSocket`](../testing/interfaces/MockSocket.md)

## Properties

### readyState

> `readonly` **readyState**: `number`

Connection state: `1` when open (`WebSocket.OPEN`).

## Methods

### addEventListener()

> **addEventListener**(`type`, `listener`): `void`

Subscribes to `open`, `message` (with `event.data` as text), `close` and `error`. Realtime subscribes to
all four; reconnection is driven by `close` (`error` is subscribed only so it is not left without a listener).

#### Parameters

##### type

`"message"` | `"error"` | `"close"` | `"open"`

Event name.

##### listener

(`event`) => `void`

Called on each event.

#### Returns

`void`

***

### close()

> **close**(`code?`, `reason?`): `void`

Closes the connection.

#### Parameters

##### code?

`number`

##### reason?

`string`

#### Returns

`void`

***

### send()

> **send**(`data`): `void`

Sends a text frame.

#### Parameters

##### data

`string`

#### Returns

`void`
