From 086f95a50c04285726ddd2a87a338f987ae192be Mon Sep 17 00:00:00 2001 From: "Eswar Prasad Clinton. A" <64120992+eswarclynn@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:58:17 +0530 Subject: [PATCH] Revert "fix: upgrade ua-parser-js to track correct mac os version" This reverts commit 8f6896c1aa9843bc625f77e38c2bcf60d04ba636. --- packages/hms-video-store/package.json | 3 ++- .../hms-video-store/src/analytics/AnalyticsEvent.ts | 4 ++-- .../src/analytics/HTTPAnalyticsTransport.ts | 13 +++++-------- packages/hms-video-store/src/sdk/index.ts | 8 ++++---- packages/hms-video-store/src/sdk/store/Store.ts | 6 +++--- .../hms-video-store/src/signal/init/init.test.ts | 8 ++++---- packages/hms-video-store/src/transport/index.ts | 12 ++---------- packages/hms-video-store/src/utils/support.ts | 2 +- packages/hms-video-store/src/utils/user-agent.ts | 12 ++++-------- .../roomkit-react/src/Prebuilt/common/constants.ts | 9 ++++----- yarn.lock | 13 +++++++++---- 11 files changed, 40 insertions(+), 50 deletions(-) diff --git a/packages/hms-video-store/package.json b/packages/hms-video-store/package.json index 86dbeb3f86..b094248bd6 100644 --- a/packages/hms-video-store/package.json +++ b/packages/hms-video-store/package.json @@ -51,7 +51,7 @@ "lodash.isequal": "^4.5.0", "reselect": "4.0.0", "sdp-transform": "^2.14.1", - "ua-parser-js": "^2.0.0-beta.2", + "ua-parser-js": "^1.0.1", "uuid": "^8.3.2", "webrtc-adapter": "^8.0.0", "zustand": "3.5.7" @@ -60,6 +60,7 @@ "@types/dom-screen-wake-lock": "^1.0.1", "@types/lodash.isequal": "^4.5.8", "@types/sdp-transform": "^2.4.4", + "@types/ua-parser-js": "^0.7.36", "@types/uuid": "^8.3.0", "jest-canvas-mock": "^2.3.1", "jsdom-worker": "^0.3.0", diff --git a/packages/hms-video-store/src/analytics/AnalyticsEvent.ts b/packages/hms-video-store/src/analytics/AnalyticsEvent.ts index ddf1aa722a..c31174b846 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEvent.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEvent.ts @@ -38,9 +38,10 @@ export default class AnalyticsEvent implements ISignalParamsProvider (this.metadata.userAgent = userAgent)); } toSignalParams() { diff --git a/packages/hms-video-store/src/analytics/HTTPAnalyticsTransport.ts b/packages/hms-video-store/src/analytics/HTTPAnalyticsTransport.ts index 5f2059b0a3..e53d020775 100644 --- a/packages/hms-video-store/src/analytics/HTTPAnalyticsTransport.ts +++ b/packages/hms-video-store/src/analytics/HTTPAnalyticsTransport.ts @@ -66,16 +66,13 @@ class ClientAnalyticsTransport implements IAnalyticsTransportProvider { }, }; const url = this.env === ENV.PROD ? CLIENT_ANAYLTICS_PROD_ENDPOINT : CLIENT_ANAYLTICS_QA_ENDPOINT; - const headers = new Headers({ - 'Content-Type': 'application/json', - Authorization: `Bearer ${event.metadata.token}`, - }); - if (event.metadata.userAgent) { - headers.set('user_agent_v2', event.metadata.userAgent); - } fetch(url, { method: 'POST', - headers, + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${event.metadata.token}`, + user_agent_v2: event.metadata.userAgent, + }, body: JSON.stringify(requestBody), }) .then(response => { diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index 526e349d18..f5c263a5d4 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -361,7 +361,7 @@ export class HMSSdk implements HMSInterface { } this.analyticsTimer.start(TimedEvent.PREVIEW); - await this.setUpPreview(config, listener); + this.setUpPreview(config, listener); // Request permissions and populate devices before waiting for policy if (config.alwaysRequestPermissions) { @@ -517,7 +517,7 @@ export class HMSSdk implements HMSInterface { this.removeDevicesFromConfig(config); this.store.setConfig(config); /** set after config since we need config to get env for user agent */ - await this.store.createAndSetUserAgent(this.frameworkInfo); + this.store.createAndSetUserAgent(this.frameworkInfo); HMSAudioContextHandler.resumeContext(); // acquire screen lock to stay awake while in call const storeConfig = this.store.getConfig(); @@ -1239,7 +1239,7 @@ export class HMSSdk implements HMSInterface { * @param {HMSConfig} config * @param {HMSPreviewListener} listener */ - private async setUpPreview(config: HMSPreviewConfig, listener: HMSPreviewListener) { + private setUpPreview(config: HMSPreviewConfig, listener: HMSPreviewListener) { this.listener = listener as unknown as HMSUpdateListener; this.sdkState.isPreviewCalled = true; this.sdkState.isPreviewInProgress = true; @@ -1247,7 +1247,7 @@ export class HMSSdk implements HMSInterface { this.commonSetup(config, roomId, listener); this.store.setConfig(config); /** set after config since we need config to get env for user agent */ - await this.store.createAndSetUserAgent(this.frameworkInfo); + this.store.createAndSetUserAgent(this.frameworkInfo); this.createAndAddLocalPeerToStore(config, role, userId, config.asRole); } diff --git a/packages/hms-video-store/src/sdk/store/Store.ts b/packages/hms-video-store/src/sdk/store/Store.ts index aea6fb4393..88d98da715 100644 --- a/packages/hms-video-store/src/sdk/store/Store.ts +++ b/packages/hms-video-store/src/sdk/store/Store.ts @@ -47,7 +47,7 @@ class Store { private roleDetailsArrived = false; private env: ENV = ENV.PROD; private simulcastEnabled = false; - private userAgent?: string; + private userAgent: string = createUserAgent(this.env); private polls = new Map(); private whiteboards = new Map(); @@ -188,8 +188,8 @@ class Store { return this.userAgent; } - async createAndSetUserAgent(frameworkInfo?: HMSFrameworkInfo) { - this.userAgent = await createUserAgent(this.env, frameworkInfo); + createAndSetUserAgent(frameworkInfo?: HMSFrameworkInfo) { + this.userAgent = createUserAgent(this.env, frameworkInfo); } setRoom(room: HMSRoom) { diff --git a/packages/hms-video-store/src/signal/init/init.test.ts b/packages/hms-video-store/src/signal/init/init.test.ts index 359c4ae666..a987765d47 100644 --- a/packages/hms-video-store/src/signal/init/init.test.ts +++ b/packages/hms-video-store/src/signal/init/init.test.ts @@ -3,8 +3,8 @@ import { HMSException } from '../../error/HMSException'; import { ENV } from '../../utils/support'; import { createUserAgent } from '../../utils/user-agent'; -describe('getUrl', async () => { - const userAgent = await createUserAgent(ENV.PROD); +describe('getUrl', () => { + const userAgent = createUserAgent(ENV.PROD); const userAgentQueryParam = new URLSearchParams(`user_agent_v2=${userAgent}`).toString(); const peerId = '1234'; it('should return the URL even if unnecesary params are passed to the endpoint', () => { @@ -67,7 +67,7 @@ describe('transformInit', () => { }); }); -describe('init API call', async () => { +describe('init API call', () => { const peerId = '2e26acc7-d2c8-4235-883e-812695ff1e7d'; const correctToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2Nlc3Nfa2V5IjoiNjEwY2Q5Y2JmMzBlNzczZjQ3NTc3YjBkIiwicm9vbV9pZCI6IjYxOGU5NGY1YWYzMTg4ZGYzM2U2N2Q0NiIsInVzZXJfaWQiOiJiZTM5MzQwZC04ZDgzLTQ5ZjQtOTNhMy00ZjRmMTgwZTVkZWUiLCJyb2xlIjoiaG9zdCIsImp0aSI6IjY0ZTRjMTgzLWZkNTktNGE2OS1hOGY2LWNkNGE5MzBmOTYzZSIsInR5cGUiOiJhcHAiLCJ2ZXJzaW9uIjoyLCJleHAiOjE2NTIyNjUyNzV9.t1Wvwl0tXyMzi386LwfDACvUeWibZYIzSf20DTwjqJU'; @@ -76,7 +76,7 @@ describe('init API call', async () => { const wrongToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2Nlc3Nfa2V5IjoiNjEwY2Q5Y2JmMzBlNzczZjQ3NTc3YjBkIiwicm9vbV9pZCI6IjYxOGU5NGY1YWYzMTg4ZGYzM2U2N2Q0NyIsInVzZXJfaWQiOiJiZTM5MzQwZC04ZDgzLTQ5ZjQtOTNhMy00ZjRmMTgwZTVkZWUiLCJyb2xlIjoiaG9zdCIsImp0aSI6IjY0ZTRjMTgzLWZkNTktNGE2OS1hOGY2LWNkNGE5MzBmOTYzZSIsInR5cGUiOiJhcHAiLCJ2ZXJzaW9uIjoyLCJleHAiOjE2NTIyNjUyNzV9.tX4BZllTjOuA5L3bgItoDYKQa6J3d-L2cayvQiEntHY'; - const userAgent = await createUserAgent(ENV.PROD); + const userAgent = createUserAgent(ENV.PROD); const mockResponse = (init: RequestInit | undefined): Promise => { const headers = init?.headers as Record; diff --git a/packages/hms-video-store/src/transport/index.ts b/packages/hms-video-store/src/transport/index.ts index 6646bcb1d3..fc6a168e99 100644 --- a/packages/hms-video-store/src/transport/index.ts +++ b/packages/hms-video-store/src/transport/index.ts @@ -896,15 +896,11 @@ export default class HMSTransport { HMSLogger.d(TAG, 'connect: started ⏰'); const connectRequestedAt = new Date(); try { - const userAgent = this.store.getUserAgent(); - if (!userAgent) { - throw ErrorFactory.GenericErrors.PeerMetadataMissing(HMSAction.INIT, 'User Agent not available'); - } this.analyticsTimer.start(TimedEvent.INIT); this.initConfig = await InitService.fetchInitConfig({ token, peerId, - userAgent, + userAgent: this.store.getUserAgent(), initEndpoint, }); const room = this.store.getRoom(); @@ -955,16 +951,12 @@ export default class HMSTransport { if (!this.initConfig) { throw ErrorFactory.APIErrors.InitConfigNotAvailable(HMSAction.INIT, 'Init Config not found'); } - const userAgent = this.store.getUserAgent(); - if (!userAgent) { - throw ErrorFactory.GenericErrors.PeerMetadataMissing(HMSAction.INIT, 'User Agent not available'); - } HMSLogger.d(TAG, '⏳ internal connect: connecting to ws endpoint', this.initConfig.endpoint); const url = new URL(this.initConfig.endpoint); url.searchParams.set('peer', peerId); url.searchParams.set('token', token); - url.searchParams.set('user_agent_v2', userAgent); + url.searchParams.set('user_agent_v2', this.store.getUserAgent()); url.searchParams.set('protocol_version', PROTOCOL_VERSION); url.searchParams.set('protocol_spec', PROTOCOL_SPEC); diff --git a/packages/hms-video-store/src/utils/support.ts b/packages/hms-video-store/src/utils/support.ts index a0badd0de4..1c48e94f73 100644 --- a/packages/hms-video-store/src/utils/support.ts +++ b/packages/hms-video-store/src/utils/support.ts @@ -29,4 +29,4 @@ export const isPageHidden = () => typeof document !== 'undefined' && document.hi export const isIOS = () => parsedUserAgent.getOS().name?.toLowerCase() === 'ios'; -export const isFirefox = parsedUserAgent.getBrowser()?.name?.toLowerCase().includes('firefox'); +export const isFirefox = parsedUserAgent.getBrowser()?.name?.toLowerCase() === 'firefox'; diff --git a/packages/hms-video-store/src/utils/user-agent.ts b/packages/hms-video-store/src/utils/user-agent.ts index 210fa08ca0..335d6c4ffc 100644 --- a/packages/hms-video-store/src/utils/user-agent.ts +++ b/packages/hms-video-store/src/utils/user-agent.ts @@ -20,7 +20,7 @@ type UserAgent = { framework_sdk_version?: HMSFrameworkInfo['sdkVersion']; }; -export async function createUserAgent(sdkEnv: ENV = ENV.PROD, frameworkInfo?: HMSFrameworkInfo) { +export function createUserAgent(sdkEnv: ENV = ENV.PROD, frameworkInfo?: HMSFrameworkInfo): string { const sdk = 'web'; const env = domainCategory !== DomainCategory.LOCAL && sdkEnv === ENV.PROD ? 'prod' : 'debug'; @@ -39,13 +39,9 @@ export async function createUserAgent(sdkEnv: ENV = ENV.PROD, frameworkInfo?: HM }); } - /** - * User agent client hints are not yet supported on firefox and safari https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API#browser_compatibility - * the fallback navigator.userAgent would still report the old/incorrect versions on these browsers - */ - const parsedOs = await parsedUserAgent.getOS().withClientHints(); - const parsedDevice = await parsedUserAgent.getDevice().withClientHints(); - const parsedBrowser = await parsedUserAgent.getBrowser().withClientHints(); + const parsedOs = parsedUserAgent.getOS(); + const parsedDevice = parsedUserAgent.getDevice(); + const parsedBrowser = parsedUserAgent.getBrowser(); const os = replaceSpaces(`web_${parsedOs.name}`); const os_version = parsedOs.version || ''; diff --git a/packages/roomkit-react/src/Prebuilt/common/constants.ts b/packages/roomkit-react/src/Prebuilt/common/constants.ts index 5b0b955454..ccbba0d456 100644 --- a/packages/roomkit-react/src/Prebuilt/common/constants.ts +++ b/packages/roomkit-react/src/Prebuilt/common/constants.ts @@ -98,12 +98,11 @@ export const HLS_TIMED_METADATA_DOC_URL = export const REMOTE_STOP_SCREENSHARE_TYPE = 'REMOTE_STOP_SCREENSHARE'; -// mweb could have browser name as "Mobile Chrome" or "Mobile Firefox" -export const isChrome = parsedUserAgent.getBrowser()?.name?.toLowerCase().includes('chrome'); -export const isFirefox = parsedUserAgent.getBrowser()?.name?.toLowerCase().includes('firefox'); -export const isSafari = parsedUserAgent.getBrowser()?.name?.toLowerCase().includes('safari'); +export const isChrome = parsedUserAgent.getBrowser()?.name?.toLowerCase() === 'chrome'; +export const isFirefox = parsedUserAgent.getBrowser()?.name?.toLowerCase() === 'firefox'; +export const isSafari = parsedUserAgent.getBrowser()?.name?.toLowerCase() === 'safari'; export const isIOS = parsedUserAgent.getOS()?.name?.toLowerCase() === 'ios'; -export const isMacOS = parsedUserAgent.getOS()?.name?.toLowerCase() === 'macos'; +export const isMacOS = parsedUserAgent.getOS()?.name?.toLowerCase() === 'mac os'; export const isAndroid = parsedUserAgent.getOS()?.name?.toLowerCase() === 'android'; export const isIPadOS = false; // typeof navigator !== "undefined" && diff --git a/yarn.lock b/yarn.lock index 351693336e..39770349d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5738,6 +5738,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c" integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw== +"@types/ua-parser-js@^0.7.36": + version "0.7.36" + resolved "https://registry.yarnpkg.com/@types/ua-parser-js/-/ua-parser-js-0.7.36.tgz#9bd0b47f26b5a3151be21ba4ce9f5fa457c5f190" + integrity sha512-N1rW+njavs70y2cApeIw1vLMYXRwfBy+7trgavGuuTfOd7j1Yh7QTRc/yqsPl6ncokt72ZXuxEU0PiCp9bSwNQ== + "@types/unist@^2.0.0": version "2.0.7" resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.7.tgz#5b06ad6894b236a1d2bd6b2f07850ca5c59cf4d6" @@ -16536,10 +16541,10 @@ typescript@~4.7.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== -ua-parser-js@^2.0.0-beta.2: - version "2.0.0-beta.2" - resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-2.0.0-beta.2.tgz#7738c5ad7f4a8f1fdd9f736130c8fd941daf686a" - integrity sha512-v1tudz3YJqB2lFtmhs/Wh2aPNsOatJBeCQp5s67rgx7UprG1pkOgzm8H1jXabaMZBXH9cWU3gePSgBTe3lFeRA== +ua-parser-js@^1.0.1: + version "1.0.35" + resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.35.tgz#c4ef44343bc3db0a3cbefdf21822f1b1fc1ab011" + integrity sha512-fKnGuqmTBnIE+/KXSzCn4db8RTigUzw1AN0DmdU6hJovUTbYJKyqj+8Mt1c4VfRDnOVJnENmfYkIPZ946UrSAA== uglify-js@^3.1.4: version "3.17.4"