Skip to content

Commit

Permalink
feat(ts) make tsc happy
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 2, 2022
1 parent 49bcf5c commit 7cd39b7
Show file tree
Hide file tree
Showing 55 changed files with 937 additions and 782 deletions.
8 changes: 5 additions & 3 deletions conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ import {
import {
checkAndNotifyForNewDevice,
getAvailableDevices,
getDefaultDeviceId,
notifyCameraError,
notifyMicError,
setAudioOutputDeviceId,
updateDeviceList
} from './react/features/base/devices';
} from './react/features/base/devices/actions.web';
import {
getDefaultDeviceId,
setAudioOutputDeviceId
} from './react/features/base/devices/functions.web';
import {
JitsiConferenceErrors,
JitsiConferenceEvents,
Expand Down
14 changes: 14 additions & 0 deletions globals.native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ interface IWindow {
JITSI_MEET_LITE_SDK: boolean;
JitsiMeetJS: any;
config: IConfig;
document: any;
innerHeight: number;
innerWidth: number;
interfaceConfig: any;
location: ILocation;
self: any;
top: any;

onerror: (event: string, source: any, lineno: any, colno: any, e: Error) => void;
onunhandledrejection: (event: any) => void;

setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
setImmediate: typeof setImmediate;
clearImmediate: typeof clearImmediate;
}

interface INavigator {
Expand All @@ -22,6 +35,7 @@ interface INavigator {

declare global {
const APP: any;
const document: any;
const interfaceConfig: any;
const navigator: INavigator;
const window: IWindow;
Expand Down
6 changes: 4 additions & 2 deletions modules/devices/mediaDeviceHelper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* global APP, JitsiMeetJS */

import {
getAudioOutputDeviceId,
notifyCameraError,
notifyMicError
} from '../../react/features/base/devices';
} from '../../react/features/base/devices/actions.web';
import {
getAudioOutputDeviceId
} from '../../react/features/base/devices/functions.web';
import {
getUserSelectedCameraDeviceId,
getUserSelectedMicDeviceId,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"tsc:web": "tsc --noEmit --project tsconfig.web.json",
"tsc:native": "tsc --noEmit --project tsconfig.native.json",
"tsc:ci": "npm run tsc:web && npm run tsc:native",
"lint:ci": "eslint --ext .js,.ts,.tsx --max-warnings 0 . && npm run tsc:web",
"lint:ci": "eslint --ext .js,.ts,.tsx --max-warnings 0 . && npm run tsc:ci",
"lang-sort": "./resources/lang-sort.sh",
"lint-fix": "eslint --ext .js,.ts,.tsx --max-warnings 0 --fix .",
"postinstall": "patch-package --error-on-fail && jetify",
Expand Down
2 changes: 1 addition & 1 deletion react/features/analytics/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { API_ID } from '../../../modules/API/constants';
import { getName as getAppName } from '../app/functions';
import { IStore } from '../app/types';
import { getAnalyticsRoomName } from '../base/conference/functions';
import checkChromeExtensionsInstalled from '../base/environment/checkChromeExtensionsInstalled';
import {
checkChromeExtensionsInstalled,
isMobileBrowser
} from '../base/environment/utils';
import JitsiMeetJS, {
Expand Down
7 changes: 6 additions & 1 deletion react/features/analytics/handlers/AmplitudeHandler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable lines-around-comment */

import logger from '../logger';

import AbstractHandler, { IEvent } from './AbstractHandler';
Expand Down Expand Up @@ -63,7 +65,7 @@ export default class AmplitudeHandler extends AbstractHandler {
* @param {Object} userProps - The user portperties.
* @returns {void}
*/
setUserProperties(userProps: Object) {
setUserProperties(userProps: any) {
if (this._enabled) {
amplitude.getInstance().setUserProperties(userProps);
}
Expand All @@ -82,6 +84,7 @@ export default class AmplitudeHandler extends AbstractHandler {
return;
}

// @ts-ignore
amplitude.getInstance().logEvent(this._extractName(event) ?? '', event);
}

Expand All @@ -100,7 +103,9 @@ export default class AmplitudeHandler extends AbstractHandler {

return {
sessionId: amplitude.getInstance().getSessionId(),
// @ts-ignore
deviceId: amplitude.getInstance().options.deviceId,
// @ts-ignore
userId: amplitude.getInstance().options.userId
};
}
Expand Down
2 changes: 1 addition & 1 deletion react/features/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IAudioOnlyState } from '../base/audio-only/reducer';
import { IConferenceState } from '../base/conference/reducer';
import { IConfigState } from '../base/config/reducer';
import { IConnectionState } from '../base/connection/reducer';
import { IDevicesState } from '../base/devices/reducer';
import { IDevicesState } from '../base/devices/types';
import { IDialogState } from '../base/dialog/reducer';
import { IFlagsState } from '../base/flags/reducer';
import { IJwtState } from '../base/jwt/reducer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IStore } from '../../app/types';
import JitsiMeetJS from '../lib-jitsi-meet';
import { updateSettings } from '../settings/actions';
import { getUserSelectedOutputDeviceId } from '../settings/functions.any';
import { getUserSelectedOutputDeviceId } from '../settings/functions.web';

import {
ADD_PENDING_DEVICE_REQUEST,
Expand Down
19 changes: 19 additions & 0 deletions react/features/base/devices/functions.any.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IReduxState } from '../../app/types';

/**
* Returns true if there are devices of a specific type or on native platform.
*
* @param {Object} state - The state of the application.
* @param {string} type - The type of device: VideoOutput | audioOutput | audioInput.
*
* @returns {boolean}
*/
export function hasAvailableDevices(state: IReduxState, type: string) {
if (state['features/base/devices'] === undefined) {
return true;
}

const availableDevices = state['features/base/devices'].availableDevices;

return Number(availableDevices[type as keyof typeof availableDevices]?.length) > 0;
}
1 change: 1 addition & 0 deletions react/features/base/devices/functions.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './functions.any';
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { ISettingsState } from '../settings/reducer';
import { parseURLParams } from '../util/parseURLParams';

import logger from './logger';
import { IDevicesState } from './reducer';
import { IDevicesState } from './types';


declare const APP: any;
export * from './functions.any';

const webrtcKindToJitsiKindTranslator = {
audioinput: 'audioInput',
Expand Down Expand Up @@ -240,24 +239,6 @@ export function getVideoDeviceIds(state: IReduxState) {
return state['features/base/devices'].availableDevices.videoInput?.map(({ deviceId }) => deviceId);
}

/**
* Returns true if there are devices of a specific type or on native platform.
*
* @param {Object} state - The state of the application.
* @param {string} type - The type of device: VideoOutput | audioOutput | audioInput.
*
* @returns {boolean}
*/
export function hasAvailableDevices(state: IReduxState, type: string) {
if (state['features/base/devices'] === undefined) {
return true;
}

const availableDevices = state['features/base/devices'].availableDevices;

return Number(availableDevices[type as keyof typeof availableDevices]?.length) > 0;
}

/**
* Set device id of the audio output device which is currently in use.
* Empty string stands for default device.
Expand Down
3 changes: 0 additions & 3 deletions react/features/base/devices/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion react/features/base/devices/middleware.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
setAudioOutputDeviceId
} from './functions';
import logger from './logger';
import { IDevicesState } from './reducer';
import { IDevicesState } from './types';

const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
microphone: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
SET_VIDEO_INPUT_DEVICE,
UPDATE_DEVICE_LIST
} from './actionTypes';
import { groupDevicesByKind } from './functions';
import { groupDevicesByKind } from './functions.web';
import logger from './logger';
import { IDevicesState } from './types';


const DEFAULT_STATE: IDevicesState = {
Expand All @@ -25,19 +26,6 @@ const DEFAULT_STATE: IDevicesState = {
}
};

export interface IDevicesState {
availableDevices: {
audioInput?: MediaDeviceInfo[];
audioOutput?: MediaDeviceInfo[];
videoInput?: MediaDeviceInfo[];
};
pendingRequests: Object[];
permissions: {
audio: boolean;
video: boolean;
};
}

/**
* Listen for actions which changes the state of known and used devices.
*
Expand Down
17 changes: 17 additions & 0 deletions react/features/base/devices/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable lines-around-comment */

export interface IDevicesState {
availableDevices: {
// @ts-ignore
audioInput?: MediaDeviceInfo[];
// @ts-ignore
audioOutput?: MediaDeviceInfo[];
// @ts-ignore
videoInput?: MediaDeviceInfo[];
};
pendingRequests: any[];
permissions: {
audio: boolean;
video: boolean;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Checks whether the chrome extensions defined in the config file are installed or not.
*
* @param {Object} _config - Objects containing info about the configured extensions.
*
* @returns {Promise[]}
*/
export default function checkChromeExtensionsInstalled(_config: any = {}) {
return Promise.resolve([]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Checks whether the chrome extensions defined in the config file are installed or not.
*
* @param {Object} config - Objects containing info about the configured extensions.
*
* @returns {Promise[]}
*/
export default function checkChromeExtensionsInstalled(config: any = {}) {
const isExtensionInstalled = (info: any) => new Promise(resolve => {
const img = new Image();

img.src = `chrome-extension://${info.id}/${info.path}`;
img.setAttribute('aria-hidden', 'true');
img.onload = function() {
resolve(true);
};
img.onerror = function() {
resolve(false);
};
});
const extensionInstalledFunction = (info: any) => isExtensionInstalled(info);

return Promise.all(
(config.chromeExtensionsInfo || []).map((info: any) => extensionInstalledFunction(info))
);
}
27 changes: 0 additions & 27 deletions react/features/base/environment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,3 @@ export function isMobileBrowser() {
export function isIosMobileBrowser() {
return Platform.OS === 'ios';
}

/**
* Checks whether the chrome extensions defined in the config file are installed or not.
*
* @param {Object} config - Objects containing info about the configured extensions.
*
* @returns {Promise[]}
*/
export function checkChromeExtensionsInstalled(config: any = {}) {
const isExtensionInstalled = (info: any) => new Promise(resolve => {
const img = new Image();

img.src = `chrome-extension://${info.id}/${info.path}`;
img.setAttribute('aria-hidden', 'true');
img.onload = function() {
resolve(true);
};
img.onerror = function() {
resolve(false);
};
});
const extensionInstalledFunction = (info: any) => isExtensionInstalled(info);

return Promise.all(
(config.chromeExtensionsInfo || []).map((info: any) => extensionInstalledFunction(info))
);
}
2 changes: 1 addition & 1 deletion react/features/base/jwt/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { MEET_FEATURES } from './constants';
* @returns {string} The JSON Web Token (JWT), if any, defined by the specified
* {@code url}; otherwise, {@code undefined}.
*/
export function parseJWTFromURLParams(url: URL | Location = window.location) {
export function parseJWTFromURLParams(url: URL | typeof window.location = window.location) {
// @ts-ignore
return parseURLParams(url, true, 'search').jwt;
}
Expand Down
Loading

0 comments on commit 7cd39b7

Please sign in to comment.