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

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