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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  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 Filmstrip from './videolayout/Filmstrip';
  11. import { JitsiTrackErrors } from '../../react/features/base/lib-jitsi-meet';
  12. import { getLocalParticipant } from '../../react/features/base/participants';
  13. import { toggleChat } from '../../react/features/chat';
  14. import { openDisplayNamePrompt } from '../../react/features/display-name';
  15. import { setEtherpadHasInitialzied } from '../../react/features/etherpad';
  16. import { setFilmstripVisible } from '../../react/features/filmstrip';
  17. import {
  18. setNotificationsEnabled,
  19. showWarningNotification
  20. } from '../../react/features/notifications';
  21. import {
  22. dockToolbox,
  23. setToolboxEnabled,
  24. showToolbox
  25. } from '../../react/features/toolbox';
  26. const EventEmitter = require('events');
  27. UI.messageHandler = messageHandler;
  28. import FollowMe from '../FollowMe';
  29. const eventEmitter = new EventEmitter();
  30. UI.eventEmitter = eventEmitter;
  31. let etherpadManager;
  32. let sharedVideoManager;
  33. let followMeHandler;
  34. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  35. microphone: {},
  36. camera: {}
  37. };
  38. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  39. .camera[JitsiTrackErrors.UNSUPPORTED_RESOLUTION]
  40. = 'dialog.cameraUnsupportedResolutionError';
  41. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.GENERAL]
  42. = 'dialog.cameraUnknownError';
  43. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.PERMISSION_DENIED]
  44. = 'dialog.cameraPermissionDeniedError';
  45. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.NOT_FOUND]
  46. = 'dialog.cameraNotFoundError';
  47. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.CONSTRAINT_FAILED]
  48. = 'dialog.cameraConstraintFailedError';
  49. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  50. .camera[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  51. = 'dialog.cameraNotSendingData';
  52. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[JitsiTrackErrors.GENERAL]
  53. = 'dialog.micUnknownError';
  54. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  55. .microphone[JitsiTrackErrors.PERMISSION_DENIED]
  56. = 'dialog.micPermissionDeniedError';
  57. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[JitsiTrackErrors.NOT_FOUND]
  58. = 'dialog.micNotFoundError';
  59. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  60. .microphone[JitsiTrackErrors.CONSTRAINT_FAILED]
  61. = 'dialog.micConstraintFailedError';
  62. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  63. .microphone[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  64. = 'dialog.micNotSendingData';
  65. const UIListeners = new Map([
  66. [
  67. UIEvents.ETHERPAD_CLICKED,
  68. () => etherpadManager && etherpadManager.toggleEtherpad()
  69. ], [
  70. UIEvents.SHARED_VIDEO_CLICKED,
  71. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  72. ], [
  73. UIEvents.TOGGLE_FILMSTRIP,
  74. () => UI.toggleFilmstrip()
  75. ], [
  76. UIEvents.FOLLOW_ME_ENABLED,
  77. enabled => followMeHandler && followMeHandler.enableFollowMe(enabled)
  78. ]
  79. ]);
  80. /**
  81. * Indicates if we're currently in full screen mode.
  82. *
  83. * @return {boolean} {true} to indicate that we're currently in full screen
  84. * mode, {false} otherwise
  85. */
  86. UI.isFullScreen = function() {
  87. return UIUtil.isFullScreen();
  88. };
  89. /**
  90. * Returns true if the etherpad window is currently visible.
  91. * @returns {Boolean} - true if the etherpad window is currently visible.
  92. */
  93. UI.isEtherpadVisible = function() {
  94. return Boolean(etherpadManager && etherpadManager.isVisible());
  95. };
  96. /**
  97. * Returns true if there is a shared video which is being shown (?).
  98. * @returns {boolean} - true if there is a shared video which is being shown.
  99. */
  100. UI.isSharedVideoShown = function() {
  101. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  102. };
  103. /**
  104. * Notify user that server has shut down.
  105. */
  106. UI.notifyGracefulShutdown = function() {
  107. messageHandler.showError({
  108. descriptionKey: 'dialog.gracefulShutdown',
  109. titleKey: 'dialog.serviceUnavailable'
  110. });
  111. };
  112. /**
  113. * Notify user that reservation error happened.
  114. */
  115. UI.notifyReservationError = function(code, msg) {
  116. messageHandler.showError({
  117. descriptionArguments: {
  118. code,
  119. msg
  120. },
  121. descriptionKey: 'dialog.reservationErrorMsg',
  122. titleKey: 'dialog.reservationError'
  123. });
  124. };
  125. /**
  126. * Notify user that he has been kicked from the server.
  127. */
  128. UI.notifyKicked = function() {
  129. messageHandler.showError({
  130. hideErrorSupportLink: true,
  131. descriptionKey: 'dialog.kickMessage',
  132. titleKey: 'dialog.kickTitle'
  133. });
  134. };
  135. /**
  136. * Notify user that conference was destroyed.
  137. * @param reason {string} the reason text
  138. */
  139. UI.notifyConferenceDestroyed = function(reason) {
  140. // FIXME: use Session Terminated from translation, but
  141. // 'reason' text comes from XMPP packet and is not translated
  142. messageHandler.showError({
  143. description: reason,
  144. titleKey: 'dialog.sessTerminated'
  145. });
  146. };
  147. /**
  148. * Change nickname for the user.
  149. * @param {string} id user id
  150. * @param {string} displayName new nickname
  151. */
  152. UI.changeDisplayName = function(id, displayName) {
  153. VideoLayout.onDisplayNameChanged(id, displayName);
  154. };
  155. /**
  156. * Sets the "raised hand" status for a participant.
  157. *
  158. * @param {string} id - The id of the participant whose raised hand UI should
  159. * be updated.
  160. * @param {string} name - The name of the participant with the raised hand
  161. * update.
  162. * @param {boolean} raisedHandStatus - Whether the participant's hand is raised
  163. * or not.
  164. * @returns {void}
  165. */
  166. UI.setRaisedHandStatus = (id, name, raisedHandStatus) => {
  167. VideoLayout.setRaisedHandStatus(id, raisedHandStatus);
  168. };
  169. /**
  170. * Sets the local "raised hand" status.
  171. */
  172. UI.setLocalRaisedHandStatus
  173. = raisedHandStatus =>
  174. VideoLayout.setRaisedHandStatus(
  175. APP.conference.getMyUserId(),
  176. raisedHandStatus);
  177. /**
  178. * Initialize conference UI.
  179. */
  180. UI.initConference = function() {
  181. const { getState } = APP.store;
  182. const { id, name } = getLocalParticipant(getState);
  183. // Update default button states before showing the toolbar
  184. // if local role changes buttons state will be again updated.
  185. UI.updateLocalRole(APP.conference.isModerator);
  186. UI.showToolbar();
  187. const displayName = config.displayJids ? id : name;
  188. if (displayName) {
  189. UI.changeDisplayName('localVideoContainer', displayName);
  190. }
  191. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  192. // other participants' UI. Consequently, it needs (1) read and write access
  193. // to the UI (depending on the moderator role of the local participant) and
  194. // (2) APP.conference as means of communication between the participants.
  195. followMeHandler = new FollowMe(APP.conference, UI);
  196. };
  197. /**
  198. * Returns the shared document manager object.
  199. * @return {EtherpadManager} the shared document manager object
  200. */
  201. UI.getSharedVideoManager = function() {
  202. return sharedVideoManager;
  203. };
  204. /**
  205. * Starts the UI module and initializes all related components.
  206. *
  207. * @returns {boolean} true if the UI is ready and the conference should be
  208. * established, false - otherwise (for example in the case of welcome page)
  209. */
  210. UI.start = function() {
  211. document.title = interfaceConfig.APP_NAME;
  212. // Set the defaults for prompt dialogs.
  213. $.prompt.setDefaults({ persistent: false });
  214. Filmstrip.init(eventEmitter);
  215. VideoLayout.init(eventEmitter);
  216. if (!interfaceConfig.filmStripOnly) {
  217. VideoLayout.initLargeVideo();
  218. }
  219. // Do not animate the video area on UI start (second argument passed into
  220. // resizeVideoArea) because the animation is not visible anyway. Plus with
  221. // the current dom layout, the quality label is part of the video layout and
  222. // will be seen animating in.
  223. VideoLayout.resizeVideoArea(true, false);
  224. sharedVideoManager = new SharedVideoManager(eventEmitter);
  225. if (interfaceConfig.filmStripOnly) {
  226. $('body').addClass('filmstrip-only');
  227. APP.store.dispatch(setNotificationsEnabled(false));
  228. } else if (config.iAmRecorder) {
  229. // in case of iAmSipGateway keep local video visible
  230. if (!config.iAmSipGateway) {
  231. VideoLayout.setLocalVideoVisible(false);
  232. }
  233. APP.store.dispatch(setToolboxEnabled(false));
  234. APP.store.dispatch(setNotificationsEnabled(false));
  235. UI.messageHandler.enablePopups(false);
  236. }
  237. document.title = interfaceConfig.APP_NAME;
  238. };
  239. /**
  240. * Setup some UI event listeners.
  241. */
  242. UI.registerListeners
  243. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  244. /**
  245. * Setup some DOM event listeners.
  246. */
  247. UI.bindEvents = () => {
  248. /**
  249. *
  250. */
  251. function onResize() {
  252. VideoLayout.resizeVideoArea();
  253. }
  254. // Resize and reposition videos in full screen mode.
  255. $(document).on(
  256. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  257. onResize);
  258. $(window).resize(onResize);
  259. };
  260. /**
  261. * Unbind some DOM event listeners.
  262. */
  263. UI.unbindEvents = () => {
  264. $(document).off(
  265. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  266. $(window).off('resize');
  267. };
  268. /**
  269. * Show local stream on UI.
  270. * @param {JitsiTrack} track stream to show
  271. */
  272. UI.addLocalStream = track => {
  273. switch (track.getType()) {
  274. case 'audio':
  275. // Local audio is not rendered so no further action is needed at this
  276. // point.
  277. break;
  278. case 'video':
  279. VideoLayout.changeLocalVideo(track);
  280. break;
  281. default:
  282. logger.error(`Unknown stream type: ${track.getType()}`);
  283. break;
  284. }
  285. };
  286. /**
  287. * Removed remote stream from UI.
  288. * @param {JitsiTrack} track stream to remove
  289. */
  290. UI.removeRemoteStream = track => VideoLayout.onRemoteStreamRemoved(track);
  291. /**
  292. * Setup and show Etherpad.
  293. * @param {string} name etherpad id
  294. */
  295. UI.initEtherpad = name => {
  296. if (etherpadManager || !config.etherpad_base || !name) {
  297. return;
  298. }
  299. logger.log('Etherpad is enabled');
  300. etherpadManager
  301. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  302. APP.store.dispatch(setEtherpadHasInitialzied());
  303. };
  304. /**
  305. * Returns the shared document manager object.
  306. * @return {EtherpadManager} the shared document manager object
  307. */
  308. UI.getSharedDocumentManager = () => etherpadManager;
  309. /**
  310. * Show user on UI.
  311. * @param {JitsiParticipant} user
  312. */
  313. UI.addUser = function(user) {
  314. const id = user.getId();
  315. const displayName = user.getDisplayName();
  316. const status = user.getStatus();
  317. if (status) {
  318. // FIXME: move updateUserStatus in participantPresenceChanged action
  319. UI.updateUserStatus(user, status);
  320. }
  321. // set initial display name
  322. if (displayName) {
  323. UI.changeDisplayName(id, displayName);
  324. }
  325. };
  326. /**
  327. * Update videotype for specified user.
  328. * @param {string} id user id
  329. * @param {string} newVideoType new videotype
  330. */
  331. UI.onPeerVideoTypeChanged
  332. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  333. /**
  334. * Update local user role and show notification if user is moderator.
  335. * @param {boolean} isModerator if local user is moderator or not
  336. */
  337. UI.updateLocalRole = isModerator => {
  338. VideoLayout.showModeratorIndicator();
  339. if (isModerator && !interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  340. messageHandler.participantNotification(
  341. null, 'notify.me', 'connected', 'notify.moderator');
  342. }
  343. };
  344. /**
  345. * Check the role for the user and reflect it in the UI, moderator ui indication
  346. * and notifies user who is the moderator
  347. * @param user to check for moderator
  348. */
  349. UI.updateUserRole = user => {
  350. VideoLayout.showModeratorIndicator();
  351. // We don't need to show moderator notifications when the focus (moderator)
  352. // indicator is disabled.
  353. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  354. return;
  355. }
  356. const displayName = user.getDisplayName();
  357. messageHandler.participantNotification(
  358. displayName,
  359. 'notify.somebody',
  360. 'connected',
  361. 'notify.grantedTo',
  362. { to: displayName
  363. ? UIUtil.escapeHtml(displayName) : '$t(notify.somebody)' });
  364. };
  365. /**
  366. * Updates the user status.
  367. *
  368. * @param {JitsiParticipant} user - The user which status we need to update.
  369. * @param {string} status - The new status.
  370. */
  371. UI.updateUserStatus = (user, status) => {
  372. const reduxState = APP.store.getState() || {};
  373. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  374. if (!status || calleeInfoVisible) {
  375. return;
  376. }
  377. const displayName = user.getDisplayName();
  378. messageHandler.participantNotification(
  379. displayName,
  380. '',
  381. 'connected',
  382. 'dialOut.statusMessage',
  383. { status: UIUtil.escapeHtml(status) });
  384. };
  385. /**
  386. * Toggles filmstrip.
  387. */
  388. UI.toggleFilmstrip = function() {
  389. const { visible } = APP.store.getState()['features/filmstrip'];
  390. APP.store.dispatch(setFilmstripVisible(!visible));
  391. };
  392. /**
  393. * Checks if the filmstrip is currently visible or not.
  394. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  395. */
  396. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  397. /**
  398. * Toggles the visibility of the chat panel.
  399. */
  400. UI.toggleChat = () => APP.store.dispatch(toggleChat());
  401. /**
  402. * Handle new user display name.
  403. */
  404. UI.inputDisplayNameHandler = function(newDisplayName) {
  405. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  406. };
  407. /**
  408. * Return the type of the remote video.
  409. * @param jid the jid for the remote video
  410. * @returns the video type video or screen.
  411. */
  412. UI.getRemoteVideoType = function(jid) {
  413. return VideoLayout.getRemoteVideoType(jid);
  414. };
  415. // FIXME check if someone user this
  416. UI.showLoginPopup = function(callback) {
  417. logger.log('password is required');
  418. const message
  419. = `<input name="username" type="text"
  420. placeholder="user@domain.net"
  421. class="input-control" autofocus>
  422. <input name="password" type="password"
  423. data-i18n="[placeholder]dialog.userPassword"
  424. class="input-control"
  425. placeholder="user password">`
  426. ;
  427. // eslint-disable-next-line max-params
  428. const submitFunction = (e, v, m, f) => {
  429. if (v && f.username && f.password) {
  430. callback(f.username, f.password);
  431. }
  432. };
  433. messageHandler.openTwoButtonDialog({
  434. titleKey: 'dialog.passwordRequired',
  435. msgString: message,
  436. leftButtonKey: 'dialog.Ok',
  437. submitFunction,
  438. focus: ':input:first'
  439. });
  440. };
  441. UI.askForNickname = function() {
  442. // eslint-disable-next-line no-alert
  443. return window.prompt('Your nickname (optional)');
  444. };
  445. /**
  446. * Sets muted audio state for participant
  447. */
  448. UI.setAudioMuted = function(id, muted) {
  449. VideoLayout.onAudioMute(id, muted);
  450. if (APP.conference.isLocalId(id)) {
  451. APP.conference.updateAudioIconEnabled();
  452. }
  453. };
  454. /**
  455. * Sets muted video state for participant
  456. */
  457. UI.setVideoMuted = function(id, muted) {
  458. VideoLayout.onVideoMute(id, muted);
  459. if (APP.conference.isLocalId(id)) {
  460. APP.conference.updateVideoIconEnabled();
  461. }
  462. };
  463. /**
  464. * Triggers an update of remote video and large video displays so they may pick
  465. * up any state changes that have occurred elsewhere.
  466. *
  467. * @returns {void}
  468. */
  469. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  470. /**
  471. * Adds a listener that would be notified on the given type of event.
  472. *
  473. * @param type the type of the event we're listening for
  474. * @param listener a function that would be called when notified
  475. */
  476. UI.addListener = function(type, listener) {
  477. eventEmitter.on(type, listener);
  478. };
  479. /**
  480. * Removes the all listeners for all events.
  481. *
  482. * @returns {void}
  483. */
  484. UI.removeAllListeners = function() {
  485. eventEmitter.removeAllListeners();
  486. };
  487. /**
  488. * Removes the given listener for the given type of event.
  489. *
  490. * @param type the type of the event we're listening for
  491. * @param listener the listener we want to remove
  492. */
  493. UI.removeListener = function(type, listener) {
  494. eventEmitter.removeListener(type, listener);
  495. };
  496. /**
  497. * Emits the event of given type by specifying the parameters in options.
  498. *
  499. * @param type the type of the event we're emitting
  500. * @param options the parameters for the event
  501. */
  502. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  503. UI.clickOnVideo = videoNumber => VideoLayout.togglePin(videoNumber);
  504. // Used by torture.
  505. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  506. // Used by torture.
  507. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  508. /**
  509. * Updates the displayed avatar for participant.
  510. *
  511. * @param {string} id - User id whose avatar should be updated.
  512. * @param {string} avatarURL - The URL to avatar image to display.
  513. * @returns {void}
  514. */
  515. UI.refreshAvatarDisplay = function(id, avatarURL) {
  516. VideoLayout.changeUserAvatar(id, avatarURL);
  517. };
  518. /**
  519. * Notify user that connection failed.
  520. * @param {string} stropheErrorMsg raw Strophe error message
  521. */
  522. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  523. let descriptionKey;
  524. let descriptionArguments;
  525. if (stropheErrorMsg) {
  526. descriptionKey = 'dialog.connectErrorWithMsg';
  527. descriptionArguments = { msg: stropheErrorMsg };
  528. } else {
  529. descriptionKey = 'dialog.connectError';
  530. }
  531. messageHandler.showError({
  532. descriptionArguments,
  533. descriptionKey,
  534. titleKey: 'connection.CONNFAIL'
  535. });
  536. };
  537. /**
  538. * Notify user that maximum users limit has been reached.
  539. */
  540. UI.notifyMaxUsersLimitReached = function() {
  541. messageHandler.showError({
  542. hideErrorSupportLink: true,
  543. descriptionKey: 'dialog.maxUsersLimitReached',
  544. titleKey: 'dialog.maxUsersLimitReachedTitle'
  545. });
  546. };
  547. /**
  548. * Notify user that he was automatically muted when joned the conference.
  549. */
  550. UI.notifyInitiallyMuted = function() {
  551. messageHandler.participantNotification(
  552. null,
  553. 'notify.mutedTitle',
  554. 'connected',
  555. 'notify.muted',
  556. null);
  557. };
  558. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  559. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  560. };
  561. /**
  562. * Prompt user for nickname.
  563. */
  564. UI.promptDisplayName = () => {
  565. APP.store.dispatch(openDisplayNamePrompt(undefined));
  566. };
  567. /**
  568. * Update audio level visualization for specified user.
  569. * @param {string} id user id
  570. * @param {number} lvl audio level
  571. */
  572. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  573. /**
  574. * Hide connection quality statistics from UI.
  575. */
  576. UI.hideStats = function() {
  577. VideoLayout.hideStats();
  578. };
  579. UI.notifyTokenAuthFailed = function() {
  580. messageHandler.showError({
  581. descriptionKey: 'dialog.tokenAuthFailed',
  582. titleKey: 'dialog.tokenAuthFailedTitle'
  583. });
  584. };
  585. UI.notifyInternalError = function(error) {
  586. messageHandler.showError({
  587. descriptionArguments: { error },
  588. descriptionKey: 'dialog.internalError',
  589. titleKey: 'dialog.internalErrorTitle'
  590. });
  591. };
  592. UI.notifyFocusDisconnected = function(focus, retrySec) {
  593. messageHandler.participantNotification(
  594. null, 'notify.focus',
  595. 'disconnected', 'notify.focusFail',
  596. { component: focus,
  597. ms: retrySec }
  598. );
  599. };
  600. /**
  601. * Notifies interested listeners that the raise hand property has changed.
  602. *
  603. * @param {boolean} isRaisedHand indicates the current state of the
  604. * "raised hand"
  605. */
  606. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  607. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  608. };
  609. /**
  610. * Update list of available physical devices.
  611. */
  612. UI.onAvailableDevicesChanged = function() {
  613. APP.conference.updateAudioIconEnabled();
  614. APP.conference.updateVideoIconEnabled();
  615. };
  616. /**
  617. * Returns the id of the current video shown on large.
  618. * Currently used by tests (torture).
  619. */
  620. UI.getLargeVideoID = function() {
  621. return VideoLayout.getLargeVideoID();
  622. };
  623. /**
  624. * Returns the current video shown on large.
  625. * Currently used by tests (torture).
  626. */
  627. UI.getLargeVideo = function() {
  628. return VideoLayout.getLargeVideo();
  629. };
  630. /**
  631. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  632. * 2 button dialog with buttons - cancel and go to web store.
  633. * @param url {string} the url of the extension.
  634. */
  635. UI.showExtensionExternalInstallationDialog = function(url) {
  636. let openedWindow = null;
  637. const submitFunction = function(e, v) {
  638. if (v) {
  639. e.preventDefault();
  640. if (openedWindow === null || openedWindow.closed) {
  641. openedWindow
  642. = window.open(
  643. url,
  644. 'extension_store_window',
  645. 'resizable,scrollbars=yes,status=1');
  646. } else {
  647. openedWindow.focus();
  648. }
  649. }
  650. };
  651. const closeFunction = function(e, v) {
  652. if (openedWindow) {
  653. // Ideally we would close the popup, but this does not seem to work
  654. // on Chrome. Leaving it uncommented in case it could work
  655. // in some version.
  656. openedWindow.close();
  657. openedWindow = null;
  658. }
  659. if (!v) {
  660. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  661. }
  662. };
  663. messageHandler.openTwoButtonDialog({
  664. titleKey: 'dialog.externalInstallationTitle',
  665. msgKey: 'dialog.externalInstallationMsg',
  666. leftButtonKey: 'dialog.goToStore',
  667. submitFunction,
  668. loadedFunction: $.noop,
  669. closeFunction
  670. });
  671. };
  672. /**
  673. * Shows a dialog which asks user to install the extension. This one is
  674. * displayed after installation is triggered from the script, but fails because
  675. * it must be initiated by user gesture.
  676. * @param callback {function} function to be executed after user clicks
  677. * the install button - it should make another attempt to install the extension.
  678. */
  679. UI.showExtensionInlineInstallationDialog = function(callback) {
  680. const submitFunction = function(e, v) {
  681. if (v) {
  682. callback();
  683. }
  684. };
  685. const closeFunction = function(e, v) {
  686. if (!v) {
  687. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  688. }
  689. };
  690. messageHandler.openTwoButtonDialog({
  691. titleKey: 'dialog.externalInstallationTitle',
  692. msgKey: 'dialog.inlineInstallationMsg',
  693. leftButtonKey: 'dialog.inlineInstallExtension',
  694. submitFunction,
  695. loadedFunction: $.noop,
  696. closeFunction
  697. });
  698. };
  699. /**
  700. * Shows a notifications about the passed in microphone error.
  701. *
  702. * @param {JitsiTrackError} micError - An error object related to using or
  703. * acquiring an audio stream.
  704. * @returns {void}
  705. */
  706. UI.showMicErrorNotification = function(micError) {
  707. if (!micError) {
  708. return;
  709. }
  710. const { message, name } = micError;
  711. const micJitsiTrackErrorMsg
  712. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  713. const micErrorMsg = micJitsiTrackErrorMsg
  714. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  715. .microphone[JitsiTrackErrors.GENERAL];
  716. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  717. APP.store.dispatch(showWarningNotification({
  718. description: additionalMicErrorMsg,
  719. descriptionKey: micErrorMsg,
  720. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  721. ? 'deviceError.microphonePermission'
  722. : 'deviceError.microphoneError'
  723. }));
  724. };
  725. /**
  726. * Shows a notifications about the passed in camera error.
  727. *
  728. * @param {JitsiTrackError} cameraError - An error object related to using or
  729. * acquiring a video stream.
  730. * @returns {void}
  731. */
  732. UI.showCameraErrorNotification = function(cameraError) {
  733. if (!cameraError) {
  734. return;
  735. }
  736. const { message, name } = cameraError;
  737. const cameraJitsiTrackErrorMsg
  738. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  739. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  740. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  741. .camera[JitsiTrackErrors.GENERAL];
  742. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  743. APP.store.dispatch(showWarningNotification({
  744. description: additionalCameraErrorMsg,
  745. descriptionKey: cameraErrorMsg,
  746. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  747. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  748. }));
  749. };
  750. /**
  751. * Shows error dialog that informs the user that no data is received from the
  752. * device.
  753. *
  754. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  755. * track error.
  756. * @returns {void}
  757. */
  758. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  759. messageHandler.showError({
  760. descriptionKey: isAudioTrack
  761. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  762. titleKey: isAudioTrack
  763. ? 'dialog.micNotSendingDataTitle'
  764. : 'dialog.cameraNotSendingDataTitle'
  765. });
  766. };
  767. UI.updateDevicesAvailability = function(id, devices) {
  768. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  769. };
  770. /**
  771. * Show shared video.
  772. * @param {string} id the id of the sender of the command
  773. * @param {string} url video url
  774. * @param {string} attributes
  775. */
  776. UI.onSharedVideoStart = function(id, url, attributes) {
  777. if (sharedVideoManager) {
  778. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  779. }
  780. };
  781. /**
  782. * Update shared video.
  783. * @param {string} id the id of the sender of the command
  784. * @param {string} url video url
  785. * @param {string} attributes
  786. */
  787. UI.onSharedVideoUpdate = function(id, url, attributes) {
  788. if (sharedVideoManager) {
  789. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  790. }
  791. };
  792. /**
  793. * Stop showing shared video.
  794. * @param {string} id the id of the sender of the command
  795. * @param {string} attributes
  796. */
  797. UI.onSharedVideoStop = function(id, attributes) {
  798. if (sharedVideoManager) {
  799. sharedVideoManager.onSharedVideoStop(id, attributes);
  800. }
  801. };
  802. /**
  803. * Handles user's features changes.
  804. */
  805. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  806. /**
  807. * Returns the number of known remote videos.
  808. *
  809. * @returns {number} The number of remote videos.
  810. */
  811. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  812. /**
  813. * Sets the remote control active status for a remote participant.
  814. *
  815. * @param {string} participantID - The id of the remote participant.
  816. * @param {boolean} isActive - The new remote control active status.
  817. * @returns {void}
  818. */
  819. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  820. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  821. };
  822. /**
  823. * Sets the remote control active status for the local participant.
  824. *
  825. * @returns {void}
  826. */
  827. UI.setLocalRemoteControlActiveChanged = function() {
  828. VideoLayout.setLocalRemoteControlActiveChanged();
  829. };
  830. // TODO: Export every function separately. For now there is no point of doing
  831. // this because we are importing everything.
  832. export default UI;