Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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