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

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