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.

actions.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import JitsiMeetJS from '../lib-jitsi-meet';
  2. import { updateSettings } from '../settings';
  3. import {
  4. SET_AUDIO_INPUT_DEVICE,
  5. SET_VIDEO_INPUT_DEVICE,
  6. UPDATE_DEVICE_LIST
  7. } from './actionTypes';
  8. import { getDevicesFromURL } from './functions';
  9. /**
  10. * Queries for connected A/V input and output devices and updates the redux
  11. * state of known devices.
  12. *
  13. * @returns {Function}
  14. */
  15. export function getAvailableDevices() {
  16. return dispatch => new Promise(resolve => {
  17. const { mediaDevices } = JitsiMeetJS;
  18. if (mediaDevices.isDeviceListAvailable()
  19. && mediaDevices.isDeviceChangeAvailable()) {
  20. mediaDevices.enumerateDevices(devices => {
  21. dispatch(updateDeviceList(devices));
  22. resolve(devices);
  23. });
  24. } else {
  25. resolve([]);
  26. }
  27. });
  28. }
  29. /**
  30. * Signals to update the currently used audio input device.
  31. *
  32. * @param {string} deviceId - The id of the new audio input device.
  33. * @returns {{
  34. * type: SET_AUDIO_INPUT_DEVICE,
  35. * deviceId: string
  36. * }}
  37. */
  38. export function setAudioInputDevice(deviceId) {
  39. return {
  40. type: SET_AUDIO_INPUT_DEVICE,
  41. deviceId
  42. };
  43. }
  44. /**
  45. * Signals to update the currently used video input device.
  46. *
  47. * @param {string} deviceId - The id of the new video input device.
  48. * @returns {{
  49. * type: SET_VIDEO_INPUT_DEVICE,
  50. * deviceId: string
  51. * }}
  52. */
  53. export function setVideoInputDevice(deviceId) {
  54. return {
  55. type: SET_VIDEO_INPUT_DEVICE,
  56. deviceId
  57. };
  58. }
  59. /**
  60. * Signals to update the list of known audio and video devices.
  61. *
  62. * @param {Array<MediaDeviceInfo>} devices - All known available audio input,
  63. * audio output, and video input devices.
  64. * @returns {{
  65. * type: UPDATE_DEVICE_LIST,
  66. * devices: Array<MediaDeviceInfo>
  67. * }}
  68. */
  69. export function updateDeviceList(devices) {
  70. return {
  71. type: UPDATE_DEVICE_LIST,
  72. devices
  73. };
  74. }
  75. /**
  76. * Configures the initial A/V devices before the conference has started.
  77. *
  78. * @returns {Function}
  79. */
  80. export function configureInitialDevices() {
  81. return (dispatch, getState) => new Promise(resolve => {
  82. const devices = getDevicesFromURL(getState());
  83. if (devices) {
  84. dispatch(updateSettings({
  85. ...devices
  86. }));
  87. resolve();
  88. }
  89. });
  90. }