瀏覽代碼

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>
```
j8
Saúl Ibarra Corretgé 6 年之前
父節點
當前提交
e729f0948c

+ 6
- 1
interface_config.js 查看文件

192
     /**
192
     /**
193
      * Specify mobile app scheme for opening the app from the mobile browser.
193
      * Specify mobile app scheme for opening the app from the mobile browser.
194
      */
194
      */
195
-    // APP_SCHEME: 'org.jitsi.meet'
195
+    // APP_SCHEME: 'org.jitsi.meet',
196
+
197
+    /**
198
+     * Specify the Android app package name.
199
+     */
200
+    // ANDROID_APP_PACKAGE: 'org.jitsi.meet'
196
 };
201
 };
197
 
202
 
198
 /* eslint-enable no-unused-vars, no-var, max-len */
203
 /* eslint-enable no-unused-vars, no-var, max-len */

+ 3
- 3
react/features/base/util/uri.js 查看文件

41
  *
41
  *
42
  * @type {string}
42
  * @type {string}
43
  */
43
  */
44
-export const URI_PROTOCOL_PATTERN = '([a-z][a-z0-9\\.\\+-]*:)';
44
+export const URI_PROTOCOL_PATTERN = '^([a-z][a-z0-9\\.\\+-]*:)';
45
 
45
 
46
 /**
46
 /**
47
  * Excludes/removes certain characters from a specific room (name) which are
47
  * Excludes/removes certain characters from a specific room (name) which are
71
  * @returns {string}
71
  * @returns {string}
72
  */
72
  */
73
 function _fixURIStringScheme(uri: string) {
73
 function _fixURIStringScheme(uri: string) {
74
-    const regex = new RegExp(`^${URI_PROTOCOL_PATTERN}+`, 'gi');
74
+    const regex = new RegExp(`${URI_PROTOCOL_PATTERN}+`, 'gi');
75
     const match: Array<string> | null = regex.exec(uri);
75
     const match: Array<string> | null = regex.exec(uri);
76
 
76
 
77
     if (match) {
77
     if (match) {
175
     str = str.replace(/\s/g, '');
175
     str = str.replace(/\s/g, '');
176
 
176
 
177
     // protocol
177
     // protocol
178
-    regex = new RegExp(`^${URI_PROTOCOL_PATTERN}`, 'gi');
178
+    regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
179
     match = regex.exec(str);
179
     match = regex.exec(str);
180
     if (match) {
180
     if (match) {
181
         obj.protocol = match[1].toLowerCase();
181
         obj.protocol = match[1].toLowerCase();

+ 2
- 22
react/features/deep-linking/components/DeepLinkingMobilePage.web.js 查看文件

50
     t: Function
50
     t: Function
51
 };
51
 };
52
 
52
 
53
-/**
54
- * The type of the React {@code Component} state of
55
- * {@link DeepLinkingMobilePage}.
56
- */
57
-type State = {
58
-
59
-    /**
60
-     * The URL to link to on the button for opening the mobile app.
61
-     */
62
-    joinURL: string
63
-};
64
-
65
 /**
53
 /**
66
  * React component representing mobile browser page.
54
  * React component representing mobile browser page.
67
  *
55
  *
68
  * @class DeepLinkingMobilePage
56
  * @class DeepLinkingMobilePage
69
  */
57
  */
70
-class DeepLinkingMobilePage extends Component<Props, State> {
71
-    state = {
72
-        joinURL: ''
73
-    };
74
-
58
+class DeepLinkingMobilePage extends Component<Props> {
75
     /**
59
     /**
76
      * Initializes a new {@code DeepLinkingMobilePage} instance.
60
      * Initializes a new {@code DeepLinkingMobilePage} instance.
77
      *
61
      *
81
     constructor(props: Props) {
65
     constructor(props: Props) {
82
         super(props);
66
         super(props);
83
 
67
 
84
-        this.state = {
85
-            joinURL: generateDeepLinkingURL()
86
-        };
87
-
88
         // Bind event handlers so they are only bound once per instance.
68
         // Bind event handlers so they are only bound once per instance.
89
         this._onDownloadApp = this._onDownloadApp.bind(this);
69
         this._onDownloadApp = this._onDownloadApp.bind(this);
90
         this._onOpenApp = this._onOpenApp.bind(this);
70
         this._onOpenApp = this._onOpenApp.bind(this);
147
                     </a>
127
                     </a>
148
                     <a
128
                     <a
149
                         className = { `${_SNS}__href` }
129
                         className = { `${_SNS}__href` }
150
-                        href = { this.state.joinURL }
130
+                        href = { generateDeepLinkingURL() }
151
                         onClick = { this._onOpenApp }
131
                         onClick = { this._onOpenApp }
152
                         rel = 'noopener noreferrer'
132
                         rel = 'noopener noreferrer'
153
                         target = '_blank'>
133
                         target = '_blank'>

+ 14
- 3
react/features/deep-linking/functions.js 查看文件

42
     // like to open the current URL in the mobile app. The only way to do it
42
     // like to open the current URL in the mobile app. The only way to do it
43
     // appears to be a link with an app-specific scheme, not a Universal
43
     // appears to be a link with an app-specific scheme, not a Universal
44
     // Link.
44
     // Link.
45
+
45
     const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
46
     const appScheme = interfaceConfig.APP_SCHEME || 'org.jitsi.meet';
47
+    const { href } = window.location;
48
+    const regex = new RegExp(URI_PROTOCOL_PATTERN, 'gi');
49
+
50
+    // Android: use an intent link, custom schemes don't work in all browsers.
51
+    // https://developer.chrome.com/multidevice/android/intents
52
+    if (Platform.OS === 'android') {
53
+        // https://meet.jit.si/foo -> meet.jit.si/foo
54
+        const url = href.replace(regex, '').substr(3);
55
+        const pkg = interfaceConfig.ANDROID_APP_PACKAGE || 'org.jitsi.meet';
46
 
56
 
47
-    // Replace the protocol part with the app scheme.
57
+        return `intent://${url}/#Intent;scheme=${appScheme};package=${pkg};end`;
58
+    }
48
 
59
 
49
-    return window.location.href.replace(
50
-            new RegExp(`^${URI_PROTOCOL_PATTERN}`), `${appScheme}:`);
60
+    // iOS: Replace the protocol part with the app scheme.
61
+    return href.replace(regex, `${appScheme}:`);
51
 }
62
 }
52
 
63
 
53
 /**
64
 /**

Loading…
取消
儲存