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 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // @flow
  2. import { parseURLParams } from '../config';
  3. import JitsiMeetJS from '../lib-jitsi-meet';
  4. import { updateSettings } from '../settings';
  5. /**
  6. * Get device id of the audio output device which is currently in use.
  7. * Empty string stands for default device.
  8. *
  9. * @returns {string}
  10. */
  11. export function getAudioOutputDeviceId() {
  12. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  13. }
  14. /**
  15. * Set device id of the audio output device which is currently in use.
  16. * Empty string stands for default device.
  17. *
  18. * @param {string} newId - New audio output device id.
  19. * @param {Function} dispatch - The Redux dispatch function.
  20. * @returns {Promise}
  21. */
  22. export function setAudioOutputDeviceId(
  23. newId: string = 'default',
  24. dispatch: Function): Promise<*> {
  25. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  26. .then(() =>
  27. dispatch(updateSettings({
  28. audioOutputDeviceId: newId
  29. })));
  30. }
  31. /**
  32. * Converts an array of media devices into an object organized by device kind.
  33. *
  34. * @param {Array<MediaDeviceInfo>} devices - Available media devices.
  35. * @private
  36. * @returns {Object} An object with the media devices split by type. The keys
  37. * are device type and the values are arrays with devices matching the device
  38. * type.
  39. */
  40. export function groupDevicesByKind(devices: Object[]): Object {
  41. return {
  42. audioInput: devices.filter(device => device.kind === 'audioinput'),
  43. audioOutput: devices.filter(device => device.kind === 'audiooutput'),
  44. videoInput: devices.filter(device => device.kind === 'videoinput')
  45. };
  46. }
  47. /**
  48. * Returns the devices set in the URL.
  49. *
  50. * @param {Object} state - The redux state.
  51. * @returns {Object|undefined}
  52. */
  53. export function getDevicesFromURL(state: Object) {
  54. const urlParams
  55. = parseURLParams(state['features/base/connection'].locationURL);
  56. const audioOutputDeviceId = urlParams['devices.audioOutput'];
  57. const cameraDeviceId = urlParams['devices.videoInput'];
  58. const micDeviceId = urlParams['devices.audioInput'];
  59. if (!audioOutputDeviceId && !cameraDeviceId && !micDeviceId) {
  60. return undefined;
  61. }
  62. const devices = {};
  63. audioOutputDeviceId && (devices.audioOutputDeviceId = audioOutputDeviceId);
  64. cameraDeviceId && (devices.cameraDeviceId = cameraDeviceId);
  65. micDeviceId && (devices.micDeviceId = micDeviceId);
  66. return devices;
  67. }