2018-04-14 00:00:40 +00:00
|
|
|
/* global interfaceConfig */
|
|
|
|
|
2020-01-29 12:30:17 +00:00
|
|
|
import { isMobileBrowser } from '../base/environment/utils';
|
2018-04-14 00:00:40 +00:00
|
|
|
import { Platform } from '../base/react';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { URI_PROTOCOL_PATTERN } from '../base/util';
|
2021-07-20 08:58:42 +00:00
|
|
|
import { isVpaasMeeting } from '../jaas/functions';
|
2018-04-14 00:00:40 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
DeepLinkingDesktopPage,
|
|
|
|
DeepLinkingMobilePage,
|
|
|
|
NoMobileApp
|
|
|
|
} from './components';
|
2019-05-24 14:38:07 +00:00
|
|
|
import { _openDesktopApp } from './openDesktopApp';
|
2018-06-17 02:28:03 +00:00
|
|
|
|
2018-04-14 00:00:40 +00:00
|
|
|
/**
|
|
|
|
* Generates a deep linking URL based on the current window URL.
|
|
|
|
*
|
|
|
|
* @returns {string} - The generated URL.
|
|
|
|
*/
|
|
|
|
export function generateDeepLinkingURL() {
|
|
|
|
// If the user installed the app while this Component was displayed
|
|
|
|
// (e.g. the user clicked the Download the App button), then we would
|
|
|
|
// like to open the current URL in the mobile app. The only way to do it
|
|
|
|
// appears to be a link with an app-specific scheme, not a Universal
|
|
|
|
// Link.
|
2019-01-30 12:16:50 +00:00
|
|
|
|
2018-04-14 00:00:40 +00:00
|
|
|
const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
|
2019-01-30 12:16:50 +00:00
|
|
|
const { href } = window.location;
|
2019-02-06 12:52:03 +00:00
|
|
|
const regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
|
2019-01-30 12:16:50 +00:00
|
|
|
|
|
|
|
// Android: use an intent link, custom schemes don't work in all browsers.
|
|
|
|
// https://developer.chrome.com/multidevice/android/intents
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
// https://meet.jit.si/foo -> meet.jit.si/foo
|
2019-02-01 13:55:43 +00:00
|
|
|
const url = href.replace(regex, '').substr(2);
|
2019-01-30 12:16:50 +00:00
|
|
|
const pkg = interfaceConfig.ANDROID_APP_PACKAGE || 'org.jitsi.meet';
|
2018-04-14 00:00:40 +00:00
|
|
|
|
2019-02-02 10:09:33 +00:00
|
|
|
return `intent://${url}#Intent;scheme=${appScheme};package=${pkg};end`;
|
2019-01-30 12:16:50 +00:00
|
|
|
}
|
2018-04-14 00:00:40 +00:00
|
|
|
|
2019-01-30 12:16:50 +00:00
|
|
|
// iOS: Replace the protocol part with the app scheme.
|
|
|
|
return href.replace(regex, `${appScheme}:`);
|
2018-04-14 00:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves with the component that should be displayed if the deep linking page
|
|
|
|
* should be shown and with <tt>undefined</tt> otherwise.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Object containing current redux state.
|
|
|
|
* @returns {Promise<Component>}
|
|
|
|
*/
|
|
|
|
export function getDeepLinkingPage(state) {
|
|
|
|
const { room } = state['features/base/conference'];
|
2020-05-19 23:11:32 +00:00
|
|
|
const { launchInWeb } = state['features/deep-linking'];
|
2021-06-09 12:41:48 +00:00
|
|
|
const appScheme = typeof interfaceConfig !== 'undefined' && interfaceConfig.APP_SCHEME;
|
2018-04-14 00:00:40 +00:00
|
|
|
|
|
|
|
// Show only if we are about to join a conference.
|
2021-06-09 12:41:48 +00:00
|
|
|
if (launchInWeb
|
|
|
|
|| !room
|
|
|
|
|| state['features/base/config'].disableDeepLinking
|
2021-07-16 13:46:07 +00:00
|
|
|
|| (isVpaasMeeting(state) && (!appScheme || appScheme === 'com.8x8.meet'))) {
|
2018-04-14 00:00:40 +00:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2020-01-29 12:30:17 +00:00
|
|
|
if (isMobileBrowser()) { // mobile
|
2018-04-14 00:00:40 +00:00
|
|
|
const mobileAppPromo
|
|
|
|
= typeof interfaceConfig === 'object'
|
|
|
|
&& interfaceConfig.MOBILE_APP_PROMO;
|
|
|
|
|
|
|
|
return Promise.resolve(
|
|
|
|
typeof mobileAppPromo === 'undefined' || Boolean(mobileAppPromo)
|
|
|
|
? DeepLinkingMobilePage : NoMobileApp);
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:06:52 +00:00
|
|
|
return _openDesktopApp(state).then(
|
2018-04-14 00:00:40 +00:00
|
|
|
// eslint-disable-next-line no-confusing-arrow
|
2019-05-24 14:38:07 +00:00
|
|
|
result => result ? DeepLinkingDesktopPage : undefined);
|
2018-04-14 00:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the desktop app.
|
|
|
|
*
|
2019-06-07 13:06:52 +00:00
|
|
|
* @param {Object} state - Object containing current redux state.
|
2019-05-24 14:38:07 +00:00
|
|
|
* @returns {Promise<boolean>} - Resolves with true if the attempt to open the desktop app was successful and resolves
|
|
|
|
* with false otherwise.
|
2018-04-14 00:00:40 +00:00
|
|
|
*/
|
2019-06-07 13:06:52 +00:00
|
|
|
export function openDesktopApp(state) {
|
|
|
|
return _openDesktopApp(state);
|
2018-04-14 00:00:40 +00:00
|
|
|
}
|