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

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