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

UI.js 35KB

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