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

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