Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MatterbridgeIntegration.vue « AdminSettings « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9074cd7189bd642dfe30cb65634a04294f60d00c (plain)
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
<!--
 - @copyright Copyright (c) 2020 Julien Veyssier <eneiluj@posteo.net>
 -
 - @author Julien Veyssier <eneiluj@posteo.net>
 -
 - @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 id="matterbridge_settings" class="matterbridge section">
		<h2>
			{{ t('spreed', 'Matterbridge integration') }}
			<small>
				{{ t('spreed', 'Beta') }}
			</small>
		</h2>

		<template v-if="matterbridgeVersion">
			<p class="settings-hint">
				{{ installedVersion }}
			</p>

			<p v-if="matterbridgeVersion">
				<input id="enable_matterbridge"
					v-model="matterbridgeEnabled"
					type="checkbox"
					name="enable_matterbridge"
					class="checkbox"
					@change="saveMatterbridgeEnabled">
				<label for="enable_matterbridge">{{ t('spreed', 'Enable Matterbridge integration') }}</label>
			</p>
		</template>

		<template v-else>
			<!-- eslint-disable-next-line vue/no-v-html -->
			<p class="settings-hint" v-html="description" />

			<!-- eslint-disable-next-line vue/no-v-html -->
			<p class="settings-hint" v-html="customBinaryText" />

			<p v-if="errorText" class="settings-hint">
				{{ errorText }}
			</p>

			<p>
				<ButtonVue v-if="isInstalling">
					<template #icon>
						<span class="icon icon-loading-small" />
					</template>
					{{ t('spreed', 'Downloading …') }}
				</ButtonVue>
				<ButtonVue v-else
					@click="enableMatterbridgeApp">
					{{ t('spreed', 'Install Talk Matterbridge') }}
				</ButtonVue>
			</p>
		</template>
	</div>
</template>

<script>
import ButtonVue from '@nextcloud/vue/dist/Components/ButtonVue.js'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import {
	enableMatterbridgeApp,
	stopAllBridges,
	getMatterbridgeVersion,
} from '../../services/matterbridgeService.js'

export default {
	name: 'MatterbridgeIntegration',

	components: {
		ButtonVue,
	},

	data() {
		return {
			matterbridgeEnabled: loadState('spreed', 'matterbridge_enable'),
			matterbridgeVersion: loadState('spreed', 'matterbridge_version'),
			isInstalling: false,
			error: loadState('spreed', 'matterbridge_error'),
		}
	},

	computed: {
		installedVersion() {
			return t('spreed', 'Installed version: {version}', {
				version: this.matterbridgeVersion,
			})
		},
		description() {
			return t('spreed', 'You can install the Matterbridge to link Nextcloud Talk to some other services, visit their {linkstart1}GitHub page{linkend} for more details. Downloading and installing the app can take a while. In case it times out, please install it manually from the {linkstart2}Nextcloud App Store{linkend}.')
				.replace('{linkstart1}', '<a  target="_blank" rel="noreferrer nofollow" class="external" href="https://github.com/42wim/matterbridge/wiki">')
				.replace('{linkstart2}', '<a  target="_blank" rel="noreferrer nofollow" class="external" href="https://apps.nextcloud.com/apps/talk_matterbridge">')
				.replace(/{linkend}/g, ' ↗</a>')
		},
		errorText() {
			if (this.error === 'binary_permissions') {
				return t('spreed', 'Matterbridge binary has incorrect permissions. Please make sure the Matterbridge binary file is owned by the correct user and can be executed. It can be found in "/.../nextcloud/apps/talk_matterbridge/bin/".')
			} else if (this.error === 'binary') {
				return t('spreed', 'Matterbridge binary was not found or couldn\'t be executed.')
			} else {
				return ''
			}
		},
		customBinaryText() {
			return t('spreed', 'You can also set the path to the Matterbridge binary manually via the config. Check the {linkstart}Matterbridge integration documentation{linkend} for more information.')
				.replace('{linkstart}', '<a  target="_blank" rel="noreferrer nofollow" class="external" href="https://nextcloud-talk.readthedocs.io/en/latest/matterbridge/">')
				.replace(/{linkend}/g, ' ↗</a>')
		},
	},

	methods: {
		saveMatterbridgeEnabled() {
			OCP.AppConfig.setValue('spreed', 'enable_matterbridge', this.matterbridgeEnabled ? '1' : '0', {
				success: function() {
					if (!this.matterbridgeEnabled) {
						stopAllBridges()
					}
				}.bind(this),
			})
		},

		async enableMatterbridgeApp() {
			if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
				OC.PasswordConfirmation.requirePasswordConfirmation(this.enableMatterbridgeAppCallback, {}, () => {
					showError(t('spreed', 'An error occurred while installing the Matterbridge app.'))
				})
			}

			this.enableMatterbridgeAppCallback()
		},

		async enableMatterbridgeAppCallback() {
			this.isInstalling = true
			try {
				await enableMatterbridgeApp()
			} catch (e) {
				showError(t('spreed', 'An error occurred while installing the Talk Matterbridge. Please install it manually.'), {
					onClick: () => {
						window.open('https://apps.nextcloud.com/apps/talk_matterbridge', '_blank')
					},
				})
				return
			}

			try {
				const response = await getMatterbridgeVersion()
				this.matterbridgeVersion = response.data.ocs.data.version
				this.matterbridgeEnabled = true
				this.saveMatterbridgeEnabled()
				this.error = ''
			} catch (error) {
				console.error(error)
				showError(t('spreed', 'Failed to execute Matterbridge binary.'))
				if (error?.response?.data?.ocs?.data?.error) {
					this.error = error.response.data.ocs.data.error
				} else {
					this.error = 'binary'
				}
			}
			this.isInstalling = false
		},
	},
}
</script>

<style scoped lang="scss">
h2 {
	small {
		color: var(--color-warning);
		border: 1px solid var(--color-warning);
		border-radius: 16px;
		padding: 0 9px;
	}
}

p {
	display: block;
	align-items: center;

	.icon {
		width: 16px;
		height: 16px;
	}

	label {
		display: block;
		margin-right: 10px;
	}
}

</style>