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.

UI.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /* global APP, $, config, interfaceConfig */
  2. const UI = {};
  3. import EventEmitter from 'events';
  4. import Logger from 'jitsi-meet-logger';
  5. import { getLocalParticipant } from '../../react/features/base/participants';
  6. import { toggleChat } from '../../react/features/chat';
  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 the etherpad window is currently visible.
  50. * @returns {Boolean} - true if the etherpad window is currently visible.
  51. */
  52. UI.isEtherpadVisible = function() {
  53. return Boolean(etherpadManager && etherpadManager.isVisible());
  54. };
  55. /**
  56. * Returns true if there is a shared video which is being shown (?).
  57. * @returns {boolean} - true if there is a shared video which is being shown.
  58. */
  59. UI.isSharedVideoShown = function() {
  60. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  61. };
  62. /**
  63. * Notify user that server has shut down.
  64. */
  65. UI.notifyGracefulShutdown = function() {
  66. messageHandler.showError({
  67. descriptionKey: 'dialog.gracefulShutdown',
  68. titleKey: 'dialog.serviceUnavailable'
  69. });
  70. };
  71. /**
  72. * Notify user that reservation error happened.
  73. */
  74. UI.notifyReservationError = function(code, msg) {
  75. messageHandler.showError({
  76. descriptionArguments: {
  77. code,
  78. msg
  79. },
  80. descriptionKey: 'dialog.reservationErrorMsg',
  81. titleKey: 'dialog.reservationError'
  82. });
  83. };
  84. /**
  85. * Change nickname for the user.
  86. * @param {string} id user id
  87. * @param {string} displayName new nickname
  88. */
  89. UI.changeDisplayName = function(id, displayName) {
  90. VideoLayout.onDisplayNameChanged(id, displayName);
  91. };
  92. /**
  93. * Initialize conference UI.
  94. */
  95. UI.initConference = function() {
  96. const { getState } = APP.store;
  97. const { id, name } = getLocalParticipant(getState);
  98. UI.showToolbar();
  99. const displayName = config.displayJids ? id : name;
  100. if (displayName) {
  101. UI.changeDisplayName('localVideoContainer', displayName);
  102. }
  103. };
  104. /**
  105. * Returns the shared document manager object.
  106. * @return {EtherpadManager} the shared document manager object
  107. */
  108. UI.getSharedVideoManager = function() {
  109. return sharedVideoManager;
  110. };
  111. /**
  112. * Starts the UI module and initializes all related components.
  113. *
  114. * @returns {boolean} true if the UI is ready and the conference should be
  115. * established, false - otherwise (for example in the case of welcome page)
  116. */
  117. UI.start = function() {
  118. // Set the defaults for prompt dialogs.
  119. $.prompt.setDefaults({ persistent: false });
  120. VideoLayout.init(eventEmitter);
  121. if (!interfaceConfig.filmStripOnly) {
  122. VideoLayout.initLargeVideo();
  123. }
  124. // Do not animate the video area on UI start (second argument passed into
  125. // resizeVideoArea) because the animation is not visible anyway. Plus with
  126. // the current dom layout, the quality label is part of the video layout and
  127. // will be seen animating in.
  128. VideoLayout.resizeVideoArea();
  129. sharedVideoManager = new SharedVideoManager(eventEmitter);
  130. if (interfaceConfig.filmStripOnly) {
  131. $('body').addClass('filmstrip-only');
  132. APP.store.dispatch(setNotificationsEnabled(false));
  133. } else if (config.iAmRecorder) {
  134. // in case of iAmSipGateway keep local video visible
  135. if (!config.iAmSipGateway) {
  136. VideoLayout.setLocalVideoVisible(false);
  137. APP.store.dispatch(setNotificationsEnabled(false));
  138. }
  139. APP.store.dispatch(setToolboxEnabled(false));
  140. UI.messageHandler.enablePopups(false);
  141. }
  142. };
  143. /**
  144. * Setup some UI event listeners.
  145. */
  146. UI.registerListeners
  147. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  148. /**
  149. * Setup some DOM event listeners.
  150. */
  151. UI.bindEvents = () => {
  152. /**
  153. *
  154. */
  155. function onResize() {
  156. VideoLayout.onResize();
  157. }
  158. // Resize and reposition videos in full screen mode.
  159. $(document).on(
  160. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  161. onResize);
  162. $(window).resize(onResize);
  163. };
  164. /**
  165. * Unbind some DOM event listeners.
  166. */
  167. UI.unbindEvents = () => {
  168. $(document).off(
  169. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  170. $(window).off('resize');
  171. };
  172. /**
  173. * Show local video stream on UI.
  174. * @param {JitsiTrack} track stream to show
  175. */
  176. UI.addLocalVideoStream = track => {
  177. VideoLayout.changeLocalVideo(track);
  178. };
  179. /**
  180. * Setup and show Etherpad.
  181. * @param {string} name etherpad id
  182. */
  183. UI.initEtherpad = name => {
  184. if (etherpadManager || !config.etherpad_base || !name) {
  185. return;
  186. }
  187. logger.log('Etherpad is enabled');
  188. etherpadManager = new EtherpadManager(eventEmitter);
  189. const url = new URL(name, config.etherpad_base);
  190. APP.store.dispatch(setDocumentUrl(url.toString()));
  191. };
  192. /**
  193. * Returns the shared document manager object.
  194. * @return {EtherpadManager} the shared document manager object
  195. */
  196. UI.getSharedDocumentManager = () => etherpadManager;
  197. /**
  198. * Show user on UI.
  199. * @param {JitsiParticipant} user
  200. */
  201. UI.addUser = function(user) {
  202. const id = user.getId();
  203. const displayName = user.getDisplayName();
  204. const status = user.getStatus();
  205. if (status) {
  206. // FIXME: move updateUserStatus in participantPresenceChanged action
  207. UI.updateUserStatus(user, status);
  208. }
  209. // set initial display name
  210. if (displayName) {
  211. UI.changeDisplayName(id, displayName);
  212. }
  213. };
  214. /**
  215. * Update videotype for specified user.
  216. * @param {string} id user id
  217. * @param {string} newVideoType new videotype
  218. */
  219. UI.onPeerVideoTypeChanged
  220. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  221. /**
  222. * Updates the user status.
  223. *
  224. * @param {JitsiParticipant} user - The user which status we need to update.
  225. * @param {string} status - The new status.
  226. */
  227. UI.updateUserStatus = (user, status) => {
  228. const reduxState = APP.store.getState() || {};
  229. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  230. // We hide status updates when join/leave notifications are disabled,
  231. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  232. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  233. return;
  234. }
  235. const displayName = user.getDisplayName();
  236. messageHandler.participantNotification(
  237. displayName,
  238. '',
  239. 'connected',
  240. 'dialOut.statusMessage',
  241. { status: UIUtil.escapeHtml(status) });
  242. };
  243. /**
  244. * Toggles filmstrip.
  245. */
  246. UI.toggleFilmstrip = function() {
  247. const { visible } = APP.store.getState()['features/filmstrip'];
  248. APP.store.dispatch(setFilmstripVisible(!visible));
  249. };
  250. /**
  251. * Toggles the visibility of the chat panel.
  252. */
  253. UI.toggleChat = () => APP.store.dispatch(toggleChat());
  254. /**
  255. * Handle new user display name.
  256. */
  257. UI.inputDisplayNameHandler = function(newDisplayName) {
  258. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  259. };
  260. // FIXME check if someone user this
  261. UI.showLoginPopup = function(callback) {
  262. logger.log('password is required');
  263. const message
  264. = `<input name="username" type="text"
  265. placeholder="user@domain.net"
  266. class="input-control" autofocus>
  267. <input name="password" type="password"
  268. data-i18n="[placeholder]dialog.userPassword"
  269. class="input-control"
  270. placeholder="user password">`
  271. ;
  272. // eslint-disable-next-line max-params
  273. const submitFunction = (e, v, m, f) => {
  274. if (v && f.username && f.password) {
  275. callback(f.username, f.password);
  276. }
  277. };
  278. messageHandler.openTwoButtonDialog({
  279. titleKey: 'dialog.passwordRequired',
  280. msgString: message,
  281. leftButtonKey: 'dialog.Ok',
  282. submitFunction,
  283. focus: ':input:first'
  284. });
  285. };
  286. UI.askForNickname = function() {
  287. // eslint-disable-next-line no-alert
  288. return window.prompt('Your nickname (optional)');
  289. };
  290. /**
  291. * Sets muted audio state for participant
  292. */
  293. UI.setAudioMuted = function(id, muted) {
  294. VideoLayout.onAudioMute(id, muted);
  295. if (APP.conference.isLocalId(id)) {
  296. APP.conference.updateAudioIconEnabled();
  297. }
  298. };
  299. /**
  300. * Sets muted video state for participant
  301. */
  302. UI.setVideoMuted = function(id, muted) {
  303. VideoLayout.onVideoMute(id, muted);
  304. if (APP.conference.isLocalId(id)) {
  305. APP.conference.updateVideoIconEnabled();
  306. }
  307. };
  308. /**
  309. * Triggers an update of remote video and large video displays so they may pick
  310. * up any state changes that have occurred elsewhere.
  311. *
  312. * @returns {void}
  313. */
  314. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  315. /**
  316. * Adds a listener that would be notified on the given type of event.
  317. *
  318. * @param type the type of the event we're listening for
  319. * @param listener a function that would be called when notified
  320. */
  321. UI.addListener = function(type, listener) {
  322. eventEmitter.on(type, listener);
  323. };
  324. /**
  325. * Removes the all listeners for all events.
  326. *
  327. * @returns {void}
  328. */
  329. UI.removeAllListeners = function() {
  330. eventEmitter.removeAllListeners();
  331. };
  332. /**
  333. * Removes the given listener for the given type of event.
  334. *
  335. * @param type the type of the event we're listening for
  336. * @param listener the listener we want to remove
  337. */
  338. UI.removeListener = function(type, listener) {
  339. eventEmitter.removeListener(type, listener);
  340. };
  341. /**
  342. * Emits the event of given type by specifying the parameters in options.
  343. *
  344. * @param type the type of the event we're emitting
  345. * @param options the parameters for the event
  346. */
  347. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  348. UI.clickOnVideo = videoNumber => VideoLayout.togglePin(videoNumber);
  349. // Used by torture.
  350. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  351. // Used by torture.
  352. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  353. /**
  354. * Updates the displayed avatar for participant.
  355. *
  356. * @param {string} id - User id whose avatar should be updated.
  357. * @param {string} avatarURL - The URL to avatar image to display.
  358. * @returns {void}
  359. */
  360. UI.refreshAvatarDisplay = function(id) {
  361. VideoLayout.changeUserAvatar(id);
  362. };
  363. /**
  364. * Notify user that connection failed.
  365. * @param {string} stropheErrorMsg raw Strophe error message
  366. */
  367. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  368. let descriptionKey;
  369. let descriptionArguments;
  370. if (stropheErrorMsg) {
  371. descriptionKey = 'dialog.connectErrorWithMsg';
  372. descriptionArguments = { msg: stropheErrorMsg };
  373. } else {
  374. descriptionKey = 'dialog.connectError';
  375. }
  376. messageHandler.showError({
  377. descriptionArguments,
  378. descriptionKey,
  379. titleKey: 'connection.CONNFAIL'
  380. });
  381. };
  382. /**
  383. * Notify user that maximum users limit has been reached.
  384. */
  385. UI.notifyMaxUsersLimitReached = function() {
  386. messageHandler.showError({
  387. hideErrorSupportLink: true,
  388. descriptionKey: 'dialog.maxUsersLimitReached',
  389. titleKey: 'dialog.maxUsersLimitReachedTitle'
  390. });
  391. };
  392. /**
  393. * Notify user that he was automatically muted when joned the conference.
  394. */
  395. UI.notifyInitiallyMuted = function() {
  396. messageHandler.participantNotification(
  397. null,
  398. 'notify.mutedTitle',
  399. 'connected',
  400. 'notify.muted',
  401. null);
  402. };
  403. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  404. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  405. };
  406. /**
  407. * Update audio level visualization for specified user.
  408. * @param {string} id user id
  409. * @param {number} lvl audio level
  410. */
  411. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  412. /**
  413. * Hide connection quality statistics from UI.
  414. */
  415. UI.hideStats = function() {
  416. VideoLayout.hideStats();
  417. };
  418. UI.notifyTokenAuthFailed = function() {
  419. messageHandler.showError({
  420. descriptionKey: 'dialog.tokenAuthFailed',
  421. titleKey: 'dialog.tokenAuthFailedTitle'
  422. });
  423. };
  424. UI.notifyInternalError = function(error) {
  425. messageHandler.showError({
  426. descriptionArguments: { error },
  427. descriptionKey: 'dialog.internalError',
  428. titleKey: 'dialog.internalErrorTitle'
  429. });
  430. };
  431. UI.notifyFocusDisconnected = function(focus, retrySec) {
  432. messageHandler.participantNotification(
  433. null, 'notify.focus',
  434. 'disconnected', 'notify.focusFail',
  435. { component: focus,
  436. ms: retrySec }
  437. );
  438. };
  439. /**
  440. * Notifies interested listeners that the raise hand property has changed.
  441. *
  442. * @param {boolean} isRaisedHand indicates the current state of the
  443. * "raised hand"
  444. */
  445. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  446. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  447. };
  448. /**
  449. * Update list of available physical devices.
  450. */
  451. UI.onAvailableDevicesChanged = function() {
  452. APP.conference.updateAudioIconEnabled();
  453. APP.conference.updateVideoIconEnabled();
  454. };
  455. /**
  456. * Returns the id of the current video shown on large.
  457. * Currently used by tests (torture).
  458. */
  459. UI.getLargeVideoID = function() {
  460. return VideoLayout.getLargeVideoID();
  461. };
  462. /**
  463. * Returns the current video shown on large.
  464. * Currently used by tests (torture).
  465. */
  466. UI.getLargeVideo = function() {
  467. return VideoLayout.getLargeVideo();
  468. };
  469. /**
  470. * Show shared video.
  471. * @param {string} id the id of the sender of the command
  472. * @param {string} url video url
  473. * @param {string} attributes
  474. */
  475. UI.onSharedVideoStart = function(id, url, attributes) {
  476. if (sharedVideoManager) {
  477. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  478. }
  479. };
  480. /**
  481. * Update shared video.
  482. * @param {string} id the id of the sender of the command
  483. * @param {string} url video url
  484. * @param {string} attributes
  485. */
  486. UI.onSharedVideoUpdate = function(id, url, attributes) {
  487. if (sharedVideoManager) {
  488. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  489. }
  490. };
  491. /**
  492. * Stop showing shared video.
  493. * @param {string} id the id of the sender of the command
  494. * @param {string} attributes
  495. */
  496. UI.onSharedVideoStop = function(id, attributes) {
  497. if (sharedVideoManager) {
  498. sharedVideoManager.onSharedVideoStop(id, attributes);
  499. }
  500. };
  501. /**
  502. * Handles user's features changes.
  503. */
  504. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  505. /**
  506. * Returns the number of known remote videos.
  507. *
  508. * @returns {number} The number of remote videos.
  509. */
  510. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  511. /**
  512. * Sets the remote control active status for a remote participant.
  513. *
  514. * @param {string} participantID - The id of the remote participant.
  515. * @param {boolean} isActive - The new remote control active status.
  516. * @returns {void}
  517. */
  518. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  519. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  520. };
  521. /**
  522. * Sets the remote control active status for the local participant.
  523. *
  524. * @returns {void}
  525. */
  526. UI.setLocalRemoteControlActiveChanged = function() {
  527. VideoLayout.setLocalRemoteControlActiveChanged();
  528. };
  529. // TODO: Export every function separately. For now there is no point of doing
  530. // this because we are importing everything.
  531. export default UI;