您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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