Integrate the Collaboration provider

Together with the Collaboration backend, providers serve as the backbone for real-time collaborative editing. They establish and manage the communication channels between users, ensuring that updates and changes to documents are synchronized across all participants.

Providers handle the complexities of real-time data exchange, including conflict resolution, network reliability, and user presence awareness.

The TiptapCollabProvider adds advanced features tailored for collaborative environments, such as WebSocket message authentication, debug modes, and flexible connection strategies.

Set up the provider

First, install the provider package in your project using:

npm install @hocuspocus/provider

For a basic setup, connect to the Collaboration backend by specifying the document's name, your app's ID (for cloud setups), or the base URL (for on-premises), along with your JWT.

Depending on your framework, register a callback to the Collaboration backend, such as useEffect() in React or onMounted() in Vue.js.

const doc = new Y.Doc()

useEffect(() => {
  const provider = new TiptapCollabProvider({
    name: note.id, // Document identifier
    appId: 'YOUR_APP_ID', // replace with YOUR_APP_ID from Cloud dashboard
    token: 'YOUR_JWT', // Authentication token
    document: doc,
    user: userId,
  })
}, [])

Note for On-Premises Customers

If you are hosting your collaboration environment on-premises, replace the appId parameter with baseUrl in your provider configuration to connect to your server.

Configure the collaboration provider

The Tiptap Collaboration provider offers several settings for custom configurations. Review the tables below for all parameters, practical use cases, and key concepts like "awareness".

SettingDefault ValueDescription
appId'' (empty)App ID for Collaboration Cloud setups
baseUrl'' (empty)URL for connecting to on-premises servers. Used as an alternative to appId for on-prem setups
name'' (empty)The document's name
token'' (empty)Authentication token for secure connections. Supports strings, functions, and Promises
documentnew Y.Doc()The Yjs document instance. Defaults to a new document if none is provided
usernullUser ID or name for attributing changes to the document.
connecttrueConnects to the server after initialization
preserveConnectiontrueKeeps the WebSocket connection open after closing the provider
broadcasttrueEnables document syncing across browser tabs
forceSyncIntervalfalseForces server sync at regular intervals, in milliseconds
quietfalseSuppresses warning outputs
WebSocketPolyfillWebSocketWebSocket implementation for Node.js environments. Use ws or another implementation

Optimize reconnection timings

The provider’s reconnection settings are preset for optimal performance in production settings. If you need to adjust these settings for specific scenarios, you can do so with our delay configurations.

Adjust initial delays, apply exponential backoff, or set maximum wait times to fine-tune your application's reconnection behavior, balancing responsiveness with server efficiency.

SettingDefault ValueDescription
delay1000Base delay between reconnection attempts, in milliseconds
factor2Multiplier applied to the delay, increasing it exponentially after each attempt
initialDelay0Time in milliseconds before the first reconnection attempt
maxAttempts0Maximum number of reconnection attempts. 0 means unlimited attempts
jittertrueAdds variability to the delay by randomly selecting a value between minDelay and the calculated delay for each attempt
minDelay1000Minimum delay when jitter is enabled. Has no effect if jitter is disabled
maxDelay30000Maximum delay allowed between reconnection attempts. Set to 0 to allow the delay to increase indefinitely using exponential backoff (factor).
timeout0Time limit, in milliseconds, for each reconnection attempt before stopping
messageReconnectTimeout30000Time in milliseconds to wait for a server message before terminating the connection. If no message is received, the connection is closed automatically

Rate limits

To maintain system integrity and protect from misconfigured clients, our infrastructure—including the management API and websocket connections through the TiptapCollabProvider—is subject to rate limits.

Default rate limits (per source IP):

  • Requests: 100
  • Time window: 5 seconds
  • Burst capacity: Up to 200 requests

If you encounter these limits under normal operation, please email us.