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.js 3.6KB

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