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

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