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.

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