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
|
<!--
- @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
-
- @author Joas Schilling <coding@schilljs.com>
-
- @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 class="signaling-server">
<input ref="signaling_server"
type="text"
name="signaling_server"
placeholder="wss://signaling.example.org"
:value="server"
:disabled="loading"
:aria-label="t('spreed', 'High-performance backend URL')"
@input="updateServer">
<input :id="'verify' + index"
type="checkbox"
:name="'verify' + index"
class="checkbox verify"
:checked="verify"
@change="updateVerify">
<label :for="'verify' + index">{{ t('spreed', 'Validate SSL certificate') }}</label>
<Button v-show="!loading"
type="tertiary-no-background"
:aria-label="t('spreed', 'Delete this server')"
@click="removeServer">
<template #icon>
<Delete :size="20" />
</template>
</Button>
<span v-if="server">{{ connectionState }}</span>
</div>
</template>
<script>
import Button from '@nextcloud/vue/dist/Components/Button'
import Delete from 'vue-material-design-icons/Delete'
import { getWelcomeMessage } from '../../services/signalingService.js'
export default {
name: 'SignalingServer',
components: {
Button,
Delete,
},
props: {
server: {
type: String,
default: '',
required: true,
},
verify: {
type: Boolean,
default: false,
required: true,
},
index: {
type: Number,
default: -1,
required: true,
},
loading: {
type: Boolean,
default: false,
},
},
data() {
return {
checked: false,
errorMessage: '',
versionFound: '',
}
},
computed: {
connectionState() {
if (!this.checked) {
return t('spreed', 'Status: Checking connection')
}
if (this.errorMessage) {
return this.errorMessage
}
return t('spreed', 'OK: Running version: {version}', {
version: this.versionFound,
})
},
},
watch: {
loading(isLoading) {
if (!isLoading) {
this.checkServerVersion()
}
},
},
mounted() {
if (this.server) {
this.checkServerVersion()
}
},
methods: {
removeServer() {
this.$emit('remove-server', this.index)
},
updateServer(event) {
this.$emit('update:server', event.target.value)
},
updateVerify(event) {
this.$emit('update:verify', event.target.checked)
},
async checkServerVersion() {
this.checked = false
this.errorMessage = ''
this.versionFound = ''
try {
const response = await getWelcomeMessage(this.index)
this.checked = true
this.versionFound = response.data.ocs.data.version
} catch (exception) {
this.checked = true
if (exception.response.data.ocs.data.error === 'CAN_NOT_CONNECT') {
this.errorMessage = t('spreed', 'Error: Cannot connect to server')
} else if (exception.response.data.ocs.data.error === 'JSON_INVALID') {
this.errorMessage = t('spreed', 'Error: Server did not respond with proper JSON')
} else if (exception.response.data.ocs.data.error === 'UPDATE_REQUIRED') {
this.versionFound = exception.response.data.ocs.data.version || t('spreed', 'Could not get version')
this.errorMessage = t('spreed', 'Error: Running version: {version}; Server needs to be updated to be compatible with this version of Talk', {
version: this.versionFound,
})
} else if (exception.response.data.ocs.data.error) {
this.errorMessage = t('spreed', 'Error: Server responded with: {error}', exception.response.data.ocs.data)
} else {
this.errorMessage = t('spreed', 'Error: Unknown error occurred')
}
}
},
},
}
</script>
<style lang="scss" scoped>
.signaling-server {
height: 44px;
display: flex;
align-items: center;
label {
margin: 0 20px;
display: inline-block;
}
}
</style>
|