Skip to content

Commit

Permalink
add logging to demo-server
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Dec 12, 2023
1 parent e3e7779 commit 76eca3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion demo-server/demo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
const WebSocket = require('ws')
const http = require('http')
const StaticServer = require('node-static').Server
const setupWSConnection = require('y-websocket/bin/utils').setupWSConnection
const ywsUtils = require('y-websocket/bin/utils')
const setupWSConnection = ywsUtils.setupWSConnection
const docs = ywsUtils.docs
const env = require('lib0/environment')
const nostatic = env.hasParam('--nostatic')

Expand Down Expand Up @@ -35,6 +37,17 @@ wss.on('connection', (conn, req) => {
setupWSConnection(conn, req, { gc: req.url.slice(1) !== 'ws/prosemirror-versions' })
})

// log some stats
setInterval(() => {
let conns = 0
docs.forEach(doc => { conns += doc.conns.size })
const stats = {
conns,
docs: docs.size
}
console.log(`${new Date().toISOString()} Stats: ${JSON.stringify(stats)}`)
}, 10000)

server.listen(port, '0.0.0.0')

console.log(`Listening to http://localhost:${port} (${production ? 'production + ' : ''} ${nostatic ? 'no static content' : 'serving static content'})`)
2 changes: 1 addition & 1 deletion prosemirror/prosemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { keymap } from 'prosemirror-keymap'

window.addEventListener('load', () => {
const ydoc = new Y.Doc()
const provider = new WebsocketProvider('wss://demos.yjs.dev/ws', 'prosemirror-demo', ydoc)
const provider = new WebsocketProvider('ws://localhost:3000/ws', 'prosemirror-demo', ydoc)
const yXmlFragment = ydoc.getXmlFragment('prosemirror')

const editor = document.createElement('div')
Expand Down

0 comments on commit 76eca3d

Please sign in to comment.