Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

middleware.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // @flow
  2. import React from 'react';
  3. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
  4. import { CONFERENCE_JOINED } from '../base/conference';
  5. import {
  6. formatDeviceLabel,
  7. setAudioInputDevice
  8. } from '../base/devices';
  9. import JitsiMeetJS, { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  10. import { MiddlewareRegistry } from '../base/redux';
  11. import { updateSettings } from '../base/settings';
  12. import { playSound, registerSound, unregisterSound } from '../base/sounds';
  13. import { hideNotification, showNotification } from '../notifications';
  14. import { setNoAudioSignalNotificationUid } from './actions';
  15. import DialInLink from './components/DialInLink';
  16. import { NO_AUDIO_SIGNAL_SOUND_ID } from './constants';
  17. import { NO_AUDIO_SIGNAL_SOUND_FILE } from './sounds';
  18. MiddlewareRegistry.register(store => next => async action => {
  19. const result = next(action);
  20. const { dispatch } = store;
  21. switch (action.type) {
  22. case APP_WILL_MOUNT:
  23. dispatch(registerSound(NO_AUDIO_SIGNAL_SOUND_ID, NO_AUDIO_SIGNAL_SOUND_FILE));
  24. break;
  25. case APP_WILL_UNMOUNT:
  26. dispatch(unregisterSound(NO_AUDIO_SIGNAL_SOUND_ID));
  27. break;
  28. case CONFERENCE_JOINED:
  29. _handleNoAudioSignalNotification(store, action);
  30. break;
  31. }
  32. return result;
  33. });
  34. /**
  35. * Handles the logic of displaying the no audio input detected notification as well as finding a valid device on the
  36. * system.
  37. *
  38. * @param {Store} store - The redux store in which the specified action is being dispatched.
  39. * @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is being dispatched in the specified redux
  40. * store.
  41. * @private
  42. * @returns {void}
  43. */
  44. async function _handleNoAudioSignalNotification({ dispatch, getState }, action) {
  45. const { conference } = action;
  46. conference.on(JitsiConferenceEvents.AUDIO_INPUT_STATE_CHANGE, hasAudioInput => {
  47. const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
  48. // In case the notification is displayed but the conference detected audio input signal we hide it.
  49. if (noAudioSignalNotificationUid && hasAudioInput) {
  50. dispatch(hideNotification(noAudioSignalNotificationUid));
  51. dispatch(setNoAudioSignalNotificationUid());
  52. }
  53. });
  54. conference.on(JitsiConferenceEvents.NO_AUDIO_INPUT, async () => {
  55. const { noSrcDataNotificationUid } = getState()['features/base/no-src-data'];
  56. // In case the 'no data detected from source' notification was already shown, we prevent the
  57. // no audio signal notification as it's redundant i.e. it's clear that the users microphone is
  58. // muted from system settings.
  59. if (noSrcDataNotificationUid) {
  60. return;
  61. }
  62. const activeDevice = await JitsiMeetJS.getActiveAudioDevice();
  63. // In case there is a previous notification displayed just hide it.
  64. const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
  65. if (noAudioSignalNotificationUid) {
  66. dispatch(hideNotification(noAudioSignalNotificationUid));
  67. dispatch(setNoAudioSignalNotificationUid());
  68. }
  69. let descriptionKey = 'toolbar.noAudioSignalDesc';
  70. let customActionNameKey;
  71. let customActionHandler;
  72. // In case the detector picked up a device show a notification with a device suggestion
  73. if (activeDevice.deviceLabel !== '') {
  74. descriptionKey = 'toolbar.noAudioSignalDescSuggestion';
  75. // Preferably the label should be passed as an argument paired with a i18next string, however
  76. // at the point of the implementation the showNotification function only supports doing that for
  77. // the description.
  78. // TODO Add support for arguments to showNotification title and customAction strings.
  79. customActionNameKey = `Switch to ${formatDeviceLabel(activeDevice.deviceLabel)}`;
  80. customActionHandler = () => {
  81. // Select device callback
  82. dispatch(
  83. updateSettings({
  84. userSelectedMicDeviceId: activeDevice.deviceId,
  85. userSelectedMicDeviceLabel: activeDevice.deviceLabel
  86. })
  87. );
  88. dispatch(setAudioInputDevice(activeDevice.deviceId));
  89. };
  90. }
  91. const notification = await dispatch(showNotification({
  92. titleKey: 'toolbar.noAudioSignalTitle',
  93. description: <DialInLink />,
  94. descriptionKey,
  95. customActionNameKey,
  96. customActionHandler
  97. }));
  98. dispatch(playSound(NO_AUDIO_SIGNAL_SOUND_ID));
  99. if (notification) {
  100. // Store the current notification uid so we can check for this state and hide it in case
  101. // a new track was added, thus changing the context of the notification
  102. dispatch(setNoAudioSignalNotificationUid(notification.uid));
  103. }
  104. });
  105. }