Skip to content

Commit

Permalink
specific ws endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Dec 11, 2023
1 parent 0d20520 commit ce30895
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion codemirror.next/codemirror.next.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const userColor = usercolors[random.uint32() % usercolors.length]
const ydoc = new Y.Doc()
// const provider = new WebrtcProvider('codemirror6-demo-room', ydoc)
const provider = new WebsocketProvider(
'wss://demos.yjs.dev',
'wss://demos.yjs.dev/ws',
'codemirror.next-demo',
ydoc
)
Expand Down
2 changes: 1 addition & 1 deletion codemirror/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'codemirror/mode/javascript/javascript.js'
window.addEventListener('load', () => {
const ydoc = new Y.Doc()
const provider = new WebsocketProvider(
'wss://demos.yjs.dev',
'wss://demos.yjs.dev/ws',
'codemirror-demo-2',
ydoc
)
Expand Down
12 changes: 8 additions & 4 deletions demo-server/demo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ const port = process.env.PORT || 3000
const staticServer = new StaticServer('../', { cache: production ? 3600 : false, gzip: production })

const server = http.createServer((request, response) => {
request.addListener('end', () => {
staticServer.serve(request, response)
}).resume()
if (!(request.url || '').startsWith('/ws/')) {
request.addListener('end', () => {
staticServer.serve(request, response)
}).resume()
}
})
const wss = new WebSocket.Server({ server })

wss.on('connection', (conn, req) => setupWSConnection(conn, req, { gc: req.url.slice(1) !== 'prosemirror-versions' }))
wss.on('connection', (conn, req) => {
setupWSConnection(conn, req, { gc: req.url.slice(1) !== 'ws/prosemirror-versions' })
})

server.listen(port, '0.0.0.0')

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Yjs Demos</h1>
<li><a href="./quill/quill.html">Quill Binding</a></li>
<li><a href="./monaco/monaco.html">Monaco Binding</a></li>
<li><a href="./codemirror/codemirror.html">CodeMirror Binding</a></li>
<li><a href="./codemirror.next/codemirror.next.html">CodeMirror 6 Binding</a></li>
</ul>
</body>
</html>
2 changes: 1 addition & 1 deletion monaco/monaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as monaco from 'monaco-editor'

window.addEventListener('load', () => {
const ydoc = new Y.Doc()
const provider = new WebsocketProvider('wss://demos.yjs.dev', 'monaco-demo', ydoc)
const provider = new WebsocketProvider('wss://demos.yjs.dev/ws', 'monaco-demo', ydoc)
const ytext = ydoc.getText('monaco')

const editor = monaco.editor.create(/** @type {HTMLElement} */ (document.getElementById('monaco-editor')), {
Expand Down
2 changes: 1 addition & 1 deletion prosemirror-versions/prosemirror-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ window.addEventListener('load', () => {
const permanentUserData = new Y.PermanentUserData(ydoc)
permanentUserData.setUserMapping(ydoc, ydoc.clientID, user.username)
ydoc.gc = false
const provider = new WebsocketProvider('wss://demos.yjs.dev', 'prosemirror-versions-demo', ydoc)
const provider = new WebsocketProvider('wss://demos.yjs.dev/ws', 'prosemirror-versions-demo', ydoc)
const yXmlFragment = ydoc.get('prosemirror', Y.XmlFragment)

const editor = document.createElement('div')
Expand Down
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', 'prosemirror-demo', ydoc)
const provider = new WebsocketProvider('wss://demos.yjs.dev/ws', 'prosemirror-demo', ydoc)
const yXmlFragment = ydoc.getXmlFragment('prosemirror')

const editor = document.createElement('div')
Expand Down
2 changes: 1 addition & 1 deletion quill/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Quill.register('modules/cursors', QuillCursors)

window.addEventListener('load', () => {
const ydoc = new Y.Doc()
const provider = new WebsocketProvider('wss://demos.yjs.dev', 'quill-demo-5', ydoc)
const provider = new WebsocketProvider('wss://demos.yjs.dev/ws', 'quill-demo-5', ydoc)
const ytext = ydoc.getText('quill')
const editorContainer = document.createElement('div')
editorContainer.setAttribute('id', 'editor')
Expand Down

0 comments on commit ce30895

Please sign in to comment.