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

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