ref: Convert some files to TS (#11929)

This commit is contained in:
Robert Pintilii 2022-07-29 16:18:14 +03:00 committed by GitHub
parent 5783e8992a
commit 69365d7e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 99 additions and 80 deletions

40
package-lock.json generated
View File

@ -146,9 +146,11 @@
"@types/js-md5": "0.4.3", "@types/js-md5": "0.4.3",
"@types/lodash": "4.14.182", "@types/lodash": "4.14.182",
"@types/react": "17.0.14", "@types/react": "17.0.14",
"@types/react-native": "0.67.6", "@types/react-native": "0.68.1",
"@types/react-redux": "7.1.24", "@types/react-redux": "7.1.24",
"@types/unorm": "1.3.28",
"@types/uuid": "8.3.4", "@types/uuid": "8.3.4",
"@types/zxcvbn": "4.4.1",
"@typescript-eslint/eslint-plugin": "5.30.5", "@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.4", "@typescript-eslint/parser": "5.30.4",
"babel-loader": "8.2.3", "babel-loader": "8.2.3",
@ -5653,9 +5655,9 @@
} }
}, },
"node_modules/@types/react-native": { "node_modules/@types/react-native": {
"version": "0.67.6", "version": "0.68.1",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.67.6.tgz", "resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.68.1.tgz",
"integrity": "sha512-NM6atxrefIXMLE/PyQ1bIQjQ/lWLdls3uVxItzKvNUUVZlGqgn/uGN4MarM9quSf90uSqJYPIAeAgTtBTUjhgg==", "integrity": "sha512-S+r6VamWqVutlQ3q/vhTn4b0F/DdZj8R6AIDdgwV9xN9Ln1kRdQd7o3mo7FnfdddVdzEkWMUVlK2sbkFOJFAiQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@types/react": "*" "@types/react": "*"
@ -5725,6 +5727,12 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/unorm": {
"version": "1.3.28",
"resolved": "https://registry.npmjs.org/@types/unorm/-/unorm-1.3.28.tgz",
"integrity": "sha512-l3uh18vcvkQ964HSK7Tx0YbhxN/Hj+k1w3nLT08n770lngqVKljmF7Ht4e7elFbx6L2WYse97whtpJOo8MHtxQ==",
"dev": true
},
"node_modules/@types/uuid": { "node_modules/@types/uuid": {
"version": "8.3.4", "version": "8.3.4",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
@ -5758,6 +5766,12 @@
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz",
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==" "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw=="
}, },
"node_modules/@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
"integrity": "sha512-3NoqvZC2W5gAC5DZbTpCeJ251vGQmgcWIHQJGq2J240HY6ErQ9aWKkwfoKJlHLx+A83WPNTZ9+3cd2ILxbvr1w==",
"dev": true
},
"node_modules/@typescript-eslint/eslint-plugin": { "node_modules/@typescript-eslint/eslint-plugin": {
"version": "5.30.5", "version": "5.30.5",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz",
@ -24977,9 +24991,9 @@
} }
}, },
"@types/react-native": { "@types/react-native": {
"version": "0.67.6", "version": "0.68.1",
"resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.67.6.tgz", "resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.68.1.tgz",
"integrity": "sha512-NM6atxrefIXMLE/PyQ1bIQjQ/lWLdls3uVxItzKvNUUVZlGqgn/uGN4MarM9quSf90uSqJYPIAeAgTtBTUjhgg==", "integrity": "sha512-S+r6VamWqVutlQ3q/vhTn4b0F/DdZj8R6AIDdgwV9xN9Ln1kRdQd7o3mo7FnfdddVdzEkWMUVlK2sbkFOJFAiQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/react": "*" "@types/react": "*"
@ -25049,6 +25063,12 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/unorm": {
"version": "1.3.28",
"resolved": "https://registry.npmjs.org/@types/unorm/-/unorm-1.3.28.tgz",
"integrity": "sha512-l3uh18vcvkQ964HSK7Tx0YbhxN/Hj+k1w3nLT08n770lngqVKljmF7Ht4e7elFbx6L2WYse97whtpJOo8MHtxQ==",
"dev": true
},
"@types/uuid": { "@types/uuid": {
"version": "8.3.4", "version": "8.3.4",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
@ -25082,6 +25102,12 @@
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz",
"integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==" "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw=="
}, },
"@types/zxcvbn": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@types/zxcvbn/-/zxcvbn-4.4.1.tgz",
"integrity": "sha512-3NoqvZC2W5gAC5DZbTpCeJ251vGQmgcWIHQJGq2J240HY6ErQ9aWKkwfoKJlHLx+A83WPNTZ9+3cd2ILxbvr1w==",
"dev": true
},
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
"version": "5.30.5", "version": "5.30.5",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz",

