Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.any.ts 4.0KB

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