# ServerPeer

<a id="serverpeer"></a>

# ServerPeer

```cpp
#include <icy/symple/server.h>

class ServerPeer
```

[Defined in src/symple/include/icy/symple/server.h:43](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L43)

Per-connection state for a connected Symple peer.

Created by the server after successful authentication. Holds the peer data, room memberships, and a reference to the underlying WebSocket connection for sending.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`ServerPeer`](#serverpeer-1)  | Constructs a peer bound to the given server-side connection. |
| `void` | [`send`](#send-20)  | Serialises and sends a JSON message over the WebSocket connection. Logs a warning if the send fails; does not throw. |
| `void` | [`sendSerialized`](#sendserialized)  | Sends a pre-serialized JSON payload over the WebSocket connection. Use this on fanout paths that already serialized once. |
| `void` | [`join`](#join-2)  | Adds this peer to the named room (local tracking only). |
| `void` | [`leave`](#leave-1)  | Removes this peer from the named room (local tracking only). |
| `void` | [`leaveAll`](#leaveall-1)  | Removes this peer from all rooms (local tracking only). |
| [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1) & | [`peer`](#peer-7) `inline` | Returns a mutable reference to the peer data object. |
| const [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1) & | [`peer`](#peer-8) `const` `inline` | Returns a const reference to the peer data object. |
| `std::string` | [`id`](#id-14) `const` | Returns the session ID assigned to this peer. |
| `const std::unordered_set< std::string > &` | [`rooms`](#rooms-2) `const` `inline` | Returns the set of room names this peer is currently joined to. |
| `bool` | [`authenticated`](#authenticated) `const` `inline` | Returns true if the peer has completed authentication. |
| `void` | [`setAuthenticated`](#setauthenticated) `inline` | Marks the peer as authenticated or unauthenticated. |
| `void` | [`setPeer`](#setpeer) `inline` | Replaces the peer's data object. |
| [`http::ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) & | [`connection`](#connection-11) `inline` | Returns a reference to the underlying server connection. |
| `bool` | [`checkRate`](#checkrate) `inline` | Per-peer rate limiter. Returns false if message should be dropped. |
| `void` | [`setRateLimit`](#setratelimit) `inline` | Configures the per-peer rate limit. |

---

<a id="serverpeer-1"></a>

### ServerPeer

```cpp
ServerPeer(http::ServerConnection & conn)
```

[Defined in src/symple/include/icy/symple/server.h:48](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L48)

Constructs a peer bound to the given server-side connection.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `conn` | [`http::ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) & | The underlying WebSocket server connection. |

---

<a id="send-20"></a>

### send

```cpp
void send(const json::Value & msg)
```

[Defined in src/symple/include/icy/symple/server.h:53](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L53)

Serialises and sends a JSON message over the WebSocket connection. Logs a warning if the send fails; does not throw.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `msg` | const [`json::Value`](https://auscaster.com/icey/docs/api-reference/icy-json.md#value) & | JSON value to send. |

---

<a id="sendserialized"></a>

### sendSerialized

```cpp
void sendSerialized(const char * data, size_t len)
```

[Defined in src/symple/include/icy/symple/server.h:57](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L57)

Sends a pre-serialized JSON payload over the WebSocket connection. Use this on fanout paths that already serialized once.

---

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

### join

```cpp
void join(const std::string & room)
```

[Defined in src/symple/include/icy/symple/server.h:61](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L61)

Adds this peer to the named room (local tracking only).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `room` | `const std::string &` | Room name to join. |

---

<a id="leave-1"></a>

### leave

```cpp
void leave(const std::string & room)
```

[Defined in src/symple/include/icy/symple/server.h:65](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L65)

Removes this peer from the named room (local tracking only).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `room` | `const std::string &` | Room name to leave. |

---

<a id="leaveall-1"></a>

### leaveAll

```cpp
void leaveAll()
```

[Defined in src/symple/include/icy/symple/server.h:68](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L68)

Removes this peer from all rooms (local tracking only).

---

<a id="peer-7"></a>

### peer

`inline`

```cpp
inline Peer & peer()
```

[Defined in src/symple/include/icy/symple/server.h:71](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L71)

Returns a mutable reference to the peer data object.

---

<a id="peer-8"></a>

### peer

`const` `inline`

```cpp
inline const Peer & peer() const
```

[Defined in src/symple/include/icy/symple/server.h:74](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L74)

Returns a const reference to the peer data object.

---

<a id="id-14"></a>

### id

`const`

```cpp
std::string id() const
```

[Defined in src/symple/include/icy/symple/server.h:77](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L77)

Returns the session ID assigned to this peer.

---

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

### rooms

`const` `inline`

```cpp
inline const std::unordered_set< std::string > & rooms() const
```

[Defined in src/symple/include/icy/symple/server.h:80](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L80)

Returns the set of room names this peer is currently joined to.

---

<a id="authenticated"></a>

### authenticated

`const` `inline`

```cpp
inline bool authenticated() const
```

[Defined in src/symple/include/icy/symple/server.h:83](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L83)

Returns true if the peer has completed authentication.

---

<a id="setauthenticated"></a>

### setAuthenticated

`inline`

```cpp
inline void setAuthenticated(bool v)
```

[Defined in src/symple/include/icy/symple/server.h:87](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L87)

Marks the peer as authenticated or unauthenticated.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `v` | `bool` | True to mark as authenticated. |

---

<a id="setpeer"></a>

### setPeer

`inline`

```cpp
inline void setPeer(const Peer & p)
```

[Defined in src/symple/include/icy/symple/server.h:91](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L91)

Replaces the peer's data object.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `p` | const [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1) & | New peer data. |

---

<a id="connection-11"></a>

### connection

`inline`

```cpp
inline http::ServerConnection & connection()
```

[Defined in src/symple/include/icy/symple/server.h:94](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L94)

Returns a reference to the underlying server connection.

---

<a id="checkrate"></a>

### checkRate

`inline`

```cpp
inline bool checkRate()
```

[Defined in src/symple/include/icy/symple/server.h:97](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L97)

Per-peer rate limiter. Returns false if message should be dropped.

---

<a id="setratelimit"></a>

### setRateLimit

`inline`

```cpp
inline void setRateLimit(double rate, double seconds)
```

[Defined in src/symple/include/icy/symple/server.h:102](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L102)

Configures the per-peer rate limit.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `rate` | `double` | Maximum messages allowed per window. |
| `seconds` | `double` | Duration of the rate window in seconds. |

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`http::ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) & | [`_conn`](#_conn)  |  |
| [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1) | [`_peer`](#_peer-1)  |  |
| `std::unordered_set< std::string >` | [`_rooms`](#_rooms-1)  |  |
| [`RateLimiter`](https://auscaster.com/icey/docs/api-reference/icy-RateLimiter.md#ratelimiter) | [`_rateLimiter`](#_ratelimiter)  | 100 messages per 10 seconds default |
| `bool` | [`_authenticated`](#_authenticated)  |  |

---

<a id="_conn"></a>

### _conn

```cpp
http::ServerConnection & _conn
```

Type: [`http::ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) &

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

---

<a id="_peer-1"></a>

### _peer

```cpp
Peer _peer
```

Type: [`Peer`](https://auscaster.com/icey/docs/api-reference/icy-smpl-Peer.md#peer-1)

[Defined in src/symple/include/icy/symple/server.h:110](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L110)

---

<a id="_rooms-1"></a>

### _rooms

```cpp
std::unordered_set< std::string > _rooms
```

[Defined in src/symple/include/icy/symple/server.h:111](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L111)

---

<a id="_ratelimiter"></a>

### _rateLimiter

```cpp
RateLimiter _rateLimiter {100.0, 10.0}
```

Type: [`RateLimiter`](https://auscaster.com/icey/docs/api-reference/icy-RateLimiter.md#ratelimiter)

[Defined in src/symple/include/icy/symple/server.h:112](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L112)

100 messages per 10 seconds default

---

<a id="_authenticated"></a>

### _authenticated

```cpp
bool _authenticated = false
```

[Defined in src/symple/include/icy/symple/server.h:113](https://github.com/auscaster/icey/blob/main/src/symple/include/icy/symple/server.h#L113)
