[]
        
(Showing Draft Content)

Presence Server

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 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.

export declare function presenceFeature(): IFeature

Return

IFeature: A functional object containing Middleware and Hook.

How to Use

  1. Install Npm Packages

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

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

Complete Example

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);