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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. micDeviceId: deviceId,
  25. timeout,
  26. ...additionalOptions
  27. })
  28. .then(([ jitsiLocalTrack ]: any[]) => jitsiLocalTrack));
  29. }
  30. /**
  31. * Determines whether analytics is enabled in a specific redux {@code store}.
  32. *
  33. * @param {IStateful} stateful - The redux store, state, or
  34. * {@code getState} function.
  35. * @returns {boolean} If analytics is enabled, {@code true}; {@code false},
  36. * otherwise.
  37. */
  38. export function isAnalyticsEnabled(stateful: IStateful) {
  39. const { disableThirdPartyRequests, analytics = {} } = toState(stateful)['features/base/config'];
  40. return !(disableThirdPartyRequests || analytics.disabled);
  41. }
  42. /**
  43. * Determines whether a specific {@link JitsiConferenceErrors} instance
  44. * indicates a fatal {@link JitsiConference} error.
  45. *
  46. * FIXME Figure out the category of errors defined by the function and describe
  47. * that category. I've currently named the category fatal because it appears to
  48. * be used in the cases of unrecoverable errors that necessitate a reload.
  49. *
  50. * @param {Error|string} error - The {@code JitsiConferenceErrors} instance to
  51. * categorize/classify or an {@link Error}-like object.
  52. * @returns {boolean} If the specified {@code JitsiConferenceErrors} instance
  53. * indicates a fatal {@code JitsiConference} error, {@code true}; otherwise,
  54. * {@code false}.
  55. */
  56. export function isFatalJitsiConferenceError(error: Error | string) {
  57. if (typeof error !== 'string') {
  58. error = error.name; // eslint-disable-line no-param-reassign
  59. }
  60. return (
  61. error === JitsiConferenceErrors.FOCUS_DISCONNECTED
  62. || error === JitsiConferenceErrors.FOCUS_LEFT
  63. || error === JitsiConferenceErrors.ICE_FAILED
  64. || error === JitsiConferenceErrors.OFFER_ANSWER_FAILED
  65. || error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  66. }
  67. /**
  68. * Determines whether a specific {@link JitsiConnectionErrors} instance
  69. * indicates a fatal {@link JitsiConnection} error.
  70. *
  71. * FIXME Figure out the category of errors defined by the function and describe
  72. * that category. I've currently named the category fatal because it appears to
  73. * be used in the cases of unrecoverable errors that necessitate a reload.
  74. *
  75. * @param {Error|string} error - The {@code JitsiConnectionErrors} instance to
  76. * categorize/classify or an {@link Error}-like object.
  77. * @returns {boolean} If the specified {@code JitsiConnectionErrors} instance
  78. * indicates a fatal {@code JitsiConnection} error, {@code true}; otherwise,
  79. * {@code false}.
  80. */
  81. export function isFatalJitsiConnectionError(error: Error | string | ConnectionFailedError) {
  82. if (typeof error !== 'string') {
  83. error = error.name; // eslint-disable-line no-param-reassign
  84. }
  85. return (
  86. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR
  87. || error === JitsiConnectionErrors.OTHER_ERROR
  88. || error === JitsiConnectionErrors.SERVER_ERROR);
  89. }