Skip to content

Commit

Permalink
Revert "fix: upgrade ua-parser-js to track correct mac os version"
Browse files Browse the repository at this point in the history
This reverts commit 8f6896c.
  • Loading branch information
eswarclynn authored Feb 22, 2024
1 parent e922bd9 commit 086f95a
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 50 deletions.
3 changes: 2 additions & 1 deletion packages/hms-video-store/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/hms-video-store/src/analytics/AnalyticsEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export default class AnalyticsEvent implements ISignalParamsProvider<SignalEvent
user_name?: string;
user_data?: string;
};
userAgent?: string;
userAgent: string;
} = {
peer: {},
userAgent: createUserAgent(),
};
timestamp: number;
event_id: string;
Expand All @@ -54,7 +55,6 @@ export default class AnalyticsEvent implements ISignalParamsProvider<SignalEvent
this.timestamp = timestamp || new Date().getTime(); // Timestamp of generating the event
this.event_id = uuid();
this.device_id = getAnalyticsDeviceId();
createUserAgent().then(userAgent => (this.metadata.userAgent = userAgent));
}

toSignalParams() {
Expand Down
13 changes: 5 additions & 8 deletions packages/hms-video-store/src/analytics/HTTPAnalyticsTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
8 changes: 4 additions & 4 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1239,15 +1239,15 @@ 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;
const { roomId, userId, role } = decodeJWT(config.authToken);
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);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/hms-video-store/src/sdk/store/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, HMSPoll>();
private whiteboards = new Map<string, HMSWhiteboard>();

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/hms-video-store/src/signal/init/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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';
Expand All @@ -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<Response> => {
const headers = init?.headers as Record<string, string>;
Expand Down
12 changes: 2 additions & 10 deletions packages/hms-video-store/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/hms-video-store/src/utils/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
12 changes: 4 additions & 8 deletions packages/hms-video-store/src/utils/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 || '';
Expand Down
9 changes: 4 additions & 5 deletions packages/roomkit-react/src/Prebuilt/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" &&
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 086f95a

Please sign in to comment.