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

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