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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. setLogLevel: function (level) {
  31. Logger.setLogLevel(level);
  32. },
  33. /**
  34. * Creates the media tracks and returns them trough the callback.
  35. * @param options Object with properties / settings specifying the tracks which should be created.
  36. * should be created or some additional configurations about resolution for example.
  37. * @param {Array} options.devices the devices that will be requested
  38. * @param {string} options.resolution resolution constraints
  39. * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
  40. * type: "audio" or "video", videoType: "camera" or "desktop"}
  41. * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
  42. * @param {string} options.cameraDeviceId
  43. * @param {string} options.micDeviceId
  44. * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
  45. * A promise that returns an array of created JitsiTracks if resolved,
  46. * or a JitsiConferenceError if rejected.
  47. */
  48. createLocalTracks: function (options) {
  49. return RTC.obtainAudioAndVideoPermissions(options || {}).then(
  50. function(tracks) {
  51. if(!RTC.options.disableAudioLevels)
  52. for(var i = 0; i < tracks.length; i++) {
  53. var track = tracks[i];
  54. var mStream = track.getOriginalStream();
  55. if(track.getType() === "audio"){
  56. Statistics.startLocalStats(mStream,
  57. track.setAudioLevel.bind(track));
  58. track.addEventListener(
  59. JitsiTrackEvents.TRACK_STOPPED,
  60. function(){
  61. Statistics.stopLocalStats(mStream);
  62. });
  63. }
  64. }
  65. return tracks;
  66. });
  67. },
  68. /**
  69. * Checks if its possible to enumerate available cameras/micropones.
  70. * @returns {boolean} true if available, false otherwise.
  71. */
  72. isDeviceListAvailable: function () {
  73. return RTC.isDeviceListAvailable();
  74. },
  75. /**
  76. * Returns true if changing the camera / microphone device is supported and
  77. * false if not.
  78. * @returns {boolean} true if available, false otherwise.
  79. */
  80. isDeviceChangeAvailable: function () {
  81. return RTC.isDeviceChangeAvailable();
  82. },
  83. enumerateDevices: function (callback) {
  84. RTC.enumerateDevices(callback);
  85. }
  86. };
  87. require("es6-promise").polyfill()
  88. //Setups the promise object.
  89. window.Promise = window.Promise || require("es6-promise").Promise;
  90. module.exports = LibJitsiMeet;