# Connection

## Content

# Class: Connection

Represents a client-side collaboration connection.

## Table of contents

### Constructors

- [constructor](Connection#constructor)

### Accessors

- [connected](Connection#connected)
- [id](Connection#id)
- [roomId](Connection#roomid)

### Methods

- [close](Connection#close)
- [destroy](Connection#destroy)
- [off](Connection#off)
- [on](Connection#on)
- [once](Connection#once)
- [send](Connection#send)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new Connection**()

## Accessors

### <a id="connected" name="connected"></a> connected

• `get` **connected**(): `boolean`

Indicates whether the connection is active and able to send messages.

#### Returns

`boolean`

True if the connection is active, false otherwise.

___

### <a id="id" name="id"></a> id

• `get` **id**(): `string`

Retrieves the unique identifier of the connection.

#### Returns

`string`

The connection's ID.

___

### <a id="roomid" name="roomid"></a> roomId

• `get` **roomId**(): `string`

Retrieves the room identifier of the connection.

#### Returns

`string`

The room ID associated with the connection.

## Methods

### <a id="close" name="close"></a> close

▸ **close**(): `void`

Closes the connection to the server.

#### Returns

`void`

___

### <a id="destroy" name="destroy"></a> destroy

▸ **destroy**(): `void`

Destroys the observable and cleans up resources.

#### Returns

`void`

___

### <a id="off" name="off"></a> off

▸ **off**<`NAME`\>(`name`, `f`): `void`

Removes a listener for a specific event.

#### Type parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `NAME` | extends keyof [`IConnectionEvents`](../interfaces/IConnectionEvents) | The type of the event name, extending keyof IConnectionEvents. |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `NAME` | The name of the event to remove the listener from. |
| `f` | [`IConnectionEvents`](../interfaces/IConnectionEvents)[`NAME`] | The event handler function to remove. |

#### Returns

`void`

___

### <a id="on" name="on"></a> on

▸ **on**<`NAME`\>(`name`, `f`): [`IConnectionEvents`](../interfaces/IConnectionEvents)[`NAME`]

Register a listener for a specific event.

#### Type parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `NAME` | extends keyof [`IConnectionEvents`](../interfaces/IConnectionEvents) | The type of the event name, extending keyof IConnectionEvents. |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `NAME` | The name of the event to listen for. |
| `f` | [`IConnectionEvents`](../interfaces/IConnectionEvents)[`NAME`] | The event handler function. |

#### Returns

[`IConnectionEvents`](../interfaces/IConnectionEvents)[`NAME`]

___

### <a id="once" name="once"></a> once

▸ **once**<`NAME`\>(`name`, `f`): `void`

Registers a one-time listener for a specific event.

#### Type parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `NAME` | extends keyof [`IConnectionEvents`](../interfaces/IConnectionEvents) | The type of the event name, extending keyof IConnectionEvents. |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `NAME` | The name of the event to listen for. |
| `f` | [`IConnectionEvents`](../interfaces/IConnectionEvents)[`NAME`] | The event handler function to be called once. |

#### Returns

`void`

___

### <a id="send" name="send"></a> send

▸ **send**(`data`, `type?`): `void`

Sends a message to the server.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `data` | `unknown` | The data to send. |
| `type?` | [`MessageType`](../README#messagetype) | - |

#### Returns

`void`
