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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. });
  52. }
  53. /**
  54. * Returns Promise that resolves with true if the device list is available
  55. * and with false if not.
  56. *
  57. * @param {Transport} transport - The @code{Transport} instance responsible for
  58. * the external communication.
  59. * @returns {Promise}
  60. */
  61. export function isDeviceListAvailable(transport: Object) {
  62. return transport.sendRequest({
  63. type: 'devices',
  64. name: 'isDeviceListAvailable'
  65. });
  66. }
  67. /**
  68. * Returns Promise that resolves with true if multiple audio input is supported
  69. * and with false if not.
  70. *
  71. * @param {Transport} transport - The @code{Transport} instance responsible for
  72. * the external communication.
  73. * @returns {Promise}
  74. */
  75. export function isMultipleAudioInputSupported(transport: Object) {
  76. return transport.sendRequest({
  77. type: 'devices',
  78. name: 'isMultipleAudioInputSupported'
  79. });
  80. }
  81. /**
  82. * Sets the audio input device to the one with the label or id that is passed.
  83. *
  84. * @param {Transport} transport - The @code{Transport} instance responsible for
  85. * the external communication.
  86. * @param {string} label - The label of the new device.
  87. * @param {string} id - The id of the new device.
  88. * @returns {Promise}
  89. */
  90. export function setAudioInputDevice(transport: Object, label: string, id: string) {
  91. return _setDevice(transport, {
  92. id,
  93. kind: 'audioinput',
  94. label
  95. });
  96. }
  97. /**
  98. * Sets the audio output device to the one with the label or id that is passed.
  99. *
  100. * @param {Transport} transport - The @code{Transport} instance responsible for
  101. * the external communication.
  102. * @param {string} label - The label of the new device.
  103. * @param {string} id - The id of the new device.
  104. * @returns {Promise}
  105. */
  106. export function setAudioOutputDevice(transport: Object, label: string, id: string) {
  107. return _setDevice(transport, {
  108. id,
  109. kind: 'audiooutput',
  110. label
  111. });
  112. }
  113. /**
  114. * Sets the currently used device to the one that is passed.
  115. *
  116. * @param {Transport} transport - The @code{Transport} instance responsible for
  117. * the external communication.
  118. * @param {Object} device - The new device to be used.
  119. * @returns {Promise}
  120. */
  121. function _setDevice(transport: Object, device) {
  122. return transport.sendRequest({
  123. type: 'devices',
  124. name: 'setDevice',
  125. device
  126. });
  127. }
  128. /**
  129. * Sets the video input device to the one with the label or id that is passed.
  130. *
  131. * @param {Transport} transport - The @code{Transport} instance responsible for
  132. * the external communication.
  133. * @param {string} label - The label of the new device.
  134. * @param {string} id - The id of the new device.
  135. * @returns {Promise}
  136. */
  137. export function setVideoInputDevice(transport: Object, label: string, id: string) {
  138. return _setDevice(transport, {
  139. id,
  140. kind: 'videoinput',
  141. label
  142. });
  143. }