snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
This commit is contained in:
74
react/features/base/lib-jitsi-meet/functions.native.ts
Normal file
74
react/features/base/lib-jitsi-meet/functions.native.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { safeJsonParse } from '@jitsi/js-utils/json';
|
||||
// @ts-ignore
|
||||
import { Worklets } from 'react-native-worklets-core';
|
||||
|
||||
import { loadScript } from '../util/loadScript.native';
|
||||
|
||||
import logger from './logger';
|
||||
|
||||
export * from './functions.any';
|
||||
|
||||
|
||||
/**
|
||||
* Worklet context usefull for running small tasks off the JS thread.
|
||||
*/
|
||||
export const workletContext = Worklets.createContext('ConfigParser');
|
||||
|
||||
|
||||
/**
|
||||
* Loads config.js from a specific remote server.
|
||||
*
|
||||
* @param {string} url - The URL to load.
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
export async function loadConfig(url: string): Promise<Object> {
|
||||
try {
|
||||
const configTxt = await loadScript(url, 10 * 1000, true);
|
||||
|
||||
const parseConfigAsync = workletContext.createRunAsync(function parseConfig(configText: string): string {
|
||||
'worklet';
|
||||
try {
|
||||
// Used IIFE wrapper to capture config object from config.js
|
||||
const configObj = eval(
|
||||
'(function(){\n'
|
||||
+ configText
|
||||
+ '\n; return (typeof config !== "undefined" ? config : globalThis.config); })()'
|
||||
);
|
||||
|
||||
if (configObj == void 0) {
|
||||
return 'Worklet_Error: config is undefined after eval()';
|
||||
}
|
||||
|
||||
if (typeof configObj !== 'object') {
|
||||
return 'Worklet_Error: config is not an object';
|
||||
}
|
||||
|
||||
return JSON.stringify(configObj);
|
||||
} catch (err) {
|
||||
return 'Worklet_Error:' + ((err as Error)?.message ?? String(err));
|
||||
}
|
||||
});
|
||||
|
||||
const workletConfig = await parseConfigAsync(configTxt);
|
||||
|
||||
if (typeof workletConfig !== 'string') {
|
||||
throw new Error('Worklet error: workletConfig is not a string');
|
||||
}
|
||||
|
||||
if (workletConfig.startsWith('Worklet_Error:')) {
|
||||
const msg = workletConfig.slice('Worklet_Error:'.length);
|
||||
|
||||
throw new Error(`Worklet error: ${msg}`);
|
||||
}
|
||||
|
||||
const config = safeJsonParse(workletConfig);
|
||||
|
||||
logger.info(`Config loaded from ${url}`);
|
||||
|
||||
return config;
|
||||
} catch (err) {
|
||||
logger.error(`Failed to load config from ${url}`, err);
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user