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.1KB

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