-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_content.vue
executable file
·145 lines (136 loc) · 3.62 KB
/
main_content.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<template>
<div class="main-content">
<navbar></navbar>
<!-- area to add live data as text is being added -->
<div class="content">
<div class="content-left">
<videocomponent id="video" :wsrtc="wsrtc" :uri="uri"></videocomponent>
<div class="doc-info">
<div>{{ count }} words</div>
<div>{{ time }} read</div>
</div>
<audiocomponent id="audio" ></audiocomponent>
</div>
<div class="content-right">
<div id="editor"></div>
</div>
<div>
<statcomponent :quill="quill"></statcomponent>
</div>
</div>
</div>
</template>
<script>
import Navbar from './navbar.vue'
import Methods from '../js/main_content.js'
import Videocomponent from './video_component.vue'
import Audiocomponent from './audio_component.vue'
import {textStats, docSubscribe} from '../js/editor.js'
import sharedb from 'sharedb/lib/client'
import richText from 'rich-text'
// import Quill from 'quill'
import Chance from 'chance'
import auth from '../js/auth.js'
import docsave from '../js/docsave.js'
import editor from '../js/editor.js'
import statcomponent from './stat_component.vue'
export default {
created() {
let chance = new Chance()
let c = this.$route.params.channel
const token = auth.getToken();
this.uri = c !== undefined && /^\w{5}$/.test(c) ? c : chance.word({length: 5})
//create RTC websocket
this.wsrtc = new WebSocket(`wss:https://${window.location.host}/ws/${this.uri}rtc`);
// update URL display. I still think we can do this with router somehow :S
window.history.pushState(window.location.origin, '/', this.uri);
// If token exists
if (token) {
// Checks if token in computer is valid then gets user resource
auth.getJwt(this, token);
}
},
mounted() {
sharedb.types.register(richText.type)
let socket = new WebSocket(`ws:https://${window.location.hostname}:3000/${this.uri}`)
const connection = new sharedb.Connection(socket)
// console.log(socket, this.wsrtc)
// console.log(socket, this.wsrtc)
// For testing reconnection
window.disconnect = function() {
connection.close();
}
window.connect = function(uri) {
let socket = new WebSocket(`ws:https://${window.location.host}`);
connection.bindToSocket(socket);
}
// Storing doc inside editor for access in other components.
editor.doc = connection.get('docs', this.uri);
// New quill
editor.makeQuill();
editor.quillOn(this, editor.doc);
editor.docSubscribe(editor.quill, editor.doc);
this.quill = editor.quill
},
data() {
return {
ws: null,
wsrtc: null,
channel: '',
count: 0,
// User data stored in auth
user: auth.user,
// Doc data stored in docsave
docData: docsave.docData,
time: '',
quill: '',
uri: ''
}
},
components: {
Navbar,
Videocomponent,
Audiocomponent,
statcomponent
},
// Methods are located in js directory
methods: Methods
}
</script>
<style>
.main-content{
width: 100vw;
}
.content{
display: inline-flex;
height: 87vh;
width: 100vw;
}
.content-right{
width: 80%;
}
.content-left{
width: 20%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
}
.doc-info{
font-size: 0.95em;
font-weight: 600;
margin: 1em;
opacity: 0.35;
}
html, body{
color: #333;
font-family: 'Monaco', courier, monospace;
}
#editor {
height: 100%;
padding: 1em;
}
code {
color: #f66;
}
</style>