# Presence Server

## Content

**Presence** on the server side needs to coordinate and broadcast the Presence data of all clients to ensure that user state information is synchronized in real-time within the collaboration room. The [presenceFeature ](/spreadjs/api/v18/collaboration/js-collaboration-presence/README#presencefeature)method provides the following main functionalities:

* **State Broadcasting**: Receives states submitted by clients and broadcasts them to other clients via the server.
* **State Management**: Maintains the latest states of all users in the current room.

## API

### presenceFeature

Enables the Presence functionality on the server side.

```typescript
export declare function presenceFeature(): IFeature
```

**Return**
IFeature: A functional object containing Middleware and Hook.

## How to Use

1. Install Npm Packages

    ```bash
    npm install @mescius/js-collaboration @mescius/js-collaboration-presence
    ```
2. Register Presence with the Server

    ```typescript
    import { presenceFeature } from '@mescius/js-collaboration-presence';
    
    server.useFeature(presenceFeature());
    ```

### Complete Example

```typescript
import { createServer } from 'http';
import { Server } from 'js-collaboration';
import * as OT from 'js-collaboration-ot';
import { presenceFeature } from 'js-collaboration-presence';

OT.types.register(type);

const httpServer = createServer();
const server = new Server({ httpServer });

server.useFeature(OT.documentFeature());
server.useFeature(presenceFeature());

httpServer.listen(8080);
```