# ClientObserver

<a id="clientobserver"></a>

# ClientObserver

```cpp
#include <icy/turn/client/client.h>

struct ClientObserver
```

[Defined in src/turn/include/icy/turn/client/client.h:69](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L69)

> **Subclassed by:** [`TCPClientObserver`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClientObserver.md#tcpclientobserver)

Abstract observer interface for TURN client events. Callers subclass this to receive allocation lifecycle and data relay callbacks.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`onClientStateChange`](#onclientstatechange) `virtual` | Called whenever the client's state machine transitions to a new state. |
| `void` | [`onRelayDataReceived`](#onrelaydatareceived) `virtual` | Called when relayed data is received from a peer via a Data Indication. |
| `void` | [`onAllocationFailed`](#onallocationfailed) `virtual` `inline` | Called when the server rejects an Allocate request with an error. |
| `void` | [`onAllocationDeleted`](#onallocationdeleted) `virtual` `inline` | Called when the server confirms deletion of the allocation. |
| `void` | [`onAllocationPermissionsCreated`](#onallocationpermissionscreated) `virtual` `inline` | Called after a CreatePermission request succeeds. |
| `void` | [`onTransactionResponse`](#ontransactionresponse) `virtual` `inline` | All received transaction responses will be routed here after local processing so the observer can easily implement extra functionality. |
| `void` | [`onTimer`](#ontimer-2) `virtual` `inline` | Fires after the client's internal timer callback. Handy for performing extra async cleanup tasks. |

---

<a id="onclientstatechange"></a>

### onClientStateChange

`virtual`

```cpp
virtual void onClientStateChange(Client & client, ClientState & state, const ClientState & oldState)
```

[Defined in src/turn/include/icy/turn/client/client.h:75](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L75)

Called whenever the client's state machine transitions to a new state.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The client that changed state. |
| `state` | [`ClientState`](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientState.md#clientstate) & | The new state. |
| `oldState` | const [`ClientState`](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientState.md#clientstate) & | The previous state. |

---

<a id="onrelaydatareceived"></a>

### onRelayDataReceived

`virtual`

```cpp
virtual void onRelayDataReceived(Client & client, const char * data, size_t size, const net::Address & peerAddress)
```

[Defined in src/turn/include/icy/turn/client/client.h:82](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L82)

Called when relayed data is received from a peer via a Data Indication.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The owning client. |
| `data` | `const char *` | Pointer to the received payload bytes. |
| `size` | `size_t` | Number of bytes in `data`. |
| `peerAddress` | const [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) & | Source address of the remote peer. |

---

<a id="onallocationfailed"></a>

### onAllocationFailed

`virtual` `inline`

```cpp
virtual inline void onAllocationFailed(Client & client, int errorCode, const std::string & reason)
```

[Defined in src/turn/include/icy/turn/client/client.h:88](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L88)

Called when the server rejects an Allocate request with an error.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The owning client. |
| `errorCode` | `int` | STUN error code (e.g. 401, 438). |
| `reason` | `const std::string &` | Human-readable error reason string. |

---

<a id="onallocationdeleted"></a>

### onAllocationDeleted

`virtual` `inline`

```cpp
virtual inline void onAllocationDeleted(Client & client, const stun::Transaction & transaction)
```

[Defined in src/turn/include/icy/turn/client/client.h:93](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L93)

Called when the server confirms deletion of the allocation.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The owning client. |
| `transaction` | const [`stun::Transaction`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#transaction-3) & | The completed Refresh transaction (lifetime == 0). |

---

<a id="onallocationpermissionscreated"></a>

### onAllocationPermissionsCreated

`virtual` `inline`

```cpp
virtual inline void onAllocationPermissionsCreated(Client & client, const PermissionList & permissions)
```

[Defined in src/turn/include/icy/turn/client/client.h:98](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L98)

Called after a CreatePermission request succeeds.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The owning client. |
| `permissions` | const [`PermissionList`](https://auscaster.com/icey/docs/api-reference/icy-turn.md#permissionlist) & | The full list of active permissions after this update. |

---

<a id="ontransactionresponse"></a>

### onTransactionResponse

`virtual` `inline`

```cpp
virtual inline void onTransactionResponse(Client & client, const stun::Transaction & transaction)
```

[Defined in src/turn/include/icy/turn/client/client.h:104](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L104)

All received transaction responses will be routed here after local processing so the observer can easily implement extra functionality.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The owning client. |
| `transaction` | const [`stun::Transaction`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#transaction-3) & | The completed transaction (request + response accessible). |

---

<a id="ontimer-2"></a>

### onTimer

`virtual` `inline`

```cpp
virtual inline void onTimer(Client & client)
```

[Defined in src/turn/include/icy/turn/client/client.h:109](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L109)

Fires after the client's internal timer callback. Handy for performing extra async cleanup tasks.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `client` | [`Client`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client.md#client-3) & | The owning client. |
