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",
"version": "2.1.0",
"name": "@y/websocket-server",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "y-websocket",
"version": "2.1.0",
"name": "@y/websocket-server",
"version": "0.1.0",
"license": "MIT",
"dependencies": {
"lib0": "^0.2.52",
"lodash.debounce": "^4.0.8",
"lib0": "^0.2.102",
"y-protocols": "^1.0.5"
},
"bin": {
"y-websocket": "bin/server.cjs",
"y-websocket-server": "bin/server.cjs"
"y-websocket": "src/server.js",
"y-websocket-server": "src/server.js"
},
"devDependencies": {
"@types/lodash.debounce": "^4.0.9",
"@types/node": "^18.15.0",
"@types/ws": "^8.5.10",
"rollup": "^3.19.1",
@ -42,21 +40,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": {
"version": "18.15.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.0.tgz",
@ -1945,9 +1928,10 @@
}
},
"node_modules/lib0": {
"version": "0.2.93",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.93.tgz",
"integrity": "sha512-M5IKsiFJYulS+8Eal8f+zAqf5ckm1vffW0fFDxfgxJ+uiVopvDdd3PxJmz0GsVi3YNO7QCFSq0nAsiDmNhLj9Q==",
"version": "0.2.102",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.102.tgz",
"integrity": "sha512-g70kydI0I1sZU0ChO8mBbhw0oUW/8U0GHzygpvEIx8k+jgOpqnTSb/E+70toYVqHxBhrERD21TwD5QcZJQ40ZQ==",
"license": "MIT",
"dependencies": {
"isomorphic.js": "^0.2.4"
},
@ -1998,11 +1982,6 @@
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"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": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",

View File

@ -26,14 +26,12 @@
"exports": {
"./package.json": "./package.json",
"./utils": {
"module": "./src/utils.js",
"import": "./src/utils.js",
"require": "./dist/utils.cjs",
"types": "./dist/src/utils.d.ts",
"default": "./src/utils.js"
},
"./callback": {
"module": "./src/callback.js",
"import": "./src/callback.js",
"require": "./dist/callback.cjs",
"types": "./dist/src/callback.d.ts",
@ -60,12 +58,10 @@
]
},
"dependencies": {
"lib0": "^0.2.52",
"lodash.debounce": "^4.0.8",
"lib0": "^0.2.102",
"y-protocols": "^1.0.5"
},
"devDependencies": {
"@types/lodash.debounce": "^4.0.9",
"@types/node": "^18.15.0",
"@types/ws": "^8.5.10",
"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
/**
* @param {Uint8Array} update
* @param {any} origin
* @param {import('./utils.js').WSSharedDoc} doc
*/
export const callbackHandler = (update, origin, doc) => {
export const callbackHandler = (doc) => {
const room = doc.name
const dataToSend = {
room,

View File

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