2022-09-23 09:03:25 +00:00
|
|
|
import { IStateful } from '../app/types';
|
|
|
|
import { toState } from '../redux/functions';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2022-09-23 09:03:25 +00:00
|
|
|
// @ts-ignore
|
2017-02-19 00:42:11 +00:00
|
|
|
import JitsiMeetJS from './_';
|
|
|
|
|
2017-11-09 13:34:42 +00:00
|
|
|
const JitsiConferenceErrors = JitsiMeetJS.errors.conference;
|
2017-02-19 00:42:11 +00:00
|
|
|
const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
|
|
|
|
|
2017-05-04 15:20:41 +00:00
|
|
|
/**
|
2018-03-06 16:08:23 +00:00
|
|
|
* Creates a {@link JitsiLocalTrack} model from the given device id.
|
2017-05-04 15:20:41 +00:00
|
|
|
*
|
|
|
|
* @param {string} type - The media type of track being created. Expected values
|
|
|
|
* are "video" or "audio".
|
|
|
|
* @param {string} deviceId - The id of the target media source.
|
2021-02-02 00:20:39 +00:00
|
|
|
* @param {number} [timeout] - A timeout for the JitsiMeetJS.createLocalTracks function call.
|
2021-03-17 08:44:18 +00:00
|
|
|
* @param {Object} additionalOptions - Extra options to be passed to lib-jitsi-meet's {@code createLocalTracks}.
|
|
|
|
*
|
2017-05-04 15:20:41 +00:00
|
|
|
* @returns {Promise<JitsiLocalTrack>}
|
|
|
|
*/
|
2022-10-18 16:21:48 +00:00
|
|
|
export function createLocalTrack(type: string, deviceId: string | null, timeout?: number | null,
|
|
|
|
additionalOptions?: Object) {
|
2017-05-04 15:20:41 +00:00
|
|
|
return (
|
|
|
|
JitsiMeetJS.createLocalTracks({
|
|
|
|
cameraDeviceId: deviceId,
|
|
|
|
devices: [ type ],
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
firefox_fake_device:
|
2022-09-23 09:03:25 +00:00
|
|
|
window.config?.firefox_fake_device,
|
2021-02-02 00:20:39 +00:00
|
|
|
micDeviceId: deviceId,
|
2021-03-17 08:44:18 +00:00
|
|
|
timeout,
|
|
|
|
...additionalOptions
|
2017-05-04 15:20:41 +00:00
|
|
|
})
|
2022-09-23 09:03:25 +00:00
|
|
|
.then(([ jitsiLocalTrack ]: any[]) => jitsiLocalTrack));
|
2017-05-04 15:20:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 17:31:19 +00:00
|
|
|
/**
|
|
|
|
* Determines whether analytics is enabled in a specific redux {@code store}.
|
|
|
|
*
|
2022-09-23 09:03:25 +00:00
|
|
|
* @param {IStateful} stateful - The redux store, state, or
|
2017-09-25 17:31:19 +00:00
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {boolean} If analytics is enabled, {@code true}; {@code false},
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2022-09-23 09:03:25 +00:00
|
|
|
export function isAnalyticsEnabled(stateful: IStateful) {
|
2019-05-23 13:52:25 +00:00
|
|
|
const { disableThirdPartyRequests, analytics = {} } = toState(stateful)['features/base/config'];
|
|
|
|
|
2020-03-28 19:23:28 +00:00
|
|
|
return !(disableThirdPartyRequests || analytics.disabled);
|
2017-09-25 17:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 13:34:42 +00:00
|
|
|
/**
|
2017-11-27 22:08:12 +00:00
|
|
|
* Determines whether a specific {@link JitsiConferenceErrors} instance
|
|
|
|
* indicates a fatal {@link JitsiConference} error.
|
2017-11-09 13:34:42 +00:00
|
|
|
*
|
|
|
|
* FIXME Figure out the category of errors defined by the function and describe
|
|
|
|
* that category. I've currently named the category fatal because it appears to
|
|
|
|
* be used in the cases of unrecoverable errors that necessitate a reload.
|
|
|
|
*
|
2022-09-23 09:03:25 +00:00
|
|
|
* @param {Error|string} error - The {@code JitsiConferenceErrors} instance to
|
2017-11-27 22:08:12 +00:00
|
|
|
* categorize/classify or an {@link Error}-like object.
|
|
|
|
* @returns {boolean} If the specified {@code JitsiConferenceErrors} instance
|
|
|
|
* indicates a fatal {@code JitsiConference} error, {@code true}; otherwise,
|
|
|
|
* {@code false}.
|
2017-11-09 13:34:42 +00:00
|
|
|
*/
|
2022-09-23 09:03:25 +00:00
|
|
|
export function isFatalJitsiConferenceError(error: Error | string) {
|
2017-11-09 13:34:42 +00:00
|
|
|
if (typeof error !== 'string') {
|
|
|
|
error = error.name; // eslint-disable-line no-param-reassign
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
error === JitsiConferenceErrors.FOCUS_DISCONNECTED
|
|
|
|
|| error === JitsiConferenceErrors.FOCUS_LEFT
|
2020-05-07 11:59:37 +00:00
|
|
|
|| error === JitsiConferenceErrors.ICE_FAILED
|
2019-06-17 10:35:47 +00:00
|
|
|
|| error === JitsiConferenceErrors.OFFER_ANSWER_FAILED
|
2017-11-09 13:34:42 +00:00
|
|
|
|| error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
|
|
|
|
}
|
|
|
|
|
2017-02-19 00:42:11 +00:00
|
|
|
/**
|
2017-11-27 22:08:12 +00:00
|
|
|
* Determines whether a specific {@link JitsiConnectionErrors} instance
|
|
|
|
* indicates a fatal {@link JitsiConnection} error.
|
2017-02-19 00:42:11 +00:00
|
|
|
*
|
2017-11-09 13:34:42 +00:00
|
|
|
* FIXME Figure out the category of errors defined by the function and describe
|
2017-02-19 00:42:11 +00:00
|
|
|
* that category. I've currently named the category fatal because it appears to
|
|
|
|
* be used in the cases of unrecoverable errors that necessitate a reload.
|
|
|
|
*
|
2022-09-23 09:03:25 +00:00
|
|
|
* @param {Error|string} error - The {@code JitsiConnectionErrors} instance to
|
2017-11-27 22:08:12 +00:00
|
|
|
* categorize/classify or an {@link Error}-like object.
|
|
|
|
* @returns {boolean} If the specified {@code JitsiConnectionErrors} instance
|
|
|
|
* indicates a fatal {@code JitsiConnection} error, {@code true}; otherwise,
|
|
|
|
* {@code false}.
|
2017-02-19 00:42:11 +00:00
|
|
|
*/
|
2022-09-23 09:03:25 +00:00
|
|
|
export function isFatalJitsiConnectionError(error: Error | string) {
|
2017-09-24 21:51:43 +00:00
|
|
|
if (typeof error !== 'string') {
|
|
|
|
error = error.name; // eslint-disable-line no-param-reassign
|
|
|
|
}
|
|
|
|
|
2017-02-19 00:42:11 +00:00
|
|
|
return (
|
|
|
|
error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
|
|
|
|
|| error === JitsiConnectionErrors.OTHER_ERROR
|
|
|
|
|| error === JitsiConnectionErrors.SERVER_ERROR);
|
|
|
|
}
|