{"_id":"@trint/y-websocket","_rev":"51-5a65d6616a44fd241cce7f7bc83035a3","name":"@trint/y-websocket","dist-tags":{"latest":"1.3.18-trint.0"},"versions":{"1.3.15-trint.0":{"name":"@trint/y-websocket","version":"1.3.15-trint.0","keywords":["Yjs"],"author":{"name":"Kevin Jahns","email":"kevin.jahns@protonmail.com"},"license":"MIT","_id":"@trint/y-websocket@1.3.15-trint.0","maintainers":[{"name":"timbutler","email":"tim.butler@trint.com"},{"name":"jonathan.beaumont.trint","email":"jonathan.beaumont@trint.com"},{"name":"liam.connolly","email":"liam.connolly@trint.com"},{"name":"zegnus","email":"ferran.garriga@trint.com"},{"name":"peterslight","email":"peter.slight@trint.com"},{"name":"bcollofftrint","email":"bret.colloff@trint.com"},{"name":"anthonybillon","email":"anthony.billon@trint.com"},{"name":"samrevanoor","email":"sam@trint.com"},{"name":"barrytrint","email":"barry@trint.com"},{"name":"chrisguest","email":"chris.guest@trint.com"},{"name":"johnstleger","email":"jstleger0@googlemail.com"},{"name":"trinthq","email":"tech@trint.com"},{"name":"kuba.gaj","email":"kuba@qubutech.com"},{"name":"hannah.bacon","email":"hannah.bacon@trint.com"},{"name":"odhran73","email":"odhran@trint.com"},{"name":"lopea","email":"lope@trint.com"},{"name":"jinntr","email":"jinn.koriech@trint.com"},{"name":"sb-trint","email":"sb@trint.com"},{"name":"andrew.jackson","email":"andrew.jackson@trint.com"},{"name":"ivantrint","email":"ivan.podgurskiy@trint.com"},{"name":"katiemc","email":"katie.mcdonagh@trint.com"},{"name":"lylafibert","email":"lyla.fibert@trint.com"},{"name":"eleanorbyass","email":"eleanor.byass@trint.com"},{"name":"bryanattrint","email":"bryan.yap@trint.com"},{"name":"ryan.feline","email":"ryan.feline@trint.com"},{"name":"bogdan_trint","email":"bogdan.largeanu@trint.com"},{"name":"noafilosof","email":"noa.filosof@trint.com"},{"name":"dafna.libman","email":"dafna.libman@trint.com"},{"name":"gregtrint","email":"gregorio.costa@trint.com"}],"homepage":"https://github.com/yjs/y-websocket#readme","bugs":{"url":"https://github.com/yjs/y-websocket/issues"},"bin":{"y-websocket-server":"bin/server.js"},"dist":{"shasum":"960ae6d030ee6cb94cdae0ae0926aa623a3071dc","tarball":"https://registry.npmjs.org/@trint/y-websocket/-/y-websocket-1.3.15-trint.0.tgz","fileCount":10,"integrity":"sha512-yaGipoaa/ZAyCb6YGfHTALAlQPtXvHc518wWRXcj3rwg9e4whTonPu5H6eRi5iDL3vSylJKbIGB1tgY6obJ09A==","signatures":[{"sig":"MEUCIQCPfobXNBBcIYNEjzGEEqmT8qkSJCT0NAek8a/m/LyTDAIgOe5pMugzC6NQ8DE8TYY/wPGAL1ojjymW9niOzvr4O1I=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":77853,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiAQEICRA9TVsSAnZWagAA+YcP/1zr9zpIYyurC8K2j0Vt\nRQvjrrkB/jt4g3zvYKWUMA+dl6ikSjT9NKuJNnz36dTtUY44J6XxiD59dIXa\nBah2VTzrfy3AoYNKq1OOOkW4cgZxnrstdMb5sP3OGCAGWasMEhK/njtSEJTN\nfPBZbyqinaamknP8I16CR7Z7+Q0gvM+WxOgmpN3pSCHKSktAY10cBrv6gjpF\n/Pp0aIUUQzN0I5X4S2Mhj3qpcPVIQSeW4anBbW7p00lmJRSmVMcnY6KNrJBj\nI7+xzC+mRAFkCjmRAIIPo3CeY7ONg+9MM/VrUqqPdnhUSiB6+ohZm7vqrxlX\nInP9G2g2ohmZN7gkHESLkvXqhyz0Sv/miy6m3AKu55XitzaWT45aNITbFUlf\nVse07xkvN6nKoCDpQkkRtAJP8+AKN14jZChcUB11d4HVLTxsG44NohZOu/KC\nkGVnZLwbQVHiKlUgLMyI+HAWOtbZI92jAw+4ZmlZvN4Q157RUi8cfrDgnAQJ\nOEHrVpZZEmJ+zq/fu8apHEjqD0l5I4yxsIp8TL5A4qZkHunfz3nSjBGdayhU\nAufrUgqcp8rrfl1g+xTK8aOnBfAva8JbS4gmmJzQ2ov79x3U8krxAa1kpHyh\nVD65Ff+nt70MmCx5QOmo5+TJPxq0q6ujPq6+N1D/gKyFETILlsClF8kOcfg4\nKV4Q\r\n=uYGH\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/y-websocket.cjs","types":"./dist/src/y-websocket.d.ts","module":"./src/y-websocket.js","exports":{".":{"import":"./src/y-websocket.js","require":"./dist/y-websocket.cjs"},"./package.json":"./package.json"},"funding":{"url":"https://github.com/sponsors/dmonad","type":"GitHub Sponsors ❤"},"gitHead":"73b74f76bbed8b1fe6299b3b92c68fead3a7c62e","scripts":{"dist":"rm -rf dist && rollup -c && tsc","lint":"standard && tsc","test":"npm run lint","start":"node ./bin/server.js","preversion":"npm run lint && npm run dist && test -e dist/src/y-websocket.d.ts && test -e dist/y-websocket.cjs"},"_npmUser":{"name":"johnstleger","email":"jstleger0@googlemail.com"},"standard":{"ignore":["/dist","/node_modules"]},"repository":{"url":"git+https://github.com/yjs/y-websocket.git","type":"git"},"_npmVersion":"6.14.11","description":"Websockets provider for Yjs","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"ws":"^6.2.1","lib0":"^0.2.42","y-leveldb":"^0.1.0","y-protocols":"^1.0.5","lodash.debounce":"^4.0.8"},"_hasShrinkwrap":false,"devDependencies":{"yjs":"^13.5.0","rollup":"^1.32.1","standard":"^12.0.1","rollup-cli":"^1.0.9","typescript":"^3.9.9"},"peerDependencies":{"yjs":"^13.5.6"},"optionalDependencies":{"ws":"^6.2.1","y-leveldb":"^0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/y-websocket_1.3.15-trint.0_1644232968063_0.01587836330819381","host":"s3://npm-registry-packages"}},"1.3.18-trint.0":{"name":"@trint/y-websocket","version":"1.3.18-trint.0","keywords":["Yjs"],"author":{"name":"Kevin Jahns","email":"kevin.jahns@protonmail.com"},"license":"MIT","_id":"@trint/y-websocket@1.3.18-trint.0","maintainers":[{"name":"timbutler","email":"tim.butler@trint.com"},{"name":"jonathan.beaumont.trint","email":"jonathan.beaumont@trint.com"},{"name":"liam.connolly","email":"liam.connolly@trint.com"},{"name":"zegnus","email":"ferran.garriga@trint.com"},{"name":"peterslight","email":"peter.slight@trint.com"},{"name":"bcollofftrint","email":"bret.colloff@trint.com"},{"name":"anthonybillon","email":"anthony.billon@trint.com"},{"name":"samrevanoor","email":"sam@trint.com"},{"name":"barrytrint","email":"barry@trint.com"},{"name":"chrisguest","email":"chris.guest@trint.com"},{"name":"johnstleger","email":"jstleger0@googlemail.com"},{"name":"trinthq","email":"tech@trint.com"},{"name":"kuba.gaj","email":"kuba@qubutech.com"},{"name":"hannah.bacon","email":"hannah.bacon@trint.com"},{"name":"odhran73","email":"odhran@trint.com"},{"name":"lopea","email":"lope@trint.com"},{"name":"jinntr","email":"jinn.koriech@trint.com"},{"name":"sb-trint","email":"sb@trint.com"},{"name":"andrew.jackson","email":"andrew.jackson@trint.com"},{"name":"ivantrint","email":"ivan.podgurskiy@trint.com"},{"name":"katiemc","email":"katie.mcdonagh@trint.com"},{"name":"lylafibert","email":"lyla.fibert@trint.com"},{"name":"eleanorbyass","email":"eleanor.byass@trint.com"},{"name":"bryanattrint","email":"bryan.yap@trint.com"},{"name":"ryan.feline","email":"ryan.feline@trint.com"},{"name":"bogdan_trint","email":"bogdan.largeanu@trint.com"},{"name":"noafilosof","email":"noa.filosof@trint.com"},{"name":"dafna.libman","email":"dafna.libman@trint.com"},{"name":"gregtrint","email":"gregorio.costa@trint.com"}],"homepage":"https://github.com/yjs/y-websocket#readme","bugs":{"url":"https://github.com/yjs/y-websocket/issues"},"bin":{"y-websocket-server":"bin/server.js"},"dist":{"shasum":"2196c281c782a9cd0fee18c24324a8ecfd410d4a","tarball":"https://registry.npmjs.org/@trint/y-websocket/-/y-websocket-1.3.18-trint.0.tgz","fileCount":10,"integrity":"sha512-ORMW457iEoWy1B7m8Qp5giieOkUGnt/1i5Fz34dTH0NiKL4jw8y638vWDecAAMcpYrjoZ4brMv8eg/L+29cj9Q==","signatures":[{"sig":"MEYCIQC63WvMk7TUWHzc+vnpaTgFfLQ1AtnhDP8IrU5HR+LV8gIhAMWNzHGeXVcNTr8eqeKl5shA3CtskPYvaEnv/L+rwGJ2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":79669,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiATpjCRA9TVsSAnZWagAAaw4P/1KNc/BaZEHdHyf0F51m\n5XPOcDXIHnD2E+GXoeLXbzcYzMwOYy0c+aUXCUpr9En5Mz7ReE1m/ZLRjbok\nsLT0py5PtLWbThGkurST/K0Uo3x7tple/EWD5lPiRkw8SaCBILAhNPyfEXI9\nAad+xC9V7DgMaaP4YM4ZorHd0OmQC7+KGz9AhtX3V4WckECb8T3x+vLk+h4C\nhMLpT62oDG9ESWhkVBp6bh1JsJVNVJHtUyLRqK1Y3fvDDZ6JITQdDGIiiQey\nYrY0K8xXRADy0NPtI/Jx+cUZS6FqVVoS76sNcinV233rBItlXKPveS2rsEnT\nju9FMWvMznNI0MEWVklmwj0LsAZrEi6mQiUwwt4k7YmstvwN/BQQn+plR1TL\nKXW+scMxRGSY2vA0rOyn8CoDKcMQhCwTHdy8h39hLiTSl40+bcoveI5k/cIW\n578UZYCLKGArnbbloEz91wbi4x553NREo6nEljAgUaKXU+MU/xNi7fQ0jUUC\nyy9WHGVVG/Dju1dvVcNWvAT2SLiJlRX4WOytLoXaPhEaGGIa234Rnt6MN9Hy\nv/NR8k+S4GCpWuRp2N9z3/vcfWKCkIC/J/HyygkG/EocbiqGBqQXJlWS0b2R\nYGsC9bpCHyfQpjpmue3dpaaYfrhQY1FnTVc6kmUTkuRsMDCV+X17/JY9vqFh\n1CX0\r\n=OeHZ\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/y-websocket.cjs","types":"./dist/src/y-websocket.d.ts","module":"./src/y-websocket.js","exports":{".":{"import":"./src/y-websocket.js","require":"./dist/y-websocket.cjs"},"./bin/utils":"./bin/utils.js","./bin/callback":"./bin/callback.js","./package.json":"./package.json"},"funding":{"url":"https://github.com/sponsors/dmonad","type":"GitHub Sponsors ❤"},"gitHead":"fb4b304bc5f0fb6089c5fe60539857c145d33af3","scripts":{"dist":"rm -rf dist && rollup -c && tsc","lint":"standard && tsc","test":"npm run lint","start":"node ./bin/server.js","preversion":"npm run lint && npm run dist && test -e dist/src/y-websocket.d.ts && test -e dist/y-websocket.cjs"},"_npmUser":{"name":"johnstleger","email":"jstleger0@googlemail.com"},"standard":{"ignore":["/dist","/node_modules"]},"repository":{"url":"git+https://github.com/yjs/y-websocket.git","type":"git"},"_npmVersion":"6.14.11","description":"Websockets provider for Yjs","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"ws":"^6.2.1","lib0":"^0.2.42","y-leveldb":"^0.1.0","y-protocols":"^1.0.5","lodash.debounce":"^4.0.8"},"_hasShrinkwrap":false,"devDependencies":{"yjs":"^13.5.0","rollup":"^1.32.1","standard":"^12.0.1","rollup-cli":"^1.0.9","typescript":"^3.9.9"},"peerDependencies":{"yjs":"^13.5.6"},"optionalDependencies":{"ws":"^6.2.1","y-leveldb":"^0.1.0"},"_npmOperationalInternal":{"tmp":"tmp/y-websocket_1.3.18-trint.0_1644247651375_0.13272539909374514","host":"s3://npm-registry-packages"}}},"time":{"created":"2022-02-07T11:22:47.911Z","modified":"2026-09-14T13:28:38.384Z","1.3.15-trint.0":"2022-02-07T11:22:48.224Z","1.3.18-trint.0":"2022-02-07T15:27:31.501Z"},"bugs":{"url":"https://github.com/yjs/y-websocket/issues"},"author":{"name":"Kevin Jahns","email":"kevin.jahns@protonmail.com"},"license":"MIT","homepage":"https://github.com/yjs/y-websocket#readme","keywords":["Yjs"],"repository":{"url":"git+https://github.com/yjs/y-websocket.git","type":"git"},"description":"Websockets provider for Yjs","maintainers":[{"email":"barry@trint.com","name":"barrytrint"},{"email":"ferran.garriga@trint.com","name":"zegnus"},{"email":"tech@trint.com","name":"trinthq"},{"email":"gregorio.costa@trint.com","name":"gregtrint"},{"email":"ale.delfino@trint.com","name":"adelfino"},{"email":"steve.doolan@trint.com","name":"steve-doolan-trint"},{"email":"prabhat.gurung@trint.com","name":"prabhat.gurung"},{"email":"dennis.cheng@trint.com","name":"trint.dennis.cheng"},{"email":"katie.mcdonagh@trint.com","name":"katiemc"}],"readme":"\n# y-websocket :tophat:\n> WebSocket Provider for Yjs\n\nThe 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.\n\nThe 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.\n\n* Supports cross-tab communication. When you open the same document in the same browser, changes on the document are exchanged via cross-tab communication ([Broadcast Channel](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) as fallback).\n* Supports exchange of awareness information (e.g. cursors).\n\n## Quick Start\n\n### Install dependencies\n\n```sh\nnpm i y-websocket\n```\n\n### Start a y-websocket server\n\nThis repository implements a basic server that you can adopt to your specific use-case. [(source code)](./bin/)\n\nStart a y-websocket server:\n\n```sh\nHOST=localhost PORT=1234 npx y-websocket-server\n```\n\n### Client Code:\n\n```js\nimport * as Y from 'yjs'\nimport { WebsocketProvider } from 'y-websocket'\n\nconst doc = new Y.Doc()\nconst wsProvider = new WebsocketProvider('ws://localhost:1234', 'my-roomname', doc)\n\nwsProvider.on('status', event => {\n  console.log(event.status) // logs \"connected\" or \"disconnected\"\n})\n```\n\n#### Client Code in Node.js\n\nThe WebSocket provider requires a [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) object to create connection to a server. You can polyfill WebSocket support in Node.js using the [`ws` package](https://www.npmjs.com/package/ws).\n\n```js\nconst wsProvider = new WebsocketProvider('ws://localhost:1234', 'my-roomname', doc, { WebSocketPolyfill: require('ws') })\n```\n\n## API\n\n```js\nimport { WebsocketProvider } from 'y-websocket'\n```\n\n<dl>\n  <b><code>wsProvider = new WebsocketProvider(serverUrl: string, room: string, ydoc: Y.Doc [, wsOpts: WsOpts])</code></b>\n  <dd>Create a new websocket-provider instance. As long as this provider, or the connected ydoc, is not destroyed, the changes will be synced to other clients via the connected server. Optionally, you may specify a configuration object. The following default values of wsOpts can be overwritten. </dd>\n</dl>\n\n```js\nwsOpts = {\n  // Set this to `false` if you want to connect manually using wsProvider.connect()\n  connect: true,\n  // Specify a query-string that will be url-encoded and attached to the `serverUrl`\n  // I.e. params = { auth: \"bearer\" } will be transformed to \"?auth=bearer\"\n  params: {}, // Object<string,string>\n  // You may polyill the Websocket object (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).\n  // E.g. In nodejs, you could specify WebsocketPolyfill = require('ws')\n  WebsocketPolyfill: Websocket,\n  // Specify an existing Awareness instance - see https://github.com/yjs/y-protocols\n  awareness: new awarenessProtocol.Awareness(ydoc)\n}\n```\n\n<dl>\n  <b><code>wsProvider.wsconnected: boolean</code></b>\n  <dd>True if this instance is currently connected to the server.</dd>\n  <b><code>wsProvider.wsconnecting: boolean</code></b>\n  <dd>True if this instance is currently connecting to the server.</dd>\n  <b><code>wsProvider.shouldConnect: boolean</code></b>\n  <dd>If false, the client will not try to reconnect.</dd>\n  <b><code>wsProvider.bcconnected: boolean</code></b>\n  <dd>True if this instance is currently communicating to other browser-windows via BroadcastChannel.</dd>\n  <b><code>wsProvider.synced: boolean</code></b>\n  <dd>True if this instance is currently connected and synced with the server.</dd>\n  <b><code>wsProvider.disconnect()</code></b>\n  <dd>Disconnect from the server and don't try to reconnect.</dd>\n  <b><code>wsProvider.connect()</code></b>\n  <dd>Establish a websocket connection to the websocket-server. Call this if you recently disconnected or if you set wsOpts.connect = false.</dd>\n  <b><code>wsProvider.destroy()</code></b>\n  <dd>Destroy this wsProvider instance. Disconnects from the server and removes all event handlers.</dd>\n  <b><code>wsProvider.on('sync', function(isSynced: boolean))</code></b>\n  <dd>Add an event listener for the sync event that is fired when the client received content from the server.</dd>\n</dl>\n\n## Websocket Server\n\nStart a y-websocket server:\n\n```sh\nHOST=localhost PORT=1234 npx y-websocket-server\n```\n\nSince npm symlinks the `y-websocket-server` 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`.\n\n### Websocket Server with Persistence\n\nPersist document updates in a LevelDB database.\n\nSee [LevelDB Persistence](https://github.com/yjs/y-leveldb) for more info.\n\n```sh\nHOST=localhost PORT=1234 YPERSISTENCE=./dbDir node ./node_modules/y-websocket/bin/server.js\n```\n\n### Websocket Server with HTTP callback\n\nSend 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.\n\nCan take the following ENV variables:\n\n* `CALLBACK_URL` : Callback server URL\n* `CALLBACK_DEBOUNCE_WAIT` : Debounce time between callbacks (in ms). Defaults to 2000 ms\n* `CALLBACK_DEBOUNCE_MAXWAIT` : Maximum time to wait before callback. Defaults to 10 seconds\n* `CALLBACK_TIMEOUT` : Timeout for the HTTP call. Defaults to 5 seconds\n* `CALLBACK_OBJECTS` : JSON of shared objects to get data (`'{\"SHARED_OBJECT_NAME\":\"SHARED_OBJECT_TYPE}'`)\n\n```sh\nCALLBACK_URL=http://localhost:3000/ CALLBACK_OBJECTS='{\"prosemirror\":\"XmlFragment\"}' npm start\n```\nThis 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.\n\n## License\n\n[The MIT License](./LICENSE) © Kevin Jahns\n","readmeFilename":"README.md"}