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.

JitsiMediaDevices.js 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. var EventEmitter = require("events");
  2. var RTCEvents = require('./service/RTC/RTCEvents');
  3. var RTC = require("./modules/RTC/RTC");
  4. var MediaType = require('./service/RTC/MediaType');
  5. var JitsiMediaDevicesEvents = require('./JitsiMediaDevicesEvents');
  6. var eventEmitter = new EventEmitter();
  7. RTC.addListener(RTCEvents.DEVICE_LIST_CHANGED,
  8. function (devices) {
  9. eventEmitter.emit(JitsiMediaDevicesEvents.DEVICE_LIST_CHANGED, devices);
  10. });
  11. var JitsiMediaDevices = {
  12. /**
  13. * Executes callback with list of media devices connected.
  14. * @param {function} callback
  15. */
  16. enumerateDevices: function (callback) {
  17. RTC.enumerateDevices(callback);
  18. },
  19. /**
  20. * Checks if its possible to enumerate available cameras/micropones.
  21. * @returns {boolean} true if available, false otherwise.
  22. */
  23. isDeviceListAvailable: function () {
  24. return RTC.isDeviceListAvailable();
  25. },
  26. /**
  27. * Returns true if changing the input (camera / microphone) or output
  28. * (audio) device is supported and false if not.
  29. * @param {string} [deviceType] - type of device to change. Default is
  30. * undefined or 'input', 'output' - for audio output device change.
  31. * @returns {boolean} true if available, false otherwise.
  32. */
  33. isDeviceChangeAvailable: function (deviceType) {
  34. return RTC.isDeviceChangeAvailable(deviceType);
  35. },
  36. /**
  37. * Returns true if user granted permission to media devices.
  38. * @param {'audio'|'video'} [type] - type of devices to check,
  39. * undefined stands for both 'audio' and 'video' together
  40. * @returns {boolean}
  41. */
  42. isDevicePermissionGranted: function (type) {
  43. var permissions = RTC.getDeviceAvailability();
  44. switch(type) {
  45. case MediaType.VIDEO:
  46. return permissions.video === true;
  47. case MediaType.AUDIO:
  48. return permissions.audio === true;
  49. default:
  50. return permissions.video === true && permissions.audio === true;
  51. }
  52. },
  53. /**
  54. * Returns currently used audio output device id, 'default' stands
  55. * for default device
  56. * @returns {string}
  57. */
  58. getAudioOutputDevice: function () {
  59. return RTC.getAudioOutputDevice();
  60. },
  61. /**
  62. * Sets current audio output device.
  63. * @param {string} deviceId - id of 'audiooutput' device from
  64. * navigator.mediaDevices.enumerateDevices(), 'default' is for
  65. * default device
  66. * @returns {Promise} - resolves when audio output is changed, is rejected
  67. * otherwise
  68. */
  69. setAudioOutputDevice: function (deviceId) {
  70. return RTC.setAudioOutputDevice(deviceId);
  71. },
  72. /**
  73. * Adds an event handler.
  74. * @param {string} event - event name
  75. * @param {function} handler - event handler
  76. */
  77. addEventListener: function (event, handler) {
  78. eventEmitter.addListener(event, handler);
  79. },
  80. /**
  81. * Removes event handler.
  82. * @param {string} event - event name
  83. * @param {function} handler - event handler
  84. */
  85. removeEventListener: function (event, handler) {
  86. eventEmitter.removeListener(event, handler);
  87. }
  88. };
  89. module.exports = JitsiMediaDevices;