android: fix deep-linking from web

Looks like custom-scheme links no longer work in all browsers. They do on
Firefox, but the don't in Chrome and other default browsers.

So, switch to intent links on Android:
https://developer.chrome.com/multidevice/android/intents

Example:
```
<a href="intent://meet.jit.si/test123#Intent;scheme=org.jitsi.meet;package=org.jitsi.meet;end">Open Jitsi Meet</a>
```
This commit is contained in:
Saúl Ibarra Corretgé 2019-01-30 13:16:50 +01:00 committed by Saúl Ibarra Corretgé
parent 6f57d58dd9
commit e729f0948c
4 changed files with 25 additions and 29 deletions

View File

@ -192,7 +192,12 @@ var interfaceConfig = {
/** /**
* Specify mobile app scheme for opening the app from the mobile browser. * Specify mobile app scheme for opening the app from the mobile browser.
*/ */
// APP_SCHEME: 'org.jitsi.meet' // APP_SCHEME: 'org.jitsi.meet',
/**
* Specify the Android app package name.
*/
// ANDROID_APP_PACKAGE: 'org.jitsi.meet'
}; };
/* eslint-enable no-unused-vars, no-var, max-len */ /* eslint-enable no-unused-vars, no-var, max-len */

View File

@ -41,7 +41,7 @@ const _URI_PATH_PATTERN = '([^?#]*)';
* *
* @type {string} * @type {string}
*/ */
export const URI_PROTOCOL_PATTERN = '([a-z][a-z0-9\\.\\+-]*:)'; export const URI_PROTOCOL_PATTERN = '^([a-z][a-z0-9\\.\\+-]*:)';
/** /**
* Excludes/removes certain characters from a specific room (name) which are * Excludes/removes certain characters from a specific room (name) which are
@ -71,7 +71,7 @@ function _fixRoom(room: ?string) {
* @returns {string} * @returns {string}
*/ */
function _fixURIStringScheme(uri: string) { function _fixURIStringScheme(uri: string) {
const regex = new RegExp(`^${URI_PROTOCOL_PATTERN}+`, 'gi'); const regex = new RegExp(`${URI_PROTOCOL_PATTERN}+`, 'gi');
const match: Array<string> | null = regex.exec(uri); const match: Array<string> | null = regex.exec(uri);
if (match) { if (match) {
@ -175,7 +175,7 @@ export function parseStandardURIString(str: string) {
str = str.replace(/\s/g, ''); str = str.replace(/\s/g, '');
// protocol // protocol
regex = new RegExp(`^${URI_PROTOCOL_PATTERN}`, 'gi'); regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
match = regex.exec(str); match = regex.exec(str);
if (match) { if (match) {
obj.protocol = match[1].toLowerCase(); obj.protocol = match[1].toLowerCase();

View File

@ -50,28 +50,12 @@ type Props = {
t: Function t: Function
}; };
/**
* The type of the React {@code Component} state of
* {@link DeepLinkingMobilePage}.
*/
type State = {
/**
* The URL to link to on the button for opening the mobile app.
*/
joinURL: string
};
/** /**
* React component representing mobile browser page. * React component representing mobile browser page.
* *
* @class DeepLinkingMobilePage * @class DeepLinkingMobilePage
*/ */
class DeepLinkingMobilePage extends Component<Props, State> { class DeepLinkingMobilePage extends Component<Props> {
state = {
joinURL: ''
};
/** /**
* Initializes a new {@code DeepLinkingMobilePage} instance. * Initializes a new {@code DeepLinkingMobilePage} instance.
* *
@ -81,10 +65,6 @@ class DeepLinkingMobilePage extends Component<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = {
joinURL: generateDeepLinkingURL()
};
// Bind event handlers so they are only bound once per instance. // Bind event handlers so they are only bound once per instance.
this._onDownloadApp = this._onDownloadApp.bind(this); this._onDownloadApp = this._onDownloadApp.bind(this);
this._onOpenApp = this._onOpenApp.bind(this); this._onOpenApp = this._onOpenApp.bind(this);
@ -147,7 +127,7 @@ class DeepLinkingMobilePage extends Component<Props, State> {
</a> </a>
<a <a
className = { `${_SNS}__href` } className = { `${_SNS}__href` }
href = { this.state.joinURL } href = { generateDeepLinkingURL() }
onClick = { this._onOpenApp } onClick = { this._onOpenApp }
rel = 'noopener noreferrer' rel = 'noopener noreferrer'
target = '_blank'> target = '_blank'>

View File

@ -42,12 +42,23 @@ export function generateDeepLinkingURL() {
// like to open the current URL in the mobile app. The only way to do it // 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 // appears to be a link with an app-specific scheme, not a Universal
// Link. // Link.
const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet'; const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
const { href } = window.location;
const regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
// Replace the protocol part with the app scheme. // 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
const url = href.replace(regex, '').substr(3);
const pkg = interfaceConfig.ANDROID_APP_PACKAGE || 'org.jitsi.meet';
return window.location.href.replace( return `intent://${url}/#Intent;scheme=${appScheme};package=${pkg};end`;
new RegExp(`^${URI_PROTOCOL_PATTERN}`), `${appScheme}:`); }
// iOS: Replace the protocol part with the app scheme.
return href.replace(regex, `${appScheme}:`);
} }
/** /**