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.8KB

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