您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.any.ts 4.0KB

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