Przeglądaj źródła

feat(rn) improve UA string

Add SDK version in addition to OS and RN versions.

Example: "JitsiMeetSDK/0.0.0 (android/34) react-native/0.75.4"
factor2
Saúl Ibarra Corretgé 7 miesięcy temu
rodzic
commit
771f5af59d
1 zmienionych plików z 19 dodań i 15 usunięć
  1. 19
    15
      react/features/mobile/polyfills/browser.js

+ 19
- 15
react/features/mobile/polyfills/browser.js Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 import { DOMParser } from '@xmldom/xmldom';
2 2
 import { atob, btoa } from 'abab';
3
-import { Platform } from 'react-native';
3
+import { NativeModules, Platform } from 'react-native';
4 4
 import BackgroundTimer from 'react-native-background-timer';
5 5
 import { TextDecoder, TextEncoder } from 'text-encoding';
6 6
 
@@ -9,6 +9,8 @@ import 'react-native-url-polyfill/auto'; // Complete URL polyfill.
9 9
 
10 10
 import Storage from './Storage';
11 11
 
12
+const { AppInfo } = NativeModules;
13
+
12 14
 /**
13 15
  * Implements an absolute minimum of the common logic of
14 16
  * {@code Document.querySelector} and {@code Element.querySelector}. Implements
@@ -254,25 +256,27 @@ function _visitNode(node, callback) {
254 256
         //
255 257
         // Required by:
256 258
         // - lib-jitsi-meet/modules/browser/BrowserDetection.js
257
-        let userAgent = navigator.userAgent || '';
258
-
259
-        // react-native/version
260
-        const { name, version } = require('react-native/package.json');
261
-        let rn = name || 'react-native';
262 259
 
263
-        version && (rn += `/${version}`);
264
-        if (userAgent.indexOf(rn) === -1) {
265
-            userAgent = userAgent ? `${rn} ${userAgent}` : rn;
266
-        }
260
+        // React Native version
261
+        const { reactNativeVersion } = Platform.constants;
262
+        const rnVersion
263
+            = `react-native/${reactNativeVersion.major}.${reactNativeVersion.minor}.${reactNativeVersion.patch}`;
267 264
 
268 265
         // (OS version)
269
-        const os = `(${Platform.OS} ${Platform.Version})`;
266
+        const os = `(${Platform.OS}/${Platform.Version})`;
270 267
 
271
-        if (userAgent.indexOf(os) === -1) {
272
-            userAgent = userAgent ? `${userAgent} ${os}` : os;
273
-        }
268
+        // SDK
269
+        const liteTxt = AppInfo.isLiteSDK ? '-lite' : '';
270
+        const sdkVersion = `JitsiMeetSDK/${AppInfo.sdkVersion}${liteTxt}`;
271
+
272
+        const parts = [
273
+            navigator.userAgent ?? '',
274
+            sdkVersion,
275
+            os,
276
+            rnVersion
277
+        ];
274 278
 
275
-        navigator.userAgent = userAgent;
279
+        navigator.userAgent = parts.filter(Boolean).join(' ');
276 280
     }
277 281
 
278 282
     // WebRTC

Ładowanie…
Anuluj
Zapisz