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

functions.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. addPendingDeviceRequest,
  5. areDeviceLabelsInitialized,
  6. getAudioOutputDeviceId,
  7. getAvailableDevices,
  8. getDeviceIdByLabel,
  9. groupDevicesByKind,
  10. setAudioInputDevice,
  11. setAudioOutputDeviceId,
  12. setVideoInputDevice
  13. } from '../base/devices';
  14. import JitsiMeetJS from '../base/lib-jitsi-meet';
  15. import { toState } from '../base/redux';
  16. /**
  17. * Returns the properties for the device selection dialog from Redux state.
  18. *
  19. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  20. * {@code getState} function to be used to retrieve the state.
  21. * @returns {Object} - The properties for the device selection dialog.
  22. */
  23. export function getDeviceSelectionDialogProps(stateful: Object | Function) {
  24. const state = toState(stateful);
  25. const settings = state['features/base/settings'];
  26. return {
  27. availableDevices: state['features/base/devices'].availableDevices,
  28. disableAudioInputChange:
  29. !JitsiMeetJS.isMultipleAudioInputSupported(),
  30. disableDeviceChange:
  31. !JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(),
  32. hideAudioInputPreview:
  33. !JitsiMeetJS.isCollectingLocalStats(),
  34. hideAudioOutputSelect: !JitsiMeetJS.mediaDevices
  35. .isDeviceChangeAvailable('output'),
  36. selectedAudioInputId: settings.micDeviceId,
  37. selectedAudioOutputId: getAudioOutputDeviceId(),
  38. selectedVideoInputId: settings.cameraDeviceId
  39. };
  40. }
  41. /**
  42. * Processes device requests from external applications.
  43. *
  44. * @param {Dispatch} dispatch - The redux {@code dispatch} function.
  45. * @param {Function} getState - The redux function that gets/retrieves the redux
  46. * state.
  47. * @param {Object} request - The request to be processed.
  48. * @param {Function} responseCallback - The callback that will send the
  49. * response.
  50. * @returns {boolean} - True if the request has been processed and false otherwise.
  51. */
  52. export function processExternalDeviceRequest( // eslint-disable-line max-params
  53. dispatch: Dispatch<any>,
  54. getState: Function,
  55. request: Object,
  56. responseCallback: Function) {
  57. if (request.type !== 'devices') {
  58. return false;
  59. }
  60. const state = getState();
  61. const settings = state['features/base/settings'];
  62. const { conference } = state['features/base/conference'];
  63. let result = true;
  64. switch (request.name) {
  65. case 'isDeviceListAvailable':
  66. responseCallback(JitsiMeetJS.mediaDevices.isDeviceListAvailable());
  67. break;
  68. case 'isDeviceChangeAvailable':
  69. responseCallback(
  70. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(
  71. request.deviceType));
  72. break;
  73. case 'isMultipleAudioInputSupported':
  74. responseCallback(JitsiMeetJS.isMultipleAudioInputSupported());
  75. break;
  76. case 'getCurrentDevices':
  77. dispatch(getAvailableDevices()).then(devices => {
  78. if (areDeviceLabelsInitialized(state)) {
  79. let audioInput, audioOutput, videoInput;
  80. const audioOutputDeviceId = getAudioOutputDeviceId();
  81. const { cameraDeviceId, micDeviceId } = settings;
  82. devices.forEach(device => {
  83. const { deviceId } = device;
  84. switch (deviceId) {
  85. case micDeviceId:
  86. audioInput = device;
  87. break;
  88. case audioOutputDeviceId:
  89. audioOutput = device;
  90. break;
  91. case cameraDeviceId:
  92. videoInput = device;
  93. break;
  94. }
  95. });
  96. responseCallback({
  97. audioInput,
  98. audioOutput,
  99. videoInput
  100. });
  101. } else {
  102. // The labels are not available if the A/V permissions are
  103. // not yet granted.
  104. dispatch(addPendingDeviceRequest({
  105. type: 'devices',
  106. name: 'getCurrentDevices',
  107. responseCallback
  108. }));
  109. }
  110. });
  111. break;
  112. case 'getAvailableDevices':
  113. dispatch(getAvailableDevices()).then(devices => {
  114. if (areDeviceLabelsInitialized(state)) {
  115. responseCallback(groupDevicesByKind(devices));
  116. } else {
  117. // The labels are not available if the A/V permissions are
  118. // not yet granted.
  119. dispatch(addPendingDeviceRequest({
  120. type: 'devices',
  121. name: 'getAvailableDevices',
  122. responseCallback
  123. }));
  124. }
  125. });
  126. break;
  127. case 'setDevice': {
  128. const { device } = request;
  129. if (!conference) {
  130. dispatch(addPendingDeviceRequest({
  131. type: 'devices',
  132. name: 'setDevice',
  133. device,
  134. responseCallback
  135. }));
  136. return true;
  137. }
  138. const { label, id } = device;
  139. const deviceId = label ? getDeviceIdByLabel(state, device.label) : id;
  140. if (deviceId) {
  141. switch (device.kind) {
  142. case 'audioinput': {
  143. dispatch(setAudioInputDevice(deviceId));
  144. break;
  145. }
  146. case 'audiooutput':
  147. setAudioOutputDeviceId(deviceId, dispatch);
  148. break;
  149. case 'videoinput':
  150. dispatch(setVideoInputDevice(deviceId));
  151. break;
  152. default:
  153. result = false;
  154. }
  155. } else {
  156. result = false;
  157. }
  158. responseCallback(result);
  159. break;
  160. }
  161. default:
  162. return false;
  163. }
  164. return true;
  165. }