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

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