Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

functions.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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'].devices,
  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}
  51. */
  52. export function processRequest( // eslint-disable-line max-params
  53. dispatch: Dispatch<any>,
  54. getState: Function,
  55. request: Object,
  56. responseCallback: Function) {
  57. if (request.type === 'devices') {
  58. const state = getState();
  59. const settings = state['features/base/settings'];
  60. const { conference } = state['features/base/conference'];
  61. let result = true;
  62. switch (request.name) {
  63. case 'isDeviceListAvailable':
  64. responseCallback(JitsiMeetJS.mediaDevices.isDeviceListAvailable());
  65. break;
  66. case 'isDeviceChangeAvailable':
  67. responseCallback(
  68. JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(
  69. request.deviceType));
  70. break;
  71. case 'isMultipleAudioInputSupported':
  72. responseCallback(JitsiMeetJS.isMultipleAudioInputSupported());
  73. break;
  74. case 'getCurrentDevices':
  75. dispatch(getAvailableDevices()).then(devices => {
  76. if (areDeviceLabelsInitialized(state)) {
  77. let audioInput, audioOutput, videoInput;
  78. const audioOutputDeviceId = getAudioOutputDeviceId();
  79. const { cameraDeviceId, micDeviceId } = settings;
  80. devices.forEach(device => {
  81. const { deviceId } = device;
  82. switch (deviceId) {
  83. case micDeviceId:
  84. audioInput = device;
  85. break;
  86. case audioOutputDeviceId:
  87. audioOutput = device;
  88. break;
  89. case cameraDeviceId:
  90. videoInput = device;
  91. break;
  92. }
  93. });
  94. responseCallback({
  95. audioInput,
  96. audioOutput,
  97. videoInput
  98. });
  99. } else {
  100. // The labels are not available if the A/V permissions are
  101. // not yet granted.
  102. dispatch(addPendingDeviceRequest({
  103. type: 'devices',
  104. name: 'getCurrentDevices',
  105. responseCallback
  106. }));
  107. }
  108. });
  109. break;
  110. case 'getAvailableDevices':
  111. dispatch(getAvailableDevices()).then(devices => {
  112. if (areDeviceLabelsInitialized(state)) {
  113. responseCallback(groupDevicesByKind(devices));
  114. } else {
  115. // The labels are not available if the A/V permissions are
  116. // not yet granted.
  117. dispatch(addPendingDeviceRequest({
  118. type: 'devices',
  119. name: 'getAvailableDevices',
  120. responseCallback
  121. }));
  122. }
  123. });
  124. break;
  125. case 'setDevice': {
  126. const { device } = request;
  127. if (!conference) {
  128. dispatch(addPendingDeviceRequest({
  129. type: 'devices',
  130. name: 'setDevice',
  131. device,
  132. responseCallback
  133. }));
  134. return true;
  135. }
  136. const { label, id } = device;
  137. const deviceId = label ? getDeviceIdByLabel(state, device.label) : id;
  138. if (deviceId) {
  139. switch (device.kind) {
  140. case 'audioinput': {
  141. dispatch(setAudioInputDevice(deviceId));
  142. break;
  143. }
  144. case 'audiooutput':
  145. setAudioOutputDeviceId(deviceId, dispatch);
  146. break;
  147. case 'videoinput':
  148. dispatch(setVideoInputDevice(deviceId));
  149. break;
  150. default:
  151. result = false;
  152. }
  153. } else {
  154. result = false;
  155. }
  156. responseCallback(result);
  157. break;
  158. }
  159. default:
  160. return false;
  161. }
  162. return true;
  163. }
  164. return false;
  165. }