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

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