You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* global Strophe, APP, $, config, interfaceConfig, toastr */
  2. /* jshint -W101 */
  3. var UI = {};
  4. var VideoLayout = require("./videolayout/VideoLayout.js");
  5. var AudioLevels = require("./audio_levels/AudioLevels.js");
  6. var Prezi = require("./prezi/Prezi.js");
  7. var Etherpad = require("./etherpad/Etherpad.js");
  8. var Chat = require("./side_pannels/chat/Chat.js");
  9. var Toolbar = require("./toolbars/Toolbar");
  10. var ToolbarToggler = require("./toolbars/ToolbarToggler");
  11. var BottomToolbar = require("./toolbars/BottomToolbar");
  12. var ContactList = require("./side_pannels/contactlist/ContactList");
  13. var Avatar = require("./avatar/Avatar");
  14. var EventEmitter = require("events");
  15. var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
  16. var Settings = require("./../settings/Settings");
  17. var PanelToggler = require("./side_pannels/SidePanelToggler");
  18. UI.messageHandler = require("./util/MessageHandler");
  19. var messageHandler = UI.messageHandler;
  20. var Authentication = require("./authentication/Authentication");
  21. var UIUtil = require("./util/UIUtil");
  22. var JitsiPopover = require("./util/JitsiPopover");
  23. var CQEvents = require("../../service/connectionquality/CQEvents");
  24. var DesktopSharingEventTypes
  25. = require("../../service/desktopsharing/DesktopSharingEventTypes");
  26. var StatisticsEvents = require("../../service/statistics/Events");
  27. var UIEvents = require("../../service/UI/UIEvents");
  28. var Feedback = require("./Feedback");
  29. var eventEmitter = new EventEmitter();
  30. UI.eventEmitter = eventEmitter;
  31. function promptDisplayName() {
  32. var message = '<h2 data-i18n="dialog.displayNameRequired">';
  33. message += APP.translation.translateString(
  34. "dialog.displayNameRequired");
  35. message += '</h2>' +
  36. '<input name="displayName" type="text" data-i18n=' +
  37. '"[placeholder]defaultNickname" placeholder="' +
  38. APP.translation.translateString(
  39. "defaultNickname", {name: "Jane Pink"}) +
  40. '" autofocus>';
  41. var buttonTxt
  42. = APP.translation.generateTranslationHTML("dialog.Ok");
  43. var buttons = [];
  44. buttons.push({title: buttonTxt, value: "ok"});
  45. messageHandler.openDialog(null, message,
  46. true,
  47. buttons,
  48. function (e, v, m, f) {
  49. if (v == "ok") {
  50. var displayName = f.displayName;
  51. if (displayName) {
  52. UI.inputDisplayNameHandler(displayName);
  53. return true;
  54. }
  55. }
  56. e.preventDefault();
  57. },
  58. function () {
  59. var form = $.prompt.getPrompt();
  60. var input = form.find("input[name='displayName']");
  61. input.focus();
  62. var button = form.find("button");
  63. button.attr("disabled", "disabled");
  64. input.keyup(function () {
  65. if(!input.val())
  66. button.attr("disabled", "disabled");
  67. else
  68. button.removeAttr("disabled");
  69. });
  70. }
  71. );
  72. }
  73. function setupPrezi() {
  74. $("#reloadPresentationLink").click(function() {
  75. Prezi.reloadPresentation();
  76. });
  77. }
  78. function setupChat() {
  79. Chat.init(eventEmitter);
  80. $("#toggle_smileys").click(function() {
  81. Chat.toggleSmileys();
  82. });
  83. }
  84. function setupToolbars() {
  85. Toolbar.init(eventEmitter);
  86. Toolbar.setupButtonsFromConfig();
  87. BottomToolbar.init(eventEmitter);
  88. }
  89. UI.notifyGracefulShudown = function () {
  90. messageHandler.openMessageDialog(
  91. 'dialog.serviceUnavailable',
  92. 'dialog.gracefulShutdown'
  93. );
  94. };
  95. UI.notifyReservationError = function (code, msg) {
  96. var title = APP.translation.generateTranslationHTML(
  97. "dialog.reservationError");
  98. var message = APP.translation.generateTranslationHTML(
  99. "dialog.reservationErrorMsg", {code: code, msg: msg});
  100. messageHandler.openDialog(
  101. title,
  102. message,
  103. true, {},
  104. function (event, value, message, formVals) {
  105. return false;
  106. }
  107. );
  108. };
  109. UI.notifyKicked = function () {
  110. messageHandler.openMessageDialog("dialog.sessTerminated", "dialog.kickMessage");
  111. };
  112. UI.notifyBridgeDown = function () {
  113. messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
  114. };
  115. UI.changeDisplayName = function (id, displayName) {
  116. ContactList.onDisplayNameChange(id, displayName);
  117. SettingsMenu.onDisplayNameChange(id, displayName);
  118. VideoLayout.onDisplayNameChanged(id, displayName);
  119. };
  120. UI.initConference = function () {
  121. var id = APP.conference.localId;
  122. Toolbar.updateRoomUrl(window.location.href);
  123. var meHTML = APP.translation.generateTranslationHTML("me");
  124. var settings = Settings.getSettings();
  125. $("#localNick").html(settings.email || settings.uid + " (" + meHTML + ")");
  126. // Make sure we configure our avatar id, before creating avatar for us
  127. UI.setUserAvatar(id, settings.email || settings.uid);
  128. // Add myself to the contact list.
  129. ContactList.addContact(id);
  130. // Once we've joined the muc show the toolbar
  131. ToolbarToggler.showToolbar();
  132. var displayName = config.displayJids ? id : settings.displayName;
  133. if (displayName) {
  134. UI.changeDisplayName('localVideoContainer', displayName);
  135. }
  136. VideoLayout.mucJoined();
  137. Toolbar.checkAutoEnableDesktopSharing();
  138. };
  139. function registerListeners() {
  140. UI.addListener(UIEvents.LARGEVIDEO_INIT, function () {
  141. AudioLevels.init();
  142. });
  143. UI.addListener(UIEvents.FILM_STRIP_TOGGLED, function (isToggled) {
  144. VideoLayout.onFilmStripToggled(isToggled);
  145. });
  146. UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
  147. UI.setUserAvatar(APP.conference.localId, email);
  148. });
  149. }
  150. function bindEvents() {
  151. function onResize() {
  152. Chat.resizeChat();
  153. VideoLayout.resizeLargeVideoContainer();
  154. }
  155. // Resize and reposition videos in full screen mode.
  156. $(document).on(
  157. 'webkitfullscreenchange mozfullscreenchange fullscreenchange', onResize
  158. );
  159. $(window).resize(onResize);
  160. }
  161. UI.start = function () {
  162. document.title = interfaceConfig.APP_NAME;
  163. var setupWelcomePage = null;
  164. if(config.enableWelcomePage && window.location.pathname == "/" &&
  165. (!window.localStorage.welcomePageDisabled ||
  166. window.localStorage.welcomePageDisabled == "false")) {
  167. $("#videoconference_page").hide();
  168. if (!setupWelcomePage)
  169. setupWelcomePage = require("./welcome_page/WelcomePage");
  170. setupWelcomePage();
  171. return;
  172. }
  173. $("#welcome_page").hide();
  174. // Set the defaults for prompt dialogs.
  175. $.prompt.setDefaults({persistent: false});
  176. registerListeners();
  177. VideoLayout.init(eventEmitter);
  178. bindEvents();
  179. setupPrezi();
  180. if (!interfaceConfig.filmStripOnly) {
  181. $("#videospace").mousemove(function () {
  182. return ToolbarToggler.showToolbar();
  183. });
  184. setupToolbars();
  185. setupChat();
  186. // Display notice message at the top of the toolbar
  187. if (config.noticeMessage) {
  188. $('#noticeText').text(config.noticeMessage);
  189. $('#notice').css({display: 'block'});
  190. }
  191. $("#downloadlog").click(function (event) {
  192. // dump(event.target);
  193. // FIXME integrate logs
  194. });
  195. Feedback.init();
  196. } else {
  197. $("#header").css("display", "none");
  198. $("#bottomToolbar").css("display", "none");
  199. $("#downloadlog").css("display", "none");
  200. $("#remoteVideos").css("padding", "0px 0px 18px 0px");
  201. $("#remoteVideos").css("right", "0px");
  202. messageHandler.disableNotifications();
  203. $('body').popover("disable");
  204. JitsiPopover.enabled = false;
  205. }
  206. document.title = interfaceConfig.APP_NAME;
  207. if(config.requireDisplayName) {
  208. if (APP.settings.getDisplayName()) {
  209. promptDisplayName();
  210. }
  211. }
  212. if (!interfaceConfig.filmStripOnly) {
  213. toastr.options = {
  214. "closeButton": true,
  215. "debug": false,
  216. "positionClass": "notification-bottom-right",
  217. "onclick": null,
  218. "showDuration": "300",
  219. "hideDuration": "1000",
  220. "timeOut": "2000",
  221. "extendedTimeOut": "1000",
  222. "showEasing": "swing",
  223. "hideEasing": "linear",
  224. "showMethod": "fadeIn",
  225. "hideMethod": "fadeOut",
  226. "reposition": function () {
  227. if (PanelToggler.isVisible()) {
  228. $("#toast-container").addClass("notification-bottom-right-center");
  229. } else {
  230. $("#toast-container").removeClass("notification-bottom-right-center");
  231. }
  232. },
  233. "newestOnTop": false
  234. };
  235. SettingsMenu.init();
  236. }
  237. };
  238. UI.addLocalStream = function (track) {
  239. switch (track.getType()) {
  240. case 'audio':
  241. VideoLayout.changeLocalAudio(track);
  242. break;
  243. case 'video':
  244. VideoLayout.changeLocalVideo(track);
  245. break;
  246. default:
  247. console.error("Unknown stream type: " + track.getType());
  248. break;
  249. }
  250. };
  251. UI.addRemoteStream = function (stream) {
  252. VideoLayout.onRemoteStreamAdded(stream);
  253. };
  254. function chatAddError(errorMessage, originalText) {
  255. return Chat.chatAddError(errorMessage, originalText);
  256. }
  257. function chatSetSubject(text) {
  258. return Chat.chatSetSubject(text);
  259. }
  260. function initEtherpad(name) {
  261. Etherpad.init(name);
  262. }
  263. UI.notifyPasswordRequired = function (callback) {
  264. // password is required
  265. Toolbar.lockLockButton();
  266. var message = '<h2 data-i18n="dialog.passwordRequired">';
  267. message += APP.translation.translateString(
  268. "dialog.passwordRequired");
  269. message += '</h2>' +
  270. '<input name="lockKey" type="text" data-i18n=' +
  271. '"[placeholder]dialog.password" placeholder="' +
  272. APP.translation.translateString("dialog.password") +
  273. '" autofocus>';
  274. messageHandler.openTwoButtonDialog(null, null, null, message,
  275. true,
  276. "dialog.Ok",
  277. function (e, v, m, f) {},
  278. null,
  279. function (e, v, m, f) {
  280. if (v) {
  281. var lockKey = f.lockKey;
  282. if (lockKey) {
  283. Toolbar.setSharedKey(lockKey);
  284. callback(lockKey);
  285. }
  286. }
  287. },
  288. ':input:first'
  289. );
  290. };
  291. /**
  292. * The dialpad button is shown iff there is at least one member that supports
  293. * DTMF (e.g. jigasi).
  294. */
  295. function onDtmfSupportChanged(dtmfSupport) {
  296. //TODO: enable when the UI is ready
  297. //Toolbar.showDialPadButton(dtmfSupport);
  298. }
  299. UI.addUser = function (jid, id, displayName) {
  300. messageHandler.notify(
  301. displayName,'notify.somebody', 'connected', 'notify.connected'
  302. );
  303. if (!config.startAudioMuted ||
  304. config.startAudioMuted > APP.conference.membersCount)
  305. UIUtil.playSoundNotification('userJoined');
  306. // Configure avatar
  307. UI.setUserAvatar(jid, id);
  308. // Add Peer's container
  309. VideoLayout.ensurePeerContainerExists(jid);
  310. };
  311. UI.removeUser = function (jid) {
  312. console.log('left.muc', jid);
  313. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  314. '>.displayname').html();
  315. messageHandler.notify(displayName,'notify.somebody',
  316. 'disconnected',
  317. 'notify.disconnected');
  318. if (!config.startAudioMuted ||
  319. config.startAudioMuted > APP.conference.membersCount) {
  320. UIUtil.playSoundNotification('userLeft');
  321. }
  322. ContactList.removeContact(jid);
  323. VideoLayout.participantLeft(jid);
  324. };
  325. function onMucPresenceStatus(jid, info) {
  326. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  327. }
  328. function onPeerVideoTypeChanged(resourceJid, newVideoType) {
  329. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  330. }
  331. UI.updateLocalRole = function (isModerator) {
  332. VideoLayout.showModeratorIndicator();
  333. Toolbar.showSipCallButton(isModerator);
  334. Toolbar.showRecordingButton(isModerator);
  335. SettingsMenu.onRoleChanged();
  336. if (isModerator) {
  337. Authentication.closeAuthenticationWindow();
  338. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  339. Toolbar.checkAutoRecord();
  340. }
  341. };
  342. UI.updateUserRole = function (user) {
  343. VideoLayout.showModeratorIndicator();
  344. if (!user.isModerator()) {
  345. return;
  346. }
  347. var displayName = user.getDisplayName();
  348. if (displayName) {
  349. messageHandler.notify(
  350. displayName, 'notify.somebody',
  351. 'connected', 'notify.grantedTo', {
  352. to: displayName
  353. }
  354. );
  355. } else {
  356. messageHandler.notify(
  357. '', 'notify.somebody',
  358. 'connected', 'notify.grantedToUnknown', {}
  359. );
  360. }
  361. };
  362. UI.notifyAuthRequired = function (intervalCallback) {
  363. Authentication.openAuthenticationDialog(
  364. APP.conference.roomName, intervalCallback, function () {
  365. Toolbar.authenticateClicked();
  366. }
  367. );
  368. };
  369. UI.toggleSmileys = function () {
  370. Chat.toggleSmileys();
  371. };
  372. UI.getSettings = function () {
  373. return Settings.getSettings();
  374. };
  375. UI.toggleFilmStrip = function () {
  376. return BottomToolbar.toggleFilmStrip();
  377. };
  378. UI.toggleChat = function () {
  379. return BottomToolbar.toggleChat();
  380. };
  381. UI.toggleContactList = function () {
  382. return BottomToolbar.toggleContactList();
  383. };
  384. UI.inputDisplayNameHandler = function (value) {
  385. VideoLayout.inputDisplayNameHandler(value);
  386. };
  387. /**
  388. * Return the type of the remote video.
  389. * @param jid the jid for the remote video
  390. * @returns the video type video or screen.
  391. */
  392. UI.getRemoteVideoType = function (jid) {
  393. return VideoLayout.getRemoteVideoType(jid);
  394. };
  395. UI.connectionIndicatorShowMore = function(jid) {
  396. return VideoLayout.showMore(jid);
  397. };
  398. UI.showLoginPopup = function(callback) {
  399. console.log('password is required');
  400. var message = '<h2 data-i18n="dialog.passwordRequired">';
  401. message += APP.translation.translateString(
  402. "dialog.passwordRequired");
  403. message += '</h2>' +
  404. '<input name="username" type="text" ' +
  405. 'placeholder="user@domain.net" autofocus>' +
  406. '<input name="password" ' +
  407. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  408. ' placeholder="user password">';
  409. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  410. true,
  411. "dialog.Ok",
  412. function (e, v, m, f) {
  413. if (v) {
  414. if (f.username && f.password) {
  415. callback(f.username, f.password);
  416. }
  417. }
  418. },
  419. null, null, ':input:first'
  420. );
  421. };
  422. UI.closeAuthenticationDialog = function () {
  423. Authentication.closeAuthenticationDialog();
  424. Authentication.stopInterval();
  425. };
  426. UI.askForNickname = function () {
  427. return window.prompt('Your nickname (optional)');
  428. };
  429. /**
  430. * Sets muted audio state for the local participant.
  431. */
  432. UI.setAudioMuted = function (mute) {
  433. VideoLayout.showLocalAudioIndicator(mute);
  434. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  435. };
  436. UI.setVideoMuted = function (muted) {
  437. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  438. };
  439. UI.addListener = function (type, listener) {
  440. eventEmitter.on(type, listener);
  441. };
  442. UI.clickOnVideo = function (videoNumber) {
  443. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  444. if (remoteVideos.length > videoNumber) {
  445. remoteVideos[videoNumber].click();
  446. }
  447. };
  448. //Used by torture
  449. UI.showToolbar = function () {
  450. return ToolbarToggler.showToolbar();
  451. };
  452. //Used by torture
  453. UI.dockToolbar = function (isDock) {
  454. return ToolbarToggler.dockToolbar(isDock);
  455. };
  456. UI.setUserAvatar = function (id, email) {
  457. // update avatar
  458. Avatar.setUserAvatar(id, email);
  459. var thumbUrl = Avatar.getThumbUrl(id);
  460. var contactListUrl = Avatar.getContactListUrl(id);
  461. VideoLayout.changeUserAvatar(id, thumbUrl);
  462. ContactList.changeUserAvatar(id, contactListUrl);
  463. if (APP.conference.isLocalId(id)) {
  464. SettingsMenu.changeAvatar(thumbUrl);
  465. }
  466. };
  467. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  468. var title = APP.translation.generateTranslationHTML(
  469. "dialog.error");
  470. var message;
  471. if (stropheErrorMsg) {
  472. message = APP.translation.generateTranslationHTML(
  473. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  474. } else {
  475. message = APP.translation.generateTranslationHTML(
  476. "dialog.connectError");
  477. }
  478. messageHandler.openDialog(
  479. title, message, true, {}, function (e, v, m, f) { return false; }
  480. );
  481. };
  482. UI.notifyFirefoxExtensionRequired = function (url) {
  483. messageHandler.openMessageDialog(
  484. "dialog.extensionRequired",
  485. null,
  486. null,
  487. APP.translation.generateTranslationHTML(
  488. "dialog.firefoxExtensionPrompt", {url: url}
  489. )
  490. );
  491. };
  492. UI.notifyInitiallyMuted = function () {
  493. messageHandler.notify(
  494. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  495. );
  496. };
  497. UI.markDominantSpiker = function (id) {
  498. VideoLayout.onDominantSpeakerChanged(id);
  499. };
  500. UI.handleLastNEndpoints = function (ids) {
  501. VideoLayout.onLastNEndpointsChanged(ids, []);
  502. };
  503. UI.setAudioLevel = function (id, lvl) {
  504. AudioLevels.updateAudioLevel(
  505. id, lvl, VideoLayout.getLargeVideoResource()
  506. );
  507. };
  508. UI.updateDesktopSharingButtons = function () {
  509. Toolbar.changeDesktopSharingButtonState();
  510. };
  511. UI.hideStats = function () {
  512. VideoLayout.hideStats();
  513. };
  514. UI.updateLocalStats = function (percent, stats) {
  515. VideoLayout.updateLocalConnectionStats(percent, stats);
  516. };
  517. UI.updateRemoteStats = function (jid, percent, stats) {
  518. VideoLayout.updateConnectionStats(jid, percent, stats);
  519. };
  520. UI.showAuthenticateButton = function (show) {
  521. Toolbar.showAuthenticateButton(show);
  522. };
  523. UI.markVideoInterrupted = function (interrupted) {
  524. if (interrupted) {
  525. VideoLayout.onVideoInterrupted();
  526. } else {
  527. VideoLayout.onVideoRestored();
  528. }
  529. };
  530. UI.addMessage = function (from, displayName, message, stamp) {
  531. Chat.updateChatConversation(from, displayName, message, stamp);
  532. };
  533. module.exports = UI;