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} />
</>
);
}<script setup lang="ts">
import { DocxEditor } from '@docx-editor.dev/vue';
import { DEMO_SIGNALING_ENDPOINTS } from '@docx-editor.dev/pro/collaboration/webrtc';
import { useWebrtcCollaboration } from '@docx-editor.dev/pro/vue/webrtc';
const props = defineProps<{
roomId: string;
bytes: Uint8Array;
actorId: string;
name: string;
}>();
const { document, modules, session, error } = useWebrtcCollaboration(() => ({
room: {
roomId: props.roomId,
identity: { actorId: props.actorId, name: props.name },
bootstrap: { kind: 'create-or-join', document: props.bytes },
// Demo only. Pass your own signaling URLs in production.
signaling: DEMO_SIGNALING_ENDPOINTS,
},
}));
</script>
<template>
<p v-if="error" role="alert">
Collaboration is unavailable. Save any local work before you reconnect.
</p>
<p v-if="!document && !error">Connecting…</p>
<DocxEditor v-if="document" :key="session?.sessionId" :document="document" :modules="modules" />
</template>The composable returns refs, and the template unwraps them.
For leaving and rejoining a room, see Connect with useWebrtcCollaboration.
Configure the room
room field | Value |
|---|---|
roomId | The 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 |
signaling | Required; it has no default |
signaling value | Use |
|---|---|
| Your signaling server URLs | Production; see Use your own signaling |
DEMO_SIGNALING_ENDPOINTS | Demos 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
- Open the application in one tab.
- Open a second tab with the same
roomIdand a differentactorId. - 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
- If the connection fails, keep the editor mounted so users can save local work before they reconnect.
- Production needs your own signaling URLs and TURN servers.
- For a server deployment, see Connect to a Hocuspocus server. For a custom Yjs deployment, see Integrate a custom Yjs provider.
- Before you deploy updates or reopen saved rooms, check collaboration compatibility.
See also
Connect an agent to a document
Choose how an agent edits a DOCX and how readers see its updates: browser tools, shared server edits, or complete file refresh.
Task recipes
Choose between the React and Vue review hooks and the Office.js-shaped editing API, then find the exact symbol for each common task.