Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UI.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. /**
  270. * The dialpad button is shown iff there is at least one member that supports
  271. * DTMF (e.g. jigasi).
  272. */
  273. function onDtmfSupportChanged(dtmfSupport) {
  274. //TODO: enable when the UI is ready
  275. //Toolbar.showDialPadButton(dtmfSupport);
  276. }
  277. UI.addUser = function (jid, id, displayName) {
  278. messageHandler.notify(
  279. displayName,'notify.somebody', 'connected', 'notify.connected'
  280. );
  281. if (!config.startAudioMuted ||
  282. config.startAudioMuted > APP.conference.membersCount)
  283. UIUtil.playSoundNotification('userJoined');
  284. // Configure avatar
  285. UI.setUserAvatar(jid, id);
  286. // Add Peer's container
  287. VideoLayout.ensurePeerContainerExists(jid);
  288. };
  289. UI.removeUser = function (jid) {
  290. console.log('left.muc', jid);
  291. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  292. '>.displayname').html();
  293. messageHandler.notify(displayName,'notify.somebody',
  294. 'disconnected',
  295. 'notify.disconnected');
  296. if (!config.startAudioMuted ||
  297. config.startAudioMuted > APP.conference.membersCount) {
  298. UIUtil.playSoundNotification('userLeft');
  299. }
  300. ContactList.removeContact(jid);
  301. VideoLayout.participantLeft(jid);
  302. };
  303. function onMucPresenceStatus(jid, info) {
  304. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  305. }
  306. function onPeerVideoTypeChanged(resourceJid, newVideoType) {
  307. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  308. }
  309. UI.updateLocalRole = function (isModerator) {
  310. VideoLayout.showModeratorIndicator();
  311. Toolbar.showSipCallButton(isModerator);
  312. Toolbar.showRecordingButton(isModerator);
  313. SettingsMenu.onRoleChanged();
  314. if (isModerator) {
  315. Authentication.closeAuthenticationWindow();
  316. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  317. Toolbar.checkAutoRecord();
  318. }
  319. };
  320. UI.updateUserRole = function (user) {
  321. VideoLayout.showModeratorIndicator();
  322. if (!user.isModerator()) {
  323. return;
  324. }
  325. var displayName = user.getDisplayName();
  326. if (displayName) {
  327. messageHandler.notify(
  328. displayName, 'notify.somebody',
  329. 'connected', 'notify.grantedTo', {
  330. to: displayName
  331. }
  332. );
  333. } else {
  334. messageHandler.notify(
  335. '', 'notify.somebody',
  336. 'connected', 'notify.grantedToUnknown', {}
  337. );
  338. }
  339. };
  340. UI.notifyAuthRequired = function (intervalCallback) {
  341. Authentication.openAuthenticationDialog(
  342. APP.conference.roomName, intervalCallback, function () {
  343. Toolbar.authenticateClicked();
  344. }
  345. );
  346. };
  347. UI.toggleSmileys = function () {
  348. Chat.toggleSmileys();
  349. };
  350. UI.getSettings = function () {
  351. return Settings.getSettings();
  352. };
  353. UI.toggleFilmStrip = function () {
  354. return BottomToolbar.toggleFilmStrip();
  355. };
  356. UI.toggleChat = function () {
  357. return BottomToolbar.toggleChat();
  358. };
  359. UI.toggleContactList = function () {
  360. return BottomToolbar.toggleContactList();
  361. };
  362. UI.inputDisplayNameHandler = function (value) {
  363. VideoLayout.inputDisplayNameHandler(value);
  364. };
  365. /**
  366. * Return the type of the remote video.
  367. * @param jid the jid for the remote video
  368. * @returns the video type video or screen.
  369. */
  370. UI.getRemoteVideoType = function (jid) {
  371. return VideoLayout.getRemoteVideoType(jid);
  372. };
  373. UI.connectionIndicatorShowMore = function(jid) {
  374. return VideoLayout.showMore(jid);
  375. };
  376. UI.showLoginPopup = function(callback) {
  377. console.log('password is required');
  378. var message = '<h2 data-i18n="dialog.passwordRequired">';
  379. message += APP.translation.translateString(
  380. "dialog.passwordRequired");
  381. message += '</h2>' +
  382. '<input name="username" type="text" ' +
  383. 'placeholder="user@domain.net" autofocus>' +
  384. '<input name="password" ' +
  385. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  386. ' placeholder="user password">';
  387. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  388. true,
  389. "dialog.Ok",
  390. function (e, v, m, f) {
  391. if (v) {
  392. if (f.username && f.password) {
  393. callback(f.username, f.password);
  394. }
  395. }
  396. },
  397. null, null, ':input:first'
  398. );
  399. };
  400. UI.closeAuthenticationDialog = function () {
  401. Authentication.closeAuthenticationDialog();
  402. Authentication.stopInterval();
  403. };
  404. UI.askForNickname = function () {
  405. return window.prompt('Your nickname (optional)');
  406. };
  407. /**
  408. * Sets muted audio state for the local participant.
  409. */
  410. UI.setAudioMuted = function (mute) {
  411. VideoLayout.showLocalAudioIndicator(mute);
  412. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  413. };
  414. UI.setVideoMuted = function (muted) {
  415. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  416. };
  417. UI.addListener = function (type, listener) {
  418. eventEmitter.on(type, listener);
  419. };
  420. UI.clickOnVideo = function (videoNumber) {
  421. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  422. if (remoteVideos.length > videoNumber) {
  423. remoteVideos[videoNumber].click();
  424. }
  425. };
  426. //Used by torture
  427. UI.showToolbar = function () {
  428. return ToolbarToggler.showToolbar();
  429. };
  430. //Used by torture
  431. UI.dockToolbar = function (isDock) {
  432. return ToolbarToggler.dockToolbar(isDock);
  433. };
  434. UI.setUserAvatar = function (id, email) {
  435. // update avatar
  436. Avatar.setUserAvatar(id, email);
  437. var thumbUrl = Avatar.getThumbUrl(id);
  438. var contactListUrl = Avatar.getContactListUrl(id);
  439. VideoLayout.changeUserAvatar(id, thumbUrl);
  440. ContactList.changeUserAvatar(id, contactListUrl);
  441. if (APP.conference.isLocalId(id)) {
  442. SettingsMenu.changeAvatar(thumbUrl);
  443. }
  444. };
  445. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  446. var title = APP.translation.generateTranslationHTML(
  447. "dialog.error");
  448. var message;
  449. if (stropheErrorMsg) {
  450. message = APP.translation.generateTranslationHTML(
  451. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  452. } else {
  453. message = APP.translation.generateTranslationHTML(
  454. "dialog.connectError");
  455. }
  456. messageHandler.openDialog(
  457. title, message, true, {}, function (e, v, m, f) { return false; }
  458. );
  459. };
  460. UI.notifyFirefoxExtensionRequired = function (url) {
  461. messageHandler.openMessageDialog(
  462. "dialog.extensionRequired",
  463. null,
  464. null,
  465. APP.translation.generateTranslationHTML(
  466. "dialog.firefoxExtensionPrompt", {url: url}
  467. )
  468. );
  469. };
  470. UI.notifyInitiallyMuted = function () {
  471. messageHandler.notify(
  472. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  473. );
  474. };
  475. UI.markDominantSpiker = function (id) {
  476. VideoLayout.onDominantSpeakerChanged(id);
  477. };
  478. UI.handleLastNEndpoints = function (ids) {
  479. VideoLayout.onLastNEndpointsChanged(ids, []);
  480. };
  481. UI.setAudioLevel = function (id, lvl) {
  482. AudioLevels.updateAudioLevel(
  483. id, lvl, VideoLayout.getLargeVideoResource()
  484. );
  485. };
  486. UI.updateDesktopSharingButtons = function () {
  487. Toolbar.changeDesktopSharingButtonState();
  488. };
  489. UI.hideStats = function () {
  490. VideoLayout.hideStats();
  491. };
  492. UI.updateLocalStats = function (percent, stats) {
  493. VideoLayout.updateLocalConnectionStats(percent, stats);
  494. };
  495. UI.updateRemoteStats = function (jid, percent, stats) {
  496. VideoLayout.updateConnectionStats(jid, percent, stats);
  497. };
  498. UI.showAuthenticateButton = function (show) {
  499. Toolbar.showAuthenticateButton(show);
  500. };
  501. UI.markVideoInterrupted = function (interrupted) {
  502. if (interrupted) {
  503. VideoLayout.onVideoInterrupted();
  504. } else {
  505. VideoLayout.onVideoRestored();
  506. }
  507. };
  508. UI.markRoomLocked = function (locked) {
  509. if (locked) {
  510. Toolbar.lockLockButton();
  511. } else {
  512. Toolbar.unlockLockButton();
  513. }
  514. };
  515. UI.addMessage = function (from, displayName, message, stamp) {
  516. Chat.updateChatConversation(from, displayName, message, stamp);
  517. };
  518. module.exports = UI;