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

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