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

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