split collab demo in three rooms

This commit is contained in:
Hans Pagel
2021-04-23 08:14:00 +02:00
parent 0a233d7885
commit 90737af725

View File

@@ -5,7 +5,7 @@
<div class="editor__footer"> <div class="editor__footer">
<div :class="`editor__status editor__status--${status}`"> <div :class="`editor__status editor__status--${status}`">
<template v-if="status === 'connected'"> <template v-if="status === 'connected'">
{{ users.length }} user{{ users.length === 1 ? '' : 's' }} online {{ users.length }} user{{ users.length === 1 ? '' : 's' }} online in {{ room }}
</template> </template>
<template v-else> <template v-else>
offline offline
@@ -37,6 +37,14 @@ const getRandomElement = list => {
return list[Math.floor(Math.random() * list.length)] return list[Math.floor(Math.random() * list.length)]
} }
const getRandomRoom = () => {
return getRandomElement([
'room.one',
'room.two',
'room.three',
])
}
export default { export default {
components: { components: {
EditorContent, EditorContent,
@@ -54,19 +62,20 @@ export default {
editor: null, editor: null,
users: [], users: [],
status: 'connecting', status: 'connecting',
room: getRandomRoom(),
} }
}, },
mounted() { mounted() {
const ydoc = new Y.Doc() const ydoc = new Y.Doc()
this.provider = new WebsocketProvider('wss://websocket.tiptap.dev', 'tiptap-collaboration-demo', ydoc) this.provider = new WebsocketProvider('wss://websocket.tiptap.dev', this.room, ydoc)
this.provider.on('status', event => { this.provider.on('status', event => {
this.status = event.status this.status = event.status
}) })
window.ydoc = ydoc window.ydoc = ydoc
this.indexdb = new IndexeddbPersistence('tiptap-collaboration-demo', ydoc) this.indexdb = new IndexeddbPersistence(this.room, ydoc)
this.editor = new Editor({ this.editor = new Editor({
extensions: [ extensions: [