Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UI.js 31KB

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