View File

@ -151,9 +151,11 @@
"@types/js-md5": "0.4.3", "@types/js-md5": "0.4.3",
"@types/lodash": "4.14.182", "@types/lodash": "4.14.182",
"@types/react": "17.0.14", "@types/react": "17.0.14",
"@types/react-native": "0.67.6", "@types/react-native": "0.68.1",
"@types/react-redux": "7.1.24", "@types/react-redux": "7.1.24",
"@types/unorm": "1.3.28",
"@types/uuid": "8.3.4", "@types/uuid": "8.3.4",
"@types/zxcvbn": "4.4.1",
"@typescript-eslint/eslint-plugin": "5.30.5", "@typescript-eslint/eslint-plugin": "5.30.5",
"@typescript-eslint/parser": "5.30.4", "@typescript-eslint/parser": "5.30.4",
"babel-loader": "8.2.3", "babel-loader": "8.2.3",

View File

@ -1,7 +1,6 @@
// @flow // @ts-ignore
import JitsiMeetJS from '../lib-jitsi-meet'; import JitsiMeetJS from '../lib-jitsi-meet';
import Platform from '../react/Platform'; import Platform from '../react/Platform.web';
import { isMobileBrowser } from './utils'; import { isMobileBrowser } from './utils';
@ -15,7 +14,7 @@ const DEFAULT_OPTIMAL_BROWSERS = [
'safari' 'safari'
]; ];
const DEFAULT_UNSUPPORTED_BROWSERS = []; const DEFAULT_UNSUPPORTED_BROWSERS: string[] = [];
const browserNameToCheck = { const browserNameToCheck = {
chrome: browser.isChrome.bind(browser), chrome: browser.isChrome.bind(browser),
@ -27,7 +26,8 @@ const browserNameToCheck = {
safari: browser.isSafari.bind(browser) safari: browser.isSafari.bind(browser)
}; };
declare var interfaceConfig: Object; // eslint-disable-next-line no-var
declare var interfaceConfig: any;
/** /**
* Returns whether or not jitsi is optimized and targeted for the provided * Returns whether or not jitsi is optimized and targeted for the provided
@ -117,9 +117,9 @@ export function isSupportedMobileBrowser() {
* @private * @private
* @returns {boolean} * @returns {boolean}
*/ */
function _isCurrentBrowserInList(list) { function _isCurrentBrowserInList(list: string[]) {
return Boolean(list.find(browserName => { return Boolean(list.find(browserName => {
const checkFunction = browserNameToCheck[browserName]; const checkFunction = browserNameToCheck[browserName as keyof typeof browserNameToCheck];
return checkFunction ? checkFunction.call(browser) : false; return checkFunction ? checkFunction.call(browser) : false;
})); }));

View File

@ -1,5 +1,4 @@
/* @flow */ // @ts-ignore
const { userAgent, maxTouchPoints, platform } = navigator; const { userAgent, maxTouchPoints, platform } = navigator;
let OS; let OS;

View File

@ -1,7 +1,5 @@
// @flow import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app/actionTypes';
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
import { MiddlewareRegistry } from '../redux';
import { USER_INTERACTION_RECEIVED } from './actionTypes'; import { USER_INTERACTION_RECEIVED } from './actionTypes';
@ -11,7 +9,7 @@ import { USER_INTERACTION_RECEIVED } from './actionTypes';
* *
* @type {Function|null} * @type {Function|null}
*/ */
let userInteractionListener = null; let userInteractionListener: Function|null = null;
/** /**
* Implements the entry point of the middleware of the feature base/user-interaction. * Implements the entry point of the middleware of the feature base/user-interaction.
@ -41,7 +39,7 @@ MiddlewareRegistry.register(store => next => action => {
* @private * @private
* @returns {void} * @returns {void}
*/ */
function _onUserInteractionReceived(dispatch, event) { function _onUserInteractionReceived(dispatch: Function, event: any) {
if (event.isTrusted) { if (event.isTrusted) {
dispatch({ dispatch({
type: USER_INTERACTION_RECEIVED type: USER_INTERACTION_RECEIVED
@ -58,12 +56,15 @@ function _onUserInteractionReceived(dispatch, event) {
* @private * @private
* @returns {void} * @returns {void}
*/ */
function _startListeningForUserInteraction({ dispatch }) { function _startListeningForUserInteraction({ dispatch }: {dispatch: Function}) {
_stopListeningForUserInteraction(); _stopListeningForUserInteraction();
userInteractionListener = _onUserInteractionReceived.bind(null, dispatch); userInteractionListener = _onUserInteractionReceived.bind(null, dispatch);
// @ts-ignore
window.addEventListener('mousedown', userInteractionListener); window.addEventListener('mousedown', userInteractionListener);
// @ts-ignore
window.addEventListener('keydown', userInteractionListener); window.addEventListener('keydown', userInteractionListener);
} }
@ -74,7 +75,10 @@ function _startListeningForUserInteraction({ dispatch }) {
* @returns {void} * @returns {void}
*/ */
function _stopListeningForUserInteraction() { function _stopListeningForUserInteraction() {
// @ts-ignore
window.removeEventListener('mousedown', userInteractionListener); window.removeEventListener('mousedown', userInteractionListener);
// @ts-ignore
window.removeEventListener('keydown', userInteractionListener); window.removeEventListener('keydown', userInteractionListener);
userInteractionListener = null; userInteractionListener = null;

View File

@ -1,5 +1,3 @@
// @flow
/** /**
* Downloads a JSON object. * Downloads a JSON object.
* *

View File

@ -1,5 +1,3 @@
// @flow
import clipboardCopy from 'clipboard-copy'; import clipboardCopy from 'clipboard-copy';
/** /**
@ -15,7 +13,7 @@ export function assignIfDefined(target: Object, source: Object) {
for (const nextKey in source) { for (const nextKey in source) {
if (source.hasOwnProperty(nextKey)) { if (source.hasOwnProperty(nextKey)) {
const value = source[nextKey]; const value = source[nextKey as keyof typeof source];
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {
to[nextKey] = value; to[nextKey] = value;
@ -49,7 +47,7 @@ export async function copyText(textToCopy: string) {
* @returns {{promise, resolve, reject}} * @returns {{promise, resolve, reject}}
*/ */
export function createDeferred(): Object { export function createDeferred(): Object {
const deferred = {}; const deferred: any = {};
deferred.promise = new Promise((resolve, reject) => { deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve; deferred.resolve = resolve;
@ -83,7 +81,7 @@ export function escapeRegexp(s: string) {
* @param {Object} w - Window object to use instead of the built in one. * @param {Object} w - Window object to use instead of the built in one.
* @returns {string} * @returns {string}
*/ */
export function getBaseUrl(w: Object = window) { export function getBaseUrl(w: Window = window) {
const doc = w.document; const doc = w.document;
const base = doc.querySelector('base'); const base = doc.querySelector('base');
@ -104,14 +102,19 @@ export function getBaseUrl(w: Object = window) {
* NOTE: After React-ifying everything this should be the only global. * NOTE: After React-ifying everything this should be the only global.
*/ */
export function getJitsiMeetGlobalNS() { export function getJitsiMeetGlobalNS() {
// @ts-ignore
if (!window.JitsiMeetJS) { if (!window.JitsiMeetJS) {
// @ts-ignore
window.JitsiMeetJS = {}; window.JitsiMeetJS = {};
} }
// @ts-ignore
if (!window.JitsiMeetJS.app) { if (!window.JitsiMeetJS.app) {
// @ts-ignore
window.JitsiMeetJS.app = {}; window.JitsiMeetJS.app = {};
} }
// @ts-ignore
return window.JitsiMeetJS.app; return window.JitsiMeetJS.app;
} }
@ -122,9 +125,9 @@ export function getJitsiMeetGlobalNS() {
* @param {string} msg - A custom message to print in addition to the error. * @param {string} msg - A custom message to print in addition to the error.
* @returns {void} * @returns {void}
*/ */
export function reportError(e: Object, msg: string = '') { export function reportError(e: Error, msg = '') {
console.error(msg, e); console.error(msg, e);
window.onerror && window.onerror(msg, null, null, null, e); window.onerror && window.onerror(msg, undefined, undefined, undefined, e);
} }
/** /**
@ -168,7 +171,7 @@ export function setColorAlpha(color: string, opacity: number) {
* @param {string} color - * @param {string} color -
* @returns {Array<number>} - Array containing parsed r, g, b values of the color. * @returns {Array<number>} - Array containing parsed r, g, b values of the color.
*/ */
function parseShorthandColor(color) { function parseShorthandColor(color: string) {
let b, g, r; let b, g, r;
r = color.substring(1, 2); r = color.substring(1, 2);

View File

@ -1,4 +1,3 @@
// @flow
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
/** /**

View File

@ -17,7 +17,7 @@ const RETRY_TIMEOUT = 3000;
* @returns {Promise<Object>} The response body, in JSON format, will be * @returns {Promise<Object>} The response body, in JSON format, will be
* through the Promise. * through the Promise.
*/ */
export function doGetJSON(url, retry, options) { export function doGetJSON(url: string, retry?: boolean, options?: Object) {
const fetchPromise = fetch(url, options) const fetchPromise = fetch(url, options)
.then(response => { .then(response => {
const jsonify = response.json(); const jsonify = response.json();

View File

@ -1,5 +1,3 @@
// @flow
import _ from 'lodash'; import _ from 'lodash';
import { NIL, parse as parseUUID } from 'uuid'; import { NIL, parse as parseUUID } from 'uuid';
import zxcvbn from 'zxcvbn'; import zxcvbn from 'zxcvbn';
@ -13,7 +11,7 @@ const NIL_UUID = parseUUID(NIL);
* @param {string} str - The string to be checked. * @param {string} str - The string to be checked.
* @returns {boolean} - Whether the string is a valid UUID or not. * @returns {boolean} - Whether the string is a valid UUID or not.
*/ */
function isValidUUID(str) { function isValidUUID(str: string) {
let uuid; let uuid;
try { try {
@ -31,6 +29,6 @@ function isValidUUID(str) {
* @param {string} roomName - The room name. * @param {string} roomName - The room name.
* @returns {boolean} * @returns {boolean}
*/ */
export default function isInsecureRoomName(roomName: string = ''): boolean { export default function isInsecureRoomName(roomName = ''): boolean {
return !isValidUUID(roomName) && zxcvbn(roomName).score < 3; return !isValidUUID(roomName) && zxcvbn(roomName).score < 3;
} }

View File

@ -1,5 +1,3 @@
// @flow
/** /**
* Default timeout for loading scripts. * Default timeout for loading scripts.
*/ */
@ -20,7 +18,7 @@ const DEFAULT_TIMEOUT = 5000;
* @returns {void} * @returns {void}
*/ */
export async function loadScript( export async function loadScript(
url: string, timeout: number = DEFAULT_TIMEOUT, skipEval: boolean = false): Promise<any> { url: string, timeout: number = DEFAULT_TIMEOUT, skipEval = false): Promise<any> {
// XXX The implementation of fetch on Android will throw an Exception on // XXX The implementation of fetch on Android will throw an Exception on
// the Java side which will break the app if the URL is invalid (which // the Java side which will break the app if the URL is invalid (which
// the implementation of fetch on Android calls 'unexpected url'). In // the implementation of fetch on Android calls 'unexpected url'). In

View File

@ -1,6 +1,5 @@
// @flow // eslint-disable-next-line no-var
declare var JitsiMeetJS: any;
declare var JitsiMeetJS: Object;
/** /**
* Loads a script from a specific URL. The script will be interpreted upon load. * Loads a script from a specific URL. The script will be interpreted upon load.

View File

@ -1,7 +1,6 @@
// @flow
import { Linking } from 'react-native'; import { Linking } from 'react-native';
// @ts-ignore
import logger from './logger'; import logger from './logger';
/** /**

View File

@ -1,5 +1,3 @@
// @flow
/** /**
* Opens URL in the browser. * Opens URL in the browser.
* *

View File

@ -1,5 +1,4 @@
/* @flow */ // @ts-ignore
import Bourne from '@hapi/bourne'; import Bourne from '@hapi/bourne';
import { reportError } from './helpers'; import { reportError } from './helpers';
@ -24,14 +23,14 @@ const blacklist = [ '__proto__', 'constructor', 'prototype' ];
*/ */
export function parseURLParams( export function parseURLParams(
url: URL | string, url: URL | string,
dontParse: boolean = false, dontParse = false,
source: string = 'hash'): Object { source = 'hash'): Object {
if (typeof url === 'string') { if (typeof url === 'string') {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
url = new URL(url); url = new URL(url);
} }
const paramStr = source === 'search' ? url.search : url.hash; const paramStr = source === 'search' ? url.search : url.hash;
const params = {}; const params: any = {};
const paramParts = (paramStr && paramStr.substr(1).split('&')) || []; const paramParts = (paramStr && paramStr.substr(1).split('&')) || [];
// Detect and ignore hash params for hash routers. // Detect and ignore hash params for hash routers.
@ -61,7 +60,7 @@ export function parseURLParams(
value = decoded === 'undefined' ? undefined : Bourne.parse(decoded); value = decoded === 'undefined' ? undefined : Bourne.parse(decoded);
} }
} catch (e) { } catch (e: any) {
reportError( reportError(
e, `Failed to parse URL parameter value: ${String(value)}`); e, `Failed to parse URL parameter value: ${String(value)}`);

View File

@ -10,7 +10,7 @@ import FocusLock, { MoveFocusInside } from 'react-focus-lock';
* @param {Object} props - The props passed to the FocusLock. * @param {Object} props - The props passed to the FocusLock.
* @returns {ReactElement} * @returns {ReactElement}
*/ */
export default (props: Object) => { export default (props: any) => {
const { children, ...otherProps } = props; const { children, ...otherProps } = props;
const forwardProps = { const forwardProps = {

View File

@ -1,5 +1,3 @@
// @flow
import * as unorm from 'unorm'; import * as unorm from 'unorm';
/** /**

View File

@ -1,5 +1,3 @@
// @flow
/** /**
* Applies NFKC normalization to the given text. * Applies NFKC normalization to the given text.
* *

View File

@ -1,5 +1,3 @@
// @flow
/** /**
* Returns a new {@code Promise} which settles when a specific {@code Promise} * Returns a new {@code Promise} which settles when a specific {@code Promise}
* settles and is automatically rejected if the specified {@code Promise} * settles and is automatically rejected if the specified {@code Promise}

View File

@ -1,6 +1,6 @@
// @flow
import { parseURLParams } from './parseURLParams'; import { parseURLParams } from './parseURLParams';
// eslint-disable-next-line lines-around-comment
// @ts-ignore
import { normalizeNFKC } from './strings'; import { normalizeNFKC } from './strings';
/** /**
@ -53,7 +53,7 @@ export const URI_PROTOCOL_PATTERN = '^([a-z][a-z0-9\\.\\+-]*:)';
* @private * @private
* @returns {?string} * @returns {?string}
*/ */
function _fixPathPart(pathPart: ?string) { function _fixPathPart(pathPart?: string) {
return pathPart return pathPart
? pathPart.replace(new RegExp(_ROOM_EXCLUDE_PATTERN, 'g'), '') ? pathPart.replace(new RegExp(_ROOM_EXCLUDE_PATTERN, 'g'), '')
: pathPart; : pathPart;
@ -107,7 +107,7 @@ function _fixURIStringScheme(uri: string) {
* @param {string?} path - The path to convert. * @param {string?} path - The path to convert.
* @returns {string?} * @returns {string?}
*/ */
export function getBackendSafePath(path: ?string): ?string { export function getBackendSafePath(path?: string): string|undefined {
if (!path) { if (!path) {
return path; return path;
} }
@ -124,7 +124,7 @@ export function getBackendSafePath(path: ?string): ?string {
* @param {string?} room - The room name to convert. * @param {string?} room - The room name to convert.
* @returns {string?} * @returns {string?}
*/ */
export function getBackendSafeRoomName(room: ?string): ?string { export function getBackendSafeRoomName(room?: string): string|undefined {
if (!room) { if (!room) {
return room; return room;
} }
@ -146,10 +146,10 @@ export function getBackendSafeRoomName(room: ?string): ?string {
room = normalizeNFKC(room); room = normalizeNFKC(room);
// Only decoded and normalized strings can be lowercased properly. // Only decoded and normalized strings can be lowercased properly.
room = room.toLowerCase(); room = room?.toLowerCase();
// But we still need to (re)encode it. // But we still need to (re)encode it.
room = encodeURIComponent(room); room = encodeURIComponent(room ?? '');
/* eslint-enable no-param-reassign */ /* eslint-enable no-param-reassign */
// Unfortunately we still need to lowercase it, because encoding a string will // Unfortunately we still need to lowercase it, because encoding a string will
@ -192,7 +192,7 @@ function _objectToURLParamsArray(obj = {}) {
for (const key in obj) { // eslint-disable-line guard-for-in for (const key in obj) { // eslint-disable-line guard-for-in
try { try {
params.push( params.push(
`${key}=${encodeURIComponent(JSON.stringify(obj[key]))}`); `${key}=${encodeURIComponent(JSON.stringify(obj[key as keyof typeof obj]))}`);
} catch (e) { } catch (e) {
console.warn(`Error encoding ${key}: ${e}`); console.warn(`Error encoding ${key}: ${e}`);
} }
@ -221,7 +221,7 @@ function _objectToURLParamsArray(obj = {}) {
export function parseStandardURIString(str: string) { export function parseStandardURIString(str: string) {
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
const obj: Object = { const obj: {[key: string]: any} = {
toString: _standardURIToString toString: _standardURIToString
}; };
@ -258,6 +258,7 @@ export function parseStandardURIString(str: string) {
authority = authority.substring(userinfoEndIndex + 1); authority = authority.substring(userinfoEndIndex + 1);
} }
// @ts-ignore
obj.host = authority; obj.host = authority;
// port // port
@ -276,7 +277,7 @@ export function parseStandardURIString(str: string) {
regex = new RegExp(`^${_URI_PATH_PATTERN}`, 'gi'); regex = new RegExp(`^${_URI_PATH_PATTERN}`, 'gi');
match = regex.exec(str); match = regex.exec(str);
let pathname: ?string; let pathname: string|undefined;
if (match) { if (match) {
pathname = match[1]; pathname = match[1];
@ -329,7 +330,7 @@ export function parseStandardURIString(str: string) {
* search: string * search: string
* }} * }}
*/ */
export function parseURIString(uri: ?string) { export function parseURIString(uri?: string) {
if (typeof uri !== 'string') { if (typeof uri !== 'string') {
return undefined; return undefined;
} }
@ -338,13 +339,14 @@ export function parseURIString(uri: ?string) {
// XXX While the components/segments of pathname are URI encoded, Jitsi Meet // XXX While the components/segments of pathname are URI encoded, Jitsi Meet
// on the client and/or server sides still don't support certain characters. // on the client and/or server sides still don't support certain characters.
obj.pathname = obj.pathname.split('/').map(pathPart => _fixPathPart(pathPart)) obj.pathname = obj.pathname.split('/').map((pathPart: any) => _fixPathPart(pathPart))
.join('/'); .join('/');
// Add the properties that are specific to a Jitsi Meet resource (location) // Add the properties that are specific to a Jitsi Meet resource (location)
// such as contextRoot, room: // such as contextRoot, room:
// contextRoot // contextRoot
// @ts-ignore
obj.contextRoot = getLocationContextRoot(obj); obj.contextRoot = getLocationContextRoot(obj);
// The room (name) is the last component/segment of pathname. // The room (name) is the last component/segment of pathname.
@ -371,7 +373,8 @@ export function parseURIString(uri: ?string) {
* function is invoked on such an instance. * function is invoked on such an instance.
* @returns {string} * @returns {string}
*/ */
function _standardURIToString(thiz: ?Object) { function _standardURIToString(thiz?: Object) {
// @ts-ignore
// eslint-disable-next-line no-invalid-this // eslint-disable-next-line no-invalid-this
const { hash, host, pathname, protocol, search } = thiz || this; const { hash, host, pathname, protocol, search } = thiz || this;
let str = ''; let str = '';
@ -418,7 +421,7 @@ export function safeDecodeURIComponent(text: string) {
* @returns {string} - A {@code String} representation of the specified * @returns {string} - A {@code String} representation of the specified
* {@code obj} which is supposed to represent a URL. * {@code obj} which is supposed to represent a URL.
*/ */
export function toURLString(obj: ?(Object | string)): ?string { export function toURLString(obj?: (Object | string)): string|undefined|null {
let str; let str;
switch (typeof obj) { switch (typeof obj) {
@ -449,7 +452,7 @@ export function toURLString(obj: ?(Object | string)): ?string {
* @returns {string} - A {@code String} representation of the specified * @returns {string} - A {@code String} representation of the specified
* {@code Object}. * {@code Object}.
*/ */
export function urlObjectToString(o: Object): ?string { export function urlObjectToString(o: {[key: string]: any}): string|undefined {
// First normalize the given url. It come as o.url or split into o.serverURL // First normalize the given url. It come as o.url or split into o.serverURL
// and o.room. // and o.room.
let tmp; let tmp;
@ -466,7 +469,7 @@ export function urlObjectToString(o: Object): ?string {
// protocol // protocol
if (!url.protocol) { if (!url.protocol) {
let protocol: ?string = o.protocol || o.scheme; let protocol: string|undefined = o.protocol || o.scheme;
if (protocol) { if (protocol) {
// Protocol is supposed to be the scheme and the final ':'. Anyway, // Protocol is supposed to be the scheme and the final ':'. Anyway,
@ -484,7 +487,7 @@ export function urlObjectToString(o: Object): ?string {
// //
// It may be host/hostname and pathname with the latter denoting the // It may be host/hostname and pathname with the latter denoting the
// tenant. // tenant.
const domain: ?string = o.domain || o.host || o.hostname; const domain: string|undefined = o.domain || o.host || o.hostname;
if (domain) { if (domain) {
const { host, hostname, pathname: contextRoot, port } const { host, hostname, pathname: contextRoot, port }