您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // @flow
  2. import { parseURLParams } from '../config';
  3. import JitsiMeetJS from '../lib-jitsi-meet';
  4. import { updateSettings } from '../settings';
  5. declare var APP: Object;
  6. /**
  7. * Detects the use case when the labels are not available if the A/V permissions
  8. * are not yet granted.
  9. *
  10. * @param {Object} state - The redux state.
  11. * @returns {boolean} - True if the labels are already initialized and false
  12. * otherwise.
  13. */
  14. export function areDeviceLabelsInitialized(state: Object) {
  15. if (APP.conference._localTracksInitialized) {
  16. return true;
  17. }
  18. for (const type of [ 'audioInput', 'audioOutput', 'videoInput' ]) {
  19. if (state['features/base/devices'][type].find(d => Boolean(d.label))) {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. /**
  26. * Get device id of the audio output device which is currently in use.
  27. * Empty string stands for default device.
  28. *
  29. * @returns {string}
  30. */
  31. export function getAudioOutputDeviceId() {
  32. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  33. }
  34. /**
  35. * Finds a device with a label that matches the passed label and returns its id.
  36. *
  37. * @param {Object} state - The redux state.
  38. * @param {string} label - The label.
  39. * @returns {string|undefined}
  40. */
  41. export function getDeviceIdByLabel(state: Object, label: string) {
  42. const types = [ 'audioInput', 'audioOutput', 'videoInput' ];
  43. for (const type of types) {
  44. const device
  45. = state['features/base/devices'][type].find(d => d.label === label);
  46. if (device) {
  47. return device.deviceId;
  48. }
  49. }
  50. }
  51. /**
  52. * Returns the devices set in the URL.
  53. *
  54. * @param {Object} state - The redux state.
  55. * @returns {Object|undefined}
  56. */
  57. export function getDevicesFromURL(state: Object) {
  58. const urlParams
  59. = parseURLParams(state['features/base/connection'].locationURL);
  60. const audioOutput = urlParams['devices.audioOutput'];
  61. const videoInput = urlParams['devices.videoInput'];
  62. const audioInput = urlParams['devices.audioInput'];
  63. if (!audioOutput && !videoInput && !audioInput) {
  64. return undefined;
  65. }
  66. const devices = {};
  67. audioOutput && (devices.audioOutput = audioOutput);
  68. videoInput && (devices.videoInput = videoInput);
  69. audioInput && (devices.audioInput = audioInput);
  70. return devices;
  71. }
  72. /**
  73. * Converts an array of media devices into an object organized by device kind.
  74. *
  75. * @param {Array<MediaDeviceInfo>} devices - Available media devices.
  76. * @private
  77. * @returns {Object} An object with the media devices split by type. The keys
  78. * are device type and the values are arrays with devices matching the device
  79. * type.
  80. */
  81. export function groupDevicesByKind(devices: Object[]): Object {
  82. return {
  83. audioInput: devices.filter(device => device.kind === 'audioinput'),
  84. audioOutput: devices.filter(device => device.kind === 'audiooutput'),
  85. videoInput: devices.filter(device => device.kind === 'videoinput')
  86. };
  87. }
  88. /**
  89. * Set device id of the audio output device which is currently in use.
  90. * Empty string stands for default device.
  91. *
  92. * @param {string} newId - New audio output device id.
  93. * @param {Function} dispatch - The Redux dispatch function.
  94. * @returns {Promise}
  95. */
  96. export function setAudioOutputDeviceId(
  97. newId: string = 'default',
  98. dispatch: Function): Promise<*> {
  99. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  100. .then(() =>
  101. dispatch(updateSettings({
  102. audioOutputDeviceId: newId
  103. })));
  104. }