"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7555/react/features/base/environment/environment.ts" (28 Sep 2023, 3390 Bytes) of package /linux/misc/jitsi-meet-7555.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "environment.ts":
7547_vs_7550.
1 import JitsiMeetJS from '../lib-jitsi-meet';
2 import Platform from '../react/Platform';
3
4 import { isMobileBrowser } from './utils';
5
6 const { browser } = JitsiMeetJS.util;
7
8 const DEFAULT_OPTIMAL_BROWSERS = [
9 'chrome',
10 'electron',
11 'firefox',
12 'nwjs',
13 'safari'
14 ];
15
16 const DEFAULT_UNSUPPORTED_BROWSERS: string[] = [];
17
18 const browserNameToCheck = {
19 chrome: browser.isChrome.bind(browser),
20 chromium: browser.isChromiumBased.bind(browser),
21 electron: browser.isElectron.bind(browser),
22 firefox: browser.isFirefox.bind(browser),
23 safari: browser.isSafari.bind(browser),
24 webkit: browser.isWebKitBased.bind(browser)
25 };
26
27 /**
28 * Returns whether or not jitsi is optimized and targeted for the provided
29 * browser name.
30 *
31 * @param {string} browserName - The name of the browser to check.
32 * @returns {boolean}
33 */
34 export function isBrowsersOptimal(browserName: string) {
35 return (interfaceConfig.OPTIMAL_BROWSERS || DEFAULT_OPTIMAL_BROWSERS)
36 .includes(browserName);
37 }
38
39 /**
40 * Returns whether or not the current OS is Mac.
41 *
42 * @returns {boolean}
43 */
44 export function isMacOS() {
45 return Platform.OS === 'macos';
46 }
47
48 /**
49 * Returns whether or not the current OS is Windows.
50 *
51 * @returns {boolean}
52 */
53 export function isWindows() {
54 return Platform.OS === 'windows';
55 }
56
57 /**
58 * Returns whether or not the current browser or the list of passed in browsers
59 * is considered suboptimal. Suboptimal means it is a supported browser but has
60 * not been explicitly listed as being optimal, possibly due to functionality
61 * issues.
62 *
63 * @param {Array<string>} [browsers] - A list of browser names to check. Will
64 * default to a whitelist.
65 * @returns {boolean}
66 */
67 export function isSuboptimalBrowser() {
68 const optimalBrowsers
69 = interfaceConfig.OPTIMAL_BROWSERS || DEFAULT_OPTIMAL_BROWSERS;
70
71 return !_isCurrentBrowserInList(optimalBrowsers) && isSupportedBrowser();
72 }
73
74 /**
75 * Returns whether or not the current browser should allow the app to display.
76 * A supported browser is assumed to be able to support WebRtc.
77 *
78 * @returns {boolean}
79 */
80 export function isSupportedBrowser() {
81 if (navigator.product === 'ReactNative') {
82 return false;
83 }
84
85 // Blacklists apply to desktop browsers only right now.
86 if (!isMobileBrowser() && _isCurrentBrowserInList(
87 interfaceConfig.UNSUPPORTED_BROWSERS || DEFAULT_UNSUPPORTED_BROWSERS
88 )) {
89 return false;
90 }
91
92 return isMobileBrowser() ? isSupportedMobileBrowser() : JitsiMeetJS.isWebRtcSupported();
93 }
94
95 /**
96 * Returns whether or not the current environment is a supported
97 * browser on a mobile device.
98 *
99 * @returns {boolean}
100 */
101 export function isSupportedMobileBrowser() {
102 return (Platform.OS === 'android' && browser.isSupportedAndroidBrowser())
103 || (Platform.OS === 'ios' && browser.isSupportedIOSBrowser());
104 }
105
106 /**
107 * Runs various browser checks to know if the current browser is found within
108 * the list.
109 *
110 * @param {Array<string>} list - Browser names to check. The names should be
111 * keys in {@link browserNameToCheck}.
112 * @private
113 * @returns {boolean}
114 */
115 function _isCurrentBrowserInList(list: string[]) {
116 return Boolean(list.find(browserName => {
117 const checkFunction = browserNameToCheck[browserName as keyof typeof browserNameToCheck];
118
119 return checkFunction ? checkFunction.call(browser) : false;
120 }));
121 }