Registry / database / y-socket.io

y-socket.io

JSON →
library1.1.3jsnpmunverified

Socket.IO connector for Yjs, inspired by y-websocket. Current stable version is 1.1.3. It provides a server and client implementation for synchronizing Yjs documents over Socket.IO, with features such as authentication, LevelDB persistence, custom callbacks, and cross-tab communication. It is a lightweight alternative to y-websocket for developers already using Socket.IO, offering easy integration and configuration.

npm install y-socket.io
INSTALL
IMPORT
SIG · Y-SOCKET.IO
Y
y-socket.io
databasejavascriptv1.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

YSocketIO
import { YSocketIO } from 'y-socket.io/dist/server'
import { YSocketIO } from 'y-socket.io'
Server-side class, exported from 'dist/server' subpath.
SocketIOProvider
import { SocketIOProvider } from 'y-socket.io'
import { SocketIOProvider } from 'y-socket.io/dist/client'
Client-side class, available as a top-level export.
default import
import ySocketIO from 'y-socket.io/dist/server'
const ySocketIO = require('y-socket.io/dist/server')
Default export is available, but named imports are recommended. CJS require works but type definitions may not be resolved.

Shows how to set up a basic y-socket.io server and client with Socket.IO and Yjs.

// server import { Server } from 'socket.io'; import { YSocketIO } from 'y-socket.io/dist/server'; const io = new Server(1234); const ysocketio = new YSocketIO(io); ysocketio.initialize(); // client (browser or node) import * as Y from 'yjs'; import { SocketIOProvider } from 'y-socket.io'; const doc = new Y.Doc(); const provider = new SocketIOProvider('ws://localhost:1234', 'my-room', doc); provider.on('status', ({ status }) => console.log(status)); doc.getMap('shared').observe(event => console.log('update', event)); // cleanup on page unload window.addEventListener('beforeunload', () => provider.disconnect());
Debug
Known issues
gotchaSocket.IO namespaces matching /^\/yjs\|.*$/ are reserved for y-socket.io. Do not use namespaces starting with '/yjs|' for other purposes.
fix
Avoid using namespaces that match the regular expression /^\/yjs\|.*$/ in your application.
affects: >=0.0.0
gotchaThe server-side YSocketIO must be initialized with the initialize() method after constructing the instance.
fix
Call ysocketio.initialize() after creating the YSocketIO instance.
affects: >=0.0.0
gotchaPersistence is disabled by default; to enable LevelDB persistence, configure it via options.
fix
Pass persistence options to YSocketIO constructor, e.g., new YSocketIO(io, { persistence: { levelPersistenceDir: './db' } }).
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'y-socket.io/dist/server'
The server import path requires the '/dist/server' subpath; importing from 'y-socket.io' only provides client exports.
fix
Use import { YSocketIO } from 'y-socket.io/dist/server' (or require('y-socket.io/dist/server')).
Error: You must provide a Yjs document
SocketIOProvider constructor's third argument (doc) is required and must be a Y.Doc instance.
fix
Ensure you pass a Yjs document: new SocketIOProvider(url, room, doc).
Error: The namespace "/yjs|my-room" is not allowed. Namespaces starting with "/yjs|" are reserved for y-socket.io.
Using a reserved namespace pattern; y-socket.io intercepts namespaces matching /^\/yjs\|.*$/.
fix
Do not use namespaces starting with '/yjs|' for other purposes in your Socket.IO server.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
yjsrequiredPeer dependency required for document synchronization
Agent activity
22 hits · last 30 days
node
20
Meta
1
Resources
y-socket.io — npm install y-socket.io · libregistry