瀏覽代碼

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

+ 6
- 1
interface_config.js 查看文件

@@ -192,7 +192,12 @@ var interfaceConfig = {
192 192
     /**
193 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 203
 /* eslint-enable no-unused-vars, no-var, max-len */

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

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

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

@@ -50,28 +50,12 @@ type Props = {
50 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 54
  * React component representing mobile browser page.
67 55
  *
68 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 60
      * Initializes a new {@code DeepLinkingMobilePage} instance.
77 61
      *
@@ -81,10 +65,6 @@ class DeepLinkingMobilePage extends Component<Props, State> {
81 65
     constructor(props: Props) {
82 66
         super(props);
83 67
 
84
-        this.state = {
85
-            joinURL: generateDeepLinkingURL()
86
-        };
87
-
88 68
         // Bind event handlers so they are only bound once per instance.
89 69
         this._onDownloadApp = this._onDownloadApp.bind(this);
90 70
         this._onOpenApp = this._onOpenApp.bind(this);
@@ -147,7 +127,7 @@ class DeepLinkingMobilePage extends Component<Props, State> {
147 127
                     </a>
148 128
                     <a
149 129
                         className = { `${_SNS}__href` }
150
-                        href = { this.state.joinURL }
130
+                        href = { generateDeepLinkingURL() }
151 131
                         onClick = { this._onOpenApp }
152 132
                         rel = 'noopener noreferrer'
153 133
                         target = '_blank'>

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

@@ -42,12 +42,23 @@ export function generateDeepLinkingURL() {
42 42
     // like to open the current URL in the mobile app. The only way to do it
43 43
     // appears to be a link with an app-specific scheme, not a Universal
44 44
     // Link.
45
+
45 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…
取消
儲存