Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.web.ts 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { IStateful } from '../base/app/types';
  2. import { createLocalTrack } from '../base/lib-jitsi-meet/functions';
  3. import { toState } from '../base/redux/functions';
  4. import { areKeyboardShortcutsEnabled, getKeyboardShortcutsHelpDescriptions } from '../keyboard-shortcuts/functions';
  5. import { isPrejoinPageVisible } from '../prejoin/functions';
  6. export * from './functions.any';
  7. /**
  8. * Returns a promise which resolves with a list of objects containing
  9. * all the video jitsiTracks and appropriate errors for the given device ids.
  10. *
  11. * @param {string[]} ids - The list of the camera ids for which to create tracks.
  12. * @param {number} [timeout] - A timeout for the createLocalTrack function call.
  13. *
  14. * @returns {Promise<Object[]>}
  15. */
  16. export function createLocalVideoTracks(ids: string[], timeout?: number) {
  17. return Promise.all(ids.map(deviceId => createLocalTrack('video', deviceId, timeout)
  18. .then((jitsiTrack: any) => {
  19. return {
  20. jitsiTrack,
  21. deviceId
  22. };
  23. })
  24. .catch(() => {
  25. return {
  26. jitsiTrack: null,
  27. deviceId,
  28. error: 'deviceSelection.previewUnavailable'
  29. };
  30. })));
  31. }
  32. /**
  33. * Returns a promise which resolves with a list of objects containing
  34. * the audio track and the corresponding audio device information.
  35. *
  36. * @param {Object[]} devices - A list of microphone devices.
  37. * @param {number} [timeout] - A timeout for the createLocalTrack function call.
  38. * @returns {Promise<{
  39. * deviceId: string,
  40. * hasError: boolean,
  41. * jitsiTrack: Object,
  42. * label: string
  43. * }[]>}
  44. */
  45. export function createLocalAudioTracks(devices: Array<{ deviceId: string; label: string; }>, timeout?: number) {
  46. return Promise.all(
  47. devices.map(async ({ deviceId, label }) => {
  48. let jitsiTrack = null;
  49. let hasError = false;
  50. try {
  51. jitsiTrack = await createLocalTrack('audio', deviceId, timeout);
  52. } catch (err) {
  53. hasError = true;
  54. }
  55. return {
  56. deviceId,
  57. hasError,
  58. jitsiTrack,
  59. label
  60. };
  61. }));
  62. }
  63. /**
  64. * Returns the properties for the "Shortcuts" tab from settings dialog from Redux
  65. * state.
  66. *
  67. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  68. * {@code getState} function to be used to retrieve the state.
  69. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the shortcuts dialog is displayed on the
  70. * welcome page or not.
  71. * @returns {Object} - The properties for the "Shortcuts" tab from settings
  72. * dialog.
  73. */
  74. export function getShortcutsTabProps(stateful: IStateful, isDisplayedOnWelcomePage?: boolean) {
  75. const state = toState(stateful);
  76. return {
  77. displayShortcuts: !isDisplayedOnWelcomePage && !isPrejoinPageVisible(state),
  78. keyboardShortcutsEnabled: areKeyboardShortcutsEnabled(state),
  79. keyboardShortcutsHelpDescriptions: getKeyboardShortcutsHelpDescriptions(state)
  80. };
  81. }