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.

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