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"
This commit is contained in:
Saúl Ibarra Corretgé
2024-10-30 14:27:47 +01:00
committed by Saúl Ibarra Corretgé
parent 2c96880985
commit 771f5af59d

View File

@@ -1,6 +1,6 @@
import { DOMParser } from '@xmldom/xmldom';
import { atob, btoa } from 'abab';
import { Platform } from 'react-native';
import { NativeModules, Platform } from 'react-native';
import BackgroundTimer from 'react-native-background-timer';
import { TextDecoder, TextEncoder } from 'text-encoding';
@@ -9,6 +9,8 @@ import 'react-native-url-polyfill/auto'; // Complete URL polyfill.
import Storage from './Storage';
const { AppInfo } = NativeModules;
/**
* Implements an absolute minimum of the common logic of
* {@code Document.querySelector} and {@code Element.querySelector}. Implements
@@ -254,25 +256,27 @@ function _visitNode(node, callback) {
//
// Required by:
// - lib-jitsi-meet/modules/browser/BrowserDetection.js
let userAgent = navigator.userAgent || '';
// react-native/version
const { name, version } = require('react-native/package.json');
let rn = name || 'react-native';
version && (rn += `/${version}`);
if (userAgent.indexOf(rn) === -1) {
userAgent = userAgent ? `${rn} ${userAgent}` : rn;
}
// React Native version
const { reactNativeVersion } = Platform.constants;
const rnVersion
= `react-native/${reactNativeVersion.major}.${reactNativeVersion.minor}.${reactNativeVersion.patch}`;
// (OS version)
const os = `(${Platform.OS} ${Platform.Version})`;
const os = `(${Platform.OS}/${Platform.Version})`;
if (userAgent.indexOf(os) === -1) {
userAgent = userAgent ? `${userAgent} ${os}` : os;
}
// SDK
const liteTxt = AppInfo.isLiteSDK ? '-lite' : '';
const sdkVersion = `JitsiMeetSDK/${AppInfo.sdkVersion}${liteTxt}`;
navigator.userAgent = userAgent;
const parts = [
navigator.userAgent ?? '',
sdkVersion,
os,
rnVersion
];
navigator.userAgent = parts.filter(Boolean).join(' ');
}
// WebRTC