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.5KB

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