Gathering detailed insights and metrics for sedestral-y-websocket
Gathering detailed insights and metrics for sedestral-y-websocket
Gathering detailed insights and metrics for sedestral-y-websocket
Gathering detailed insights and metrics for sedestral-y-websocket
npm install sedestral-y-websocket
Typescript
Module System
Node Version
NPM Version
JavaScript (98.58%)
Dockerfile (1.42%)
Total Downloads
2,763
Last Day
2
Last Week
6
Last Month
30
Last Year
356
MIT License
589 Stars
259 Commits
287 Forks
17 Watchers
3 Branches
29 Contributors
Updated on May 03, 2025
Minified
Minified + Gzipped
Latest Version
1.6.1
Package Id
sedestral-y-websocket@1.6.1
Unpacked Size
40.60 kB
Size
10.81 kB
File Count
8
NPM Version
8.19.2
Node Version
16.13.0
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
-14.3%
6
Compared to previous week
Last Month
-54.5%
30
Compared to previous month
Last Year
9.2%
356
Compared to previous year
5
1
3
WebSocket Provider for Yjs
The Websocket Provider implements a classical client server model. Clients connect to a single endpoint over Websocket. The server distributes awareness information and document updates among clients.
The Websocket Provider is a solid choice if you want a central source that handles authentication and authorization. Websockets also send header information and cookies, so you can use existing authentication mechanisms with this server.
1npm i y-websocket
This repository implements a basic server that you can adopt to your specific use-case. (source code)
Start a y-websocket server:
1HOST=localhost PORT=1234 npx y-websocket
1import * as Y from 'yjs' 2import { WebsocketProvider } from 'y-websocket' 3 4const doc = new Y.Doc() 5const wsProvider = new WebsocketProvider('ws://localhost:1234', 'my-roomname', doc) 6 7wsProvider.on('status', event => { 8 console.log(event.status) // logs "connected" or "disconnected" 9})
The WebSocket provider requires a WebSocket
object to create connection to a server. You can polyfill WebSocket support in Node.js using the ws
package.
1const wsProvider = new WebsocketProvider('ws://localhost:1234', 'my-roomname', doc, { WebSocketPolyfill: require('ws') })
1import { WebsocketProvider } from 'y-websocket'
wsProvider = new WebsocketProvider(serverUrl: string, room: string, ydoc: Y.Doc [, wsOpts: WsOpts])
1wsOpts = { 2 // Set this to `false` if you want to connect manually using wsProvider.connect() 3 connect: true, 4 // Specify a query-string that will be url-encoded and attached to the `serverUrl` 5 // I.e. params = { auth: "bearer" } will be transformed to "?auth=bearer" 6 params: {}, // Object<string,string> 7 // You may polyill the Websocket object (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket). 8 // E.g. In nodejs, you could specify WebsocketPolyfill = require('ws') 9 WebsocketPolyfill: Websocket, 10 // Specify an existing Awareness instance - see https://github.com/yjs/y-protocols 11 awareness: new awarenessProtocol.Awareness(ydoc), 12 // Specify the maximum amount to wait between reconnects (we use exponential backoff). 13 maxBackoffTime: 2500 14}
wsProvider.wsconnected: boolean
wsProvider.wsconnecting: boolean
wsProvider.shouldConnect: boolean
wsProvider.bcconnected: boolean
wsProvider.synced: boolean
wsProvider.disconnect()
wsProvider.connect()
wsProvider.destroy()
wsProvider.on('sync', function(isSynced: boolean))
wsProvider.on('status', function({ status: 'disconnected' | 'connecting' | 'connected' }))
wsProvider.on('connection-close', function(WSClosedEvent))
wsProvider.on('connection-error', function(WSErrorEvent))
Start a y-websocket server:
1HOST=localhost PORT=1234 npx y-websocket
Since npm symlinks the y-websocket
executable from your local ./node_modules/.bin
folder, you can simply run npx. The PORT
environment variable already defaults to 1234, and HOST
defaults to localhost
.
Persist document updates in a LevelDB database.
See LevelDB Persistence for more info.
1HOST=localhost PORT=1234 YPERSISTENCE=./dbDir node ./node_modules/y-websocket/bin/server.js
Send a debounced callback to an HTTP server (POST
) on document update. Note that this implementation doesn't implement a retry logic in case the CALLBACK_URL
does not work.
Can take the following ENV variables:
CALLBACK_URL
: Callback server URLCALLBACK_DEBOUNCE_WAIT
: Debounce time between callbacks (in ms). Defaults to 2000 msCALLBACK_DEBOUNCE_MAXWAIT
: Maximum time to wait before callback. Defaults to 10 secondsCALLBACK_TIMEOUT
: Timeout for the HTTP call. Defaults to 5 secondsCALLBACK_OBJECTS
: JSON of shared objects to get data ('{"SHARED_OBJECT_NAME":"SHARED_OBJECT_TYPE}'
)1CALLBACK_URL=http://localhost:3000/ CALLBACK_OBJECTS='{"prosemirror":"XmlFragment"}' npm start
This sends a debounced callback to localhost:3000
2 seconds after receiving an update (default DEBOUNCE_WAIT
) with the data of an XmlFragment named "prosemirror"
in the body.
The MIT License © Kevin Jahns
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
5 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 3/27 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More