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

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