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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. var Resolutions = require("./service/RTC/Resolutions");
  12. function getLowerResolution(resolution) {
  13. if(!Resolutions[resolution])
  14. return null;
  15. var order = Resolutions[resolution].order;
  16. var res = null;
  17. var resName = null;
  18. for(var i in Resolutions) {
  19. var tmp = Resolutions[i];
  20. if (!res || (res.order < tmp.order && tmp.order < order)) {
  21. resName = i;
  22. res = tmp;
  23. }
  24. }
  25. return resName;
  26. }
  27. /**
  28. * Namespace for the interface of Jitsi Meet Library.
  29. */
  30. var LibJitsiMeet = {
  31. JitsiConnection: JitsiConnection,
  32. events: {
  33. conference: JitsiConferenceEvents,
  34. connection: JitsiConnectionEvents,
  35. track: JitsiTrackEvents
  36. },
  37. errors: {
  38. conference: JitsiConferenceErrors,
  39. connection: JitsiConnectionErrors,
  40. track: JitsiTrackErrors
  41. },
  42. logLevels: Logger.levels,
  43. init: function (options) {
  44. return RTC.init(options || {});
  45. },
  46. /**
  47. * Returns whether the desktop sharing is enabled or not.
  48. * @returns {boolean}
  49. */
  50. isDesktopSharingEnabled: function () {
  51. return RTC.isDesktopSharingEnabled();
  52. },
  53. setLogLevel: function (level) {
  54. Logger.setLogLevel(level);
  55. },
  56. /**
  57. * Creates the media tracks and returns them trough the callback.
  58. * @param options Object with properties / settings specifying the tracks which should be created.
  59. * should be created or some additional configurations about resolution for example.
  60. * @param {Array} options.devices the devices that will be requested
  61. * @param {string} options.resolution resolution constraints
  62. * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
  63. * type: "audio" or "video", videoType: "camera" or "desktop"}
  64. * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
  65. * @param {string} options.cameraDeviceId
  66. * @param {string} options.micDeviceId
  67. * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
  68. * A promise that returns an array of created JitsiTracks if resolved,
  69. * or a JitsiConferenceError if rejected.
  70. */
  71. createLocalTracks: function (options) {
  72. return RTC.obtainAudioAndVideoPermissions(options || {}).then(
  73. function(tracks) {
  74. if(!RTC.options.disableAudioLevels)
  75. for(var i = 0; i < tracks.length; i++) {
  76. var track = tracks[i];
  77. var mStream = track.getOriginalStream();
  78. if(track.getType() === "audio"){
  79. Statistics.startLocalStats(mStream,
  80. track.setAudioLevel.bind(track));
  81. track.addEventListener(
  82. JitsiTrackEvents.TRACK_STOPPED,
  83. function(){
  84. Statistics.stopLocalStats(mStream);
  85. });
  86. }
  87. }
  88. return tracks;
  89. }).catch(function (error) {
  90. if(error === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
  91. var oldResolution = options.resolution || '360';
  92. var newResolution = getLowerResolution(oldResolution);
  93. if(newResolution === null)
  94. return Promise.reject(error);
  95. options.resolution = newResolution;
  96. return LibJitsiMeet.createLocalTracks(options);
  97. }
  98. return Promise.reject(error);
  99. });
  100. },
  101. /**
  102. * Checks if its possible to enumerate available cameras/micropones.
  103. * @returns {boolean} true if available, false otherwise.
  104. */
  105. isDeviceListAvailable: function () {
  106. return RTC.isDeviceListAvailable();
  107. },
  108. /**
  109. * Returns true if changing the camera / microphone device is supported and
  110. * false if not.
  111. * @returns {boolean} true if available, false otherwise.
  112. */
  113. isDeviceChangeAvailable: function () {
  114. return RTC.isDeviceChangeAvailable();
  115. },
  116. enumerateDevices: function (callback) {
  117. RTC.enumerateDevices(callback);
  118. }
  119. };
  120. //Setups the promise object.
  121. window.Promise = window.Promise || require("es6-promise").Promise;
  122. module.exports = LibJitsiMeet;