-
Notifications
You must be signed in to change notification settings - Fork 446
/
Copy pathScreen.vue
182 lines (147 loc) · 3.56 KB
/
Screen.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
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
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div :id="screenContainerId" class="screenContainer">
<video v-show="(localMediaModel && localMediaModel.attributes.localScreen) || (callParticipantModel && callParticipantModel.attributes.screen)"
ref="screen"
:disablePictureInPicture="!isBig ? 'true' : 'false'"
class="screen"
:class="screenClass" />
<VideoBottomBar v-if="isBig"
:token="token"
:shared-data="sharedData"
is-big
is-screen
:model="model"
:participant-name="remoteParticipantName" />
</div>
</template>
<script>
import Hex from 'crypto-js/enc-hex.js'
import SHA1 from 'crypto-js/sha1.js'
import { t } from '@nextcloud/l10n'
import VideoBottomBar from './VideoBottomBar.vue'
import { useGuestNameStore } from '../../../stores/guestName.js'
import attachMediaStream from '../../../utils/attachmediastream.js'
export default {
name: 'Screen',
components: {
VideoBottomBar,
},
props: {
token: {
type: String,
required: true,
},
localMediaModel: {
type: Object,
default: null,
},
callParticipantModel: {
type: Object,
default: null,
},
sharedData: {
type: Object,
required: true,
},
isBig: {
type: Boolean,
default: false,
},
},
setup() {
const guestNameStore = useGuestNameStore()
return { guestNameStore }
},
computed: {
model() {
if (this.callParticipantModel) {
return this.callParticipantModel
}
return this.localMediaModel
},
screenContainerId() {
if (this.localMediaModel) {
return 'localScreenContainer'
}
return 'container_' + this.callParticipantModel.attributes.peerId + '_screen_incoming'
},
remoteSessionHash() {
if (!this.callParticipantModel) {
return null
}
return Hex.stringify(SHA1(this.callParticipantModel.attributes.peerId))
},
remoteParticipantName() {
if (!this.callParticipantModel) {
return t('spreed', 'You')
}
let remoteParticipantName = this.callParticipantModel.attributes.name
// The name is undefined and not shown until a connection is made
// for registered users, so do not fall back to the guest name in
// the store either until the connection was made.
if (!this.callParticipantModel.attributes.userId && !remoteParticipantName && remoteParticipantName !== undefined) {
remoteParticipantName = this.guestNameStore.getGuestName(
this.$store.getters.getToken(),
this.remoteSessionHash,
)
}
return remoteParticipantName
},
screenClass() {
if (this.isBig) {
return 'screen--fit'
} else {
return 'screen--fill'
}
},
},
watch: {
'localMediaModel.attributes.localScreen'(localScreen) {
this._setScreen(localScreen)
},
'callParticipantModel.attributes.screen'(screen) {
this._setScreen(screen)
},
},
mounted() {
// Set initial state
if (this.localMediaModel) {
this._setScreen(this.localMediaModel.attributes.localScreen)
} else {
this._setScreen(this.callParticipantModel.attributes.screen)
}
},
methods: {
t,
_setScreen(screen) {
if (!screen) {
this.$refs.screen.srcObject = null
return
}
// The audio is played using an audio element in the model to be
// able to hear it even if there is no view for it.
attachMediaStream(screen, this.$refs.screen)
this.$refs.screen.muted = true
},
},
}
</script>
<style lang="scss" scoped>
.screen {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
&--fit {
object-fit: contain;
}
&--fill {
object-fit: cover;
}
}
</style>