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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /* global APP, $, config, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. const UI = {};
  4. import messageHandler from './util/MessageHandler';
  5. import UIUtil from './util/UIUtil';
  6. import UIEvents from '../../service/UI/UIEvents';
  7. import EtherpadManager from './etherpad/Etherpad';
  8. import SharedVideoManager from './shared_video/SharedVideo';
  9. import VideoLayout from './videolayout/VideoLayout';
  10. import { getLocalParticipant } from '../../react/features/base/participants';
  11. import { toggleChat } from '../../react/features/chat';
  12. import { setDocumentUrl } from '../../react/features/etherpad';
  13. import { setFilmstripVisible } from '../../react/features/filmstrip';
  14. import { joinLeaveNotificationsDisabled, setNotificationsEnabled } from '../../react/features/notifications';
  15. import {
  16. dockToolbox,
  17. setToolboxEnabled,
  18. showToolbox
  19. } from '../../react/features/toolbox';
  20. const EventEmitter = require('events');
  21. UI.messageHandler = messageHandler;
  22. const eventEmitter = new EventEmitter();
  23. UI.eventEmitter = eventEmitter;
  24. let etherpadManager;
  25. let sharedVideoManager;
  26. const UIListeners = new Map([
  27. [
  28. UIEvents.ETHERPAD_CLICKED,
  29. () => etherpadManager && etherpadManager.toggleEtherpad()
  30. ], [
  31. UIEvents.SHARED_VIDEO_CLICKED,
  32. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  33. ], [
  34. UIEvents.TOGGLE_FILMSTRIP,
  35. () => UI.toggleFilmstrip()
  36. ]
  37. ]);
  38. /**
  39. * Indicates if we're currently in full screen mode.
  40. *
  41. * @return {boolean} {true} to indicate that we're currently in full screen
  42. * mode, {false} otherwise
  43. */
  44. UI.isFullScreen = function() {
  45. return UIUtil.isFullScreen();
  46. };
  47. /**
  48. * Returns true if the etherpad window is currently visible.
  49. * @returns {Boolean} - true if the etherpad window is currently visible.
  50. */
  51. UI.isEtherpadVisible = function() {
  52. return Boolean(etherpadManager && etherpadManager.isVisible());
  53. };
  54. /**
  55. * Returns true if there is a shared video which is being shown (?).
  56. * @returns {boolean} - true if there is a shared video which is being shown.
  57. */
  58. UI.isSharedVideoShown = function() {
  59. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  60. };
  61. /**
  62. * Notify user that server has shut down.
  63. */
  64. UI.notifyGracefulShutdown = function() {
  65. messageHandler.showError({
  66. descriptionKey: 'dialog.gracefulShutdown',
  67. titleKey: 'dialog.serviceUnavailable'
  68. });
  69. };
  70. /**
  71. * Notify user that reservation error happened.
  72. */
  73. UI.notifyReservationError = function(code, msg) {
  74. messageHandler.showError({
  75. descriptionArguments: {
  76. code,
  77. msg
  78. },
  79. descriptionKey: 'dialog.reservationErrorMsg',
  80. titleKey: 'dialog.reservationError'
  81. });
  82. };
  83. /**
  84. * Notify user that conference was destroyed.
  85. * @param reason {string} the reason text
  86. */
  87. UI.notifyConferenceDestroyed = function(reason) {
  88. // FIXME: use Session Terminated from translation, but
  89. // 'reason' text comes from XMPP packet and is not translated
  90. messageHandler.showError({
  91. description: reason,
  92. titleKey: 'dialog.sessTerminated'
  93. });
  94. };
  95. /**
  96. * Change nickname for the user.
  97. * @param {string} id user id
  98. * @param {string} displayName new nickname
  99. */
  100. UI.changeDisplayName = function(id, displayName) {
  101. VideoLayout.onDisplayNameChanged(id, displayName);
  102. };
  103. /**
  104. * Initialize conference UI.
  105. */
  106. UI.initConference = function() {
  107. const { getState } = APP.store;
  108. const { id, name } = getLocalParticipant(getState);
  109. UI.showToolbar();
  110. const displayName = config.displayJids ? id : name;
  111. if (displayName) {
  112. UI.changeDisplayName('localVideoContainer', displayName);
  113. }
  114. };
  115. /**
  116. * Returns the shared document manager object.
  117. * @return {EtherpadManager} the shared document manager object
  118. */
  119. UI.getSharedVideoManager = function() {
  120. return sharedVideoManager;
  121. };
  122. /**
  123. * Starts the UI module and initializes all related components.
  124. *
  125. * @returns {boolean} true if the UI is ready and the conference should be
  126. * established, false - otherwise (for example in the case of welcome page)
  127. */
  128. UI.start = function() {
  129. // Set the defaults for prompt dialogs.
  130. $.prompt.setDefaults({ persistent: false });
  131. VideoLayout.init(eventEmitter);
  132. if (!interfaceConfig.filmStripOnly) {
  133. VideoLayout.initLargeVideo();
  134. }
  135. // Do not animate the video area on UI start (second argument passed into
  136. // resizeVideoArea) because the animation is not visible anyway. Plus with
  137. // the current dom layout, the quality label is part of the video layout and
  138. // will be seen animating in.
  139. VideoLayout.resizeVideoArea();
  140. sharedVideoManager = new SharedVideoManager(eventEmitter);
  141. if (interfaceConfig.filmStripOnly) {
  142. $('body').addClass('filmstrip-only');
  143. APP.store.dispatch(setNotificationsEnabled(false));
  144. } else if (config.iAmRecorder) {
  145. // in case of iAmSipGateway keep local video visible
  146. if (!config.iAmSipGateway) {
  147. VideoLayout.setLocalVideoVisible(false);
  148. APP.store.dispatch(setNotificationsEnabled(false));
  149. }
  150. APP.store.dispatch(setToolboxEnabled(false));
  151. UI.messageHandler.enablePopups(false);
  152. }
  153. };
  154. /**
  155. * Setup some UI event listeners.
  156. */
  157. UI.registerListeners
  158. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  159. /**
  160. * Setup some DOM event listeners.
  161. */
  162. UI.bindEvents = () => {
  163. /**
  164. *
  165. */
  166. function onResize() {
  167. VideoLayout.onResize();
  168. }
  169. // Resize and reposition videos in full screen mode.
  170. $(document).on(
  171. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  172. onResize);
  173. $(window).resize(onResize);
  174. };
  175. /**
  176. * Unbind some DOM event listeners.
  177. */
  178. UI.unbindEvents = () => {
  179. $(document).off(
  180. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  181. $(window).off('resize');
  182. };
  183. /**
  184. * Show local video stream on UI.
  185. * @param {JitsiTrack} track stream to show
  186. */
  187. UI.addLocalVideoStream = track => {
  188. VideoLayout.changeLocalVideo(track);
  189. };
  190. /**
  191. * Setup and show Etherpad.
  192. * @param {string} name etherpad id
  193. */
  194. UI.initEtherpad = name => {
  195. if (etherpadManager || !config.etherpad_base || !name) {
  196. return;
  197. }
  198. logger.log('Etherpad is enabled');
  199. etherpadManager = new EtherpadManager(eventEmitter);
  200. const url = new URL(name, config.etherpad_base);
  201. APP.store.dispatch(setDocumentUrl(url.toString()));
  202. };
  203. /**
  204. * Returns the shared document manager object.
  205. * @return {EtherpadManager} the shared document manager object
  206. */
  207. UI.getSharedDocumentManager = () => etherpadManager;
  208. /**
  209. * Show user on UI.
  210. * @param {JitsiParticipant} user
  211. */
  212. UI.addUser = function(user) {
  213. const id = user.getId();
  214. const displayName = user.getDisplayName();
  215. const status = user.getStatus();
  216. if (status) {
  217. // FIXME: move updateUserStatus in participantPresenceChanged action
  218. UI.updateUserStatus(user, status);
  219. }
  220. // set initial display name
  221. if (displayName) {
  222. UI.changeDisplayName(id, displayName);
  223. }
  224. };
  225. /**
  226. * Update videotype for specified user.
  227. * @param {string} id user id
  228. * @param {string} newVideoType new videotype
  229. */
  230. UI.onPeerVideoTypeChanged
  231. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  232. /**
  233. * Updates the user status.
  234. *
  235. * @param {JitsiParticipant} user - The user which status we need to update.
  236. * @param {string} status - The new status.
  237. */
  238. UI.updateUserStatus = (user, status) => {
  239. const reduxState = APP.store.getState() || {};
  240. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  241. // We hide status updates when join/leave notifications are disabled,
  242. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  243. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  244. return;
  245. }
  246. const displayName = user.getDisplayName();
  247. messageHandler.participantNotification(
  248. displayName,
  249. '',
  250. 'connected',
  251. 'dialOut.statusMessage',
  252. { status: UIUtil.escapeHtml(status) });
  253. };
  254. /**
  255. * Toggles filmstrip.
  256. */
  257. UI.toggleFilmstrip = function() {
  258. const { visible } = APP.store.getState()['features/filmstrip'];
  259. APP.store.dispatch(setFilmstripVisible(!visible));
  260. };
  261. /**
  262. * Toggles the visibility of the chat panel.
  263. */
  264. UI.toggleChat = () => APP.store.dispatch(toggleChat());
  265. /**
  266. * Handle new user display name.
  267. */
  268. UI.inputDisplayNameHandler = function(newDisplayName) {
  269. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  270. };
  271. // FIXME check if someone user this
  272. UI.showLoginPopup = function(callback) {
  273. logger.log('password is required');
  274. const message
  275. = `<input name="username" type="text"
  276. placeholder="user@domain.net"
  277. class="input-control" autofocus>
  278. <input name="password" type="password"
  279. data-i18n="[placeholder]dialog.userPassword"
  280. class="input-control"
  281. placeholder="user password">`
  282. ;
  283. // eslint-disable-next-line max-params
  284. const submitFunction = (e, v, m, f) => {
  285. if (v && f.username && f.password) {
  286. callback(f.username, f.password);
  287. }
  288. };
  289. messageHandler.openTwoButtonDialog({
  290. titleKey: 'dialog.passwordRequired',
  291. msgString: message,
  292. leftButtonKey: 'dialog.Ok',
  293. submitFunction,
  294. focus: ':input:first'
  295. });
  296. };
  297. UI.askForNickname = function() {
  298. // eslint-disable-next-line no-alert
  299. return window.prompt('Your nickname (optional)');
  300. };
  301. /**
  302. * Sets muted audio state for participant
  303. */
  304. UI.setAudioMuted = function(id, muted) {
  305. VideoLayout.onAudioMute(id, muted);
  306. if (APP.conference.isLocalId(id)) {
  307. APP.conference.updateAudioIconEnabled();
  308. }
  309. };
  310. /**
  311. * Sets muted video state for participant
  312. */
  313. UI.setVideoMuted = function(id, muted) {
  314. VideoLayout.onVideoMute(id, muted);
  315. if (APP.conference.isLocalId(id)) {
  316. APP.conference.updateVideoIconEnabled();
  317. }
  318. };
  319. /**
  320. * Triggers an update of remote video and large video displays so they may pick
  321. * up any state changes that have occurred elsewhere.
  322. *
  323. * @returns {void}
  324. */
  325. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  326. /**
  327. * Adds a listener that would be notified on the given type of event.
  328. *
  329. * @param type the type of the event we're listening for
  330. * @param listener a function that would be called when notified
  331. */
  332. UI.addListener = function(type, listener) {
  333. eventEmitter.on(type, listener);
  334. };
  335. /**
  336. * Removes the all listeners for all events.
  337. *
  338. * @returns {void}
  339. */
  340. UI.removeAllListeners = function() {
  341. eventEmitter.removeAllListeners();
  342. };
  343. /**
  344. * Removes the given listener for the given type of event.
  345. *
  346. * @param type the type of the event we're listening for
  347. * @param listener the listener we want to remove
  348. */
  349. UI.removeListener = function(type, listener) {
  350. eventEmitter.removeListener(type, listener);
  351. };
  352. /**
  353. * Emits the event of given type by specifying the parameters in options.
  354. *
  355. * @param type the type of the event we're emitting
  356. * @param options the parameters for the event
  357. */
  358. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  359. UI.clickOnVideo = videoNumber => VideoLayout.togglePin(videoNumber);
  360. // Used by torture.
  361. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  362. // Used by torture.
  363. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  364. /**
  365. * Updates the displayed avatar for participant.
  366. *
  367. * @param {string} id - User id whose avatar should be updated.
  368. * @param {string} avatarURL - The URL to avatar image to display.
  369. * @returns {void}
  370. */
  371. UI.refreshAvatarDisplay = function(id) {
  372. VideoLayout.changeUserAvatar(id);
  373. };
  374. /**
  375. * Notify user that connection failed.
  376. * @param {string} stropheErrorMsg raw Strophe error message
  377. */
  378. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  379. let descriptionKey;
  380. let descriptionArguments;
  381. if (stropheErrorMsg) {
  382. descriptionKey = 'dialog.connectErrorWithMsg';
  383. descriptionArguments = { msg: stropheErrorMsg };
  384. } else {
  385. descriptionKey = 'dialog.connectError';
  386. }
  387. messageHandler.showError({
  388. descriptionArguments,
  389. descriptionKey,
  390. titleKey: 'connection.CONNFAIL'
  391. });
  392. };
  393. /**
  394. * Notify user that maximum users limit has been reached.
  395. */
  396. UI.notifyMaxUsersLimitReached = function() {
  397. messageHandler.showError({
  398. hideErrorSupportLink: true,
  399. descriptionKey: 'dialog.maxUsersLimitReached',
  400. titleKey: 'dialog.maxUsersLimitReachedTitle'
  401. });
  402. };
  403. /**
  404. * Notify user that he was automatically muted when joned the conference.
  405. */
  406. UI.notifyInitiallyMuted = function() {
  407. messageHandler.participantNotification(
  408. null,
  409. 'notify.mutedTitle',
  410. 'connected',
  411. 'notify.muted',
  412. null);
  413. };
  414. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  415. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  416. };
  417. /**
  418. * Update audio level visualization for specified user.
  419. * @param {string} id user id
  420. * @param {number} lvl audio level
  421. */
  422. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  423. /**
  424. * Hide connection quality statistics from UI.
  425. */
  426. UI.hideStats = function() {
  427. VideoLayout.hideStats();
  428. };
  429. UI.notifyTokenAuthFailed = function() {
  430. messageHandler.showError({
  431. descriptionKey: 'dialog.tokenAuthFailed',
  432. titleKey: 'dialog.tokenAuthFailedTitle'
  433. });
  434. };
  435. UI.notifyInternalError = function(error) {
  436. messageHandler.showError({
  437. descriptionArguments: { error },
  438. descriptionKey: 'dialog.internalError',
  439. titleKey: 'dialog.internalErrorTitle'
  440. });
  441. };
  442. UI.notifyFocusDisconnected = function(focus, retrySec) {
  443. messageHandler.participantNotification(
  444. null, 'notify.focus',
  445. 'disconnected', 'notify.focusFail',
  446. { component: focus,
  447. ms: retrySec }
  448. );
  449. };
  450. /**
  451. * Notifies interested listeners that the raise hand property has changed.
  452. *
  453. * @param {boolean} isRaisedHand indicates the current state of the
  454. * "raised hand"
  455. */
  456. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  457. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  458. };
  459. /**
  460. * Update list of available physical devices.
  461. */
  462. UI.onAvailableDevicesChanged = function() {
  463. APP.conference.updateAudioIconEnabled();
  464. APP.conference.updateVideoIconEnabled();
  465. };
  466. /**
  467. * Returns the id of the current video shown on large.
  468. * Currently used by tests (torture).
  469. */
  470. UI.getLargeVideoID = function() {
  471. return VideoLayout.getLargeVideoID();
  472. };
  473. /**
  474. * Returns the current video shown on large.
  475. * Currently used by tests (torture).
  476. */
  477. UI.getLargeVideo = function() {
  478. return VideoLayout.getLargeVideo();
  479. };
  480. /**
  481. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  482. * 2 button dialog with buttons - cancel and go to web store.
  483. * @param url {string} the url of the extension.
  484. */
  485. UI.showExtensionExternalInstallationDialog = function(url) {
  486. let openedWindow = null;
  487. const submitFunction = function(e, v) {
  488. if (v) {
  489. e.preventDefault();
  490. if (openedWindow === null || openedWindow.closed) {
  491. openedWindow
  492. = window.open(
  493. url,
  494. 'extension_store_window',
  495. 'resizable,scrollbars=yes,status=1');
  496. } else {
  497. openedWindow.focus();
  498. }
  499. }
  500. };
  501. const closeFunction = function(e, v) {
  502. if (openedWindow) {
  503. // Ideally we would close the popup, but this does not seem to work
  504. // on Chrome. Leaving it uncommented in case it could work
  505. // in some version.
  506. openedWindow.close();
  507. openedWindow = null;
  508. }
  509. if (!v) {
  510. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  511. }
  512. };
  513. messageHandler.openTwoButtonDialog({
  514. titleKey: 'dialog.externalInstallationTitle',
  515. msgKey: 'dialog.externalInstallationMsg',
  516. leftButtonKey: 'dialog.goToStore',
  517. submitFunction,
  518. loadedFunction: $.noop,
  519. closeFunction
  520. });
  521. };
  522. /**
  523. * Shows a dialog which asks user to install the extension. This one is
  524. * displayed after installation is triggered from the script, but fails because
  525. * it must be initiated by user gesture.
  526. * @param callback {function} function to be executed after user clicks
  527. * the install button - it should make another attempt to install the extension.
  528. */
  529. UI.showExtensionInlineInstallationDialog = function(callback) {
  530. const submitFunction = function(e, v) {
  531. if (v) {
  532. callback();
  533. }
  534. };
  535. const closeFunction = function(e, v) {
  536. if (!v) {
  537. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  538. }
  539. };
  540. messageHandler.openTwoButtonDialog({
  541. titleKey: 'dialog.externalInstallationTitle',
  542. msgKey: 'dialog.inlineInstallationMsg',
  543. leftButtonKey: 'dialog.inlineInstallExtension',
  544. submitFunction,
  545. loadedFunction: $.noop,
  546. closeFunction
  547. });
  548. };
  549. /**
  550. * Show shared video.
  551. * @param {string} id the id of the sender of the command
  552. * @param {string} url video url
  553. * @param {string} attributes
  554. */
  555. UI.onSharedVideoStart = function(id, url, attributes) {
  556. if (sharedVideoManager) {
  557. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  558. }
  559. };
  560. /**
  561. * Update shared video.
  562. * @param {string} id the id of the sender of the command
  563. * @param {string} url video url
  564. * @param {string} attributes
  565. */
  566. UI.onSharedVideoUpdate = function(id, url, attributes) {
  567. if (sharedVideoManager) {
  568. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  569. }
  570. };
  571. /**
  572. * Stop showing shared video.
  573. * @param {string} id the id of the sender of the command
  574. * @param {string} attributes
  575. */
  576. UI.onSharedVideoStop = function(id, attributes) {
  577. if (sharedVideoManager) {
  578. sharedVideoManager.onSharedVideoStop(id, attributes);
  579. }
  580. };
  581. /**
  582. * Handles user's features changes.
  583. */
  584. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  585. /**
  586. * Returns the number of known remote videos.
  587. *
  588. * @returns {number} The number of remote videos.
  589. */
  590. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  591. /**
  592. * Sets the remote control active status for a remote participant.
  593. *
  594. * @param {string} participantID - The id of the remote participant.
  595. * @param {boolean} isActive - The new remote control active status.
  596. * @returns {void}
  597. */
  598. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  599. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  600. };
  601. /**
  602. * Sets the remote control active status for the local participant.
  603. *
  604. * @returns {void}
  605. */
  606. UI.setLocalRemoteControlActiveChanged = function() {
  607. VideoLayout.setLocalRemoteControlActiveChanged();
  608. };
  609. // TODO: Export every function separately. For now there is no point of doing
  610. // this because we are importing everything.
  611. export default UI;