Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/hms-video-store/package.json

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

58 changes: 56 additions & 2 deletions packages/hms-video-store/src/utils/support.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
import { UAParser } from 'ua-parser-js';
import { type IResult, UAParser } from 'ua-parser-js';
import HMSLogger from './logger';

export const parsedUserAgent = new UAParser();
// Initialize the parser
const uaParser = new UAParser();

// Store the enhanced result with clientHints when available
let enhancedResult: IResult | null = null;
let clientHintsPromise: Promise<IResult> | null = null;

export const isBrowser = typeof window !== 'undefined';

// Initialize clientHints in browser environment
if (isBrowser) {
try {
// Get the initial result
const initialResult = uaParser.getResult();

// Attempt to get clientHints asynchronously
// This will return a Promise in browser environments with clientHints support
const result = initialResult.withClientHints();

// Check if it's a Promise (browser environment)
if (result && typeof (result as Promise<IResult>).then === 'function') {
clientHintsPromise = result as Promise<IResult>;
clientHintsPromise
.then(enhancedData => {
enhancedResult = enhancedData;
})
.catch(() => {
// Silently fail - fallback to standard UA parsing
enhancedResult = initialResult;
});
} else {
HMSLogger.d('UAParser', 'Client Hints not supported, using standard UA parsing');
// Synchronous result (non-browser or no clientHints support)
enhancedResult = result as IResult;
}
} catch {
// Fallback to standard parsing if clientHints fails
enhancedResult = uaParser.getResult();
}
}

// Helper to get the best available parser result
const getParserResult = (): IResult => {
return enhancedResult || uaParser.getResult();
};

export const parsedUserAgent = {
getBrowser: () => getParserResult().browser,
getOS: () => getParserResult().os,
getDevice: () => getParserResult().device,
getCPU: () => getParserResult().cpu,
getEngine: () => getParserResult().engine,
getUA: () => getParserResult().ua,
getResult: getParserResult,
withClientHints: () => clientHintsPromise || Promise.resolve(getParserResult()),
};

export const isNode =
typeof window === 'undefined' && !parsedUserAgent.getBrowser().name?.toLowerCase().includes('electron');

Expand Down
35 changes: 27 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6458,10 +6458,10 @@
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.5.tgz#cb6e2a691b70cb177c6e3ae9c1d2e8b2ea8cd304"
integrity sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==

"@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/ua-parser-js@^0.7.39":
version "0.7.39"
resolved "https://registry.yarnpkg.com/@types/ua-parser-js/-/ua-parser-js-0.7.39.tgz#832c58e460c9435e4e34bb866e85e9146e12cdbb"
integrity sha512-P/oDfpofrdtF5xw433SPALpdSchtJmY7nsJItf8h3KXqOslkbySh8zq4dSWXH2oTjRvJ5PczVEoCZPow6GicLg==

"@types/unist@^2.0.0":
version "2.0.7"
Expand Down Expand Up @@ -8871,6 +8871,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015"
integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==

detect-europe-js@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/detect-europe-js/-/detect-europe-js-0.1.2.tgz#aa76642e05dae786efc2e01a23d4792cd24c7b88"
integrity sha512-lgdERlL3u0aUdHocoouzT10d9I89VVhk0qNRmll7mXdGfJT1/wqZ2ZLA4oJAjeACPY5fT1wsbq2AT+GkuInsow==

detect-indent@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
Expand Down Expand Up @@ -11730,6 +11735,11 @@ is-ssh@^1.4.0:
dependencies:
protocols "^2.0.1"

is-standalone-pwa@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/is-standalone-pwa/-/is-standalone-pwa-0.1.1.tgz#7a1b0459471a95378aa0764d5dc0a9cec95f2871"
integrity sha512-9Cbovsa52vNQCjdXOzeQq5CnCbAcRk05aU62K20WO372NrTv0NxibLFCK6lQ4/iZEFdEA3p3t2VNOn8AJ53F5g==

is-stream@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077"
Expand Down Expand Up @@ -16958,10 +16968,19 @@ typescript@~4.7.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

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==
ua-is-frozen@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ua-is-frozen/-/ua-is-frozen-0.1.2.tgz#bfbc5f06336e379590e36beca444188c7dc3a7f3"
integrity sha512-RwKDW2p3iyWn4UbaxpP2+VxwqXh0jpvdxsYpZ5j/MLLiQOfbsV5shpgQiw93+KMYQPcteeMQ289MaAFzs3G9pw==

ua-parser-js@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-2.0.6.tgz#1dd221f7f2a27357c6a342296852f6391d77d4f0"
integrity sha512-EmaxXfltJaDW75SokrY4/lXMrVyXomE/0FpIIqP2Ctic93gK7rlme55Cwkz8l3YZ6gqf94fCU7AnIkidd/KXPg==
dependencies:
detect-europe-js "^0.1.2"
is-standalone-pwa "^0.1.1"
ua-is-frozen "^0.1.2"

uglify-js@^3.1.4:
version "3.17.4"
Expand Down