Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UI.js 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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. const reduxState = APP.store.getState() || {};
  426. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  427. if (!status || calleeInfoVisible) {
  428. return;
  429. }
  430. const displayName = user.getDisplayName();
  431. messageHandler.participantNotification(
  432. displayName,
  433. '',
  434. 'connected',
  435. 'dialOut.statusMessage',
  436. { status: UIUtil.escapeHtml(status) });
  437. };
  438. /**
  439. * Toggles smileys in the chat.
  440. */
  441. UI.toggleSmileys = () => Chat.toggleSmileys();
  442. /**
  443. * Toggles filmstrip.
  444. */
  445. UI.toggleFilmstrip = function() {
  446. // eslint-disable-next-line prefer-rest-params
  447. Filmstrip.toggleFilmstrip(...arguments);
  448. VideoLayout.resizeVideoArea(true, false);
  449. };
  450. /**
  451. * Checks if the filmstrip is currently visible or not.
  452. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  453. */
  454. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  455. /**
  456. * @returns {true} if the chat panel is currently visible, and false otherwise.
  457. */
  458. UI.isChatVisible = () => Chat.isVisible();
  459. /**
  460. * Toggles chat panel.
  461. */
  462. UI.toggleChat = () => UI.toggleSidePanel('chat_container');
  463. /**
  464. * Toggles the given side panel.
  465. *
  466. * @param {String} sidePanelId the identifier of the side panel to toggle
  467. */
  468. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  469. /**
  470. * Handle new user display name.
  471. */
  472. UI.inputDisplayNameHandler = function(newDisplayName) {
  473. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  474. };
  475. /**
  476. * Return the type of the remote video.
  477. * @param jid the jid for the remote video
  478. * @returns the video type video or screen.
  479. */
  480. UI.getRemoteVideoType = function(jid) {
  481. return VideoLayout.getRemoteVideoType(jid);
  482. };
  483. // FIXME check if someone user this
  484. UI.showLoginPopup = function(callback) {
  485. logger.log('password is required');
  486. const message
  487. = `<input name="username" type="text"
  488. placeholder="user@domain.net"
  489. class="input-control" autofocus>
  490. <input name="password" type="password"
  491. data-i18n="[placeholder]dialog.userPassword"
  492. class="input-control"
  493. placeholder="user password">`
  494. ;
  495. // eslint-disable-next-line max-params
  496. const submitFunction = (e, v, m, f) => {
  497. if (v && f.username && f.password) {
  498. callback(f.username, f.password);
  499. }
  500. };
  501. messageHandler.openTwoButtonDialog({
  502. titleKey: 'dialog.passwordRequired',
  503. msgString: message,
  504. leftButtonKey: 'dialog.Ok',
  505. submitFunction,
  506. focus: ':input:first'
  507. });
  508. };
  509. UI.askForNickname = function() {
  510. // eslint-disable-next-line no-alert
  511. return window.prompt('Your nickname (optional)');
  512. };
  513. /**
  514. * Sets muted audio state for participant
  515. */
  516. UI.setAudioMuted = function(id, muted) {
  517. VideoLayout.onAudioMute(id, muted);
  518. if (APP.conference.isLocalId(id)) {
  519. APP.conference.updateAudioIconEnabled();
  520. }
  521. };
  522. /**
  523. * Sets muted video state for participant
  524. */
  525. UI.setVideoMuted = function(id, muted) {
  526. VideoLayout.onVideoMute(id, muted);
  527. if (APP.conference.isLocalId(id)) {
  528. APP.conference.updateVideoIconEnabled();
  529. }
  530. };
  531. /**
  532. * Triggers an update of remote video and large video displays so they may pick
  533. * up any state changes that have occurred elsewhere.
  534. *
  535. * @returns {void}
  536. */
  537. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  538. /**
  539. * Adds a listener that would be notified on the given type of event.
  540. *
  541. * @param type the type of the event we're listening for
  542. * @param listener a function that would be called when notified
  543. */
  544. UI.addListener = function(type, listener) {
  545. eventEmitter.on(type, listener);
  546. };
  547. /**
  548. * Removes the given listener for the given type of event.
  549. *
  550. * @param type the type of the event we're listening for
  551. * @param listener the listener we want to remove
  552. */
  553. UI.removeListener = function(type, listener) {
  554. eventEmitter.removeListener(type, listener);
  555. };
  556. /**
  557. * Emits the event of given type by specifying the parameters in options.
  558. *
  559. * @param type the type of the event we're emitting
  560. * @param options the parameters for the event
  561. */
  562. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  563. UI.clickOnVideo = function(videoNumber) {
  564. const videos = $('#remoteVideos .videocontainer:not(#mixedstream)');
  565. const videosLength = videos.length;
  566. if (videosLength <= videoNumber) {
  567. return;
  568. }
  569. const videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  570. videos[videoIndex].click();
  571. };
  572. // Used by torture.
  573. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  574. // Used by torture.
  575. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  576. /**
  577. * Updates the displayed avatar for participant.
  578. *
  579. * @param {string} id - User id whose avatar should be updated.
  580. * @param {string} avatarURL - The URL to avatar image to display.
  581. * @returns {void}
  582. */
  583. UI.refreshAvatarDisplay = function(id, avatarURL) {
  584. VideoLayout.changeUserAvatar(id, avatarURL);
  585. };
  586. /**
  587. * Notify user that connection failed.
  588. * @param {string} stropheErrorMsg raw Strophe error message
  589. */
  590. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  591. let descriptionKey;
  592. let descriptionArguments;
  593. if (stropheErrorMsg) {
  594. descriptionKey = 'dialog.connectErrorWithMsg';
  595. descriptionArguments = { msg: stropheErrorMsg };
  596. } else {
  597. descriptionKey = 'dialog.connectError';
  598. }
  599. messageHandler.showError({
  600. descriptionArguments,
  601. descriptionKey,
  602. titleKey: 'connection.CONNFAIL'
  603. });
  604. };
  605. /**
  606. * Notify user that maximum users limit has been reached.
  607. */
  608. UI.notifyMaxUsersLimitReached = function() {
  609. messageHandler.showError({
  610. hideErrorSupportLink: true,
  611. descriptionKey: 'dialog.maxUsersLimitReached',
  612. titleKey: 'dialog.maxUsersLimitReachedTitle'
  613. });
  614. };
  615. /**
  616. * Notify user that he was automatically muted when joned the conference.
  617. */
  618. UI.notifyInitiallyMuted = function() {
  619. messageHandler.participantNotification(
  620. null,
  621. 'notify.mutedTitle',
  622. 'connected',
  623. 'notify.muted',
  624. null);
  625. };
  626. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  627. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  628. };
  629. /**
  630. * Prompt user for nickname.
  631. */
  632. UI.promptDisplayName = () => {
  633. APP.store.dispatch(openDisplayNamePrompt());
  634. };
  635. /**
  636. * Update audio level visualization for specified user.
  637. * @param {string} id user id
  638. * @param {number} lvl audio level
  639. */
  640. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  641. /**
  642. * Hide connection quality statistics from UI.
  643. */
  644. UI.hideStats = function() {
  645. VideoLayout.hideStats();
  646. };
  647. /**
  648. * Add chat message.
  649. * @param {string} from user id
  650. * @param {string} displayName user nickname
  651. * @param {string} message message text
  652. * @param {number} stamp timestamp when message was created
  653. */
  654. // eslint-disable-next-line max-params
  655. UI.addMessage = function(from, displayName, message, stamp) {
  656. Chat.updateChatConversation(from, displayName, message, stamp);
  657. };
  658. UI.notifyTokenAuthFailed = function() {
  659. messageHandler.showError({
  660. descriptionKey: 'dialog.tokenAuthFailed',
  661. titleKey: 'dialog.tokenAuthFailedTitle'
  662. });
  663. };
  664. UI.notifyInternalError = function(error) {
  665. messageHandler.showError({
  666. descriptionArguments: { error },
  667. descriptionKey: 'dialog.internalError',
  668. titleKey: 'dialog.internalErrorTitle'
  669. });
  670. };
  671. UI.notifyFocusDisconnected = function(focus, retrySec) {
  672. messageHandler.participantNotification(
  673. null, 'notify.focus',
  674. 'disconnected', 'notify.focusFail',
  675. { component: focus,
  676. ms: retrySec }
  677. );
  678. };
  679. /**
  680. * Notifies interested listeners that the raise hand property has changed.
  681. *
  682. * @param {boolean} isRaisedHand indicates the current state of the
  683. * "raised hand"
  684. */
  685. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  686. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  687. };
  688. /**
  689. * Update list of available physical devices.
  690. * @param {object[]} devices new list of available devices
  691. */
  692. UI.onAvailableDevicesChanged = function(devices) {
  693. APP.store.dispatch(updateDeviceList(devices));
  694. APP.conference.updateAudioIconEnabled();
  695. APP.conference.updateVideoIconEnabled();
  696. };
  697. /**
  698. * Returns the id of the current video shown on large.
  699. * Currently used by tests (torture).
  700. */
  701. UI.getLargeVideoID = function() {
  702. return VideoLayout.getLargeVideoID();
  703. };
  704. /**
  705. * Returns the current video shown on large.
  706. * Currently used by tests (torture).
  707. */
  708. UI.getLargeVideo = function() {
  709. return VideoLayout.getLargeVideo();
  710. };
  711. /**
  712. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  713. * 2 button dialog with buttons - cancel and go to web store.
  714. * @param url {string} the url of the extension.
  715. */
  716. UI.showExtensionExternalInstallationDialog = function(url) {
  717. let openedWindow = null;
  718. const submitFunction = function(e, v) {
  719. if (v) {
  720. e.preventDefault();
  721. if (openedWindow === null || openedWindow.closed) {
  722. openedWindow
  723. = window.open(
  724. url,
  725. 'extension_store_window',
  726. 'resizable,scrollbars=yes,status=1');
  727. } else {
  728. openedWindow.focus();
  729. }
  730. }
  731. };
  732. const closeFunction = function(e, v) {
  733. if (openedWindow) {
  734. // Ideally we would close the popup, but this does not seem to work
  735. // on Chrome. Leaving it uncommented in case it could work
  736. // in some version.
  737. openedWindow.close();
  738. openedWindow = null;
  739. }
  740. if (!v) {
  741. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  742. }
  743. };
  744. messageHandler.openTwoButtonDialog({
  745. titleKey: 'dialog.externalInstallationTitle',
  746. msgKey: 'dialog.externalInstallationMsg',
  747. leftButtonKey: 'dialog.goToStore',
  748. submitFunction,
  749. loadedFunction: $.noop,
  750. closeFunction
  751. });
  752. };
  753. /**
  754. * Shows a dialog which asks user to install the extension. This one is
  755. * displayed after installation is triggered from the script, but fails because
  756. * it must be initiated by user gesture.
  757. * @param callback {function} function to be executed after user clicks
  758. * the install button - it should make another attempt to install the extension.
  759. */
  760. UI.showExtensionInlineInstallationDialog = function(callback) {
  761. const submitFunction = function(e, v) {
  762. if (v) {
  763. callback();
  764. }
  765. };
  766. const closeFunction = function(e, v) {
  767. if (!v) {
  768. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  769. }
  770. };
  771. messageHandler.openTwoButtonDialog({
  772. titleKey: 'dialog.externalInstallationTitle',
  773. msgKey: 'dialog.inlineInstallationMsg',
  774. leftButtonKey: 'dialog.inlineInstallExtension',
  775. submitFunction,
  776. loadedFunction: $.noop,
  777. closeFunction
  778. });
  779. };
  780. /**
  781. * Shows a notifications about the passed in microphone error.
  782. *
  783. * @param {JitsiTrackError} micError - An error object related to using or
  784. * acquiring an audio stream.
  785. * @returns {void}
  786. */
  787. UI.showMicErrorNotification = function(micError) {
  788. if (!micError) {
  789. return;
  790. }
  791. const { message, name } = micError;
  792. const micJitsiTrackErrorMsg
  793. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  794. const micErrorMsg = micJitsiTrackErrorMsg
  795. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  796. .microphone[JitsiTrackErrors.GENERAL];
  797. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  798. APP.store.dispatch(showWarningNotification({
  799. description: additionalMicErrorMsg,
  800. descriptionKey: micErrorMsg,
  801. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  802. ? 'deviceError.microphonePermission'
  803. : 'deviceError.microphoneError'
  804. }));
  805. };
  806. /**
  807. * Shows a notifications about the passed in camera error.
  808. *
  809. * @param {JitsiTrackError} cameraError - An error object related to using or
  810. * acquiring a video stream.
  811. * @returns {void}
  812. */
  813. UI.showCameraErrorNotification = function(cameraError) {
  814. if (!cameraError) {
  815. return;
  816. }
  817. const { message, name } = cameraError;
  818. const cameraJitsiTrackErrorMsg
  819. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  820. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  821. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  822. .camera[JitsiTrackErrors.GENERAL];
  823. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  824. APP.store.dispatch(showWarningNotification({
  825. description: additionalCameraErrorMsg,
  826. descriptionKey: cameraErrorMsg,
  827. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  828. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  829. }));
  830. };
  831. /**
  832. * Shows error dialog that informs the user that no data is received from the
  833. * device.
  834. *
  835. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  836. * track error.
  837. * @returns {void}
  838. */
  839. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  840. messageHandler.showError({
  841. descriptionKey: isAudioTrack
  842. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  843. titleKey: isAudioTrack
  844. ? 'dialog.micNotSendingDataTitle'
  845. : 'dialog.cameraNotSendingDataTitle'
  846. });
  847. };
  848. UI.updateDevicesAvailability = function(id, devices) {
  849. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  850. };
  851. /**
  852. * Show shared video.
  853. * @param {string} id the id of the sender of the command
  854. * @param {string} url video url
  855. * @param {string} attributes
  856. */
  857. UI.onSharedVideoStart = function(id, url, attributes) {
  858. if (sharedVideoManager) {
  859. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  860. }
  861. };
  862. /**
  863. * Update shared video.
  864. * @param {string} id the id of the sender of the command
  865. * @param {string} url video url
  866. * @param {string} attributes
  867. */
  868. UI.onSharedVideoUpdate = function(id, url, attributes) {
  869. if (sharedVideoManager) {
  870. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  871. }
  872. };
  873. /**
  874. * Stop showing shared video.
  875. * @param {string} id the id of the sender of the command
  876. * @param {string} attributes
  877. */
  878. UI.onSharedVideoStop = function(id, attributes) {
  879. if (sharedVideoManager) {
  880. sharedVideoManager.onSharedVideoStop(id, attributes);
  881. }
  882. };
  883. /**
  884. * Handles user's features changes.
  885. */
  886. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  887. /**
  888. * Returns the number of known remote videos.
  889. *
  890. * @returns {number} The number of remote videos.
  891. */
  892. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  893. /**
  894. * Sets the remote control active status for a remote participant.
  895. *
  896. * @param {string} participantID - The id of the remote participant.
  897. * @param {boolean} isActive - The new remote control active status.
  898. * @returns {void}
  899. */
  900. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  901. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  902. };
  903. /**
  904. * Sets the remote control active status for the local participant.
  905. *
  906. * @returns {void}
  907. */
  908. UI.setLocalRemoteControlActiveChanged = function() {
  909. VideoLayout.setLocalRemoteControlActiveChanged();
  910. };
  911. /**
  912. * Remove media tracks and UI elements so the user no longer sees media in the
  913. * UI. The intent is to provide a feeling that the meeting has ended.
  914. *
  915. * @returns {void}
  916. */
  917. UI.removeLocalMedia = function() {
  918. APP.store.dispatch(destroyLocalTracks());
  919. VideoLayout.resetLargeVideo();
  920. $('#videospace').hide();
  921. };
  922. // TODO: Export every function separately. For now there is no point of doing
  923. // this because we are importing everything.
  924. export default UI;