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 19KB

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