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

functions.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // @flow
  2. import Logger from 'jitsi-meet-logger';
  3. const logger = Logger.getLogger(__filename);
  4. /**
  5. * Returns Promise that resolves with result an list of available devices.
  6. *
  7. * @param {Transport} transport - The @code{Transport} instance responsible for
  8. * the external communication.
  9. * @returns {Promise}
  10. */
  11. export function getAvailableDevices(transport: Object) {
  12. return transport.sendRequest({
  13. type: 'devices',
  14. name: 'getAvailableDevices'
  15. }).catch(e => {
  16. logger.error(e);
  17. return {};
  18. });
  19. }
  20. /**
  21. * Returns Promise that resolves with current selected devices.
  22. *
  23. * @param {Transport} transport - The @code{Transport} instance responsible for
  24. * the external communication.
  25. * @returns {Promise}
  26. */
  27. export function getCurrentDevices(transport: Object) {
  28. return transport.sendRequest({
  29. type: 'devices',
  30. name: 'getCurrentDevices'
  31. }).catch(e => {
  32. logger.error(e);
  33. return {};
  34. });
  35. }
  36. /**
  37. * Returns Promise that resolves with true if the device change is available
  38. * and with false if not.
  39. *
  40. * @param {Transport} transport - The @code{Transport} instance responsible for
  41. * the external communication.
  42. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  43. * Default - 'input'.
  44. * @returns {Promise}
  45. */
  46. export function isDeviceChangeAvailable(transport: Object, deviceType: string) {
  47. return transport.sendRequest({
  48. deviceType,
  49. type: 'devices',
  50. name: 'isDeviceChangeAvailable'
  51. }).catch(e => {
  52. logger.error(e);
  53. return false;
  54. });
  55. }
  56. /**
  57. * Returns Promise that resolves with true if the device list is available
  58. * and with false if not.
  59. *
  60. * @param {Transport} transport - The @code{Transport} instance responsible for
  61. * the external communication.
  62. * @returns {Promise}
  63. */
  64. export function isDeviceListAvailable(transport: Object) {
  65. return transport.sendRequest({
  66. type: 'devices',
  67. name: 'isDeviceListAvailable'
  68. }).catch(e => {
  69. logger.error(e);
  70. return false;
  71. });
  72. }
  73. /**
  74. * Returns Promise that resolves with true if the device list is available
  75. * and with false if not.
  76. *
  77. * @param {Transport} transport - The @code{Transport} instance responsible for
  78. * the external communication.
  79. * @returns {Promise}
  80. */
  81. export function isMultipleAudioInputSupported(transport: Object) {
  82. return transport.sendRequest({
  83. type: 'devices',
  84. name: 'isMultipleAudioInputSupported'
  85. }).catch(e => {
  86. logger.error(e);
  87. return false;
  88. });
  89. }
  90. /**
  91. * Sets the audio input device to the one with the id that is passed.
  92. *
  93. * @param {Transport} transport - The @code{Transport} instance responsible for
  94. * the external communication.
  95. * @param {string} id - The id of the new device.
  96. * @returns {Promise}
  97. */
  98. export function setAudioInputDevice(transport: Object, id: string) {
  99. return _setDevice(transport, {
  100. id,
  101. kind: 'audioinput'
  102. });
  103. }
  104. /**
  105. * Sets the audio output device to the one with the id that is passed.
  106. *
  107. * @param {Transport} transport - The @code{Transport} instance responsible for
  108. * the external communication.
  109. * @param {string} id - The id of the new device.
  110. * @returns {Promise}
  111. */
  112. export function setAudioOutputDevice(transport: Object, id: string) {
  113. return _setDevice(transport, {
  114. id,
  115. kind: 'audiooutput'
  116. });
  117. }
  118. /**
  119. * Sets the currently used device to the one that is passed.
  120. *
  121. * @param {Transport} transport - The @code{Transport} instance responsible for
  122. * the external communication.
  123. * @param {Object} device - The new device to be used.
  124. * @returns {Promise}
  125. */
  126. function _setDevice(transport: Object, device) {
  127. return transport.sendRequest({
  128. type: 'devices',
  129. name: 'setDevice',
  130. device
  131. });
  132. }
  133. /**
  134. * Sets the video input device to the one with the id that is passed.
  135. *
  136. * @param {Transport} transport - The @code{Transport} instance responsible for
  137. * the external communication.
  138. * @param {string} id - The id of the new device.
  139. * @returns {Promise}
  140. */
  141. export function setVideoInputDevice(transport: Object, id: string) {
  142. return _setDevice(transport, {
  143. id,
  144. kind: 'videoinput'
  145. });
  146. }