您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /* global APP, $, config */
  2. const UI = {};
  3. import EventEmitter from 'events';
  4. import Logger from 'jitsi-meet-logger';
  5. import { isMobileBrowser } from '../../react/features/base/environment/utils';
  6. import { setColorAlpha } from '../../react/features/base/util';
  7. import { setDocumentUrl } from '../../react/features/etherpad';
  8. import { setFilmstripVisible } from '../../react/features/filmstrip';
  9. import { joinLeaveNotificationsDisabled, setNotificationsEnabled } from '../../react/features/notifications';
  10. import {
  11. dockToolbox,
  12. setToolboxEnabled,
  13. showToolbox
  14. } from '../../react/features/toolbox/actions.web';
  15. import UIEvents from '../../service/UI/UIEvents';
  16. import EtherpadManager from './etherpad/Etherpad';
  17. import SharedVideoManager from './shared_video/SharedVideo';
  18. import messageHandler from './util/MessageHandler';
  19. import UIUtil from './util/UIUtil';
  20. import VideoLayout from './videolayout/VideoLayout';
  21. const logger = Logger.getLogger(__filename);
  22. UI.messageHandler = messageHandler;
  23. const eventEmitter = new EventEmitter();
  24. UI.eventEmitter = eventEmitter;
  25. let etherpadManager;
  26. let sharedVideoManager;
  27. const UIListeners = new Map([
  28. [
  29. UIEvents.ETHERPAD_CLICKED,
  30. () => etherpadManager && etherpadManager.toggleEtherpad()
  31. ], [
  32. UIEvents.SHARED_VIDEO_CLICKED,
  33. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  34. ], [
  35. UIEvents.TOGGLE_FILMSTRIP,
  36. () => UI.toggleFilmstrip()
  37. ]
  38. ]);
  39. /**
  40. * Indicates if we're currently in full screen mode.
  41. *
  42. * @return {boolean} {true} to indicate that we're currently in full screen
  43. * mode, {false} otherwise
  44. */
  45. UI.isFullScreen = function() {
  46. return UIUtil.isFullScreen();
  47. };
  48. /**
  49. * Returns true if there is a shared video which is being shown (?).
  50. * @returns {boolean} - true if there is a shared video which is being shown.
  51. */
  52. UI.isSharedVideoShown = function() {
  53. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  54. };
  55. /**
  56. * Notify user that server has shut down.
  57. */
  58. UI.notifyGracefulShutdown = function() {
  59. messageHandler.showError({
  60. descriptionKey: 'dialog.gracefulShutdown',
  61. titleKey: 'dialog.serviceUnavailable'
  62. });
  63. };
  64. /**
  65. * Notify user that reservation error happened.
  66. */
  67. UI.notifyReservationError = function(code, msg) {
  68. messageHandler.showError({
  69. descriptionArguments: {
  70. code,
  71. msg
  72. },
  73. descriptionKey: 'dialog.reservationErrorMsg',
  74. titleKey: 'dialog.reservationError'
  75. });
  76. };
  77. /**
  78. * Initialize conference UI.
  79. */
  80. UI.initConference = function() {
  81. UI.showToolbar();
  82. };
  83. /**
  84. * Starts the UI module and initializes all related components.
  85. *
  86. * @returns {boolean} true if the UI is ready and the conference should be
  87. * established, false - otherwise (for example in the case of welcome page)
  88. */
  89. UI.start = function() {
  90. // Set the defaults for prompt dialogs.
  91. $.prompt.setDefaults({ persistent: false });
  92. VideoLayout.initLargeVideo();
  93. // Do not animate the video area on UI start (second argument passed into
  94. // resizeVideoArea) because the animation is not visible anyway. Plus with
  95. // the current dom layout, the quality label is part of the video layout and
  96. // will be seen animating in.
  97. VideoLayout.resizeVideoArea();
  98. sharedVideoManager = new SharedVideoManager(eventEmitter);
  99. if (isMobileBrowser()) {
  100. $('body').addClass('mobile-browser');
  101. } else {
  102. $('body').addClass('desktop-browser');
  103. if (config.backgroundAlpha !== undefined) {
  104. const backgroundColor = $('body').css('background-color');
  105. const alphaColor = setColorAlpha(backgroundColor, config.backgroundAlpha);
  106. $('body').css('background-color', alphaColor);
  107. }
  108. }
  109. if (config.iAmRecorder) {
  110. // in case of iAmSipGateway keep local video visible
  111. if (!config.iAmSipGateway) {
  112. APP.store.dispatch(setNotificationsEnabled(false));
  113. }
  114. APP.store.dispatch(setToolboxEnabled(false));
  115. }
  116. };
  117. /**
  118. * Setup some UI event listeners.
  119. */
  120. UI.registerListeners
  121. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  122. /**
  123. * Setup some DOM event listeners.
  124. */
  125. UI.bindEvents = () => {
  126. /**
  127. *
  128. */
  129. function onResize() {
  130. VideoLayout.onResize();
  131. }
  132. // Resize and reposition videos in full screen mode.
  133. $(document).on(
  134. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  135. onResize);
  136. $(window).resize(onResize);
  137. };
  138. /**
  139. * Unbind some DOM event listeners.
  140. */
  141. UI.unbindEvents = () => {
  142. $(document).off(
  143. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  144. $(window).off('resize');
  145. };
  146. /**
  147. * Setup and show Etherpad.
  148. * @param {string} name etherpad id
  149. */
  150. UI.initEtherpad = name => {
  151. if (etherpadManager || !config.etherpad_base || !name) {
  152. return;
  153. }
  154. logger.log('Etherpad is enabled');
  155. etherpadManager = new EtherpadManager(eventEmitter);
  156. const url = new URL(name, config.etherpad_base);
  157. APP.store.dispatch(setDocumentUrl(url.toString()));
  158. if (config.openSharedDocumentOnJoin) {
  159. etherpadManager.toggleEtherpad();
  160. }
  161. };
  162. /**
  163. * Returns the shared document manager object.
  164. * @return {EtherpadManager} the shared document manager object
  165. */
  166. UI.getSharedDocumentManager = () => etherpadManager;
  167. /**
  168. * Show user on UI.
  169. * @param {JitsiParticipant} user
  170. */
  171. UI.addUser = function(user) {
  172. const status = user.getStatus();
  173. if (status) {
  174. // FIXME: move updateUserStatus in participantPresenceChanged action
  175. UI.updateUserStatus(user, status);
  176. }
  177. };
  178. /**
  179. * Updates the user status.
  180. *
  181. * @param {JitsiParticipant} user - The user which status we need to update.
  182. * @param {string} status - The new status.
  183. */
  184. UI.updateUserStatus = (user, status) => {
  185. const reduxState = APP.store.getState() || {};
  186. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  187. // We hide status updates when join/leave notifications are disabled,
  188. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  189. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  190. return;
  191. }
  192. const displayName = user.getDisplayName();
  193. messageHandler.participantNotification(
  194. displayName,
  195. '',
  196. 'connected',
  197. 'dialOut.statusMessage',
  198. { status: UIUtil.escapeHtml(status) });
  199. };
  200. /**
  201. * Toggles filmstrip.
  202. */
  203. UI.toggleFilmstrip = function() {
  204. const { visible } = APP.store.getState()['features/filmstrip'];
  205. APP.store.dispatch(setFilmstripVisible(!visible));
  206. };
  207. /**
  208. * Sets muted audio state for participant
  209. */
  210. UI.setAudioMuted = function(id) {
  211. // FIXME: Maybe this can be removed!
  212. if (APP.conference.isLocalId(id)) {
  213. APP.conference.updateAudioIconEnabled();
  214. }
  215. };
  216. /**
  217. * Sets muted video state for participant
  218. */
  219. UI.setVideoMuted = function(id) {
  220. VideoLayout._updateLargeVideoIfDisplayed(id, true);
  221. if (APP.conference.isLocalId(id)) {
  222. APP.conference.updateVideoIconEnabled();
  223. }
  224. };
  225. UI.updateLargeVideo = (id, forceUpdate) => VideoLayout.updateLargeVideo(id, forceUpdate);
  226. /**
  227. * Adds a listener that would be notified on the given type of event.
  228. *
  229. * @param type the type of the event we're listening for
  230. * @param listener a function that would be called when notified
  231. */
  232. UI.addListener = function(type, listener) {
  233. eventEmitter.on(type, listener);
  234. };
  235. /**
  236. * Removes the all listeners for all events.
  237. *
  238. * @returns {void}
  239. */
  240. UI.removeAllListeners = function() {
  241. eventEmitter.removeAllListeners();
  242. };
  243. /**
  244. * Emits the event of given type by specifying the parameters in options.
  245. *
  246. * @param type the type of the event we're emitting
  247. * @param options the parameters for the event
  248. */
  249. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  250. // Used by torture.
  251. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  252. // Used by torture.
  253. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  254. /**
  255. * Updates the displayed avatar for participant.
  256. *
  257. * @param {string} id - User id whose avatar should be updated.
  258. * @param {string} avatarURL - The URL to avatar image to display.
  259. * @returns {void}
  260. */
  261. UI.refreshAvatarDisplay = function(id) {
  262. VideoLayout.changeUserAvatar(id);
  263. };
  264. /**
  265. * Notify user that connection failed.
  266. * @param {string} stropheErrorMsg raw Strophe error message
  267. */
  268. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  269. let descriptionKey;
  270. let descriptionArguments;
  271. if (stropheErrorMsg) {
  272. descriptionKey = 'dialog.connectErrorWithMsg';
  273. descriptionArguments = { msg: stropheErrorMsg };
  274. } else {
  275. descriptionKey = 'dialog.connectError';
  276. }
  277. messageHandler.showError({
  278. descriptionArguments,
  279. descriptionKey,
  280. titleKey: 'connection.CONNFAIL'
  281. });
  282. };
  283. /**
  284. * Notify user that maximum users limit has been reached.
  285. */
  286. UI.notifyMaxUsersLimitReached = function() {
  287. messageHandler.showError({
  288. hideErrorSupportLink: true,
  289. descriptionKey: 'dialog.maxUsersLimitReached',
  290. titleKey: 'dialog.maxUsersLimitReachedTitle'
  291. });
  292. };
  293. /**
  294. * Notify user that he was automatically muted when joned the conference.
  295. */
  296. UI.notifyInitiallyMuted = function() {
  297. messageHandler.participantNotification(
  298. null,
  299. 'notify.mutedTitle',
  300. 'connected',
  301. 'notify.muted',
  302. null);
  303. };
  304. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  305. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  306. };
  307. /**
  308. * Update audio level visualization for specified user.
  309. * @param {string} id user id
  310. * @param {number} lvl audio level
  311. */
  312. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  313. UI.notifyTokenAuthFailed = function() {
  314. messageHandler.showError({
  315. descriptionKey: 'dialog.tokenAuthFailed',
  316. titleKey: 'dialog.tokenAuthFailedTitle'
  317. });
  318. };
  319. UI.notifyFocusDisconnected = function(focus, retrySec) {
  320. messageHandler.participantNotification(
  321. null, 'notify.focus',
  322. 'disconnected', 'notify.focusFail',
  323. { component: focus,
  324. ms: retrySec }
  325. );
  326. };
  327. /**
  328. * Update list of available physical devices.
  329. */
  330. UI.onAvailableDevicesChanged = function() {
  331. APP.conference.updateAudioIconEnabled();
  332. APP.conference.updateVideoIconEnabled();
  333. };
  334. /**
  335. * Returns the id of the current video shown on large.
  336. * Currently used by tests (torture).
  337. */
  338. UI.getLargeVideoID = function() {
  339. return VideoLayout.getLargeVideoID();
  340. };
  341. /**
  342. * Returns the current video shown on large.
  343. * Currently used by tests (torture).
  344. */
  345. UI.getLargeVideo = function() {
  346. return VideoLayout.getLargeVideo();
  347. };
  348. /**
  349. * Show shared video.
  350. * @param {string} id the id of the sender of the command
  351. * @param {string} url video url
  352. * @param {string} attributes
  353. */
  354. UI.onSharedVideoStart = function(id, url, attributes) {
  355. if (sharedVideoManager) {
  356. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  357. }
  358. };
  359. /**
  360. * Update shared video.
  361. * @param {string} id the id of the sender of the command
  362. * @param {string} url video url
  363. * @param {string} attributes
  364. */
  365. UI.onSharedVideoUpdate = function(id, url, attributes) {
  366. if (sharedVideoManager) {
  367. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  368. }
  369. };
  370. /**
  371. * Stop showing shared video.
  372. * @param {string} id the id of the sender of the command
  373. * @param {string} attributes
  374. */
  375. UI.onSharedVideoStop = function(id, attributes) {
  376. if (sharedVideoManager) {
  377. sharedVideoManager.onSharedVideoStop(id, attributes);
  378. }
  379. };
  380. /**
  381. * Show shared video.
  382. * @param {string} url video url
  383. */
  384. UI.startSharedVideoEmitter = function(url) {
  385. if (sharedVideoManager) {
  386. sharedVideoManager.startSharedVideoEmitter(url);
  387. }
  388. };
  389. /**
  390. * Stop shared video.
  391. */
  392. UI.stopSharedVideoEmitter = function() {
  393. if (sharedVideoManager) {
  394. sharedVideoManager.stopSharedVideoEmitter();
  395. }
  396. };
  397. // TODO: Export every function separately. For now there is no point of doing
  398. // this because we are importing everything.
  399. export default UI;