You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.any.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { IStateful } from '../app/types';
  2. import { ConnectionFailedError } from '../connection/types';
  3. import { toState } from '../redux/functions';
  4. import JitsiMeetJS from './_';
  5. const JitsiConferenceErrors = JitsiMeetJS.errors.conference;
  6. const JitsiConnectionErrors = JitsiMeetJS.errors.connection;
  7. /**
  8. * Creates a {@link JitsiLocalTrack} model from the given device id.
  9. *
  10. * @param {string} type - The media type of track being created. Expected values
  11. * are "video" or "audio".
  12. * @param {string} deviceId - The id of the target media source.
  13. * @param {number} [timeout] - A timeout for the JitsiMeetJS.createLocalTracks function call.
  14. * @param {Object} additionalOptions - Extra options to be passed to lib-jitsi-meet's {@code createLocalTracks}.
  15. *
  16. * @returns {Promise<JitsiLocalTrack>}
  17. */
  18. export function createLocalTrack(type: string, deviceId: string | null, timeout?: number | null,
  19. additionalOptions?: Object) {
  20. return (
  21. JitsiMeetJS.createLocalTracks({
  22. cameraDeviceId: deviceId,
  23. devices: [ type ],
  24. // eslint-disable-next-line camelcase
  25. firefox_fake_device:
  26. window.config?.firefox_fake_device,
  27. micDeviceId: deviceId,
  28. timeout,
  29. ...additionalOptions
  30. })
  31. .then(([ jitsiLocalTrack ]: any[]) => jitsiLocalTrack));
  32. }
  33. /**
  34. * Determines whether analytics is enabled in a specific redux {@code store}.
  35. *
  36. * @param {IStateful} stateful - The redux store, state, or
  37. * {@code getState} function.
  38. * @returns {boolean} If analytics is enabled, {@code true}; {@code false},
  39. * otherwise.
  40. */
  41. export function isAnalyticsEnabled(stateful: IStateful) {
  42. const { disableThirdPartyRequests, analytics = {} } = toState(stateful)['features/base/config'];
  43. return !(disableThirdPartyRequests || analytics.disabled);
  44. }
  45. /**
  46. * Determines whether a specific {@link JitsiConferenceErrors} instance
  47. * indicates a fatal {@link JitsiConference} error.
  48. *
  49. * FIXME Figure out the category of errors defined by the function and describe
  50. * that category. I've currently named the category fatal because it appears to
  51. * be used in the cases of unrecoverable errors that necessitate a reload.
  52. *
  53. * @param {Error|string} error - The {@code JitsiConferenceErrors} instance to
  54. * categorize/classify or an {@link Error}-like object.
  55. * @returns {boolean} If the specified {@code JitsiConferenceErrors} instance
  56. * indicates a fatal {@code JitsiConference} error, {@code true}; otherwise,
  57. * {@code false}.
  58. */
  59. export function isFatalJitsiConferenceError(error: Error | string) {
  60. if (typeof error !== 'string') {
  61. error = error.name; // eslint-disable-line no-param-reassign
  62. }
  63. return (
  64. error === JitsiConferenceErrors.FOCUS_DISCONNECTED
  65. || error === JitsiConferenceErrors.FOCUS_LEFT
  66. || error === JitsiConferenceErrors.ICE_FAILED
  67. || error === JitsiConferenceErrors.OFFER_ANSWER_FAILED
  68. || error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  69. }
  70. /**
  71. * Determines whether a specific {@link JitsiConnectionErrors} instance
  72. * indicates a fatal {@link JitsiConnection} error.
  73. *
  74. * FIXME Figure out the category of errors defined by the function and describe
  75. * that category. I've currently named the category fatal because it appears to
  76. * be used in the cases of unrecoverable errors that necessitate a reload.
  77. *
  78. * @param {Error|string} error - The {@code JitsiConnectionErrors} instance to
  79. * categorize/classify or an {@link Error}-like object.
  80. * @returns {boolean} If the specified {@code JitsiConnectionErrors} instance
  81. * indicates a fatal {@code JitsiConnection} error, {@code true}; otherwise,
  82. * {@code false}.
  83. */
  84. export function isFatalJitsiConnectionError(error: Error | string | ConnectionFailedError) {
  85. if (typeof error !== 'string') {
  86. error = error.name; // eslint-disable-line no-param-reassign
  87. }
  88. return (
  89. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
  90. || error === JitsiConnectionErrors.OTHER_ERROR
  91. || error === JitsiConnectionErrors.SERVER_ERROR);
  92. }