選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UI.js 29KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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 { JitsiTrackErrors } from '../../react/features/base/lib-jitsi-meet';
  15. import {
  16. getLocalParticipant,
  17. showParticipantJoinedNotification
  18. } from '../../react/features/base/participants';
  19. import { destroyLocalTracks } from '../../react/features/base/tracks';
  20. import { openDisplayNamePrompt } from '../../react/features/display-name';
  21. import { setEtherpadHasInitialzied } from '../../react/features/etherpad';
  22. import { setFilmstripVisible } from '../../react/features/filmstrip';
  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.toggleFilmstrip()
  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.kickTitle'
  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. * Returns the shared document manager object.
  228. * @return {EtherpadManager} the shared document manager object
  229. */
  230. UI.getSharedVideoManager = function() {
  231. return sharedVideoManager;
  232. };
  233. /**
  234. * Starts the UI module and initializes all related components.
  235. *
  236. * @returns {boolean} true if the UI is ready and the conference should be
  237. * established, false - otherwise (for example in the case of welcome page)
  238. */
  239. UI.start = function() {
  240. document.title = interfaceConfig.APP_NAME;
  241. // Set the defaults for prompt dialogs.
  242. $.prompt.setDefaults({ persistent: false });
  243. SideContainerToggler.init(eventEmitter);
  244. Filmstrip.init(eventEmitter);
  245. VideoLayout.init(eventEmitter);
  246. if (!interfaceConfig.filmStripOnly) {
  247. VideoLayout.initLargeVideo();
  248. }
  249. // Do not animate the video area on UI start (second argument passed into
  250. // resizeVideoArea) because the animation is not visible anyway. Plus with
  251. // the current dom layout, the quality label is part of the video layout and
  252. // will be seen animating in.
  253. VideoLayout.resizeVideoArea(true, false);
  254. sharedVideoManager = new SharedVideoManager(eventEmitter);
  255. if (interfaceConfig.filmStripOnly) {
  256. $('body').addClass('filmstrip-only');
  257. APP.store.dispatch(setNotificationsEnabled(false));
  258. } else {
  259. // Initialize recording mode UI.
  260. if (config.iAmRecorder) {
  261. // in case of iAmSipGateway keep local video visible
  262. if (!config.iAmSipGateway) {
  263. VideoLayout.setLocalVideoVisible(false);
  264. }
  265. APP.store.dispatch(setToolboxEnabled(false));
  266. APP.store.dispatch(setNotificationsEnabled(false));
  267. UI.messageHandler.enablePopups(false);
  268. }
  269. // Initialize side panels
  270. SidePanels.init(eventEmitter);
  271. }
  272. document.title = interfaceConfig.APP_NAME;
  273. };
  274. /**
  275. * Setup some UI event listeners.
  276. */
  277. UI.registerListeners
  278. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  279. /**
  280. * Unregister some UI event listeners.
  281. */
  282. UI.unregisterListeners
  283. = () => UIListeners.forEach((value, key) => UI.removeListener(key, value));
  284. /**
  285. * Setup some DOM event listeners.
  286. */
  287. UI.bindEvents = () => {
  288. /**
  289. *
  290. */
  291. function onResize() {
  292. SideContainerToggler.resize();
  293. VideoLayout.resizeVideoArea();
  294. }
  295. // Resize and reposition videos in full screen mode.
  296. $(document).on(
  297. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  298. onResize);
  299. $(window).resize(onResize);
  300. };
  301. /**
  302. * Unbind some DOM event listeners.
  303. */
  304. UI.unbindEvents = () => {
  305. $(document).off(
  306. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  307. $(window).off('resize');
  308. };
  309. /**
  310. * Show local stream on UI.
  311. * @param {JitsiTrack} track stream to show
  312. */
  313. UI.addLocalStream = track => {
  314. switch (track.getType()) {
  315. case 'audio':
  316. // Local audio is not rendered so no further action is needed at this
  317. // point.
  318. break;
  319. case 'video':
  320. VideoLayout.changeLocalVideo(track);
  321. break;
  322. default:
  323. logger.error(`Unknown stream type: ${track.getType()}`);
  324. break;
  325. }
  326. };
  327. /**
  328. * Removed remote stream from UI.
  329. * @param {JitsiTrack} track stream to remove
  330. */
  331. UI.removeRemoteStream = track => VideoLayout.onRemoteStreamRemoved(track);
  332. /**
  333. * Setup and show Etherpad.
  334. * @param {string} name etherpad id
  335. */
  336. UI.initEtherpad = name => {
  337. if (etherpadManager || !config.etherpad_base || !name) {
  338. return;
  339. }
  340. logger.log('Etherpad is enabled');
  341. etherpadManager
  342. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  343. APP.store.dispatch(setEtherpadHasInitialzied());
  344. };
  345. /**
  346. * Returns the shared document manager object.
  347. * @return {EtherpadManager} the shared document manager object
  348. */
  349. UI.getSharedDocumentManager = () => etherpadManager;
  350. /**
  351. * Show user on UI.
  352. * @param {JitsiParticipant} user
  353. */
  354. UI.addUser = function(user) {
  355. const id = user.getId();
  356. const displayName = user.getDisplayName();
  357. const status = user.getStatus();
  358. if (status) {
  359. // FIXME: move updateUserStatus in participantPresenceChanged action
  360. UI.updateUserStatus(user, status);
  361. } else {
  362. APP.store.dispatch(showParticipantJoinedNotification(displayName));
  363. }
  364. // set initial display name
  365. if (displayName) {
  366. UI.changeDisplayName(id, displayName);
  367. }
  368. };
  369. /**
  370. * Update videotype for specified user.
  371. * @param {string} id user id
  372. * @param {string} newVideoType new videotype
  373. */
  374. UI.onPeerVideoTypeChanged
  375. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  376. /**
  377. * Update local user role and show notification if user is moderator.
  378. * @param {boolean} isModerator if local user is moderator or not
  379. */
  380. UI.updateLocalRole = isModerator => {
  381. VideoLayout.showModeratorIndicator();
  382. if (isModerator && !interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  383. messageHandler.participantNotification(
  384. null, 'notify.me', 'connected', 'notify.moderator');
  385. }
  386. };
  387. /**
  388. * Check the role for the user and reflect it in the UI, moderator ui indication
  389. * and notifies user who is the moderator
  390. * @param user to check for moderator
  391. */
  392. UI.updateUserRole = user => {
  393. VideoLayout.showModeratorIndicator();
  394. // We don't need to show moderator notifications when the focus (moderator)
  395. // indicator is disabled.
  396. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  397. return;
  398. }
  399. const displayName = user.getDisplayName();
  400. messageHandler.participantNotification(
  401. displayName,
  402. 'notify.somebody',
  403. 'connected',
  404. 'notify.grantedTo',
  405. { to: displayName
  406. ? UIUtil.escapeHtml(displayName) : '$t(notify.somebody)' });
  407. };
  408. /**
  409. * Updates the user status.
  410. *
  411. * @param {JitsiParticipant} user - The user which status we need to update.
  412. * @param {string} status - The new status.
  413. */
  414. UI.updateUserStatus = (user, status) => {
  415. const reduxState = APP.store.getState() || {};
  416. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  417. if (!status || calleeInfoVisible) {
  418. return;
  419. }
  420. const displayName = user.getDisplayName();
  421. messageHandler.participantNotification(
  422. displayName,
  423. '',
  424. 'connected',
  425. 'dialOut.statusMessage',
  426. { status: UIUtil.escapeHtml(status) });
  427. };
  428. /**
  429. * Toggles smileys in the chat.
  430. */
  431. UI.toggleSmileys = () => Chat.toggleSmileys();
  432. /**
  433. * Toggles filmstrip.
  434. */
  435. UI.toggleFilmstrip = function() {
  436. const { visible } = APP.store.getState()['features/filmstrip'];
  437. APP.store.dispatch(setFilmstripVisible(!visible));
  438. };
  439. /**
  440. * Checks if the filmstrip is currently visible or not.
  441. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  442. */
  443. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  444. /**
  445. * @returns {true} if the chat panel is currently visible, and false otherwise.
  446. */
  447. UI.isChatVisible = () => Chat.isVisible();
  448. /**
  449. * Toggles chat panel.
  450. */
  451. UI.toggleChat = () => UI.toggleSidePanel('chat_container');
  452. /**
  453. * Toggles the given side panel.
  454. *
  455. * @param {String} sidePanelId the identifier of the side panel to toggle
  456. */
  457. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  458. /**
  459. * Handle new user display name.
  460. */
  461. UI.inputDisplayNameHandler = function(newDisplayName) {
  462. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  463. };
  464. /**
  465. * Return the type of the remote video.
  466. * @param jid the jid for the remote video
  467. * @returns the video type video or screen.
  468. */
  469. UI.getRemoteVideoType = function(jid) {
  470. return VideoLayout.getRemoteVideoType(jid);
  471. };
  472. // FIXME check if someone user this
  473. UI.showLoginPopup = function(callback) {
  474. logger.log('password is required');
  475. const message
  476. = `<input name="username" type="text"
  477. placeholder="user@domain.net"
  478. class="input-control" autofocus>
  479. <input name="password" type="password"
  480. data-i18n="[placeholder]dialog.userPassword"
  481. class="input-control"
  482. placeholder="user password">`
  483. ;
  484. // eslint-disable-next-line max-params
  485. const submitFunction = (e, v, m, f) => {
  486. if (v && f.username && f.password) {
  487. callback(f.username, f.password);
  488. }
  489. };
  490. messageHandler.openTwoButtonDialog({
  491. titleKey: 'dialog.passwordRequired',
  492. msgString: message,
  493. leftButtonKey: 'dialog.Ok',
  494. submitFunction,
  495. focus: ':input:first'
  496. });
  497. };
  498. UI.askForNickname = function() {
  499. // eslint-disable-next-line no-alert
  500. return window.prompt('Your nickname (optional)');
  501. };
  502. /**
  503. * Sets muted audio state for participant
  504. */
  505. UI.setAudioMuted = function(id, muted) {
  506. VideoLayout.onAudioMute(id, muted);
  507. if (APP.conference.isLocalId(id)) {
  508. APP.conference.updateAudioIconEnabled();
  509. }
  510. };
  511. /**
  512. * Sets muted video state for participant
  513. */
  514. UI.setVideoMuted = function(id, muted) {
  515. VideoLayout.onVideoMute(id, muted);
  516. if (APP.conference.isLocalId(id)) {
  517. APP.conference.updateVideoIconEnabled();
  518. }
  519. };
  520. /**
  521. * Triggers an update of remote video and large video displays so they may pick
  522. * up any state changes that have occurred elsewhere.
  523. *
  524. * @returns {void}
  525. */
  526. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  527. /**
  528. * Adds a listener that would be notified on the given type of event.
  529. *
  530. * @param type the type of the event we're listening for
  531. * @param listener a function that would be called when notified
  532. */
  533. UI.addListener = function(type, listener) {
  534. eventEmitter.on(type, listener);
  535. };
  536. /**
  537. * Removes the given listener for the given type of event.
  538. *
  539. * @param type the type of the event we're listening for
  540. * @param listener the listener we want to remove
  541. */
  542. UI.removeListener = function(type, listener) {
  543. eventEmitter.removeListener(type, listener);
  544. };
  545. /**
  546. * Emits the event of given type by specifying the parameters in options.
  547. *
  548. * @param type the type of the event we're emitting
  549. * @param options the parameters for the event
  550. */
  551. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  552. UI.clickOnVideo = function(videoNumber) {
  553. const videos = $('#remoteVideos .videocontainer:not(#mixedstream)');
  554. const videosLength = videos.length;
  555. if (videosLength <= videoNumber) {
  556. return;
  557. }
  558. const videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  559. videos[videoIndex].click();
  560. };
  561. // Used by torture.
  562. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  563. // Used by torture.
  564. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  565. /**
  566. * Updates the displayed avatar for participant.
  567. *
  568. * @param {string} id - User id whose avatar should be updated.
  569. * @param {string} avatarURL - The URL to avatar image to display.
  570. * @returns {void}
  571. */
  572. UI.refreshAvatarDisplay = function(id, avatarURL) {
  573. VideoLayout.changeUserAvatar(id, avatarURL);
  574. };
  575. /**
  576. * Notify user that connection failed.
  577. * @param {string} stropheErrorMsg raw Strophe error message
  578. */
  579. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  580. let descriptionKey;
  581. let descriptionArguments;
  582. if (stropheErrorMsg) {
  583. descriptionKey = 'dialog.connectErrorWithMsg';
  584. descriptionArguments = { msg: stropheErrorMsg };
  585. } else {
  586. descriptionKey = 'dialog.connectError';
  587. }
  588. messageHandler.showError({
  589. descriptionArguments,
  590. descriptionKey,
  591. titleKey: 'connection.CONNFAIL'
  592. });
  593. };
  594. /**
  595. * Notify user that maximum users limit has been reached.
  596. */
  597. UI.notifyMaxUsersLimitReached = function() {
  598. messageHandler.showError({
  599. hideErrorSupportLink: true,
  600. descriptionKey: 'dialog.maxUsersLimitReached',
  601. titleKey: 'dialog.maxUsersLimitReachedTitle'
  602. });
  603. };
  604. /**
  605. * Notify user that he was automatically muted when joned the conference.
  606. */
  607. UI.notifyInitiallyMuted = function() {
  608. messageHandler.participantNotification(
  609. null,
  610. 'notify.mutedTitle',
  611. 'connected',
  612. 'notify.muted',
  613. null);
  614. };
  615. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  616. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  617. };
  618. /**
  619. * Prompt user for nickname.
  620. */
  621. UI.promptDisplayName = () => {
  622. APP.store.dispatch(openDisplayNamePrompt());
  623. };
  624. /**
  625. * Update audio level visualization for specified user.
  626. * @param {string} id user id
  627. * @param {number} lvl audio level
  628. */
  629. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  630. /**
  631. * Hide connection quality statistics from UI.
  632. */
  633. UI.hideStats = function() {
  634. VideoLayout.hideStats();
  635. };
  636. /**
  637. * Add chat message.
  638. * @param {string} from user id
  639. * @param {string} displayName user nickname
  640. * @param {string} message message text
  641. * @param {number} stamp timestamp when message was created
  642. */
  643. // eslint-disable-next-line max-params
  644. UI.addMessage = function(from, displayName, message, stamp) {
  645. Chat.updateChatConversation(from, displayName, message, stamp);
  646. };
  647. UI.notifyTokenAuthFailed = function() {
  648. messageHandler.showError({
  649. descriptionKey: 'dialog.tokenAuthFailed',
  650. titleKey: 'dialog.tokenAuthFailedTitle'
  651. });
  652. };
  653. UI.notifyInternalError = function(error) {
  654. messageHandler.showError({
  655. descriptionArguments: { error },
  656. descriptionKey: 'dialog.internalError',
  657. titleKey: 'dialog.internalErrorTitle'
  658. });
  659. };
  660. UI.notifyFocusDisconnected = function(focus, retrySec) {
  661. messageHandler.participantNotification(
  662. null, 'notify.focus',
  663. 'disconnected', 'notify.focusFail',
  664. { component: focus,
  665. ms: retrySec }
  666. );
  667. };
  668. /**
  669. * Notifies interested listeners that the raise hand property has changed.
  670. *
  671. * @param {boolean} isRaisedHand indicates the current state of the
  672. * "raised hand"
  673. */
  674. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  675. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  676. };
  677. /**
  678. * Update list of available physical devices.
  679. */
  680. UI.onAvailableDevicesChanged = function() {
  681. APP.conference.updateAudioIconEnabled();
  682. APP.conference.updateVideoIconEnabled();
  683. };
  684. /**
  685. * Returns the id of the current video shown on large.
  686. * Currently used by tests (torture).
  687. */
  688. UI.getLargeVideoID = function() {
  689. return VideoLayout.getLargeVideoID();
  690. };
  691. /**
  692. * Returns the current video shown on large.
  693. * Currently used by tests (torture).
  694. */
  695. UI.getLargeVideo = function() {
  696. return VideoLayout.getLargeVideo();
  697. };
  698. /**
  699. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  700. * 2 button dialog with buttons - cancel and go to web store.
  701. * @param url {string} the url of the extension.
  702. */
  703. UI.showExtensionExternalInstallationDialog = function(url) {
  704. let openedWindow = null;
  705. const submitFunction = function(e, v) {
  706. if (v) {
  707. e.preventDefault();
  708. if (openedWindow === null || openedWindow.closed) {
  709. openedWindow
  710. = window.open(
  711. url,
  712. 'extension_store_window',
  713. 'resizable,scrollbars=yes,status=1');
  714. } else {
  715. openedWindow.focus();
  716. }
  717. }
  718. };
  719. const closeFunction = function(e, v) {
  720. if (openedWindow) {
  721. // Ideally we would close the popup, but this does not seem to work
  722. // on Chrome. Leaving it uncommented in case it could work
  723. // in some version.
  724. openedWindow.close();
  725. openedWindow = null;
  726. }
  727. if (!v) {
  728. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  729. }
  730. };
  731. messageHandler.openTwoButtonDialog({
  732. titleKey: 'dialog.externalInstallationTitle',
  733. msgKey: 'dialog.externalInstallationMsg',
  734. leftButtonKey: 'dialog.goToStore',
  735. submitFunction,
  736. loadedFunction: $.noop,
  737. closeFunction
  738. });
  739. };
  740. /**
  741. * Shows a dialog which asks user to install the extension. This one is
  742. * displayed after installation is triggered from the script, but fails because
  743. * it must be initiated by user gesture.
  744. * @param callback {function} function to be executed after user clicks
  745. * the install button - it should make another attempt to install the extension.
  746. */
  747. UI.showExtensionInlineInstallationDialog = function(callback) {
  748. const submitFunction = function(e, v) {
  749. if (v) {
  750. callback();
  751. }
  752. };
  753. const closeFunction = function(e, v) {
  754. if (!v) {
  755. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  756. }
  757. };
  758. messageHandler.openTwoButtonDialog({
  759. titleKey: 'dialog.externalInstallationTitle',
  760. msgKey: 'dialog.inlineInstallationMsg',
  761. leftButtonKey: 'dialog.inlineInstallExtension',
  762. submitFunction,
  763. loadedFunction: $.noop,
  764. closeFunction
  765. });
  766. };
  767. /**
  768. * Shows a notifications about the passed in microphone error.
  769. *
  770. * @param {JitsiTrackError} micError - An error object related to using or
  771. * acquiring an audio stream.
  772. * @returns {void}
  773. */
  774. UI.showMicErrorNotification = function(micError) {
  775. if (!micError) {
  776. return;
  777. }
  778. const { message, name } = micError;
  779. const micJitsiTrackErrorMsg
  780. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  781. const micErrorMsg = micJitsiTrackErrorMsg
  782. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  783. .microphone[JitsiTrackErrors.GENERAL];
  784. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  785. APP.store.dispatch(showWarningNotification({
  786. description: additionalMicErrorMsg,
  787. descriptionKey: micErrorMsg,
  788. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  789. ? 'deviceError.microphonePermission'
  790. : 'deviceError.microphoneError'
  791. }));
  792. };
  793. /**
  794. * Shows a notifications about the passed in camera error.
  795. *
  796. * @param {JitsiTrackError} cameraError - An error object related to using or
  797. * acquiring a video stream.
  798. * @returns {void}
  799. */
  800. UI.showCameraErrorNotification = function(cameraError) {
  801. if (!cameraError) {
  802. return;
  803. }
  804. const { message, name } = cameraError;
  805. const cameraJitsiTrackErrorMsg
  806. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  807. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  808. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  809. .camera[JitsiTrackErrors.GENERAL];
  810. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  811. APP.store.dispatch(showWarningNotification({
  812. description: additionalCameraErrorMsg,
  813. descriptionKey: cameraErrorMsg,
  814. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  815. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  816. }));
  817. };
  818. /**
  819. * Shows error dialog that informs the user that no data is received from the
  820. * device.
  821. *
  822. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  823. * track error.
  824. * @returns {void}
  825. */
  826. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  827. messageHandler.showError({
  828. descriptionKey: isAudioTrack
  829. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  830. titleKey: isAudioTrack
  831. ? 'dialog.micNotSendingDataTitle'
  832. : 'dialog.cameraNotSendingDataTitle'
  833. });
  834. };
  835. UI.updateDevicesAvailability = function(id, devices) {
  836. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  837. };
  838. /**
  839. * Show shared video.
  840. * @param {string} id the id of the sender of the command
  841. * @param {string} url video url
  842. * @param {string} attributes
  843. */
  844. UI.onSharedVideoStart = function(id, url, attributes) {
  845. if (sharedVideoManager) {
  846. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  847. }
  848. };
  849. /**
  850. * Update shared video.
  851. * @param {string} id the id of the sender of the command
  852. * @param {string} url video url
  853. * @param {string} attributes
  854. */
  855. UI.onSharedVideoUpdate = function(id, url, attributes) {
  856. if (sharedVideoManager) {
  857. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  858. }
  859. };
  860. /**
  861. * Stop showing shared video.
  862. * @param {string} id the id of the sender of the command
  863. * @param {string} attributes
  864. */
  865. UI.onSharedVideoStop = function(id, attributes) {
  866. if (sharedVideoManager) {
  867. sharedVideoManager.onSharedVideoStop(id, attributes);
  868. }
  869. };
  870. /**
  871. * Handles user's features changes.
  872. */
  873. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  874. /**
  875. * Returns the number of known remote videos.
  876. *
  877. * @returns {number} The number of remote videos.
  878. */
  879. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  880. /**
  881. * Sets the remote control active status for a remote participant.
  882. *
  883. * @param {string} participantID - The id of the remote participant.
  884. * @param {boolean} isActive - The new remote control active status.
  885. * @returns {void}
  886. */
  887. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  888. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  889. };
  890. /**
  891. * Sets the remote control active status for the local participant.
  892. *
  893. * @returns {void}
  894. */
  895. UI.setLocalRemoteControlActiveChanged = function() {
  896. VideoLayout.setLocalRemoteControlActiveChanged();
  897. };
  898. /**
  899. * Remove media tracks and UI elements so the user no longer sees media in the
  900. * UI. The intent is to provide a feeling that the meeting has ended.
  901. *
  902. * @returns {void}
  903. */
  904. UI.removeLocalMedia = function() {
  905. APP.store.dispatch(destroyLocalTracks());
  906. VideoLayout.resetLargeVideo();
  907. $('#videospace').hide();
  908. };
  909. // TODO: Export every function separately. For now there is no point of doing
  910. // this because we are importing everything.
  911. export default UI;