-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyjs-server.js
More file actions
79 lines (62 loc) · 1.94 KB
/
yjs-server.js
File metadata and controls
79 lines (62 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
/**
* Hocuspocus WebSocket Server for collaborative editing
* Run this server to enable real-time collaboration with Yjs
*
* Usage: node yjs-server.js [port]
* Default port: 1234
*/
import { Server } from '@hocuspocus/server';
const port = process.env.YJS_PORT || process.argv[2] || 1234;
const server = new Server({
port: Number(port),
// Logging
quiet: false,
// Increase max payload size to 100MB to handle large documents
maxPayload: 100 * 1024 * 1024,
// Disable authentication - allow all connections
async onAuthenticate() {
return {
user: {
id: 'anonymous',
name: 'Anonymous User',
},
};
},
// Enable connection tracking
onConnect: (data) => {
console.log(`[Hocuspocus] ✅ Client connected to document: ${data.documentName}`);
},
onDisconnect: (data) => {
console.log(`[Hocuspocus] Client disconnected from: ${data.documentName}`);
},
onLoadDocument: (data) => {
console.log(`[Hocuspocus] Document loaded: ${data.documentName}`);
},
onStoreDocument: (data) => {
console.log(`[Hocuspocus] Document stored: ${data.documentName}`);
},
onChange: (data) => {
console.log(`[Hocuspocus] Document changed: ${data.documentName}`);
},
onStateless: (data) => {
console.log(`[Hocuspocus] Received stateless message for: ${data.documentName}`);
},
});
await server.listen();
console.log(`🚀 Hocuspocus server running on ws://localhost:${port}`);
console.log(' Ready for collaborative editing!');
console.log(' Press Ctrl+C to stop');
// Graceful shutdown
process.on('SIGINT', async () => {
console.log('\n[Hocuspocus] Shutting down server...');
await server.destroy();
console.log('[Hocuspocus] Server closed');
process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('\n[Hocuspocus] Shutting down server...');
await server.destroy();
console.log('[Hocuspocus] Server closed');
process.exit(0);
});