您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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