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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. data-i18n="[placeholder]dialog.user"
  268. class="input-control" autofocus>
  269. <input name="password" type="password"
  270. data-i18n="[placeholder]dialog.userPassword"
  271. class="input-control"
  272. placeholder="user password">`
  273. ;
  274. // eslint-disable-next-line max-params
  275. const submitFunction = (e, v, m, f) => {
  276. if (v && f.username && f.password) {
  277. callback(f.username, f.password);
  278. }
  279. };
  280. messageHandler.openTwoButtonDialog({
  281. titleKey: 'dialog.passwordRequired',
  282. msgString: message,
  283. leftButtonKey: 'dialog.Ok',
  284. submitFunction,
  285. focus: ':input:first'
  286. });
  287. };
  288. /**
  289. * Sets muted audio state for participant
  290. */
  291. UI.setAudioMuted = function(id) {
  292. // FIXME: Maybe this can be removed!
  293. if (APP.conference.isLocalId(id)) {
  294. APP.conference.updateAudioIconEnabled();
  295. }
  296. };
  297. /**
  298. * Sets muted video state for participant
  299. */
  300. UI.setVideoMuted = function(id) {
  301. VideoLayout.onVideoMute(id);
  302. if (APP.conference.isLocalId(id)) {
  303. APP.conference.updateVideoIconEnabled();
  304. }
  305. };
  306. /**
  307. * Triggers an update of remote video and large video displays so they may pick
  308. * up any state changes that have occurred elsewhere.
  309. *
  310. * @returns {void}
  311. */
  312. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  313. /**
  314. * Adds a listener that would be notified on the given type of event.
  315. *
  316. * @param type the type of the event we're listening for
  317. * @param listener a function that would be called when notified
  318. */
  319. UI.addListener = function(type, listener) {
  320. eventEmitter.on(type, listener);
  321. };
  322. /**
  323. * Removes the all listeners for all events.
  324. *
  325. * @returns {void}
  326. */
  327. UI.removeAllListeners = function() {
  328. eventEmitter.removeAllListeners();
  329. };
  330. /**
  331. * Removes the given listener for the given type of event.
  332. *
  333. * @param type the type of the event we're listening for
  334. * @param listener the listener we want to remove
  335. */
  336. UI.removeListener = function(type, listener) {
  337. eventEmitter.removeListener(type, listener);
  338. };
  339. /**
  340. * Emits the event of given type by specifying the parameters in options.
  341. *
  342. * @param type the type of the event we're emitting
  343. * @param options the parameters for the event
  344. */
  345. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  346. UI.clickOnVideo = videoNumber => VideoLayout.togglePin(videoNumber);
  347. // Used by torture.
  348. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  349. // Used by torture.
  350. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  351. /**
  352. * Updates the displayed avatar for participant.
  353. *
  354. * @param {string} id - User id whose avatar should be updated.
  355. * @param {string} avatarURL - The URL to avatar image to display.
  356. * @returns {void}
  357. */
  358. UI.refreshAvatarDisplay = function(id) {
  359. VideoLayout.changeUserAvatar(id);
  360. };
  361. /**
  362. * Notify user that connection failed.
  363. * @param {string} stropheErrorMsg raw Strophe error message
  364. */
  365. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  366. let descriptionKey;
  367. let descriptionArguments;
  368. if (stropheErrorMsg) {
  369. descriptionKey = 'dialog.connectErrorWithMsg';
  370. descriptionArguments = { msg: stropheErrorMsg };
  371. } else {
  372. descriptionKey = 'dialog.connectError';
  373. }
  374. messageHandler.showError({
  375. descriptionArguments,
  376. descriptionKey,
  377. titleKey: 'connection.CONNFAIL'
  378. });
  379. };
  380. /**
  381. * Notify user that maximum users limit has been reached.
  382. */
  383. UI.notifyMaxUsersLimitReached = function() {
  384. messageHandler.showError({
  385. hideErrorSupportLink: true,
  386. descriptionKey: 'dialog.maxUsersLimitReached',
  387. titleKey: 'dialog.maxUsersLimitReachedTitle'
  388. });
  389. };
  390. /**
  391. * Notify user that he was automatically muted when joned the conference.
  392. */
  393. UI.notifyInitiallyMuted = function() {
  394. messageHandler.participantNotification(
  395. null,
  396. 'notify.mutedTitle',
  397. 'connected',
  398. 'notify.muted',
  399. null);
  400. };
  401. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  402. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  403. };
  404. /**
  405. * Update audio level visualization for specified user.
  406. * @param {string} id user id
  407. * @param {number} lvl audio level
  408. */
  409. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  410. /**
  411. * Hide connection quality statistics from UI.
  412. */
  413. UI.hideStats = function() {
  414. VideoLayout.hideStats();
  415. };
  416. UI.notifyTokenAuthFailed = function() {
  417. messageHandler.showError({
  418. descriptionKey: 'dialog.tokenAuthFailed',
  419. titleKey: 'dialog.tokenAuthFailedTitle'
  420. });
  421. };
  422. UI.notifyInternalError = function(error) {
  423. messageHandler.showError({
  424. descriptionArguments: { error },
  425. descriptionKey: 'dialog.internalError',
  426. titleKey: 'dialog.internalErrorTitle'
  427. });
  428. };
  429. UI.notifyFocusDisconnected = function(focus, retrySec) {
  430. messageHandler.participantNotification(
  431. null, 'notify.focus',
  432. 'disconnected', 'notify.focusFail',
  433. { component: focus,
  434. ms: retrySec }
  435. );
  436. };
  437. /**
  438. * Notifies interested listeners that the raise hand property has changed.
  439. *
  440. * @param {boolean} isRaisedHand indicates the current state of the
  441. * "raised hand"
  442. */
  443. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  444. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  445. };
  446. /**
  447. * Update list of available physical devices.
  448. */
  449. UI.onAvailableDevicesChanged = function() {
  450. APP.conference.updateAudioIconEnabled();
  451. APP.conference.updateVideoIconEnabled();
  452. };
  453. /**
  454. * Returns the id of the current video shown on large.
  455. * Currently used by tests (torture).
  456. */
  457. UI.getLargeVideoID = function() {
  458. return VideoLayout.getLargeVideoID();
  459. };
  460. /**
  461. * Returns the current video shown on large.
  462. * Currently used by tests (torture).
  463. */
  464. UI.getLargeVideo = function() {
  465. return VideoLayout.getLargeVideo();
  466. };
  467. /**
  468. * Show shared video.
  469. * @param {string} id the id of the sender of the command
  470. * @param {string} url video url
  471. * @param {string} attributes
  472. */
  473. UI.onSharedVideoStart = function(id, url, attributes) {
  474. if (sharedVideoManager) {
  475. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  476. }
  477. };
  478. /**
  479. * Update shared video.
  480. * @param {string} id the id of the sender of the command
  481. * @param {string} url video url
  482. * @param {string} attributes
  483. */
  484. UI.onSharedVideoUpdate = function(id, url, attributes) {
  485. if (sharedVideoManager) {
  486. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  487. }
  488. };
  489. /**
  490. * Stop showing shared video.
  491. * @param {string} id the id of the sender of the command
  492. * @param {string} attributes
  493. */
  494. UI.onSharedVideoStop = function(id, attributes) {
  495. if (sharedVideoManager) {
  496. sharedVideoManager.onSharedVideoStop(id, attributes);
  497. }
  498. };
  499. /**
  500. * Handles user's features changes.
  501. */
  502. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  503. /**
  504. * Returns the number of known remote videos.
  505. *
  506. * @returns {number} The number of remote videos.
  507. */
  508. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  509. /**
  510. * Sets the remote control active status for a remote participant.
  511. *
  512. * @param {string} participantID - The id of the remote participant.
  513. * @param {boolean} isActive - The new remote control active status.
  514. * @returns {void}
  515. */
  516. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  517. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  518. };
  519. /**
  520. * Sets the remote control active status for the local participant.
  521. *
  522. * @returns {void}
  523. */
  524. UI.setLocalRemoteControlActiveChanged = function() {
  525. VideoLayout.setLocalRemoteControlActiveChanged();
  526. };
  527. // TODO: Export every function separately. For now there is no point of doing
  528. // this because we are importing everything.
  529. export default UI;