Class SimpleWebSocketServerExample

java.lang.Object
net.carcdr.yhocuspocus.websocket.examples.SimpleWebSocketServerExample

public final class SimpleWebSocketServerExample extends Object
Simple example of running a YHocuspocus WebSocket server.

This example demonstrates:

  • Creating a YHocuspocus instance with an in-memory database
  • Configuring persistence settings (debounce, maxDebounce)
  • Starting a WebSocket server on port 1234
  • Graceful shutdown with try-with-resources

Usage:


 java net.carcdr.yhocuspocus.websocket.examples.SimpleWebSocketServerExample
 

Then connect from a browser using Yjs:


 import * as Y from 'yjs'
 import { WebsocketProvider } from 'y-websocket'

 const ydoc = new Y.Doc()
 const provider = new WebsocketProvider('ws://localhost:1234', 'my-document', ydoc)

 const ytext = ydoc.getText('content')
 ytext.insert(0, 'Hello from Yjs!')
 
Since:
1.0.0