add number of connected users

This commit is contained in:
Hans Pagel
2020-09-26 14:17:51 +02:00
parent 870f52065e
commit c44c30dc50
3 changed files with 31 additions and 1 deletions

View File

@@ -1,5 +1,11 @@
<template>
<editor-content :editor="editor" />
<div>
<editor-content :editor="editor" />
<div class="collaboration-status">
{{ numberOfConnectedUsers }} user{{ numberOfConnectedUsers === 1 ? '' : 's' }}
</div>
</div>
</template>
<script>
@@ -22,6 +28,7 @@ export default {
ydoc: null,
provider: null,
type: null,
numberOfConnectedUsers: 0,
editor: null,
}
},
@@ -30,6 +37,9 @@ export default {
this.ydoc = new Y.Doc()
this.provider = new WebrtcProvider('example', this.ydoc)
this.type = this.ydoc.getXmlFragment('prosemirror')
this.provider.on('peers', ({ bcPeers, webrtcPeers }) => {
this.numberOfConnectedUsers = bcPeers.length + webrtcPeers.length
})
this.editor = new Editor({
// TODO: This is added by every new user.

View File

@@ -1,3 +1,21 @@
.collaboration-status {
background: #eee;
color: #666;
border-radius: 5px;
padding: 0.5rem 1rem;
margin-top: 1rem;
&::before {
content: ' ';
display: inline-block;
width: 0.5rem;
height: 0.5rem;
background: green;
border-radius: 50%;
margin-right: 0.5rem;
}
}
/* this is a rough fix for the first cursor position when the first paragraph is empty */
.ProseMirror > .collaboration-cursor:first-child {
margin-top: 16px;

View File

@@ -1,5 +1,7 @@
# Collaboration
The content of this editor is shared with every users that opens that example.
<!-- <demo name="Examples/Collaboration" :show-source="false"/> -->
<demo name="Examples/Collaboration" />