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