Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UI.js 36KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /* global APP, JitsiMeetJS, $, config, interfaceConfig */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. var UI = {};
  4. import Chat from "./side_pannels/chat/Chat";
  5. import SidePanels from "./side_pannels/SidePanels";
  6. import Avatar from "./avatar/Avatar";
  7. import SideContainerToggler from "./side_pannels/SideContainerToggler";
  8. import messageHandler from "./util/MessageHandler";
  9. import UIUtil from "./util/UIUtil";
  10. import UIEvents from "../../service/UI/UIEvents";
  11. import EtherpadManager from './etherpad/Etherpad';
  12. import SharedVideoManager from './shared_video/SharedVideo';
  13. import Recording from "./recording/Recording";
  14. import VideoLayout from "./videolayout/VideoLayout";
  15. import Filmstrip from "./videolayout/Filmstrip";
  16. import SettingsMenu from "./side_pannels/settings/SettingsMenu";
  17. import Profile from "./side_pannels/profile/Profile";
  18. import Settings from "./../settings/Settings";
  19. import { debounce } from "../util/helpers";
  20. import { updateDeviceList } from '../../react/features/base/devices';
  21. import {
  22. openDeviceSelectionDialog
  23. } from '../../react/features/device-selection';
  24. import { openDisplayNamePrompt } from '../../react/features/display-name';
  25. import {
  26. checkAutoEnableDesktopSharing,
  27. clearButtonPopup,
  28. dockToolbox,
  29. setButtonPopupTimeout,
  30. setToolbarButton,
  31. showDialPadButton,
  32. showEtherpadButton,
  33. showSharedVideoButton,
  34. showDialOutButton,
  35. showToolbox
  36. } from '../../react/features/toolbox';
  37. import {
  38. maybeShowNotificationWithDoNotDisplay,
  39. setNotificationsEnabled
  40. } from '../../react/features/notifications';
  41. var EventEmitter = require("events");
  42. UI.messageHandler = messageHandler;
  43. import FollowMe from "../FollowMe";
  44. var eventEmitter = new EventEmitter();
  45. UI.eventEmitter = eventEmitter;
  46. let etherpadManager;
  47. let sharedVideoManager;
  48. let followMeHandler;
  49. const TrackErrors = JitsiMeetJS.errors.track;
  50. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  51. microphone: {},
  52. camera: {}
  53. };
  54. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.UNSUPPORTED_RESOLUTION]
  55. = "dialog.cameraUnsupportedResolutionError";
  56. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  57. = "dialog.cameraUnknownError";
  58. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.PERMISSION_DENIED]
  59. = "dialog.cameraPermissionDeniedError";
  60. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NOT_FOUND]
  61. = "dialog.cameraNotFoundError";
  62. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.CONSTRAINT_FAILED]
  63. = "dialog.cameraConstraintFailedError";
  64. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NO_DATA_FROM_SOURCE]
  65. = "dialog.cameraNotSendingData";
  66. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  67. = "dialog.micUnknownError";
  68. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.PERMISSION_DENIED]
  69. = "dialog.micPermissionDeniedError";
  70. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NOT_FOUND]
  71. = "dialog.micNotFoundError";
  72. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.CONSTRAINT_FAILED]
  73. = "dialog.micConstraintFailedError";
  74. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NO_DATA_FROM_SOURCE]
  75. = "dialog.micNotSendingData";
  76. /**
  77. * Toggles the application in and out of full screen mode
  78. * (a.k.a. presentation mode in Chrome).
  79. */
  80. UI.toggleFullScreen = function() {
  81. (UIUtil.isFullScreen())
  82. ? UIUtil.exitFullScreen()
  83. : UIUtil.enterFullScreen();
  84. };
  85. /**
  86. * Notify user that server has shut down.
  87. */
  88. UI.notifyGracefulShutdown = function () {
  89. messageHandler.openMessageDialog(
  90. 'dialog.serviceUnavailable',
  91. 'dialog.gracefulShutdown'
  92. );
  93. };
  94. /**
  95. * Notify user that reservation error happened.
  96. */
  97. UI.notifyReservationError = function (code, msg) {
  98. var message = APP.translation.generateTranslationHTML(
  99. "dialog.reservationErrorMsg", {code: code, msg: msg});
  100. messageHandler.openDialog(
  101. "dialog.reservationError", message, true, {}, () => false);
  102. };
  103. /**
  104. * Notify user that he has been kicked from the server.
  105. */
  106. UI.notifyKicked = function () {
  107. messageHandler.openMessageDialog(
  108. "dialog.sessTerminated",
  109. "dialog.kickMessage");
  110. };
  111. /**
  112. * Notify user that conference was destroyed.
  113. * @param reason {string} the reason text
  114. */
  115. UI.notifyConferenceDestroyed = function (reason) {
  116. //FIXME: use Session Terminated from translation, but
  117. // 'reason' text comes from XMPP packet and is not translated
  118. messageHandler.openDialog(
  119. "dialog.sessTerminated", reason, true, {}, () => false);
  120. };
  121. /**
  122. * Show chat error.
  123. * @param err the Error
  124. * @param msg
  125. */
  126. UI.showChatError = function (err, msg) {
  127. if (interfaceConfig.filmStripOnly) {
  128. return;
  129. }
  130. Chat.chatAddError(err, msg);
  131. };
  132. /**
  133. * Change nickname for the user.
  134. * @param {string} id user id
  135. * @param {string} displayName new nickname
  136. */
  137. UI.changeDisplayName = function (id, displayName) {
  138. if (UI.ContactList)
  139. UI.ContactList.onDisplayNameChange(id, displayName);
  140. VideoLayout.onDisplayNameChanged(id, displayName);
  141. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  142. Profile.changeDisplayName(displayName);
  143. Chat.setChatConversationMode(!!displayName);
  144. }
  145. };
  146. /**
  147. * Shows/hides the indication about local connection being interrupted.
  148. *
  149. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  150. * currently in the interrupted state or <tt>false</tt> if the connection
  151. * is fine.
  152. */
  153. UI.showLocalConnectionInterrupted = function (isInterrupted) {
  154. VideoLayout.showLocalConnectionInterrupted(isInterrupted);
  155. };
  156. /**
  157. * Sets the "raised hand" status for a participant.
  158. */
  159. UI.setRaisedHandStatus = (participant, raisedHandStatus) => {
  160. VideoLayout.setRaisedHandStatus(participant.getId(), raisedHandStatus);
  161. if (raisedHandStatus) {
  162. messageHandler.participantNotification(participant.getDisplayName(),
  163. 'notify.somebody', 'connected', 'notify.raisedHand');
  164. }
  165. };
  166. /**
  167. * Sets the local "raised hand" status.
  168. */
  169. UI.setLocalRaisedHandStatus
  170. = raisedHandStatus =>
  171. VideoLayout.setRaisedHandStatus(
  172. APP.conference.getMyUserId(),
  173. raisedHandStatus);
  174. /**
  175. * Initialize conference UI.
  176. */
  177. UI.initConference = function () {
  178. let id = APP.conference.getMyUserId();
  179. // Add myself to the contact list.
  180. if (UI.ContactList)
  181. UI.ContactList.addContact(id, true);
  182. // Update default button states before showing the toolbar
  183. // if local role changes buttons state will be again updated.
  184. UI.updateLocalRole(APP.conference.isModerator);
  185. UI.showToolbar();
  186. let displayName = config.displayJids ? id : Settings.getDisplayName();
  187. if (displayName) {
  188. UI.changeDisplayName('localVideoContainer', displayName);
  189. }
  190. // Make sure we configure our avatar id, before creating avatar for us
  191. let email = Settings.getEmail();
  192. if (email) {
  193. UI.setUserEmail(id, email);
  194. } else {
  195. UI.setUserAvatarID(id, Settings.getAvatarId());
  196. }
  197. APP.store.dispatch(checkAutoEnableDesktopSharing());
  198. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  199. // other participants' UI. Consequently, it needs (1) read and write access
  200. // to the UI (depending on the moderator role of the local participant) and
  201. // (2) APP.conference as means of communication between the participants.
  202. followMeHandler = new FollowMe(APP.conference, UI);
  203. };
  204. UI.mucJoined = function () {
  205. VideoLayout.mucJoined();
  206. // Update local video now that a conference is joined a user ID should be
  207. // set.
  208. UI.changeDisplayName('localVideoContainer', APP.settings.getDisplayName());
  209. };
  210. /***
  211. * Handler for toggling filmstrip
  212. */
  213. UI.handleToggleFilmstrip = () => UI.toggleFilmstrip();
  214. /**
  215. * Returns the shared document manager object.
  216. * @return {EtherpadManager} the shared document manager object
  217. */
  218. UI.getSharedVideoManager = function () {
  219. return sharedVideoManager;
  220. };
  221. /**
  222. * Starts the UI module and initializes all related components.
  223. *
  224. * @returns {boolean} true if the UI is ready and the conference should be
  225. * established, false - otherwise (for example in the case of welcome page)
  226. */
  227. UI.start = function () {
  228. document.title = interfaceConfig.APP_NAME;
  229. // Set the defaults for prompt dialogs.
  230. $.prompt.setDefaults({persistent: false});
  231. SideContainerToggler.init(eventEmitter);
  232. Filmstrip.init(eventEmitter);
  233. VideoLayout.init(eventEmitter);
  234. if (!interfaceConfig.filmStripOnly) {
  235. VideoLayout.initLargeVideo();
  236. }
  237. VideoLayout.resizeVideoArea(true, true);
  238. sharedVideoManager = new SharedVideoManager(eventEmitter);
  239. if (!interfaceConfig.filmStripOnly) {
  240. let debouncedShowToolbar
  241. = debounce(
  242. () => UI.showToolbar(),
  243. 100,
  244. { leading: true, trailing: false });
  245. $("#videoconference_page").mousemove(debouncedShowToolbar);
  246. // Initialise the recording module.
  247. if (config.enableRecording) {
  248. Recording.init(eventEmitter, config.recordingType);
  249. }
  250. // Initialize side panels
  251. SidePanels.init(eventEmitter);
  252. } else {
  253. $("body").addClass("filmstrip-only");
  254. UI.showToolbar();
  255. Filmstrip.setFilmstripOnly();
  256. APP.store.dispatch(setNotificationsEnabled(false));
  257. }
  258. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  259. $("body").addClass("vertical-filmstrip");
  260. }
  261. document.title = interfaceConfig.APP_NAME;
  262. };
  263. /**
  264. * Invokes cleanup of any deferred execution within relevant UI modules.
  265. *
  266. * @returns {void}
  267. */
  268. UI.stopDaemons = () => {
  269. VideoLayout.resetLargeVideo();
  270. };
  271. /**
  272. * Setup some UI event listeners.
  273. */
  274. UI.registerListeners
  275. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  276. /**
  277. * Unregister some UI event listeners.
  278. */
  279. UI.unregisterListeners
  280. = () => UIListeners.forEach((value, key) => UI.removeListener(key, value));
  281. /**
  282. * Setup some DOM event listeners.
  283. */
  284. UI.bindEvents = () => {
  285. function onResize() {
  286. SideContainerToggler.resize();
  287. VideoLayout.resizeVideoArea();
  288. }
  289. // Resize and reposition videos in full screen mode.
  290. $(document).on(
  291. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  292. () => {
  293. eventEmitter.emit(
  294. UIEvents.FULLSCREEN_TOGGLED,
  295. UIUtil.isFullScreen());
  296. onResize();
  297. });
  298. $(window).resize(onResize);
  299. };
  300. /**
  301. * Unbind some DOM event listeners.
  302. */
  303. UI.unbindEvents = () => {
  304. $(document).off(
  305. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  306. $(window).off('resize');
  307. };
  308. /**
  309. * Show local stream on UI.
  310. * @param {JitsiTrack} track stream to show
  311. */
  312. UI.addLocalStream = track => {
  313. switch (track.getType()) {
  314. case 'audio':
  315. // 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;