remove client-side code

This commit is contained in:
Kevin Jahns 2025-04-02 23:26:24 +02:00
parent f840a89e51
commit a77737071e
4 changed files with 19 additions and 46 deletions

43
package-lock.json generated
View File

@ -1,24 +1,22 @@
{ {
"name": "y-websocket", "name": "@y/websocket-server",
"version": "2.1.0", "version": "0.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "y-websocket", "name": "@y/websocket-server",
"version": "2.1.0", "version": "0.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"lib0": "^0.2.52", "lib0": "^0.2.102",
"lodash.debounce": "^4.0.8",
"y-protocols": "^1.0.5" "y-protocols": "^1.0.5"
}, },
"bin": { "bin": {
"y-websocket": "bin/server.cjs", "y-websocket": "src/server.js",
"y-websocket-server": "bin/server.cjs" "y-websocket-server": "src/server.js"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash.debounce": "^4.0.9",
"@types/node": "^18.15.0", "@types/node": "^18.15.0",
"@types/ws": "^8.5.10", "@types/ws": "^8.5.10",
"rollup": "^3.19.1", "rollup": "^3.19.1",
@ -42,21 +40,6 @@
"yjs": "^13.5.6" "yjs": "^13.5.6"
} }
}, },
"node_modules/@types/lodash": {
"version": "4.17.0",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.0.tgz",
"integrity": "sha512-t7dhREVv6dbNj0q17X12j7yDG4bD/DHYX7o5/DbDxobP0HnGPgpRz2Ej77aL7TZT3DSw13fqUTj8J4mMnqa7WA==",
"dev": true
},
"node_modules/@types/lodash.debounce": {
"version": "4.0.9",
"resolved": "https://registry.npmjs.org/@types/lodash.debounce/-/lodash.debounce-4.0.9.tgz",
"integrity": "sha512-Ma5JcgTREwpLRwMM+XwBR7DaWe96nC38uCBDFKZWbNKD+osjVzdpnUSwBcqCptrp16sSOLBAUb50Car5I0TCsQ==",
"dev": true,
"dependencies": {
"@types/lodash": "*"
}
},
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.15.0", "version": "18.15.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.0.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.0.tgz",
@ -1945,9 +1928,10 @@
} }
}, },
"node_modules/lib0": { "node_modules/lib0": {
"version": "0.2.93", "version": "0.2.102",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.93.tgz", "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.102.tgz",
"integrity": "sha512-M5IKsiFJYulS+8Eal8f+zAqf5ckm1vffW0fFDxfgxJ+uiVopvDdd3PxJmz0GsVi3YNO7QCFSq0nAsiDmNhLj9Q==", "integrity": "sha512-g70kydI0I1sZU0ChO8mBbhw0oUW/8U0GHzygpvEIx8k+jgOpqnTSb/E+70toYVqHxBhrERD21TwD5QcZJQ40ZQ==",
"license": "MIT",
"dependencies": { "dependencies": {
"isomorphic.js": "^0.2.4" "isomorphic.js": "^0.2.4"
}, },
@ -1998,11 +1982,6 @@
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true "dev": true
}, },
"node_modules/lodash.debounce": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
"integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow=="
},
"node_modules/loose-envify": { "node_modules/loose-envify": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",

View File

@ -26,14 +26,12 @@
"exports": { "exports": {
"./package.json": "./package.json", "./package.json": "./package.json",
"./utils": { "./utils": {
"module": "./src/utils.js",
"import": "./src/utils.js", "import": "./src/utils.js",
"require": "./dist/utils.cjs", "require": "./dist/utils.cjs",
"types": "./dist/src/utils.d.ts", "types": "./dist/src/utils.d.ts",
"default": "./src/utils.js" "default": "./src/utils.js"
}, },
"./callback": { "./callback": {
"module": "./src/callback.js",
"import": "./src/callback.js", "import": "./src/callback.js",
"require": "./dist/callback.cjs", "require": "./dist/callback.cjs",
"types": "./dist/src/callback.d.ts", "types": "./dist/src/callback.d.ts",
@ -60,12 +58,10 @@
] ]
}, },
"dependencies": { "dependencies": {
"lib0": "^0.2.52", "lib0": "^0.2.102",
"lodash.debounce": "^4.0.8",
"y-protocols": "^1.0.5" "y-protocols": "^1.0.5"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash.debounce": "^4.0.9",
"@types/node": "^18.15.0", "@types/node": "^18.15.0",
"@types/ws": "^8.5.10", "@types/ws": "^8.5.10",
"rollup": "^3.19.1", "rollup": "^3.19.1",

View File

@ -8,11 +8,9 @@ const CALLBACK_OBJECTS = process.env.CALLBACK_OBJECTS ? JSON.parse(process.env.C
export const isCallbackSet = !!CALLBACK_URL export const isCallbackSet = !!CALLBACK_URL
/** /**
* @param {Uint8Array} update
* @param {any} origin
* @param {import('./utils.js').WSSharedDoc} doc * @param {import('./utils.js').WSSharedDoc} doc
*/ */
export const callbackHandler = (update, origin, doc) => { export const callbackHandler = (doc) => {
const room = doc.name const room = doc.name
const dataToSend = { const dataToSend = {
room, room,

View File

@ -6,13 +6,15 @@ import * as encoding from 'lib0/encoding'
import * as decoding from 'lib0/decoding' import * as decoding from 'lib0/decoding'
import * as map from 'lib0/map' import * as map from 'lib0/map'
import debounce from 'lodash.debounce' import * as eventloop from 'lib0/eventloop'
import { callbackHandler, isCallbackSet } from './callback.js' import { callbackHandler, isCallbackSet } from './callback.js'
const CALLBACK_DEBOUNCE_WAIT = parseInt(process.env.CALLBACK_DEBOUNCE_WAIT || '2000') const CALLBACK_DEBOUNCE_WAIT = parseInt(process.env.CALLBACK_DEBOUNCE_WAIT || '2000')
const CALLBACK_DEBOUNCE_MAXWAIT = parseInt(process.env.CALLBACK_DEBOUNCE_MAXWAIT || '10000') const CALLBACK_DEBOUNCE_MAXWAIT = parseInt(process.env.CALLBACK_DEBOUNCE_MAXWAIT || '10000')
const debouncer = eventloop.createDebouncer(CALLBACK_DEBOUNCE_WAIT, CALLBACK_DEBOUNCE_MAXWAIT)
const wsReadyStateConnecting = 0 const wsReadyStateConnecting = 0
const wsReadyStateOpen = 1 const wsReadyStateOpen = 1
const wsReadyStateClosing = 2 // eslint-disable-line const wsReadyStateClosing = 2 // eslint-disable-line
@ -139,11 +141,9 @@ export class WSSharedDoc extends Y.Doc {
this.awareness.on('update', awarenessChangeHandler) this.awareness.on('update', awarenessChangeHandler)
this.on('update', /** @type {any} */ (updateHandler)) this.on('update', /** @type {any} */ (updateHandler))
if (isCallbackSet) { if (isCallbackSet) {
this.on('update', /** @type {any} */ (debounce( this.on('update', (_update, _origin, doc) => {
callbackHandler, debouncer(() => callbackHandler(/** @type {WSSharedDoc} */ (doc)))
CALLBACK_DEBOUNCE_WAIT, })
{ maxWait: CALLBACK_DEBOUNCE_MAXWAIT }
)))
} }
this.whenInitialized = contentInitializor(this) this.whenInitialized = contentInitializor(this)
} }