Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UI.js 20KB

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