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 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. UI.addListener(UIEvents.PREZI_CLICKED, function () {
  150. Prezi.openPreziDialog();
  151. });
  152. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  153. Etherpad.toggleEtherpad(0);
  154. });
  155. }
  156. function bindEvents() {
  157. function onResize() {
  158. Chat.resizeChat();
  159. VideoLayout.resizeLargeVideoContainer();
  160. }
  161. // Resize and reposition videos in full screen mode.
  162. $(document).on(
  163. 'webkitfullscreenchange mozfullscreenchange fullscreenchange', onResize
  164. );
  165. $(window).resize(onResize);
  166. }
  167. UI.start = function () {
  168. document.title = interfaceConfig.APP_NAME;
  169. var setupWelcomePage = null;
  170. if(config.enableWelcomePage && window.location.pathname == "/" &&
  171. (!window.localStorage.welcomePageDisabled ||
  172. window.localStorage.welcomePageDisabled == "false")) {
  173. $("#videoconference_page").hide();
  174. if (!setupWelcomePage)
  175. setupWelcomePage = require("./welcome_page/WelcomePage");
  176. setupWelcomePage();
  177. return;
  178. }
  179. $("#welcome_page").hide();
  180. // Set the defaults for prompt dialogs.
  181. $.prompt.setDefaults({persistent: false});
  182. registerListeners();
  183. VideoLayout.init(eventEmitter);
  184. bindEvents();
  185. setupPrezi();
  186. if (!interfaceConfig.filmStripOnly) {
  187. $("#videospace").mousemove(function () {
  188. return ToolbarToggler.showToolbar();
  189. });
  190. setupToolbars();
  191. setupChat();
  192. // Display notice message at the top of the toolbar
  193. if (config.noticeMessage) {
  194. $('#noticeText').text(config.noticeMessage);
  195. $('#notice').css({display: 'block'});
  196. }
  197. $("#downloadlog").click(function (event) {
  198. // dump(event.target);
  199. // FIXME integrate logs
  200. });
  201. Feedback.init();
  202. } else {
  203. $("#header").css("display", "none");
  204. $("#bottomToolbar").css("display", "none");
  205. $("#downloadlog").css("display", "none");
  206. $("#remoteVideos").css("padding", "0px 0px 18px 0px");
  207. $("#remoteVideos").css("right", "0px");
  208. messageHandler.disableNotifications();
  209. $('body').popover("disable");
  210. JitsiPopover.enabled = false;
  211. }
  212. document.title = interfaceConfig.APP_NAME;
  213. if(config.requireDisplayName) {
  214. if (APP.settings.getDisplayName()) {
  215. promptDisplayName();
  216. }
  217. }
  218. if (!interfaceConfig.filmStripOnly) {
  219. toastr.options = {
  220. "closeButton": true,
  221. "debug": false,
  222. "positionClass": "notification-bottom-right",
  223. "onclick": null,
  224. "showDuration": "300",
  225. "hideDuration": "1000",
  226. "timeOut": "2000",
  227. "extendedTimeOut": "1000",
  228. "showEasing": "swing",
  229. "hideEasing": "linear",
  230. "showMethod": "fadeIn",
  231. "hideMethod": "fadeOut",
  232. "reposition": function () {
  233. if (PanelToggler.isVisible()) {
  234. $("#toast-container").addClass("notification-bottom-right-center");
  235. } else {
  236. $("#toast-container").removeClass("notification-bottom-right-center");
  237. }
  238. },
  239. "newestOnTop": false
  240. };
  241. SettingsMenu.init();
  242. }
  243. };
  244. UI.addLocalStream = function (track) {
  245. switch (track.getType()) {
  246. case 'audio':
  247. VideoLayout.changeLocalAudio(track);
  248. break;
  249. case 'video':
  250. VideoLayout.changeLocalVideo(track);
  251. break;
  252. default:
  253. console.error("Unknown stream type: " + track.getType());
  254. break;
  255. }
  256. };
  257. UI.addRemoteStream = function (stream) {
  258. VideoLayout.onRemoteStreamAdded(stream);
  259. };
  260. function chatAddError(errorMessage, originalText) {
  261. return Chat.chatAddError(errorMessage, originalText);
  262. }
  263. function chatSetSubject(text) {
  264. return Chat.chatSetSubject(text);
  265. }
  266. function initEtherpad(name) {
  267. Etherpad.init(name);
  268. }
  269. UI.addUser = function (jid, id, displayName) {
  270. messageHandler.notify(
  271. displayName,'notify.somebody', 'connected', 'notify.connected'
  272. );
  273. if (!config.startAudioMuted ||
  274. config.startAudioMuted > APP.conference.membersCount)
  275. UIUtil.playSoundNotification('userJoined');
  276. // Configure avatar
  277. UI.setUserAvatar(jid, id);
  278. // Add Peer's container
  279. VideoLayout.ensurePeerContainerExists(jid);
  280. };
  281. UI.removeUser = function (jid) {
  282. console.log('left.muc', jid);
  283. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  284. '>.displayname').html();
  285. messageHandler.notify(displayName,'notify.somebody',
  286. 'disconnected',
  287. 'notify.disconnected');
  288. if (!config.startAudioMuted ||
  289. config.startAudioMuted > APP.conference.membersCount) {
  290. UIUtil.playSoundNotification('userLeft');
  291. }
  292. ContactList.removeContact(jid);
  293. VideoLayout.participantLeft(jid);
  294. };
  295. function onMucPresenceStatus(jid, info) {
  296. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  297. }
  298. function onPeerVideoTypeChanged(resourceJid, newVideoType) {
  299. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  300. }
  301. UI.updateLocalRole = function (isModerator) {
  302. VideoLayout.showModeratorIndicator();
  303. Toolbar.showSipCallButton(isModerator);
  304. Toolbar.showRecordingButton(isModerator);
  305. SettingsMenu.onRoleChanged();
  306. if (isModerator) {
  307. Authentication.closeAuthenticationWindow();
  308. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  309. Toolbar.checkAutoRecord();
  310. }
  311. };
  312. UI.updateUserRole = function (user) {
  313. VideoLayout.showModeratorIndicator();
  314. if (!user.isModerator()) {
  315. return;
  316. }
  317. var displayName = user.getDisplayName();
  318. if (displayName) {
  319. messageHandler.notify(
  320. displayName, 'notify.somebody',
  321. 'connected', 'notify.grantedTo', {
  322. to: displayName
  323. }
  324. );
  325. } else {
  326. messageHandler.notify(
  327. '', 'notify.somebody',
  328. 'connected', 'notify.grantedToUnknown', {}
  329. );
  330. }
  331. };
  332. UI.notifyAuthRequired = function (intervalCallback) {
  333. Authentication.openAuthenticationDialog(
  334. APP.conference.roomName, intervalCallback, function () {
  335. Toolbar.authenticateClicked();
  336. }
  337. );
  338. };
  339. UI.toggleSmileys = function () {
  340. Chat.toggleSmileys();
  341. };
  342. UI.getSettings = function () {
  343. return Settings.getSettings();
  344. };
  345. UI.toggleFilmStrip = function () {
  346. return BottomToolbar.toggleFilmStrip();
  347. };
  348. UI.toggleChat = function () {
  349. return BottomToolbar.toggleChat();
  350. };
  351. UI.toggleContactList = function () {
  352. return BottomToolbar.toggleContactList();
  353. };
  354. UI.inputDisplayNameHandler = function (value) {
  355. VideoLayout.inputDisplayNameHandler(value);
  356. };
  357. /**
  358. * Return the type of the remote video.
  359. * @param jid the jid for the remote video
  360. * @returns the video type video or screen.
  361. */
  362. UI.getRemoteVideoType = function (jid) {
  363. return VideoLayout.getRemoteVideoType(jid);
  364. };
  365. UI.connectionIndicatorShowMore = function(jid) {
  366. return VideoLayout.showMore(jid);
  367. };
  368. UI.showLoginPopup = function(callback) {
  369. console.log('password is required');
  370. var message = '<h2 data-i18n="dialog.passwordRequired">';
  371. message += APP.translation.translateString(
  372. "dialog.passwordRequired");
  373. message += '</h2>' +
  374. '<input name="username" type="text" ' +
  375. 'placeholder="user@domain.net" autofocus>' +
  376. '<input name="password" ' +
  377. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  378. ' placeholder="user password">';
  379. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  380. true,
  381. "dialog.Ok",
  382. function (e, v, m, f) {
  383. if (v) {
  384. if (f.username && f.password) {
  385. callback(f.username, f.password);
  386. }
  387. }
  388. },
  389. null, null, ':input:first'
  390. );
  391. };
  392. UI.closeAuthenticationDialog = function () {
  393. Authentication.closeAuthenticationDialog();
  394. Authentication.stopInterval();
  395. };
  396. UI.askForNickname = function () {
  397. return window.prompt('Your nickname (optional)');
  398. };
  399. /**
  400. * Sets muted audio state for the local participant.
  401. */
  402. UI.setAudioMuted = function (mute) {
  403. VideoLayout.showLocalAudioIndicator(mute);
  404. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  405. };
  406. UI.setVideoMuted = function (muted) {
  407. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  408. };
  409. UI.addListener = function (type, listener) {
  410. eventEmitter.on(type, listener);
  411. };
  412. UI.clickOnVideo = function (videoNumber) {
  413. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  414. if (remoteVideos.length > videoNumber) {
  415. remoteVideos[videoNumber].click();
  416. }
  417. };
  418. //Used by torture
  419. UI.showToolbar = function () {
  420. return ToolbarToggler.showToolbar();
  421. };
  422. //Used by torture
  423. UI.dockToolbar = function (isDock) {
  424. return ToolbarToggler.dockToolbar(isDock);
  425. };
  426. UI.setUserAvatar = function (id, email) {
  427. // update avatar
  428. Avatar.setUserAvatar(id, email);
  429. var thumbUrl = Avatar.getThumbUrl(id);
  430. var contactListUrl = Avatar.getContactListUrl(id);
  431. VideoLayout.changeUserAvatar(id, thumbUrl);
  432. ContactList.changeUserAvatar(id, contactListUrl);
  433. if (APP.conference.isLocalId(id)) {
  434. SettingsMenu.changeAvatar(thumbUrl);
  435. }
  436. };
  437. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  438. var title = APP.translation.generateTranslationHTML(
  439. "dialog.error");
  440. var message;
  441. if (stropheErrorMsg) {
  442. message = APP.translation.generateTranslationHTML(
  443. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  444. } else {
  445. message = APP.translation.generateTranslationHTML(
  446. "dialog.connectError");
  447. }
  448. messageHandler.openDialog(
  449. title, message, true, {}, function (e, v, m, f) { return false; }
  450. );
  451. };
  452. UI.notifyFirefoxExtensionRequired = function (url) {
  453. messageHandler.openMessageDialog(
  454. "dialog.extensionRequired",
  455. null,
  456. null,
  457. APP.translation.generateTranslationHTML(
  458. "dialog.firefoxExtensionPrompt", {url: url}
  459. )
  460. );
  461. };
  462. UI.notifyInitiallyMuted = function () {
  463. messageHandler.notify(
  464. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  465. );
  466. };
  467. UI.markDominantSpiker = function (id) {
  468. VideoLayout.onDominantSpeakerChanged(id);
  469. };
  470. UI.handleLastNEndpoints = function (ids) {
  471. VideoLayout.onLastNEndpointsChanged(ids, []);
  472. };
  473. UI.setAudioLevel = function (id, lvl) {
  474. AudioLevels.updateAudioLevel(
  475. id, lvl, VideoLayout.getLargeVideoResource()
  476. );
  477. };
  478. UI.updateDesktopSharingButtons = function () {
  479. Toolbar.changeDesktopSharingButtonState();
  480. };
  481. UI.hideStats = function () {
  482. VideoLayout.hideStats();
  483. };
  484. UI.updateLocalStats = function (percent, stats) {
  485. VideoLayout.updateLocalConnectionStats(percent, stats);
  486. };
  487. UI.updateRemoteStats = function (jid, percent, stats) {
  488. VideoLayout.updateConnectionStats(jid, percent, stats);
  489. };
  490. UI.showAuthenticateButton = function (show) {
  491. Toolbar.showAuthenticateButton(show);
  492. };
  493. UI.markVideoInterrupted = function (interrupted) {
  494. if (interrupted) {
  495. VideoLayout.onVideoInterrupted();
  496. } else {
  497. VideoLayout.onVideoRestored();
  498. }
  499. };
  500. UI.markRoomLocked = function (locked) {
  501. if (locked) {
  502. Toolbar.lockLockButton();
  503. } else {
  504. Toolbar.unlockLockButton();
  505. }
  506. };
  507. UI.addMessage = function (from, displayName, message, stamp) {
  508. Chat.updateChatConversation(from, displayName, message, stamp);
  509. };
  510. UI.updateDTMFSupport = function (isDTMFSupported) {
  511. //TODO: enable when the UI is ready
  512. //Toolbar.showDialPadButton(dtmfSupport);
  513. };
  514. module.exports = UI;