選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

JitsiMeetJS.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /**
  44. * Array of functions that will receive the GUM error.
  45. */
  46. _gumFailedHandler: [],
  47. init: function (options) {
  48. return RTC.init(options || {});
  49. },
  50. /**
  51. * Returns whether the desktop sharing is enabled or not.
  52. * @returns {boolean}
  53. */
  54. isDesktopSharingEnabled: function () {
  55. return RTC.isDesktopSharingEnabled();
  56. },
  57. setLogLevel: function (level) {
  58. Logger.setLogLevel(level);
  59. },
  60. /**
  61. * Creates the media tracks and returns them trough the callback.
  62. * @param options Object with properties / settings specifying the tracks which should be created.
  63. * should be created or some additional configurations about resolution for example.
  64. * @param {Array} options.devices the devices that will be requested
  65. * @param {string} options.resolution resolution constraints
  66. * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
  67. * type: "audio" or "video", videoType: "camera" or "desktop"}
  68. * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
  69. * @param {string} options.cameraDeviceId
  70. * @param {string} options.micDeviceId
  71. * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
  72. * A promise that returns an array of created JitsiTracks if resolved,
  73. * or a JitsiConferenceError if rejected.
  74. */
  75. createLocalTracks: function (options) {
  76. return RTC.obtainAudioAndVideoPermissions(options || {}).then(
  77. function(tracks) {
  78. if(!RTC.options.disableAudioLevels)
  79. for(var i = 0; i < tracks.length; i++) {
  80. var track = tracks[i];
  81. var mStream = track.getOriginalStream();
  82. if(track.getType() === "audio"){
  83. Statistics.startLocalStats(mStream,
  84. track.setAudioLevel.bind(track));
  85. track.addEventListener(
  86. JitsiTrackEvents.TRACK_STOPPED,
  87. function(){
  88. Statistics.stopLocalStats(mStream);
  89. });
  90. }
  91. }
  92. return tracks;
  93. }).catch(function (error) {
  94. this._gumFailedHandler.forEach(function (handler) {
  95. handler(error);
  96. });
  97. Statistics.sendGetUserMediaFailed(error);
  98. if(error === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
  99. var oldResolution = options.resolution || '360';
  100. var newResolution = getLowerResolution(oldResolution);
  101. if(newResolution === null)
  102. return Promise.reject(error);
  103. options.resolution = newResolution;
  104. return LibJitsiMeet.createLocalTracks(options);
  105. }
  106. return Promise.reject(error);
  107. }.bind(this));
  108. },
  109. /**
  110. * Checks if its possible to enumerate available cameras/micropones.
  111. * @returns {boolean} true if available, false otherwise.
  112. */
  113. isDeviceListAvailable: function () {
  114. return RTC.isDeviceListAvailable();
  115. },
  116. /**
  117. * Returns true if changing the camera / microphone device is supported and
  118. * false if not.
  119. * @returns {boolean} true if available, false otherwise.
  120. */
  121. isDeviceChangeAvailable: function () {
  122. return RTC.isDeviceChangeAvailable();
  123. },
  124. enumerateDevices: function (callback) {
  125. RTC.enumerateDevices(callback);
  126. }
  127. };
  128. //Setups the promise object.
  129. window.Promise = window.Promise || require("es6-promise").Promise;
  130. module.exports = LibJitsiMeet;