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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
<!--
- @copyright Copyright (c) 2019, Daniel Calviño Sánchez <danxuliu@gmail.com>
-
- @author Marco Ambrosini <marcoambrosini@pm.me>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<div v-if="isInFile">
<CallView
v-show="showCallView"
:token="token"
:is-sidebar="true" />
<PreventUnload :when="warnLeaving" />
</div>
</template>
<script>
import CallView from './components/CallView/CallView'
import PreventUnload from 'vue-prevent-unload'
import sessionIssueHandler from './mixins/sessionIssueHandler'
import isInCall from './mixins/isInCall'
import participant from './mixins/participant'
import talkHashCheck from './mixins/talkHashCheck'
import '@nextcloud/dialogs/styles/toast.scss'
export default {
name: 'FilesSidebarCallViewApp',
components: {
CallView,
PreventUnload,
},
mixins: [
sessionIssueHandler,
isInCall,
participant,
talkHashCheck,
],
data() {
return {
// Needed for reactivity.
Talk: OCA.Talk,
}
},
computed: {
fileInfo() {
// When changing files OCA.Talk.fileInfo is cleared as soon as the
// new file starts to be loaded; "setFileInfo()" is called once the
// new file has loaded, so fileInfo is got from OCA.Talk to hide the
// call view at the same time as the rest of the sidebar UI.
return this.Talk.fileInfo || {}
},
fileId() {
return this.fileInfo.id
},
token() {
return this.$store.getters.getToken()
},
fileIdForToken() {
return this.$store.getters.getFileIdForToken()
},
/**
* Returns whether the sidebar is opened in the file of the current
* conversation or not.
*
* Note that false is returned too when the sidebar is closed, even if
* the conversation is active in the current file.
*
* @returns {Boolean} true if the sidebar is opened in the file, false
* otherwise.
*/
isInFile() {
return this.fileId === this.fileIdForToken
},
showCallView() {
// FIXME Remove participants as soon as the file changes so this
// condition is not needed.
if (!this.isInFile) {
return false
}
return this.isInCall
},
warnLeaving() {
return !this.isLeavingAfterSessionIssue && this.showCallView
},
},
watch: {
showCallView(showCallView) {
if (showCallView) {
this.replaceSidebarHeaderContentsWithCallView()
} else {
this.restoreSidebarHeaderContents()
}
},
/**
* Force restoring the sidebar header contents on file changes.
*
* If the sidebar is opened in a different file during a call the
* sidebar header contents may not be properly restored due to the order
* in which the updates are handled, so it needs to be executed again
* when the FileInfo has been set and it does not match the current
* conversation.
*
* @param {Object} fileInfo the watched FileInfo
*/
fileInfo(fileInfo) {
if (!fileInfo) {
return
}
if (this.isInFile) {
return
}
const headerAction = document.querySelector('.app-sidebar-header__action')
if (!headerAction) {
return
}
if (this.$el.parentElement === headerAction) {
return
}
this.restoreSidebarHeaderContents()
},
},
methods: {
setFileInfo(fileInfo) {
},
/**
* Adds a special style sheet to hide the sidebar header contents during
* a call.
*
* The style sheet contains a rule to hide ".hidden-by-call" elements,
* which is the CSS class set in the sidebar header contents during a
* call.
*/
addCallInFilesSidebarStyleSheet() {
const isCallInFilesSidebarStyleSheet = (sheet) => {
try {
// cssRules may not be defined in Chromium if the stylesheet
// is loaded from a different domain.
if (!sheet.cssRules) {
return false
}
// None of the default properties of a style sheet can be used
// as an ID. Adding a "data-id" attribute would work in Firefox,
// but not in Chromium, as it does not provide a "dataset"
// property in styleSheet objects. Therefore it is necessary to
// check the rules themselves, but as the order is undefined a
// matching rule needs to be looked for in all of them.
if (sheet.cssRules.length !== 2) {
return false
}
for (const cssRule of sheet.cssRules) {
if (cssRule.cssText === '.app-sidebar-header .hidden-by-call { display: none !important; }') {
return true
}
}
} catch (exception) {
// Accessing cssRules may throw a SecurityError in Firefox
// if the style sheet is loaded from a different domain.
if (exception.name !== 'SecurityError') {
throw exception
}
}
return false
}
for (let i = 0; i < document.styleSheets.length; i++) {
if (isCallInFilesSidebarStyleSheet(document.styleSheets[i])) {
return
}
}
const style = document.createElement('style')
document.head.appendChild(style)
// "insertRule" calls below need to be kept in sync with the
// condition above.
// Shadow is added to forced white icons to ensure that they are
// visible even against a bright video background.
// White color of forced white icons needs to be set in "icons.scss"
// file to be able to use the SCSS functions.
style.sheet.insertRule('.app-sidebar-header .forced-white { filter: drop-shadow(1px 1px 4px var(--color-box-shadow)); }', 0)
style.sheet.insertRule('.app-sidebar-header .hidden-by-call { display: none !important; }', 0)
},
/**
* Hides the sidebar header contents (except the close button) and shows
* the call view instead.
*/
replaceSidebarHeaderContentsWithCallView() {
this.addCallInFilesSidebarStyleSheet()
const header = document.querySelector('.app-sidebar-header')
if (!header) {
return
}
for (let i = 0; i < header.children.length; i++) {
const headerChild = header.children[i]
if (headerChild.classList.contains('app-sidebar__close')) {
headerChild.classList.add('forced-white')
} else {
headerChild.classList.add('hidden-by-call')
}
}
header.appendChild(this.$el)
},
/**
* Shows the sidebar header contents and moves the call view back to the
* actions.
*/
restoreSidebarHeaderContents() {
const header = document.querySelector('.app-sidebar-header')
if (!header) {
return
}
for (let i = 0; i < header.children.length; i++) {
const headerChild = header.children[i]
if (headerChild.classList.contains('app-sidebar__close')) {
headerChild.classList.remove('forced-white')
} else {
headerChild.classList.remove('hidden-by-call')
}
}
const headerAction = document.querySelector('.app-sidebar-header__action')
if (headerAction) {
headerAction.appendChild(this.$el)
}
},
},
}
</script>
<style lang="scss" scoped>
#call-container {
position: relative;
/* Prevent shadows of videos from leaking on other elements. */
overflow: hidden;
/* Show the call container in a 16/9 proportion based on the sidebar
* width. */
padding-bottom: 56.25%;
max-height: 56.25%;
}
</style>
|