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

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