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

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