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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. /* global APP, $, config, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. const UI = {};
  4. import Chat from './side_pannels/chat/Chat';
  5. import SidePanels from './side_pannels/SidePanels';
  6. import SideContainerToggler from './side_pannels/SideContainerToggler';
  7. import messageHandler from './util/MessageHandler';
  8. import UIUtil from './util/UIUtil';
  9. import UIEvents from '../../service/UI/UIEvents';
  10. import EtherpadManager from './etherpad/Etherpad';
  11. import SharedVideoManager from './shared_video/SharedVideo';
  12. import VideoLayout from './videolayout/VideoLayout';
  13. import Filmstrip from './videolayout/Filmstrip';
  14. import { updateDeviceList } from '../../react/features/base/devices';
  15. import { JitsiTrackErrors } from '../../react/features/base/lib-jitsi-meet';
  16. import {
  17. getLocalParticipant,
  18. showParticipantJoinedNotification
  19. } from '../../react/features/base/participants';
  20. import { destroyLocalTracks } from '../../react/features/base/tracks';
  21. import { openDisplayNamePrompt } from '../../react/features/display-name';
  22. import { setEtherpadHasInitialzied } from '../../react/features/etherpad';
  23. import {
  24. setNotificationsEnabled,
  25. showWarningNotification
  26. } from '../../react/features/notifications';
  27. import {
  28. dockToolbox,
  29. setToolboxEnabled,
  30. showToolbox
  31. } from '../../react/features/toolbox';
  32. const EventEmitter = require('events');
  33. UI.messageHandler = messageHandler;
  34. import FollowMe from '../FollowMe';
  35. const eventEmitter = new EventEmitter();
  36. UI.eventEmitter = eventEmitter;
  37. let etherpadManager;
  38. let sharedVideoManager;
  39. let followMeHandler;
  40. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  41. microphone: {},
  42. camera: {}
  43. };
  44. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  45. .camera[JitsiTrackErrors.UNSUPPORTED_RESOLUTION]
  46. = 'dialog.cameraUnsupportedResolutionError';
  47. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.GENERAL]
  48. = 'dialog.cameraUnknownError';
  49. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.PERMISSION_DENIED]
  50. = 'dialog.cameraPermissionDeniedError';
  51. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.NOT_FOUND]
  52. = 'dialog.cameraNotFoundError';
  53. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.CONSTRAINT_FAILED]
  54. = 'dialog.cameraConstraintFailedError';
  55. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  56. .camera[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  57. = 'dialog.cameraNotSendingData';
  58. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[JitsiTrackErrors.GENERAL]
  59. = 'dialog.micUnknownError';
  60. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  61. .microphone[JitsiTrackErrors.PERMISSION_DENIED]
  62. = 'dialog.micPermissionDeniedError';
  63. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[JitsiTrackErrors.NOT_FOUND]
  64. = 'dialog.micNotFoundError';
  65. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  66. .microphone[JitsiTrackErrors.CONSTRAINT_FAILED]
  67. = 'dialog.micConstraintFailedError';
  68. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  69. .microphone[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  70. = 'dialog.micNotSendingData';
  71. const UIListeners = new Map([
  72. [
  73. UIEvents.ETHERPAD_CLICKED,
  74. () => etherpadManager && etherpadManager.toggleEtherpad()
  75. ], [
  76. UIEvents.SHARED_VIDEO_CLICKED,
  77. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  78. ], [
  79. UIEvents.TOGGLE_CHAT,
  80. () => UI.toggleChat()
  81. ], [
  82. UIEvents.TOGGLE_FILMSTRIP,
  83. () => UI.handleToggleFilmstrip()
  84. ], [
  85. UIEvents.FOLLOW_ME_ENABLED,
  86. enabled => followMeHandler && followMeHandler.enableFollowMe(enabled)
  87. ]
  88. ]);
  89. /**
  90. * Indicates if we're currently in full screen mode.
  91. *
  92. * @return {boolean} {true} to indicate that we're currently in full screen
  93. * mode, {false} otherwise
  94. */
  95. UI.isFullScreen = function() {
  96. return UIUtil.isFullScreen();
  97. };
  98. /**
  99. * Returns true if the etherpad window is currently visible.
  100. * @returns {Boolean} - true if the etherpad window is currently visible.
  101. */
  102. UI.isEtherpadVisible = function() {
  103. return Boolean(etherpadManager && etherpadManager.isVisible());
  104. };
  105. /**
  106. * Returns true if there is a shared video which is being shown (?).
  107. * @returns {boolean} - true if there is a shared video which is being shown.
  108. */
  109. UI.isSharedVideoShown = function() {
  110. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  111. };
  112. /**
  113. * Notify user that server has shut down.
  114. */
  115. UI.notifyGracefulShutdown = function() {
  116. messageHandler.showError({
  117. descriptionKey: 'dialog.gracefulShutdown',
  118. titleKey: 'dialog.serviceUnavailable'
  119. });
  120. };
  121. /**
  122. * Notify user that reservation error happened.
  123. */
  124. UI.notifyReservationError = function(code, msg) {
  125. messageHandler.showError({
  126. descriptionArguments: {
  127. code,
  128. msg
  129. },
  130. descriptionKey: 'dialog.reservationErrorMsg',
  131. titleKey: 'dialog.reservationError'
  132. });
  133. };
  134. /**
  135. * Notify user that he has been kicked from the server.
  136. */
  137. UI.notifyKicked = function() {
  138. messageHandler.showError({
  139. hideErrorSupportLink: true,
  140. descriptionKey: 'dialog.kickMessage',
  141. titleKey: 'dialog.sessTerminated'
  142. });
  143. };
  144. /**
  145. * Notify user that conference was destroyed.
  146. * @param reason {string} the reason text
  147. */
  148. UI.notifyConferenceDestroyed = function(reason) {
  149. // FIXME: use Session Terminated from translation, but
  150. // 'reason' text comes from XMPP packet and is not translated
  151. messageHandler.showError({
  152. description: reason,
  153. titleKey: 'dialog.sessTerminated'
  154. });
  155. };
  156. /**
  157. * Show chat error.
  158. * @param err the Error
  159. * @param msg
  160. */
  161. UI.showChatError = function(err, msg) {
  162. if (!interfaceConfig.filmStripOnly) {
  163. Chat.chatAddError(err, msg);
  164. }
  165. };
  166. /**
  167. * Change nickname for the user.
  168. * @param {string} id user id
  169. * @param {string} displayName new nickname
  170. */
  171. UI.changeDisplayName = function(id, displayName) {
  172. VideoLayout.onDisplayNameChanged(id, displayName);
  173. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  174. Chat.setChatConversationMode(Boolean(displayName));
  175. }
  176. };
  177. /**
  178. * Sets the "raised hand" status for a participant.
  179. *
  180. * @param {string} id - The id of the participant whose raised hand UI should
  181. * be updated.
  182. * @param {string} name - The name of the participant with the raised hand
  183. * update.
  184. * @param {boolean} raisedHandStatus - Whether the participant's hand is raised
  185. * or not.
  186. * @returns {void}
  187. */
  188. UI.setRaisedHandStatus = (id, name, raisedHandStatus) => {
  189. VideoLayout.setRaisedHandStatus(id, raisedHandStatus);
  190. if (raisedHandStatus) {
  191. messageHandler.participantNotification(
  192. name,
  193. 'notify.somebody',
  194. 'connected',
  195. 'notify.raisedHand');
  196. }
  197. };
  198. /**
  199. * Sets the local "raised hand" status.
  200. */
  201. UI.setLocalRaisedHandStatus
  202. = raisedHandStatus =>
  203. VideoLayout.setRaisedHandStatus(
  204. APP.conference.getMyUserId(),
  205. raisedHandStatus);
  206. /**
  207. * Initialize conference UI.
  208. */
  209. UI.initConference = function() {
  210. const { getState } = APP.store;
  211. const { id, name } = getLocalParticipant(getState);
  212. // Update default button states before showing the toolbar
  213. // if local role changes buttons state will be again updated.
  214. UI.updateLocalRole(APP.conference.isModerator);
  215. UI.showToolbar();
  216. const displayName = config.displayJids ? id : name;
  217. if (displayName) {
  218. UI.changeDisplayName('localVideoContainer', displayName);
  219. }
  220. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  221. // other participants' UI. Consequently, it needs (1) read and write access
  222. // to the UI (depending on the moderator role of the local participant) and
  223. // (2) APP.conference as means of communication between the participants.
  224. followMeHandler = new FollowMe(APP.conference, UI);
  225. };
  226. /** *
  227. * Handler for toggling filmstrip
  228. */
  229. UI.handleToggleFilmstrip = () => UI.toggleFilmstrip();
  230. /**
  231. * Returns the shared document manager object.
  232. * @return {EtherpadManager} the shared document manager object
  233. */
  234. UI.getSharedVideoManager = function() {
  235. return sharedVideoManager;
  236. };
  237. /**
  238. * Starts the UI module and initializes all related components.
  239. *
  240. * @returns {boolean} true if the UI is ready and the conference should be
  241. * established, false - otherwise (for example in the case of welcome page)
  242. */
  243. UI.start = function() {
  244. document.title = interfaceConfig.APP_NAME;
  245. // Set the defaults for prompt dialogs.
  246. $.prompt.setDefaults({ persistent: false });
  247. SideContainerToggler.init(eventEmitter);
  248. Filmstrip.init(eventEmitter);
  249. VideoLayout.init(eventEmitter);
  250. if (!interfaceConfig.filmStripOnly) {
  251. VideoLayout.initLargeVideo();
  252. }
  253. // Do not animate the video area on UI start (second argument passed into
  254. // resizeVideoArea) because the animation is not visible anyway. Plus with
  255. // the current dom layout, the quality label is part of the video layout and
  256. // will be seen animating in.
  257. VideoLayout.resizeVideoArea(true, false);
  258. sharedVideoManager = new SharedVideoManager(eventEmitter);
  259. if (interfaceConfig.filmStripOnly) {
  260. $('body').addClass('filmstrip-only');
  261. Filmstrip.setFilmstripOnly();
  262. APP.store.dispatch(setNotificationsEnabled(false));
  263. } else {
  264. // Initialize recording mode UI.
  265. if (config.iAmRecorder) {
  266. VideoLayout.enableDeviceAvailabilityIcons(
  267. APP.conference.getMyUserId(), false);
  268. // in case of iAmSipGateway keep local video visible
  269. if (!config.iAmSipGateway) {
  270. VideoLayout.setLocalVideoVisible(false);
  271. }
  272. APP.store.dispatch(setToolboxEnabled(false));
  273. APP.store.dispatch(setNotificationsEnabled(false));
  274. UI.messageHandler.enablePopups(false);
  275. }
  276. // Initialize side panels
  277. SidePanels.init(eventEmitter);
  278. }
  279. const filmstripTypeClassname = interfaceConfig.VERTICAL_FILMSTRIP
  280. ? 'vertical-filmstrip' : 'horizontal-filmstrip';
  281. $('body').addClass(filmstripTypeClassname);
  282. document.title = interfaceConfig.APP_NAME;
  283. };
  284. /**
  285. * Setup some UI event listeners.
  286. */
  287. UI.registerListeners
  288. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  289. /**
  290. * Unregister some UI event listeners.
  291. */
  292. UI.unregisterListeners
  293. = () => UIListeners.forEach((value, key) => UI.removeListener(key, value));
  294. /**
  295. * Setup some DOM event listeners.
  296. */
  297. UI.bindEvents = () => {
  298. /**
  299. *
  300. */
  301. function onResize() {
  302. SideContainerToggler.resize();
  303. VideoLayout.resizeVideoArea();
  304. }
  305. // Resize and reposition videos in full screen mode.
  306. $(document).on(
  307. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  308. onResize);
  309. $(window).resize(onResize);
  310. };
  311. /**
  312. * Unbind some DOM event listeners.
  313. */
  314. UI.unbindEvents = () => {
  315. $(document).off(
  316. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  317. $(window).off('resize');
  318. };
  319. /**
  320. * Show local stream on UI.
  321. * @param {JitsiTrack} track stream to show
  322. */
  323. UI.addLocalStream = track => {
  324. switch (track.getType()) {
  325. case 'audio':
  326. // Local audio is not rendered so no further action is needed at this
  327. // point.
  328. break;
  329. case 'video':
  330. VideoLayout.changeLocalVideo(track);
  331. break;
  332. default:
  333. logger.error(`Unknown stream type: ${track.getType()}`);
  334. break;
  335. }
  336. };
  337. /**
  338. * Removed remote stream from UI.
  339. * @param {JitsiTrack} track stream to remove
  340. */
  341. UI.removeRemoteStream = track => VideoLayout.onRemoteStreamRemoved(track);
  342. /**
  343. * Setup and show Etherpad.
  344. * @param {string} name etherpad id
  345. */
  346. UI.initEtherpad = name => {
  347. if (etherpadManager || !config.etherpad_base || !name) {
  348. return;
  349. }
  350. logger.log('Etherpad is enabled');
  351. etherpadManager
  352. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  353. APP.store.dispatch(setEtherpadHasInitialzied());
  354. };
  355. /**
  356. * Returns the shared document manager object.
  357. * @return {EtherpadManager} the shared document manager object
  358. */
  359. UI.getSharedDocumentManager = () => etherpadManager;
  360. /**
  361. * Show user on UI.
  362. * @param {JitsiParticipant} user
  363. */
  364. UI.addUser = function(user) {
  365. const id = user.getId();
  366. const displayName = user.getDisplayName();
  367. const status = user.getStatus();
  368. if (status) {
  369. // FIXME: move updateUserStatus in participantPresenceChanged action
  370. UI.updateUserStatus(user, status);
  371. } else {
  372. APP.store.dispatch(showParticipantJoinedNotification(displayName));
  373. }
  374. // set initial display name
  375. if (displayName) {
  376. UI.changeDisplayName(id, displayName);
  377. }
  378. };
  379. /**
  380. * Update videotype for specified user.
  381. * @param {string} id user id
  382. * @param {string} newVideoType new videotype
  383. */
  384. UI.onPeerVideoTypeChanged
  385. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  386. /**
  387. * Update local user role and show notification if user is moderator.
  388. * @param {boolean} isModerator if local user is moderator or not
  389. */
  390. UI.updateLocalRole = isModerator => {
  391. VideoLayout.showModeratorIndicator();
  392. if (isModerator && !interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  393. messageHandler.participantNotification(
  394. null, 'notify.me', 'connected', 'notify.moderator');
  395. }
  396. };
  397. /**
  398. * Check the role for the user and reflect it in the UI, moderator ui indication
  399. * and notifies user who is the moderator
  400. * @param user to check for moderator
  401. */
  402. UI.updateUserRole = user => {
  403. VideoLayout.showModeratorIndicator();
  404. // We don't need to show moderator notifications when the focus (moderator)
  405. // indicator is disabled.
  406. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  407. return;
  408. }
  409. const displayName = user.getDisplayName();
  410. if (displayName) {
  411. messageHandler.participantNotification(
  412. displayName,
  413. 'notify.somebody',
  414. 'connected',
  415. 'notify.grantedTo',
  416. { to: UIUtil.escapeHtml(displayName) });
  417. } else {
  418. messageHandler.participantNotification(
  419. '',
  420. 'notify.somebody',
  421. 'connected',
  422. 'notify.grantedToUnknown');
  423. }
  424. };
  425. /**
  426. * Updates the user status.
  427. *
  428. * @param {JitsiParticipant} user - The user which status we need to update.
  429. * @param {string} status - The new status.
  430. */
  431. UI.updateUserStatus = (user, status) => {
  432. if (!status) {
  433. return;
  434. }
  435. const displayName = user.getDisplayName();
  436. messageHandler.participantNotification(
  437. displayName,
  438. '',
  439. 'connected',
  440. 'dialOut.statusMessage',
  441. { status: UIUtil.escapeHtml(status) });
  442. };
  443. /**
  444. * Toggles smileys in the chat.
  445. */
  446. UI.toggleSmileys = () => Chat.toggleSmileys();
  447. /**
  448. * Toggles filmstrip.
  449. */
  450. UI.toggleFilmstrip = function() {
  451. // eslint-disable-next-line prefer-rest-params
  452. Filmstrip.toggleFilmstrip(...arguments);
  453. VideoLayout.resizeVideoArea(true, false);
  454. };
  455. /**
  456. * Checks if the filmstrip is currently visible or not.
  457. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  458. */
  459. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  460. /**
  461. * @returns {true} if the chat panel is currently visible, and false otherwise.
  462. */
  463. UI.isChatVisible = () => Chat.isVisible();
  464. /**
  465. * Toggles chat panel.
  466. */
  467. UI.toggleChat = () => UI.toggleSidePanel('chat_container');
  468. /**
  469. * Toggles the given side panel.
  470. *
  471. * @param {String} sidePanelId the identifier of the side panel to toggle
  472. */
  473. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  474. /**
  475. * Handle new user display name.
  476. */
  477. UI.inputDisplayNameHandler = function(newDisplayName) {
  478. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  479. };
  480. /**
  481. * Return the type of the remote video.
  482. * @param jid the jid for the remote video
  483. * @returns the video type video or screen.
  484. */
  485. UI.getRemoteVideoType = function(jid) {
  486. return VideoLayout.getRemoteVideoType(jid);
  487. };
  488. // FIXME check if someone user this
  489. UI.showLoginPopup = function(callback) {
  490. logger.log('password is required');
  491. const message
  492. = `<input name="username" type="text"
  493. placeholder="user@domain.net"
  494. class="input-control" autofocus>
  495. <input name="password" type="password"
  496. data-i18n="[placeholder]dialog.userPassword"
  497. class="input-control"
  498. placeholder="user password">`
  499. ;
  500. // eslint-disable-next-line max-params
  501. const submitFunction = (e, v, m, f) => {
  502. if (v && f.username && f.password) {
  503. callback(f.username, f.password);
  504. }
  505. };
  506. messageHandler.openTwoButtonDialog({
  507. titleKey: 'dialog.passwordRequired',
  508. msgString: message,
  509. leftButtonKey: 'dialog.Ok',
  510. submitFunction,
  511. focus: ':input:first'
  512. });
  513. };
  514. UI.askForNickname = function() {
  515. // eslint-disable-next-line no-alert
  516. return window.prompt('Your nickname (optional)');
  517. };
  518. /**
  519. * Sets muted audio state for participant
  520. */
  521. UI.setAudioMuted = function(id, muted) {
  522. VideoLayout.onAudioMute(id, muted);
  523. if (APP.conference.isLocalId(id)) {
  524. APP.conference.updateAudioIconEnabled();
  525. }
  526. };
  527. /**
  528. * Sets muted video state for participant
  529. */
  530. UI.setVideoMuted = function(id, muted) {
  531. VideoLayout.onVideoMute(id, muted);
  532. if (APP.conference.isLocalId(id)) {
  533. APP.conference.updateVideoIconEnabled();
  534. }
  535. };
  536. /**
  537. * Triggers an update of remote video and large video displays so they may pick
  538. * up any state changes that have occurred elsewhere.
  539. *
  540. * @returns {void}
  541. */
  542. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  543. /**
  544. * Adds a listener that would be notified on the given type of event.
  545. *
  546. * @param type the type of the event we're listening for
  547. * @param listener a function that would be called when notified
  548. */
  549. UI.addListener = function(type, listener) {
  550. eventEmitter.on(type, listener);
  551. };
  552. /**
  553. * Removes the given listener for the given type of event.
  554. *
  555. * @param type the type of the event we're listening for
  556. * @param listener the listener we want to remove
  557. */
  558. UI.removeListener = function(type, listener) {
  559. eventEmitter.removeListener(type, listener);
  560. };
  561. /**
  562. * Emits the event of given type by specifying the parameters in options.
  563. *
  564. * @param type the type of the event we're emitting
  565. * @param options the parameters for the event
  566. */
  567. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  568. UI.clickOnVideo = function(videoNumber) {
  569. const videos = $('#remoteVideos .videocontainer:not(#mixedstream)');
  570. const videosLength = videos.length;
  571. if (videosLength <= videoNumber) {
  572. return;
  573. }
  574. const videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  575. videos[videoIndex].click();
  576. };
  577. // Used by torture.
  578. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  579. // Used by torture.
  580. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  581. /**
  582. * Updates the displayed avatar for participant.
  583. *
  584. * @param {string} id - User id whose avatar should be updated.
  585. * @param {string} avatarURL - The URL to avatar image to display.
  586. * @returns {void}
  587. */
  588. UI.refreshAvatarDisplay = function(id, avatarURL) {
  589. VideoLayout.changeUserAvatar(id, avatarURL);
  590. };
  591. /**
  592. * Notify user that connection failed.
  593. * @param {string} stropheErrorMsg raw Strophe error message
  594. */
  595. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  596. let descriptionKey;
  597. let descriptionArguments;
  598. if (stropheErrorMsg) {
  599. descriptionKey = 'dialog.connectErrorWithMsg';
  600. descriptionArguments = { msg: stropheErrorMsg };
  601. } else {
  602. descriptionKey = 'dialog.connectError';
  603. }
  604. messageHandler.showError({
  605. descriptionArguments,
  606. descriptionKey,
  607. titleKey: 'connection.CONNFAIL'
  608. });
  609. };
  610. /**
  611. * Notify user that maximum users limit has been reached.
  612. */
  613. UI.notifyMaxUsersLimitReached = function() {
  614. messageHandler.showError({
  615. hideErrorSupportLink: true,
  616. descriptionKey: 'dialog.maxUsersLimitReached',
  617. titleKey: 'dialog.maxUsersLimitReachedTitle'
  618. });
  619. };
  620. /**
  621. * Notify user that he was automatically muted when joned the conference.
  622. */
  623. UI.notifyInitiallyMuted = function() {
  624. messageHandler.participantNotification(
  625. null,
  626. 'notify.mutedTitle',
  627. 'connected',
  628. 'notify.muted',
  629. null);
  630. };
  631. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  632. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  633. };
  634. /**
  635. * Prompt user for nickname.
  636. */
  637. UI.promptDisplayName = () => {
  638. APP.store.dispatch(openDisplayNamePrompt());
  639. };
  640. /**
  641. * Update audio level visualization for specified user.
  642. * @param {string} id user id
  643. * @param {number} lvl audio level
  644. */
  645. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  646. /**
  647. * Hide connection quality statistics from UI.
  648. */
  649. UI.hideStats = function() {
  650. VideoLayout.hideStats();
  651. };
  652. /**
  653. * Add chat message.
  654. * @param {string} from user id
  655. * @param {string} displayName user nickname
  656. * @param {string} message message text
  657. * @param {number} stamp timestamp when message was created
  658. */
  659. // eslint-disable-next-line max-params
  660. UI.addMessage = function(from, displayName, message, stamp) {
  661. Chat.updateChatConversation(from, displayName, message, stamp);
  662. };
  663. UI.notifyTokenAuthFailed = function() {
  664. messageHandler.showError({
  665. descriptionKey: 'dialog.tokenAuthFailed',
  666. titleKey: 'dialog.tokenAuthFailedTitle'
  667. });
  668. };
  669. UI.notifyInternalError = function(error) {
  670. messageHandler.showError({
  671. descriptionArguments: { error },
  672. descriptionKey: 'dialog.internalError',
  673. titleKey: 'dialog.internalErrorTitle'
  674. });
  675. };
  676. UI.notifyFocusDisconnected = function(focus, retrySec) {
  677. messageHandler.participantNotification(
  678. null, 'notify.focus',
  679. 'disconnected', 'notify.focusFail',
  680. { component: focus,
  681. ms: retrySec }
  682. );
  683. };
  684. /**
  685. * Notifies interested listeners that the raise hand property has changed.
  686. *
  687. * @param {boolean} isRaisedHand indicates the current state of the
  688. * "raised hand"
  689. */
  690. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  691. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  692. };
  693. /**
  694. * Update list of available physical devices.
  695. * @param {object[]} devices new list of available devices
  696. */
  697. UI.onAvailableDevicesChanged = function(devices) {
  698. APP.store.dispatch(updateDeviceList(devices));
  699. APP.conference.updateAudioIconEnabled();
  700. APP.conference.updateVideoIconEnabled();
  701. };
  702. /**
  703. * Returns the id of the current video shown on large.
  704. * Currently used by tests (torture).
  705. */
  706. UI.getLargeVideoID = function() {
  707. return VideoLayout.getLargeVideoID();
  708. };
  709. /**
  710. * Returns the current video shown on large.
  711. * Currently used by tests (torture).
  712. */
  713. UI.getLargeVideo = function() {
  714. return VideoLayout.getLargeVideo();
  715. };
  716. /**
  717. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  718. * 2 button dialog with buttons - cancel and go to web store.
  719. * @param url {string} the url of the extension.
  720. */
  721. UI.showExtensionExternalInstallationDialog = function(url) {
  722. let openedWindow = null;
  723. const submitFunction = function(e, v) {
  724. if (v) {
  725. e.preventDefault();
  726. if (openedWindow === null || openedWindow.closed) {
  727. openedWindow
  728. = window.open(
  729. url,
  730. 'extension_store_window',
  731. 'resizable,scrollbars=yes,status=1');
  732. } else {
  733. openedWindow.focus();
  734. }
  735. }
  736. };
  737. const closeFunction = function(e, v) {
  738. if (openedWindow) {
  739. // Ideally we would close the popup, but this does not seem to work
  740. // on Chrome. Leaving it uncommented in case it could work
  741. // in some version.
  742. openedWindow.close();
  743. openedWindow = null;
  744. }
  745. if (!v) {
  746. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  747. }
  748. };
  749. messageHandler.openTwoButtonDialog({
  750. titleKey: 'dialog.externalInstallationTitle',
  751. msgKey: 'dialog.externalInstallationMsg',
  752. leftButtonKey: 'dialog.goToStore',
  753. submitFunction,
  754. loadedFunction: $.noop,
  755. closeFunction
  756. });
  757. };
  758. /**
  759. * Shows a dialog which asks user to install the extension. This one is
  760. * displayed after installation is triggered from the script, but fails because
  761. * it must be initiated by user gesture.
  762. * @param callback {function} function to be executed after user clicks
  763. * the install button - it should make another attempt to install the extension.
  764. */
  765. UI.showExtensionInlineInstallationDialog = function(callback) {
  766. const submitFunction = function(e, v) {
  767. if (v) {
  768. callback();
  769. }
  770. };
  771. const closeFunction = function(e, v) {
  772. if (!v) {
  773. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  774. }
  775. };
  776. messageHandler.openTwoButtonDialog({
  777. titleKey: 'dialog.externalInstallationTitle',
  778. msgKey: 'dialog.inlineInstallationMsg',
  779. leftButtonKey: 'dialog.inlineInstallExtension',
  780. submitFunction,
  781. loadedFunction: $.noop,
  782. closeFunction
  783. });
  784. };
  785. /**
  786. * Shows a notifications about the passed in microphone error.
  787. *
  788. * @param {JitsiTrackError} micError - An error object related to using or
  789. * acquiring an audio stream.
  790. * @returns {void}
  791. */
  792. UI.showMicErrorNotification = function(micError) {
  793. if (!micError) {
  794. return;
  795. }
  796. const { message, name } = micError;
  797. const micJitsiTrackErrorMsg
  798. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  799. const micErrorMsg = micJitsiTrackErrorMsg
  800. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  801. .microphone[JitsiTrackErrors.GENERAL];
  802. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  803. APP.store.dispatch(showWarningNotification({
  804. description: additionalMicErrorMsg,
  805. descriptionKey: micErrorMsg,
  806. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  807. ? 'deviceError.microphonePermission'
  808. : 'deviceError.microphoneError'
  809. }));
  810. };
  811. /**
  812. * Shows a notifications about the passed in camera error.
  813. *
  814. * @param {JitsiTrackError} cameraError - An error object related to using or
  815. * acquiring a video stream.
  816. * @returns {void}
  817. */
  818. UI.showCameraErrorNotification = function(cameraError) {
  819. if (!cameraError) {
  820. return;
  821. }
  822. const { message, name } = cameraError;
  823. const cameraJitsiTrackErrorMsg
  824. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  825. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  826. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  827. .camera[JitsiTrackErrors.GENERAL];
  828. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  829. APP.store.dispatch(showWarningNotification({
  830. description: additionalCameraErrorMsg,
  831. descriptionKey: cameraErrorMsg,
  832. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  833. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  834. }));
  835. };
  836. /**
  837. * Shows error dialog that informs the user that no data is received from the
  838. * device.
  839. *
  840. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  841. * track error.
  842. * @returns {void}
  843. */
  844. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  845. messageHandler.showError({
  846. descriptionKey: isAudioTrack
  847. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  848. titleKey: isAudioTrack
  849. ? 'dialog.micNotSendingDataTitle'
  850. : 'dialog.cameraNotSendingDataTitle'
  851. });
  852. };
  853. UI.updateDevicesAvailability = function(id, devices) {
  854. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  855. };
  856. /**
  857. * Show shared video.
  858. * @param {string} id the id of the sender of the command
  859. * @param {string} url video url
  860. * @param {string} attributes
  861. */
  862. UI.onSharedVideoStart = function(id, url, attributes) {
  863. if (sharedVideoManager) {
  864. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  865. }
  866. };
  867. /**
  868. * Update shared video.
  869. * @param {string} id the id of the sender of the command
  870. * @param {string} url video url
  871. * @param {string} attributes
  872. */
  873. UI.onSharedVideoUpdate = function(id, url, attributes) {
  874. if (sharedVideoManager) {
  875. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  876. }
  877. };
  878. /**
  879. * Stop showing shared video.
  880. * @param {string} id the id of the sender of the command
  881. * @param {string} attributes
  882. */
  883. UI.onSharedVideoStop = function(id, attributes) {
  884. if (sharedVideoManager) {
  885. sharedVideoManager.onSharedVideoStop(id, attributes);
  886. }
  887. };
  888. /**
  889. * Handles user's features changes.
  890. */
  891. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  892. /**
  893. * Returns the number of known remote videos.
  894. *
  895. * @returns {number} The number of remote videos.
  896. */
  897. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  898. /**
  899. * Sets the remote control active status for a remote participant.
  900. *
  901. * @param {string} participantID - The id of the remote participant.
  902. * @param {boolean} isActive - The new remote control active status.
  903. * @returns {void}
  904. */
  905. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  906. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  907. };
  908. /**
  909. * Sets the remote control active status for the local participant.
  910. *
  911. * @returns {void}
  912. */
  913. UI.setLocalRemoteControlActiveChanged = function() {
  914. VideoLayout.setLocalRemoteControlActiveChanged();
  915. };
  916. /**
  917. * Remove media tracks and UI elements so the user no longer sees media in the
  918. * UI. The intent is to provide a feeling that the meeting has ended.
  919. *
  920. * @returns {void}
  921. */
  922. UI.removeLocalMedia = function() {
  923. APP.store.dispatch(destroyLocalTracks());
  924. VideoLayout.resetLargeVideo();
  925. $('#videospace').hide();
  926. };
  927. // TODO: Export every function separately. For now there is no point of doing
  928. // this because we are importing everything.
  929. export default UI;