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

functions.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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'].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'].devices[type]
  46. .find(d => d.label === label);
  47. if (device) {
  48. return device.deviceId;
  49. }
  50. }
  51. }
  52. /**
  53. * Returns the devices set in the URL.
  54. *
  55. * @param {Object} state - The redux state.
  56. * @returns {Object|undefined}
  57. */
  58. export function getDevicesFromURL(state: Object) {
  59. const urlParams
  60. = parseURLParams(state['features/base/connection'].locationURL);
  61. const audioOutput = urlParams['devices.audioOutput'];
  62. const videoInput = urlParams['devices.videoInput'];
  63. const audioInput = urlParams['devices.audioInput'];
  64. if (!audioOutput && !videoInput && !audioInput) {
  65. return undefined;
  66. }
  67. const devices = {};
  68. audioOutput && (devices.audioOutput = audioOutput);
  69. videoInput && (devices.videoInput = videoInput);
  70. audioInput && (devices.audioInput = audioInput);
  71. return devices;
  72. }
  73. /**
  74. * Converts an array of media devices into an object organized by device kind.
  75. *
  76. * @param {Array<MediaDeviceInfo>} devices - Available media devices.
  77. * @private
  78. * @returns {Object} An object with the media devices split by type. The keys
  79. * are device type and the values are arrays with devices matching the device
  80. * type.
  81. */
  82. export function groupDevicesByKind(devices: Object[]): Object {
  83. return {
  84. audioInput: devices.filter(device => device.kind === 'audioinput'),
  85. audioOutput: devices.filter(device => device.kind === 'audiooutput'),
  86. videoInput: devices.filter(device => device.kind === 'videoinput')
  87. };
  88. }
  89. /**
  90. * Set device id of the audio output device which is currently in use.
  91. * Empty string stands for default device.
  92. *
  93. * @param {string} newId - New audio output device id.
  94. * @param {Function} dispatch - The Redux dispatch function.
  95. * @returns {Promise}
  96. */
  97. export function setAudioOutputDeviceId(
  98. newId: string = 'default',
  99. dispatch: Function): Promise<*> {
  100. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  101. .then(() =>
  102. dispatch(updateSettings({
  103. audioOutputDeviceId: newId
  104. })));
  105. }