summaryrefslogtreecommitdiffstats
path: root/src/mixins/browserCheck.js
blob: c7370ee90d4fa361b1fa08d5427f4018941b6234 (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
/**
 * @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@icloud.com>
 *
 * @author Marco Ambrosini <marcoambrosini@icloud.com>
 *
 * @license AGPL-3.0-or-later
 *
 * 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/>.
 *
 */

import UAParser from 'ua-parser-js'

import { showError, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'

const browserCheck = {
	methods: {
		checkBrowser() {
			console.info('Detected browser ' + this.browser.name + ' ' + this.majorVersion + ' (' + this.browser.version + ')')
			if (!this.isFullySupported) {
				showError(
					this.unsupportedWarning,
					{
						timeout: TOAST_PERMANENT_TIMEOUT,
					})
			}
		},
	},
	computed: {
		parser() {
			return new UAParser()
		},

		browser() {
			return this.parser.getBrowser()
		},

		isFirefox() {
			return this.browser.name === 'Firefox'
		},
		isChrome() {
			return this.browser.name === 'Chrome' || this.browser.name === 'Chromium'
		},
		isOpera() {
			return this.browser.name === 'Opera'
		},
		isSafari() {
			return this.browser.name === 'Safari' || this.browser.name === 'Mobile Safari'
		},
		isEdge() {
			return this.browser.name === 'Edge'
		},
		isBrave() {
			return this.browser.name === 'Brave'
		},
		isIE() {
			return this.browser.name === 'IE' || this.browser.name === 'IEMobile'
		},
		isYandex() {
			return this.browser.name === 'Yandex'
		},
		browserVersion() {
			if (this.browser.version) {
				return this.browser.version
			}

			if (this.browser.name === 'Safari') {
				// Workaround for https://github.com/faisalman/ua-parser-js/issues/599
				const match = this.parser.getUA().match(' Version/([0-9.,]+) ')
				if (match) {
					return match[1]
				}
			}

			return undefined
		},

		majorVersion() {
			if (this.browserVersion) {
				return parseInt(this.browserVersion.split('.')[0], 10)
			}

			return 0
		},

		isFullySupported() {
			return (this.isFirefox && this.majorVersion >= 52)
			|| (this.isChrome && this.majorVersion >= 49)
			|| (this.isOpera && this.majorVersion >= 72)
			|| (this.isSafari && this.majorVersion >= 12)
			|| this.isEdge
			|| this.isBrave
			|| this.isYandex
		},
		// Disable the call button and show the tooltip
		blockCalls() {
			return (this.isFirefox && this.majorVersion < 52)
			|| (this.isChrome && this.majorVersion < 49)
			|| (this.isOpera && this.majorVersion < 72)
			|| (this.isSafari && this.majorVersion < 12)
			|| this.isIE
		},
		// Used both in the toast and in the call button tooltip
		unsupportedWarning() {
			return t('spreed', "The browser you're using is not fully supported by Nextcloud Talk. Please use the latest version of Mozilla Firefox, Microsoft Edge, Google Chrome, Opera or Apple Safari.")
		},
		// Used in CallButton.vue
		callButtonTooltipText() {
			if (this.blockCalls) {
				return this.unsupportedWarning
			} else {
				// Passing a falsy value into the content of the tooltip
				// is the only way to disable it conditionally.
				return false
			}
		},

	},
}

export default browserCheck