Get started with DOCX collaboration

Connect two React or Vue DOCX editors through one WebRTC room.

This quickstart connects two editors through WebRTC with useWebrtcCollaboration. Start with a working editor from the Quickstart.

Install collaboration packages

Install the Pro package, Yjs, and the WebRTC provider next to @docx-editor.dev/react or @docx-editor.dev/vue:

npm install @docx-editor.dev/pro yjs y-webrtc

@docx-editor.dev/pro requires the EigenPal Pro License.

Connect an editor

Create one room ID and share it with each participant. Store it in application state or the URL; do not create a new ID on each render:

import { createCollaborationRoomId } from '@docx-editor.dev/pro/collaboration/webrtc';

const roomId = createCollaborationRoomId();

The following component joins the room. The first editor creates it, and later editors join its document:

import { DocxEditor } from '@docx-editor.dev/react';
import { DEMO_SIGNALING_ENDPOINTS } from '@docx-editor.dev/pro/collaboration/webrtc';
import { useWebrtcCollaboration } from '@docx-editor.dev/pro/react/webrtc';

interface CollaborativeEditorProps {
  roomId: string;
  bytes: Uint8Array;
  actorId: string;
  name: string;
}

export function CollaborativeEditor({ roomId, bytes, actorId, name }: CollaborativeEditorProps) {
  const { document, modules, session, error } = useWebrtcCollaboration({
    room: {
      roomId,
      identity: { actorId, name },
      bootstrap: { kind: 'create-or-join', document: bytes },
      // Demo only. Pass your own signaling URLs in production.
      signaling: DEMO_SIGNALING_ENDPOINTS,
    },
  });

  if (!document) {
    return <p>{error ? 'Could not join this document.' : 'Connecting…'}</p>;
  }

  return (
    <>
      {error && (
        <p role="alert">Collaboration needs attention. Save a copy before you reconnect.</p>
      )}
      <DocxEditor key={session?.sessionId} document={document} modules={modules} />
    </>
  );
}

For leaving and rejoining a room, see Connect with useWebrtcCollaboration.

Configure the room

room fieldValue
roomIdThe same ID for every participant
identity{ actorId, name }; use a distinct actorId for each active editor, including tabs of the same user
bootstrap{ kind: 'create-or-join', document: bytes } with the initial DOCX bytes
signalingRequired; it has no default
signaling valueUse
Your signaling server URLsProduction; see Use your own signaling
DEMO_SIGNALING_ENDPOINTSDemos only; a shared public service
[]Tabs of the same browser only

If you omit signaling, the hook reports a transport error and opens no connection.

Verify two participants

  1. Open the application in one tab.
  2. Open a second tab with the same roomId and a different actorId.
  3. Type in either editor, and check that the other one updates.

Open the first tab before the second, so both peers do not seed an empty room at once.

Limits

See also