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

JitsiMeetJS.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. var logger = require("jitsi-meet-logger").getLogger(__filename);
  2. var AuthUtil = require("./modules/util/AuthUtil");
  3. var JitsiConnection = require("./JitsiConnection");
  4. var JitsiMediaDevices = require("./JitsiMediaDevices");
  5. var JitsiConferenceEvents = require("./JitsiConferenceEvents");
  6. var JitsiConnectionEvents = require("./JitsiConnectionEvents");
  7. var JitsiMediaDevicesEvents = require('./JitsiMediaDevicesEvents');
  8. var JitsiConnectionErrors = require("./JitsiConnectionErrors");
  9. var JitsiConferenceErrors = require("./JitsiConferenceErrors");
  10. var JitsiTrackEvents = require("./JitsiTrackEvents");
  11. var JitsiTrackErrors = require("./JitsiTrackErrors");
  12. var JitsiTrackError = require("./JitsiTrackError");
  13. var JitsiRecorderErrors = require("./JitsiRecorderErrors");
  14. var Logger = require("jitsi-meet-logger");
  15. var MediaType = require("./service/RTC/MediaType");
  16. var RTC = require("./modules/RTC/RTC");
  17. var RTCUIHelper = require("./modules/RTC/RTCUIHelper");
  18. var Statistics = require("./modules/statistics/statistics");
  19. var AnalyticsAdapter = require("./modules/statistics/AnalyticsAdapter");
  20. var Resolutions = require("./service/RTC/Resolutions");
  21. var ScriptUtil = require("./modules/util/ScriptUtil");
  22. var GlobalOnErrorHandler = require("./modules/util/GlobalOnErrorHandler");
  23. var RTCBrowserType = require("./modules/RTC/RTCBrowserType");
  24. // The amount of time to wait until firing
  25. // JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN event
  26. var USER_MEDIA_PERMISSION_PROMPT_TIMEOUT = 500;
  27. function getLowerResolution(resolution) {
  28. if(!Resolutions[resolution])
  29. return null;
  30. var order = Resolutions[resolution].order;
  31. var res = null;
  32. var resName = null;
  33. for(var i in Resolutions) {
  34. var tmp = Resolutions[i];
  35. if (!res || (res.order < tmp.order && tmp.order < order)) {
  36. resName = i;
  37. res = tmp;
  38. }
  39. }
  40. return resName;
  41. }
  42. /**
  43. * Namespace for the interface of Jitsi Meet Library.
  44. */
  45. var LibJitsiMeet = {
  46. version: '{#COMMIT_HASH#}',
  47. JitsiConnection: JitsiConnection,
  48. events: {
  49. conference: JitsiConferenceEvents,
  50. connection: JitsiConnectionEvents,
  51. track: JitsiTrackEvents,
  52. mediaDevices: JitsiMediaDevicesEvents
  53. },
  54. errors: {
  55. conference: JitsiConferenceErrors,
  56. connection: JitsiConnectionErrors,
  57. recorder: JitsiRecorderErrors,
  58. track: JitsiTrackErrors
  59. },
  60. errorTypes: {
  61. JitsiTrackError: JitsiTrackError
  62. },
  63. logLevels: Logger.levels,
  64. mediaDevices: JitsiMediaDevices,
  65. analytics: AnalyticsAdapter,
  66. init: function (options) {
  67. var logObject, attr;
  68. Statistics.audioLevelsEnabled = !options.disableAudioLevels;
  69. if(typeof options.audioLevelsInterval === 'number') {
  70. Statistics.audioLevelsInterval = options.audioLevelsInterval;
  71. }
  72. if (options.enableWindowOnErrorHandler) {
  73. GlobalOnErrorHandler.addHandler(
  74. this.getGlobalOnErrorHandler.bind(this));
  75. }
  76. // Log deployment-specific information, if available.
  77. if (window.jitsiRegionInfo
  78. && Object.keys(window.jitsiRegionInfo).length > 0) {
  79. logObject = {};
  80. for (attr in window.jitsiRegionInfo) {
  81. if (window.jitsiRegionInfo.hasOwnProperty(attr)) {
  82. logObject[attr] = window.jitsiRegionInfo[attr];
  83. }
  84. }
  85. logObject.id = "deployment_info";
  86. Statistics.sendLog(JSON.stringify(logObject));
  87. }
  88. if(this.version) {
  89. logObject = {
  90. id: "component_version",
  91. component: "lib-jitsi-meet",
  92. version: this.version
  93. }
  94. Statistics.sendLog(JSON.stringify(logObject));
  95. }
  96. return RTC.init(options || {});
  97. },
  98. /**
  99. * Returns whether the desktop sharing is enabled or not.
  100. * @returns {boolean}
  101. */
  102. isDesktopSharingEnabled: function () {
  103. return RTC.isDesktopSharingEnabled();
  104. },
  105. setLogLevel: function (level) {
  106. Logger.setLogLevel(level);
  107. },
  108. /**
  109. * Creates the media tracks and returns them trough the callback.
  110. * @param options Object with properties / settings specifying the tracks which should be created.
  111. * should be created or some additional configurations about resolution for example.
  112. * @param {Array} options.devices the devices that will be requested
  113. * @param {string} options.resolution resolution constraints
  114. * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
  115. * type: "audio" or "video", videoType: "camera" or "desktop"}
  116. * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
  117. * @param {string} options.cameraDeviceId
  118. * @param {string} options.micDeviceId
  119. * @param {boolean} (firePermissionPromptIsShownEvent) - if event
  120. * JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
  121. * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
  122. * A promise that returns an array of created JitsiTracks if resolved,
  123. * or a JitsiConferenceError if rejected.
  124. */
  125. createLocalTracks: function (options, firePermissionPromptIsShownEvent) {
  126. var promiseFulfilled = false;
  127. if (firePermissionPromptIsShownEvent === true) {
  128. window.setTimeout(function () {
  129. if (!promiseFulfilled) {
  130. JitsiMediaDevices.emitEvent(
  131. JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN,
  132. RTCBrowserType.getBrowserName());
  133. }
  134. }, USER_MEDIA_PERMISSION_PROMPT_TIMEOUT);
  135. }
  136. return RTC.obtainAudioAndVideoPermissions(options || {})
  137. .then(function(tracks) {
  138. promiseFulfilled = true;
  139. if(!RTC.options.disableAudioLevels)
  140. for(var i = 0; i < tracks.length; i++) {
  141. var track = tracks[i];
  142. var mStream = track.getOriginalStream();
  143. if(track.getType() === MediaType.AUDIO){
  144. Statistics.startLocalStats(mStream,
  145. track.setAudioLevel.bind(track));
  146. track.addEventListener(
  147. JitsiTrackEvents.LOCAL_TRACK_STOPPED,
  148. function(){
  149. Statistics.stopLocalStats(mStream);
  150. });
  151. }
  152. }
  153. return tracks;
  154. }).catch(function (error) {
  155. promiseFulfilled = true;
  156. if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
  157. var oldResolution = options.resolution || '360',
  158. newResolution = getLowerResolution(oldResolution);
  159. if (newResolution !== null) {
  160. options.resolution = newResolution;
  161. logger.debug("Retry createLocalTracks with resolution",
  162. newResolution);
  163. return LibJitsiMeet.createLocalTracks(options);
  164. }
  165. }
  166. if (JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED ===
  167. error.name) {
  168. // User cancelled action is not really an error, so only
  169. // log it as an event to avoid having conference classified
  170. // as partially failed
  171. var logObject = {
  172. id: "chrome_extension_user_canceled",
  173. message: error.message
  174. };
  175. Statistics.sendLog(JSON.stringify(logObject));
  176. } else {
  177. // Report gUM failed to the stats
  178. Statistics.sendGetUserMediaFailed(error);
  179. }
  180. return Promise.reject(error);
  181. }.bind(this));
  182. },
  183. /**
  184. * Checks if its possible to enumerate available cameras/micropones.
  185. * @returns {Promise<boolean>} a Promise which will be resolved only once
  186. * the WebRTC stack is ready, either with true if the device listing is
  187. * available available or with false otherwise.
  188. * @deprecated use JitsiMeetJS.mediaDevices.isDeviceListAvailable instead
  189. */
  190. isDeviceListAvailable: function () {
  191. logger.warn('This method is deprecated, use ' +
  192. 'JitsiMeetJS.mediaDevices.isDeviceListAvailable instead');
  193. return this.mediaDevices.isDeviceListAvailable();
  194. },
  195. /**
  196. * Returns true if changing the input (camera / microphone) or output
  197. * (audio) device is supported and false if not.
  198. * @params {string} [deviceType] - type of device to change. Default is
  199. * undefined or 'input', 'output' - for audio output device change.
  200. * @returns {boolean} true if available, false otherwise.
  201. * @deprecated use JitsiMeetJS.mediaDevices.isDeviceChangeAvailable instead
  202. */
  203. isDeviceChangeAvailable: function (deviceType) {
  204. logger.warn('This method is deprecated, use ' +
  205. 'JitsiMeetJS.mediaDevices.isDeviceChangeAvailable instead');
  206. return this.mediaDevices.isDeviceChangeAvailable(deviceType);
  207. },
  208. /**
  209. * Executes callback with list of media devices connected.
  210. * @param {function} callback
  211. * @deprecated use JitsiMeetJS.mediaDevices.enumerateDevices instead
  212. */
  213. enumerateDevices: function (callback) {
  214. logger.warn('This method is deprecated, use ' +
  215. 'JitsiMeetJS.mediaDevices.enumerateDevices instead');
  216. this.mediaDevices.enumerateDevices(callback);
  217. },
  218. /**
  219. * @returns function that can be used to be attached to window.onerror and
  220. * if options.enableWindowOnErrorHandler is enabled returns
  221. * the function used by the lib.
  222. * (function(message, source, lineno, colno, error)).
  223. */
  224. getGlobalOnErrorHandler: function (message, source, lineno, colno, error) {
  225. logger.error(
  226. 'UnhandledError: ' + message,
  227. 'Script: ' + source,
  228. 'Line: ' + lineno,
  229. 'Column: ' + colno,
  230. 'StackTrace: ', error);
  231. Statistics.reportGlobalError(error);
  232. },
  233. /**
  234. * Represents a hub/namespace for utility functionality which may be of
  235. * interest to LibJitsiMeet clients.
  236. */
  237. util: {
  238. ScriptUtil: ScriptUtil,
  239. RTCUIHelper: RTCUIHelper,
  240. AuthUtil: AuthUtil
  241. }
  242. };
  243. //Setups the promise object.
  244. window.Promise = window.Promise || require("es6-promise").Promise;
  245. module.exports = LibJitsiMeet;