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.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // @flow
  2. import {
  3. getAudioOutputDeviceId,
  4. getAvailableDevices,
  5. groupDevicesByKind,
  6. setAudioInputDevice,
  7. setAudioOutputDeviceId,
  8. setVideoInputDevice
  9. } from '../base/devices';
  10. import JitsiMeetJS from '../base/lib-jitsi-meet';
  11. import { toState } from '../base/redux';
  12. /**
  13. * Returns the properties for the device selection dialog from Redux state.
  14. *
  15. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  16. * {@code getState} function to be used to retrieve the state.
  17. * @returns {Object} - The properties for the device selection dialog.
  18. */
  19. export function getDeviceSelectionDialogProps(stateful: Object | Function) {
  20. const state = toState(stateful);
  21. const settings = state['features/base/settings'];
  22. return {
  23. availableDevices: state['features/base/devices'],
  24. disableAudioInputChange:
  25. !JitsiMeetJS.isMultipleAudioInputSupported(),
  26. disableDeviceChange:
  27. !JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(),
  28. hideAudioInputPreview:
  29. !JitsiMeetJS.isCollectingLocalStats(),
  30. hideAudioOutputSelect: !JitsiMeetJS.mediaDevices
  31. .isDeviceChangeAvailable('output'),
  32. selectedAudioInputId: settings.micDeviceId,
  33. selectedAudioOutputId: getAudioOutputDeviceId(),
  34. selectedVideoInputId: settings.cameraDeviceId
  35. };
  36. }
  37. /**
  38. * Processes device requests from external applications.
  39. *
  40. * @param {Dispatch} dispatch - The redux {@code dispatch} function.
  41. * @param {Function} getState - The redux function that gets/retrieves the redux
  42. * state.
  43. * @param {Object} request - The request to be processed.
  44. * @param {Function} responseCallback - The callback that will send the
  45. * response.
  46. * @returns {boolean}
  47. */
  48. export function processRequest( // eslint-disable-line max-params
  49. dispatch: Dispatch<*>,
  50. getState: Function,
  51. request: Object,
  52. responseCallback: Function) {
  53. if (request.type === 'devices') {
  54. const state = getState();
  55. const settings = state['features/base/settings'];
  56. switch (request.name) {
  57. case 'isDeviceListAvailable':
  58. responseCallback(JitsiMeetJS.mediaDevices.isDeviceListAvailable());
  59. break;
  60. case 'isDeviceChangeAvailable':
  61. responseCallback(
  62. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(
  63. request.deviceType));
  64. break;
  65. case 'isMultipleAudioInputSupported':
  66. responseCallback(JitsiMeetJS.isMultipleAudioInputSupported());
  67. break;
  68. case 'getCurrentDevices':
  69. responseCallback({
  70. audioInput: settings.micDeviceId,
  71. audioOutput: getAudioOutputDeviceId(),
  72. videoInput: settings.cameraDeviceId
  73. });
  74. break;
  75. case 'getAvailableDevices':
  76. dispatch(getAvailableDevices()).then(
  77. devices => responseCallback(groupDevicesByKind(devices)));
  78. break;
  79. case 'setDevice': {
  80. const { device } = request;
  81. switch (device.kind) {
  82. case 'audioinput':
  83. dispatch(setAudioInputDevice(device.id));
  84. break;
  85. case 'audiooutput':
  86. setAudioOutputDeviceId(device.id, dispatch);
  87. break;
  88. case 'videoinput':
  89. dispatch(setVideoInputDevice(device.id));
  90. break;
  91. default:
  92. responseCallback(false);
  93. }
  94. responseCallback(true);
  95. break;
  96. }
  97. default:
  98. return false;
  99. }
  100. return true;
  101. }
  102. return false;
  103. }