@node-projects/web-component-designer-collaboration-service
v0.2.0
Published
web-component-designer addon for collaboration features
Keywords
Readme
@node-projects/web-component-designer-collaboration-service
https://www.npmjs.com/package/@node-projects/web-component-designer-collaboration-service
npm i @node-projects/web-component-designer-collaboration-serviceDescription
This package adds collaboration features to @node-projects/web-component-designer.
It provides:
- a per-document collaboration service
- remote selection and presence overlays
- remote cursor overlays
- comment context menu integration
- a WebRTC transport with
broadcast-channeland manual copy/paste signaling
The package is an addon. It does not patch the default designer bootstrap automatically. You enable it explicitly on your ServiceContainer.
Quick Start
import { createDefaultServiceContainer } from '@node-projects/web-component-designer';
import {
setupCollaborationService,
WebRtcTabCollaborationTransport,
} from '@node-projects/web-component-designer-collaboration-service';
const serviceContainer = createDefaultServiceContainer();
setupCollaborationService(serviceContainer);After that, each DocumentContainer gets a collaboration service instance on its instanceServiceContainer.
const collaborationService = documentContainer.instanceServiceContainer.collaborationService;
collaborationService.attachTransport(new WebRtcTabCollaborationTransport({
enabledSignalingChannels: ['broadcast-channel', 'manual'],
rtcConfiguration: {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'turns:turn.example.com:5349?transport=tcp', username: 'demo', credential: 'secret' }
]
}
}));
collaborationService.connect(
'my-session-id',
'peer-a',
'Browser A'
);What setupCollaborationService() Adds
setupCollaborationService(serviceContainer) registers:
- the
collaborationServiceinstance factory - the collaboration node/comment overlay extension
- the collaboration cursor overlay extension
- the collaboration comments context menu entry
If you want more control, the package also exports the individual classes:
DefaultCollaborationServiceWebRtcTabCollaborationTransportCollaborationOverlayExtensionProviderCollaborationCursorOverlayExtensionProviderCollaborationCommentsContextMenu
Signaling Modes
WebRtcTabCollaborationTransport supports two signaling channels:
broadcast-channelUse this for same-origin tabs in the same browser.manualUse this for different browsers or when you want to move signaling data yourself.
Both channels are enabled by default.
const transport = new WebRtcTabCollaborationTransport({
enabledSignalingChannels: ['manual']
});Manual Copy/Paste Signaling
The manual signaling API is useful for connecting different browsers without a backend signaling server.
For same-browser tabs you usually do not need extra RTC configuration. For different machines, browsers, subnets, VPNs, or internet connections, configure rtcConfiguration with suitable STUN or TURN servers. Without that, the browser only has local host candidates available, which often works on one computer but is unreliable across machines.
If your TURN credentials rotate, update them before reconnecting. WebRtcTabCollaborationTransport also exposes setRtcConfiguration() for that use case.
const transport = new WebRtcTabCollaborationTransport({
enabledSignalingChannels: ['manual'],
rtcConfiguration: {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: ['turn:turn.example.com:3478?transport=udp', 'turns:turn.example.com:5349?transport=tcp'], username: 'demo', credential: 'secret' }
]
}
});
transport.setRtcConfiguration({
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'turns:turn.example.com:5349?transport=tcp', username: 'demo', credential: 'next-secret' }
]
});
const bundle = transport.exportManualSignalingData();
await transport.importManualSignalingData(bundleFromOtherClient);Typical flow:
- Use the same collaboration session id in both clients.
- Copy the signaling bundle from client A and import it in client B.
- Copy the updated signaling bundle from client B and import it in client A.
- If one client still has a newer signaling bundle because of trickled ICE candidates, copy that bundle back once more.
Demo Notes
The demo toolbar contains a collab menu with:
- session id selection
- signaling-channel toggles
- copy/paste signaling bundle actions
- a help popup with the connection steps
In the demo:
- Use the same session id in both clients.
- For same-browser tabs, keep
broadcast signalingenabled. - For different browsers, keep
manual copy/paste signalingenabled and exchange bundles through the menu.
Package Exports
Main exports:
setupCollaborationServiceDefaultCollaborationServiceWebRtcTabCollaborationTransportCollaborationCommentsContextMenuCollaborationOverlayExtensionProviderCollaborationCursorOverlayExtensionProvider
