You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 36KB

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