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.

JitsiMeetJS.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var JitsiConnection = require("./JitsiConnection");
  2. var JitsiConferenceEvents = require("./JitsiConferenceEvents");
  3. var JitsiConnectionEvents = require("./JitsiConnectionEvents");
  4. var JitsiConnectionErrors = require("./JitsiConnectionErrors");
  5. var JitsiConferenceErrors = require("./JitsiConferenceErrors");
  6. var JitsiTrackEvents = require("./JitsiTrackEvents");
  7. var JitsiTrackErrors = require("./JitsiTrackErrors");
  8. var Logger = require("jitsi-meet-logger");
  9. var RTC = require("./modules/RTC/RTC");
  10. var Statistics = require("./modules/statistics/statistics");
  11. /**
  12. * Namespace for the interface of Jitsi Meet Library.
  13. */
  14. var LibJitsiMeet = {
  15. JitsiConnection: JitsiConnection,
  16. events: {
  17. conference: JitsiConferenceEvents,
  18. connection: JitsiConnectionEvents,
  19. track: JitsiTrackEvents
  20. },
  21. errors: {
  22. conference: JitsiConferenceErrors,
  23. connection: JitsiConnectionErrors,
  24. track: JitsiTrackErrors
  25. },
  26. logLevels: Logger.levels,
  27. init: function (options) {
  28. return RTC.init(options || {});
  29. },
  30. /**
  31. * Returns whether the desktop sharing is enabled or not.
  32. * @returns {boolean}
  33. */
  34. isDesktopSharingEnabled: function () {
  35. return RTC.isDesktopSharingEnabled();
  36. },
  37. setLogLevel: function (level) {
  38. Logger.setLogLevel(level);
  39. },
  40. /**
  41. * Creates the media tracks and returns them trough the callback.
  42. * @param options Object with properties / settings specifying the tracks which should be created.
  43. * should be created or some additional configurations about resolution for example.
  44. * @param {Array} options.devices the devices that will be requested
  45. * @param {string} options.resolution resolution constraints
  46. * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
  47. * type: "audio" or "video", videoType: "camera" or "desktop"}
  48. * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
  49. * @param {string} options.cameraDeviceId
  50. * @param {string} options.micDeviceId
  51. * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
  52. * A promise that returns an array of created JitsiTracks if resolved,
  53. * or a JitsiConferenceError if rejected.
  54. */
  55. createLocalTracks: function (options) {
  56. return RTC.obtainAudioAndVideoPermissions(options || {}).then(
  57. function(tracks) {
  58. if(!RTC.options.disableAudioLevels)
  59. for(var i = 0; i < tracks.length; i++) {
  60. var track = tracks[i];
  61. var mStream = track.getOriginalStream();
  62. if(track.getType() === "audio"){
  63. Statistics.startLocalStats(mStream,
  64. track.setAudioLevel.bind(track));
  65. track.addEventListener(
  66. JitsiTrackEvents.TRACK_STOPPED,
  67. function(){
  68. Statistics.stopLocalStats(mStream);
  69. });
  70. }
  71. }
  72. return tracks;
  73. });
  74. },
  75. /**
  76. * Checks if its possible to enumerate available cameras/micropones.
  77. * @returns {boolean} true if available, false otherwise.
  78. */
  79. isDeviceListAvailable: function () {
  80. return RTC.isDeviceListAvailable();
  81. },
  82. /**
  83. * Returns true if changing the camera / microphone device is supported and
  84. * false if not.
  85. * @returns {boolean} true if available, false otherwise.
  86. */
  87. isDeviceChangeAvailable: function () {
  88. return RTC.isDeviceChangeAvailable();
  89. },
  90. enumerateDevices: function (callback) {
  91. RTC.enumerateDevices(callback);
  92. }
  93. };
  94. require("es6-promise").polyfill()
  95. //Setups the promise object.
  96. window.Promise = window.Promise || require("es6-promise").Promise;
  97. module.exports = LibJitsiMeet;