Skip to content

Commit 7d47b43

Browse files
Merge pull request #11009 from nextcloud/refactor/browser-detection
refactor: make browserCheck an util instead of mixin
2 parents 1fecac7 + 23a6ef1 commit 7d47b43

File tree

7 files changed

+100
-154
lines changed

7 files changed

+100
-154
lines changed

src/App.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ import SettingsDialog from './components/SettingsDialog/SettingsDialog.vue'
5757
import { useActiveSession } from './composables/useActiveSession.js'
5858
import { useIsInCall } from './composables/useIsInCall.js'
5959
import { CONVERSATION, PARTICIPANT } from './constants.js'
60-
import browserCheck from './mixins/browserCheck.js'
6160
import participant from './mixins/participant.js'
6261
import sessionIssueHandler from './mixins/sessionIssueHandler.js'
6362
import talkHashCheck from './mixins/talkHashCheck.js'
6463
import Router from './router/router.js'
6564
import BrowserStorage from './services/BrowserStorage.js'
6665
import { EventBus } from './services/EventBus.js'
6766
import { leaveConversationSync } from './services/participantsService.js'
67+
import { checkBrowser } from './utils/browserCheck.js'
6868
import { signalingKill } from './utils/webrtc/index.js'
6969

7070
export default {
@@ -81,7 +81,6 @@ export default {
8181
},
8282

8383
mixins: [
84-
browserCheck,
8584
talkHashCheck,
8685
sessionIssueHandler,
8786
participant,
@@ -474,8 +473,7 @@ export default {
474473

475474
async mounted() {
476475
if (!IS_DESKTOP) {
477-
// see browserCheck mixin
478-
this.checkBrowser()
476+
checkBrowser()
479477
}
480478
// Check sidebar status in previous sessions
481479
if (BrowserStorage.getItem('sidebarOpen') === 'false') {

src/FilesSidebarTabApp.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
5252

5353
import LoadingComponent from './components/LoadingComponent.vue'
5454

55-
import browserCheck from './mixins/browserCheck.js'
5655
import sessionIssueHandler from './mixins/sessionIssueHandler.js'
5756
import { EventBus } from './services/EventBus.js'
5857
import { getFileConversation } from './services/filesIntegrationServices.js'
5958
import {
6059
leaveConversationSync,
6160
} from './services/participantsService.js'
61+
import { checkBrowser } from './utils/browserCheck.js'
6262
import CancelableRequest from './utils/cancelableRequest.js'
6363
import { signalingKill } from './utils/webrtc/index.js'
6464

@@ -77,7 +77,6 @@ export default {
7777
},
7878

7979
mixins: [
80-
browserCheck,
8180
sessionIssueHandler,
8281
],
8382

@@ -171,8 +170,7 @@ export default {
171170

172171
methods: {
173172
async joinConversation() {
174-
// see browserCheck mixin
175-
this.checkBrowser()
173+
checkBrowser()
176174

177175
try {
178176
await this.getFileConversation()

src/PublicShareAuthRequestPasswordButton.vue

+2-7
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<script>
4242
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
4343

44-
import browserCheck from './mixins/browserCheck.js'
4544
import { getPublicShareAuthConversationToken } from './services/publicShareAuthService.js'
45+
import { checkBrowser } from './utils/browserCheck.js'
4646

4747
export default {
4848

@@ -52,10 +52,6 @@ export default {
5252
NcButton,
5353
},
5454

55-
mixins: [
56-
browserCheck,
57-
],
58-
5955
props: {
6056
shareToken: {
6157
type: String,
@@ -89,8 +85,7 @@ export default {
8985

9086
methods: {
9187
async requestPassword() {
92-
// see browserCheck mixin
93-
this.checkBrowser()
88+
checkBrowser()
9489

9590
this.hasRequestFailed = false
9691
this.isRequestLoading = true

src/PublicShareSidebar.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import TopBar from './components/TopBar/TopBar.vue'
6868
import TransitionWrapper from './components/TransitionWrapper.vue'
6969

7070
import { useIsInCall } from './composables/useIsInCall.js'
71-
import browserCheck from './mixins/browserCheck.js'
7271
import participant from './mixins/participant.js'
7372
import sessionIssueHandler from './mixins/sessionIssueHandler.js'
7473
import talkHashCheck from './mixins/talkHashCheck.js'
@@ -77,6 +76,7 @@ import { getPublicShareConversationData } from './services/filesIntegrationServi
7776
import {
7877
leaveConversationSync,
7978
} from './services/participantsService.js'
79+
import { checkBrowser } from './utils/browserCheck.js'
8080
import { signalingKill } from './utils/webrtc/index.js'
8181

8282
export default {
@@ -95,7 +95,6 @@ export default {
9595
},
9696

9797
mixins: [
98-
browserCheck,
9998
sessionIssueHandler,
10099
participant,
101100
talkHashCheck,
@@ -160,8 +159,7 @@ export default {
160159
methods: {
161160

162161
async joinConversation() {
163-
// see browserCheck mixin
164-
this.checkBrowser()
162+
checkBrowser()
165163

166164
this.joiningConversation = true
167165

src/components/TopBar/CallButton.vue

+12-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip.js'
112112

113113
import { useIsInCall } from '../../composables/useIsInCall.js'
114114
import { ATTENDEE, CALL, CONVERSATION, PARTICIPANT } from '../../constants.js'
115-
import browserCheck from '../../mixins/browserCheck.js'
116115
import isInLobby from '../../mixins/isInLobby.js'
117116
import participant from '../../mixins/participant.js'
118117
import { callSIPDialOut } from '../../services/callsService.js'
119118
import { EventBus } from '../../services/EventBus.js'
120119
import { useSettingsStore } from '../../stores/settings.js'
120+
import { blockCalls, unsupportedWarning } from '../../utils/browserCheck.js'
121121

122122
export default {
123123
name: 'CallButton',
@@ -140,7 +140,6 @@ export default {
140140
},
141141

142142
mixins: [
143-
browserCheck,
144143
isInLobby,
145144
participant,
146145
],
@@ -310,7 +309,17 @@ export default {
310309

311310
isPhoneRoom() {
312311
return this.conversation.objectType === CONVERSATION.OBJECT_TYPE.PHONE
313-
}
312+
},
313+
314+
callButtonTooltipText() {
315+
if (blockCalls) {
316+
return unsupportedWarning
317+
} else {
318+
// Passing a falsy value into the content of the tooltip
319+
// is the only way to disable it conditionally.
320+
return false
321+
}
322+
},
314323
},
315324

316325
mounted() {

src/mixins/browserCheck.js

-132
This file was deleted.

src/utils/browserCheck.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @copyright Copyright (c) 2019 Marco Ambrosini <[email protected]>
3+
*
4+
* @author Marco Ambrosini <[email protected]>
5+
* @author Grigorii K. Shartsev <[email protected]>
6+
*
7+
* @license AGPL-3.0-or-later
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
import UAParser from 'ua-parser-js'
25+
26+
import { showError, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'
27+
import { translate as t } from '@nextcloud/l10n'
28+
29+
const parser = new UAParser()
30+
const browser = parser.getBrowser()
31+
32+
/**
33+
* Per-browser flags and a major version
34+
*/
35+
36+
export const isFirefox = browser.name === 'Firefox'
37+
export const isChrome = browser.name === 'Chrome' || browser.name === 'Chromium'
38+
export const isOpera = browser.name === 'Opera'
39+
export const isSafari = browser.name === 'Safari' || browser.name === 'Mobile Safari'
40+
export const isEdge = browser.name === 'Edge'
41+
export const isBrave = browser.name === 'Brave'
42+
export const isIE = browser.name === 'IE' || browser.name === 'IEMobile'
43+
export const isYandex = browser.name === 'Yandex'
44+
45+
export const majorVersion = browser.version ? parseInt(browser.version.split('.')[0], 10) : 0
46+
47+
/**
48+
* Is the browser fully supported by Talk
49+
*/
50+
export const isFullySupported = (isFirefox && majorVersion >= 52)
51+
|| (isChrome && majorVersion >= 49)
52+
|| (isOpera && majorVersion >= 72)
53+
|| (isSafari && majorVersion >= 12)
54+
|| isEdge
55+
|| isBrave
56+
|| isYandex
57+
58+
/**
59+
* Are calls should be blocked due to browser incompatibility
60+
*/
61+
export const blockCalls = (isFirefox && majorVersion < 52)
62+
|| (isChrome && majorVersion < 49)
63+
|| (isOpera && majorVersion < 72)
64+
|| (isSafari && majorVersion < 12)
65+
|| isIE
66+
67+
/**
68+
* Reusable error message for unsupported browsers
69+
*/
70+
export const unsupportedWarning = 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.")
71+
72+
/**
73+
* Show an error toast if the browser is not fully supported
74+
*/
75+
export function checkBrowser() {
76+
console.info('Detected browser ' + browser.name + ' ' + majorVersion + ' (' + browser.version + ')')
77+
if (!isFullySupported) {
78+
showError(unsupportedWarning, { timeout: TOAST_PERMANENT_TIMEOUT })
79+
}
80+
}

0 commit comments

Comments
 (0)