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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /* global APP, $, config, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. const UI = {};
  4. import messageHandler from './util/MessageHandler';
  5. import UIUtil from './util/UIUtil';
  6. import UIEvents from '../../service/UI/UIEvents';
  7. import EtherpadManager from './etherpad/Etherpad';
  8. import SharedVideoManager from './shared_video/SharedVideo';
  9. import VideoLayout from './videolayout/VideoLayout';
  10. import { getLocalParticipant } from '../../react/features/base/participants';
  11. import { toggleChat } from '../../react/features/chat';
  12. import { setDocumentUrl } from '../../react/features/etherpad';
  13. import { setFilmstripVisible } from '../../react/features/filmstrip';
  14. import { joinLeaveNotificationsDisabled, setNotificationsEnabled } from '../../react/features/notifications';
  15. import {
  16. dockToolbox,
  17. setToolboxEnabled,
  18. showToolbox
  19. } from '../../react/features/toolbox';
  20. const EventEmitter = require('events');
  21. UI.messageHandler = messageHandler;
  22. const eventEmitter = new EventEmitter();
  23. UI.eventEmitter = eventEmitter;
  24. let etherpadManager;
  25. let sharedVideoManager;
  26. const UIListeners = new Map([
  27. [
  28. UIEvents.ETHERPAD_CLICKED,
  29. () => etherpadManager && etherpadManager.toggleEtherpad()
  30. ], [
  31. UIEvents.SHARED_VIDEO_CLICKED,
  32. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  33. ], [
  34. UIEvents.TOGGLE_FILMSTRIP,
  35. () => UI.toggleFilmstrip()
  36. ]
  37. ]);
  38. /**
  39. * Indicates if we're currently in full screen mode.
  40. *
  41. * @return {boolean} {true} to indicate that we're currently in full screen
  42. * mode, {false} otherwise
  43. */
  44. UI.isFullScreen = function() {
  45. return UIUtil.isFullScreen();
  46. };
  47. /**
  48. * Returns true if the etherpad window is currently visible.
  49. * @returns {Boolean} - true if the etherpad window is currently visible.
  50. */
  51. UI.isEtherpadVisible = function() {
  52. return Boolean(etherpadManager && etherpadManager.isVisible());
  53. };
  54. /**
  55. * Returns true if there is a shared video which is being shown (?).
  56. * @returns {boolean} - true if there is a shared video which is being shown.
  57. */
  58. UI.isSharedVideoShown = function() {
  59. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  60. };
  61. /**
  62. * Notify user that server has shut down.
  63. */
  64. UI.notifyGracefulShutdown = function() {
  65. messageHandler.showError({
  66. descriptionKey: 'dialog.gracefulShutdown',
  67. titleKey: 'dialog.serviceUnavailable'
  68. });
  69. };
  70. /**
  71. * Notify user that reservation error happened.
  72. */
  73. UI.notifyReservationError = function(code, msg) {
  74. messageHandler.showError({
  75. descriptionArguments: {
  76. code,
  77. msg
  78. },
  79. descriptionKey: 'dialog.reservationErrorMsg',
  80. titleKey: 'dialog.reservationError'
  81. });
  82. };
  83. /**
  84. * Notify user that conference was destroyed.
  85. * @param reason {string} the reason text
  86. */
  87. UI.notifyConferenceDestroyed = function(reason) {
  88. // FIXME: use Session Terminated from translation, but
  89. // 'reason' text comes from XMPP packet and is not translated
  90. messageHandler.showError({
  91. description: reason,
  92. titleKey: 'dialog.sessTerminated'
  93. });
  94. };
  95. /**
  96. * Change nickname for the user.
  97. * @param {string} id user id
  98. * @param {string} displayName new nickname
  99. */
  100. UI.changeDisplayName = function(id, displayName) {
  101. VideoLayout.onDisplayNameChanged(id, displayName);
  102. };
  103. /**
  104. * Initialize conference UI.
  105. */
  106. UI.initConference = function() {
  107. const { getState } = APP.store;
  108. const { id, name } = getLocalParticipant(getState);
  109. UI.showToolbar();
  110. const displayName = config.displayJids ? id : name;
  111. if (displayName) {
  112. UI.changeDisplayName('localVideoContainer', displayName);
  113. }
  114. };
  115. /**
  116. * Returns the shared document manager object.
  117. * @return {EtherpadManager} the shared document manager object
  118. */
  119. UI.getSharedVideoManager = function() {
  120. return sharedVideoManager;
  121. };
  122. /**
  123. * Starts the UI module and initializes all related components.
  124. *
  125. * @returns {boolean} true if the UI is ready and the conference should be
  126. * established, false - otherwise (for example in the case of welcome page)
  127. */
  128. UI.start = function() {
  129. clog("dgbt log UI.start")
  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. // dev hook
  363. // UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  364. UI.showToolbar = timeout => {
  365. try {
  366. var fn_name = "UI_arr_showToolbar"
  367. var fn_ret
  368. glob_dev_fns[fn_name] ? fn_ret = glob_dev_fns[fn_name]({that:this,kv:{
  369. // ret,
  370. // _feedbackConfigured,_fullScreen,_screensharing,_sharingVideo,t,
  371. },args:[...arguments],fn_name,arg0:arguments}) : 0
  372. if (fn_ret){ return fn_ret.ret };
  373. } catch (err) { clog(`react_fn fn_name:${fn_name} err:`,err) }
  374. return APP.store.dispatch(showToolbox(timeout));
  375. }
  376. // Used by torture.
  377. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  378. /**
  379. * Updates the displayed avatar for participant.
  380. *
  381. * @param {string} id - User id whose avatar should be updated.
  382. * @param {string} avatarURL - The URL to avatar image to display.
  383. * @returns {void}
  384. */
  385. UI.refreshAvatarDisplay = function(id) {
  386. VideoLayout.changeUserAvatar(id);
  387. };
  388. /**
  389. * Notify user that connection failed.
  390. * @param {string} stropheErrorMsg raw Strophe error message
  391. */
  392. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  393. let descriptionKey;
  394. let descriptionArguments;
  395. if (stropheErrorMsg) {
  396. descriptionKey = 'dialog.connectErrorWithMsg';
  397. descriptionArguments = { msg: stropheErrorMsg };
  398. } else {
  399. descriptionKey = 'dialog.connectError';
  400. }
  401. messageHandler.showError({
  402. descriptionArguments,
  403. descriptionKey,
  404. titleKey: 'connection.CONNFAIL'
  405. });
  406. };
  407. /**
  408. * Notify user that maximum users limit has been reached.
  409. */
  410. UI.notifyMaxUsersLimitReached = function() {
  411. messageHandler.showError({
  412. hideErrorSupportLink: true,
  413. descriptionKey: 'dialog.maxUsersLimitReached',
  414. titleKey: 'dialog.maxUsersLimitReachedTitle'
  415. });
  416. };
  417. /**
  418. * Notify user that he was automatically muted when joned the conference.
  419. */
  420. UI.notifyInitiallyMuted = function() {
  421. messageHandler.participantNotification(
  422. null,
  423. 'notify.mutedTitle',
  424. 'connected',
  425. 'notify.muted',
  426. null);
  427. };
  428. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  429. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  430. };
  431. /**
  432. * Update audio level visualization for specified user.
  433. * @param {string} id user id
  434. * @param {number} lvl audio level
  435. */
  436. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  437. /**
  438. * Hide connection quality statistics from UI.
  439. */
  440. UI.hideStats = function() {
  441. VideoLayout.hideStats();
  442. };
  443. UI.notifyTokenAuthFailed = function() {
  444. messageHandler.showError({
  445. descriptionKey: 'dialog.tokenAuthFailed',
  446. titleKey: 'dialog.tokenAuthFailedTitle'
  447. });
  448. };
  449. UI.notifyInternalError = function(error) {
  450. messageHandler.showError({
  451. descriptionArguments: { error },
  452. descriptionKey: 'dialog.internalError',
  453. titleKey: 'dialog.internalErrorTitle'
  454. });
  455. };
  456. UI.notifyFocusDisconnected = function(focus, retrySec) {
  457. messageHandler.participantNotification(
  458. null, 'notify.focus',
  459. 'disconnected', 'notify.focusFail',
  460. { component: focus,
  461. ms: retrySec }
  462. );
  463. };
  464. /**
  465. * Notifies interested listeners that the raise hand property has changed.
  466. *
  467. * @param {boolean} isRaisedHand indicates the current state of the
  468. * "raised hand"
  469. */
  470. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  471. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  472. };
  473. /**
  474. * Update list of available physical devices.
  475. */
  476. UI.onAvailableDevicesChanged = function() {
  477. APP.conference.updateAudioIconEnabled();
  478. APP.conference.updateVideoIconEnabled();
  479. };
  480. /**
  481. * Returns the id of the current video shown on large.
  482. * Currently used by tests (torture).
  483. */
  484. UI.getLargeVideoID = function() {
  485. return VideoLayout.getLargeVideoID();
  486. };
  487. /**
  488. * Returns the current video shown on large.
  489. * Currently used by tests (torture).
  490. */
  491. UI.getLargeVideo = function() {
  492. return VideoLayout.getLargeVideo();
  493. };
  494. /**
  495. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  496. * 2 button dialog with buttons - cancel and go to web store.
  497. * @param url {string} the url of the extension.
  498. */
  499. UI.showExtensionExternalInstallationDialog = function(url) {
  500. let openedWindow = null;
  501. const submitFunction = function(e, v) {
  502. if (v) {
  503. e.preventDefault();
  504. if (openedWindow === null || openedWindow.closed) {
  505. openedWindow
  506. = window.open(
  507. url,
  508. 'extension_store_window',
  509. 'resizable,scrollbars=yes,status=1');
  510. } else {
  511. openedWindow.focus();
  512. }
  513. }
  514. };
  515. const closeFunction = function(e, v) {
  516. if (openedWindow) {
  517. // Ideally we would close the popup, but this does not seem to work
  518. // on Chrome. Leaving it uncommented in case it could work
  519. // in some version.
  520. openedWindow.close();
  521. openedWindow = null;
  522. }
  523. if (!v) {
  524. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  525. }
  526. };
  527. messageHandler.openTwoButtonDialog({
  528. titleKey: 'dialog.externalInstallationTitle',
  529. msgKey: 'dialog.externalInstallationMsg',
  530. leftButtonKey: 'dialog.goToStore',
  531. submitFunction,
  532. loadedFunction: $.noop,
  533. closeFunction
  534. });
  535. };
  536. /**
  537. * Shows a dialog which asks user to install the extension. This one is
  538. * displayed after installation is triggered from the script, but fails because
  539. * it must be initiated by user gesture.
  540. * @param callback {function} function to be executed after user clicks
  541. * the install button - it should make another attempt to install the extension.
  542. */
  543. UI.showExtensionInlineInstallationDialog = function(callback) {
  544. const submitFunction = function(e, v) {
  545. if (v) {
  546. callback();
  547. }
  548. };
  549. const closeFunction = function(e, v) {
  550. if (!v) {
  551. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  552. }
  553. };
  554. messageHandler.openTwoButtonDialog({
  555. titleKey: 'dialog.externalInstallationTitle',
  556. msgKey: 'dialog.inlineInstallationMsg',
  557. leftButtonKey: 'dialog.inlineInstallExtension',
  558. submitFunction,
  559. loadedFunction: $.noop,
  560. closeFunction
  561. });
  562. };
  563. /**
  564. * Show shared video.
  565. * @param {string} id the id of the sender of the command
  566. * @param {string} url video url
  567. * @param {string} attributes
  568. */
  569. UI.onSharedVideoStart = function(id, url, attributes) {
  570. if (sharedVideoManager) {
  571. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  572. }
  573. };
  574. /**
  575. * Update shared video.
  576. * @param {string} id the id of the sender of the command
  577. * @param {string} url video url
  578. * @param {string} attributes
  579. */
  580. UI.onSharedVideoUpdate = function(id, url, attributes) {
  581. if (sharedVideoManager) {
  582. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  583. }
  584. };
  585. /**
  586. * Stop showing shared video.
  587. * @param {string} id the id of the sender of the command
  588. * @param {string} attributes
  589. */
  590. UI.onSharedVideoStop = function(id, attributes) {
  591. if (sharedVideoManager) {
  592. sharedVideoManager.onSharedVideoStop(id, attributes);
  593. }
  594. };
  595. /**
  596. * Handles user's features changes.
  597. */
  598. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  599. /**
  600. * Returns the number of known remote videos.
  601. *
  602. * @returns {number} The number of remote videos.
  603. */
  604. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  605. /**
  606. * Sets the remote control active status for a remote participant.
  607. *
  608. * @param {string} participantID - The id of the remote participant.
  609. * @param {boolean} isActive - The new remote control active status.
  610. * @returns {void}
  611. */
  612. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  613. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  614. };
  615. /**
  616. * Sets the remote control active status for the local participant.
  617. *
  618. * @returns {void}
  619. */
  620. UI.setLocalRemoteControlActiveChanged = function() {
  621. VideoLayout.setLocalRemoteControlActiveChanged();
  622. };
  623. // TODO: Export every function separately. For now there is no point of doing
  624. // this because we are importing everything.
  625. export default UI;