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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 label or id that is passed.
  92. *
  93. * @param {Transport} transport - The @code{Transport} instance responsible for
  94. * the external communication.
  95. * @param {string} label - The label of the new device.
  96. * @param {string} id - The id of the new device.
  97. * @returns {Promise}
  98. */
  99. export function setAudioInputDevice(transport: Object, label: string, id: string) {
  100. return _setDevice(transport, {
  101. id,
  102. kind: 'audioinput',
  103. label
  104. });
  105. }
  106. /**
  107. * Sets the audio output device to the one with the label or id that is passed.
  108. *
  109. * @param {Transport} transport - The @code{Transport} instance responsible for
  110. * the external communication.
  111. * @param {string} label - The label of the new device.
  112. * @param {string} id - The id of the new device.
  113. * @returns {Promise}
  114. */
  115. export function setAudioOutputDevice(transport: Object, label: string, id: string) {
  116. return _setDevice(transport, {
  117. id,
  118. kind: 'audiooutput',
  119. label
  120. });
  121. }
  122. /**
  123. * Sets the currently used device to the one that is passed.
  124. *
  125. * @param {Transport} transport - The @code{Transport} instance responsible for
  126. * the external communication.
  127. * @param {Object} device - The new device to be used.
  128. * @returns {Promise}
  129. */
  130. function _setDevice(transport: Object, device) {
  131. return transport.sendRequest({
  132. type: 'devices',
  133. name: 'setDevice',
  134. device
  135. });
  136. }
  137. /**
  138. * Sets the video input device to the one with the label or id that is passed.
  139. *
  140. * @param {Transport} transport - The @code{Transport} instance responsible for
  141. * the external communication.
  142. * @param {string} label - The label of the new device.
  143. * @param {string} id - The id of the new device.
  144. * @returns {Promise}
  145. */
  146. export function setVideoInputDevice(transport: Object, label: string, id: string) {
  147. return _setDevice(transport, {
  148. id,
  149. kind: 'videoinput',
  150. label
  151. });
  152. }