Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. }
  201. else
  202. {
  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. // $("[data-toggle=popover]").popover("disable");
  211. JitsiPopover.enabled = false;
  212. }
  213. document.title = interfaceConfig.APP_NAME;
  214. if(config.requireDisplayName) {
  215. if (APP.settings.getDisplayName()) {
  216. promptDisplayName();
  217. }
  218. }
  219. if (!interfaceConfig.filmStripOnly) {
  220. toastr.options = {
  221. "closeButton": true,
  222. "debug": false,
  223. "positionClass": "notification-bottom-right",
  224. "onclick": null,
  225. "showDuration": "300",
  226. "hideDuration": "1000",
  227. "timeOut": "2000",
  228. "extendedTimeOut": "1000",
  229. "showEasing": "swing",
  230. "hideEasing": "linear",
  231. "showMethod": "fadeIn",
  232. "hideMethod": "fadeOut",
  233. "reposition": function () {
  234. if (PanelToggler.isVisible()) {
  235. $("#toast-container").addClass("notification-bottom-right-center");
  236. } else {
  237. $("#toast-container").removeClass("notification-bottom-right-center");
  238. }
  239. },
  240. "newestOnTop": false
  241. };
  242. SettingsMenu.init();
  243. }
  244. };
  245. UI.addLocalStream = function (stream, isMuted) {
  246. switch (stream.type) {
  247. case 'audio':
  248. VideoLayout.changeLocalAudio(stream, isMuted);
  249. break;
  250. case 'video':
  251. VideoLayout.changeLocalVideo(stream, isMuted);
  252. break;
  253. default:
  254. console.error("Unknown stream type: " + stream.type);
  255. break;
  256. }
  257. };
  258. UI.addRemoteStream = function (stream) {
  259. VideoLayout.onRemoteStreamAdded(stream);
  260. };
  261. function chatAddError(errorMessage, originalText) {
  262. return Chat.chatAddError(errorMessage, originalText);
  263. }
  264. function chatSetSubject(text) {
  265. return Chat.chatSetSubject(text);
  266. }
  267. function updateChatConversation(from, displayName, message, stamp) {
  268. return Chat.updateChatConversation(from, displayName, message, stamp);
  269. }
  270. function initEtherpad(name) {
  271. Etherpad.init(name);
  272. }
  273. function onLocalRoleChanged(jid, info, pres, isModerator) {
  274. console.info("My role changed, new role: " + info.role);
  275. onModeratorStatusChanged(isModerator);
  276. VideoLayout.showModeratorIndicator();
  277. SettingsMenu.onRoleChanged();
  278. if (isModerator) {
  279. Authentication.closeAuthenticationWindow();
  280. messageHandler.notify(null, "notify.me",
  281. 'connected', "notify.moderator");
  282. Toolbar.checkAutoRecord();
  283. }
  284. }
  285. function onModeratorStatusChanged(isModerator) {
  286. Toolbar.showSipCallButton(isModerator);
  287. Toolbar.showRecordingButton(
  288. isModerator); //&&
  289. // FIXME:
  290. // Recording visible if
  291. // there are at least 2(+ 1 focus) participants
  292. //Object.keys(connection.emuc.members).length >= 3);
  293. }
  294. UI.notifyPasswordRequired = function (callback) {
  295. // password is required
  296. Toolbar.lockLockButton();
  297. var message = '<h2 data-i18n="dialog.passwordRequired">';
  298. message += APP.translation.translateString(
  299. "dialog.passwordRequired");
  300. message += '</h2>' +
  301. '<input name="lockKey" type="text" data-i18n=' +
  302. '"[placeholder]dialog.password" placeholder="' +
  303. APP.translation.translateString("dialog.password") +
  304. '" autofocus>';
  305. messageHandler.openTwoButtonDialog(null, null, null, message,
  306. true,
  307. "dialog.Ok",
  308. function (e, v, m, f) {},
  309. null,
  310. function (e, v, m, f) {
  311. if (v) {
  312. var lockKey = f.lockKey;
  313. if (lockKey) {
  314. Toolbar.setSharedKey(lockKey);
  315. callback(lockKey);
  316. }
  317. }
  318. },
  319. ':input:first'
  320. );
  321. };
  322. /**
  323. * The dialpad button is shown iff there is at least one member that supports
  324. * DTMF (e.g. jigasi).
  325. */
  326. function onDtmfSupportChanged(dtmfSupport) {
  327. //TODO: enable when the UI is ready
  328. //Toolbar.showDialPadButton(dtmfSupport);
  329. }
  330. UI.addUser = function (jid, id, displayName) {
  331. messageHandler.notify(displayName,'notify.somebody',
  332. 'connected',
  333. 'notify.connected');
  334. if (!config.startAudioMuted ||
  335. config.startAudioMuted > APP.members.size())
  336. UIUtil.playSoundNotification('userJoined');
  337. // Configure avatar
  338. Avatar.setUserAvatar(jid, id);
  339. // Add Peer's container
  340. VideoLayout.ensurePeerContainerExists(jid);
  341. };
  342. UI.removeUser = function (jid) {
  343. console.log('left.muc', jid);
  344. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  345. '>.displayname').html();
  346. messageHandler.notify(displayName,'notify.somebody',
  347. 'disconnected',
  348. 'notify.disconnected');
  349. if (!config.startAudioMuted ||
  350. config.startAudioMuted > APP.members.size()) {
  351. UIUtil.playSoundNotification('userLeft');
  352. }
  353. ContactList.removeContact(jid);
  354. VideoLayout.participantLeft(jid);
  355. };
  356. function onMucPresenceStatus(jid, info) {
  357. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  358. }
  359. function onPeerVideoTypeChanged(resourceJid, newVideoType) {
  360. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  361. }
  362. function onMucRoleChanged(role, displayName) {
  363. VideoLayout.showModeratorIndicator();
  364. if (role === 'moderator') {
  365. var messageKey, messageOptions = {};
  366. if (!displayName) {
  367. messageKey = "notify.grantedToUnknown";
  368. }
  369. else {
  370. messageKey = "notify.grantedTo";
  371. messageOptions = {to: displayName};
  372. }
  373. messageHandler.notify(
  374. displayName,'notify.somebody',
  375. 'connected', messageKey,
  376. messageOptions);
  377. }
  378. }
  379. UI.notifyAuthRequired = function (intervalCallback) {
  380. Authentication.openAuthenticationDialog(
  381. roomName, intervalCallback, function () {
  382. Toolbar.authenticateClicked();
  383. }
  384. );
  385. };
  386. UI.toggleSmileys = function () {
  387. Chat.toggleSmileys();
  388. };
  389. UI.getSettings = function () {
  390. return Settings.getSettings();
  391. };
  392. UI.toggleFilmStrip = function () {
  393. return BottomToolbar.toggleFilmStrip();
  394. };
  395. UI.toggleChat = function () {
  396. return BottomToolbar.toggleChat();
  397. };
  398. UI.toggleContactList = function () {
  399. return BottomToolbar.toggleContactList();
  400. };
  401. UI.inputDisplayNameHandler = function (value) {
  402. VideoLayout.inputDisplayNameHandler(value);
  403. };
  404. /**
  405. * Return the type of the remote video.
  406. * @param jid the jid for the remote video
  407. * @returns the video type video or screen.
  408. */
  409. UI.getRemoteVideoType = function (jid) {
  410. return VideoLayout.getRemoteVideoType(jid);
  411. };
  412. UI.getRoomNode = function () {
  413. if (roomNode)
  414. return roomNode;
  415. var path = window.location.pathname;
  416. // determinde the room node from the url
  417. // TODO: just the roomnode or the whole bare jid?
  418. if (config.getroomnode && typeof config.getroomnode === 'function') {
  419. // custom function might be responsible for doing the pushstate
  420. roomNode = config.getroomnode(path);
  421. } else {
  422. /* fall back to default strategy
  423. * this is making assumptions about how the URL->room mapping happens.
  424. * It currently assumes deployment at root, with a rewrite like the
  425. * following one (for nginx):
  426. location ~ ^/([a-zA-Z0-9]+)$ {
  427. rewrite ^/(.*)$ / break;
  428. }
  429. */
  430. if (path.length > 1) {
  431. roomNode = path.substr(1).toLowerCase();
  432. } else {
  433. var word = RoomnameGenerator.generateRoomWithoutSeparator();
  434. roomNode = word.toLowerCase();
  435. window.history.pushState('VideoChat',
  436. 'Room: ' + word, window.location.pathname + word);
  437. }
  438. }
  439. return roomNode;
  440. };
  441. UI.generateRoomName = function () {
  442. if (roomName)
  443. return roomName;
  444. var roomNode = UI.getRoomNode();
  445. roomName = roomNode + '@' + config.hosts.muc;
  446. return roomName;
  447. };
  448. UI.connectionIndicatorShowMore = function(jid) {
  449. return VideoLayout.showMore(jid);
  450. };
  451. UI.showLoginPopup = function(callback) {
  452. console.log('password is required');
  453. var message = '<h2 data-i18n="dialog.passwordRequired">';
  454. message += APP.translation.translateString(
  455. "dialog.passwordRequired");
  456. message += '</h2>' +
  457. '<input name="username" type="text" ' +
  458. 'placeholder="user@domain.net" autofocus>' +
  459. '<input name="password" ' +
  460. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  461. ' placeholder="user password">';
  462. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  463. true,
  464. "dialog.Ok",
  465. function (e, v, m, f) {
  466. if (v) {
  467. if (f.username && f.password) {
  468. callback(f.username, f.password);
  469. }
  470. }
  471. },
  472. null, null, ':input:first'
  473. );
  474. };
  475. UI.closeAuthenticationDialog = function () {
  476. Authentication.closeAuthenticationDialog();
  477. Authentication.stopInterval();
  478. };
  479. UI.askForNickname = function () {
  480. return window.prompt('Your nickname (optional)');
  481. };
  482. UI.getRoomName = function () {
  483. return roomName;
  484. };
  485. /**
  486. * Sets muted audio state for the local participant.
  487. */
  488. UI.setAudioMuted = function (mute) {
  489. VideoLayout.showLocalAudioIndicator(mute);
  490. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  491. };
  492. UI.setVideoMuted = function (muted) {
  493. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  494. };
  495. UI.addListener = function (type, listener) {
  496. eventEmitter.on(type, listener);
  497. };
  498. UI.clickOnVideo = function (videoNumber) {
  499. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  500. if (remoteVideos.length > videoNumber) {
  501. remoteVideos[videoNumber].click();
  502. }
  503. };
  504. //Used by torture
  505. UI.showToolbar = function () {
  506. return ToolbarToggler.showToolbar();
  507. };
  508. //Used by torture
  509. UI.dockToolbar = function (isDock) {
  510. return ToolbarToggler.dockToolbar(isDock);
  511. };
  512. UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
  513. VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
  514. ContactList.userAvatarChanged(resourceJid, contactListUrl);
  515. if(resourceJid === APP.xmpp.myResource()) {
  516. SettingsMenu.changeAvatar(thumbUrl);
  517. }
  518. };
  519. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  520. var title = APP.translation.generateTranslationHTML(
  521. "dialog.error");
  522. var message;
  523. if (stropheErrorMsg) {
  524. message = APP.translation.generateTranslationHTML(
  525. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  526. } else {
  527. message = APP.translation.generateTranslationHTML(
  528. "dialog.connectError");
  529. }
  530. messageHandler.openDialog(
  531. title, message, true, {}, function (e, v, m, f) { return false; }
  532. );
  533. };
  534. UI.notifyFirefoxExtensionRequired = function (url) {
  535. messageHandler.openMessageDialog(
  536. "dialog.extensionRequired",
  537. null,
  538. null,
  539. APP.translation.generateTranslationHTML(
  540. "dialog.firefoxExtensionPrompt", {url: url}
  541. )
  542. );
  543. };
  544. UI.notifyInitiallyMuted = function () {
  545. messageHandler.notify(
  546. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  547. );
  548. };
  549. UI.markDominantSpiker = function (id) {
  550. VideoLayout.onDominantSpeakerChanged(id);
  551. };
  552. UI.handleLastNEndpoints = function (ids) {
  553. VideoLayout.onLastNEndpointsChanged(ids, []);
  554. };
  555. UI.setAudioLevel = function (targetJid, lvl) {
  556. AudioLevels.updateAudioLevel(
  557. targetJid, lvl, VideoLayout.getLargeVideoResource()
  558. );
  559. };
  560. UI.updateDesktopSharingButtons = function () {
  561. Toolbar.changeDesktopSharingButtonState();
  562. };
  563. UI.hideStats = function () {
  564. VideoLayout.hideStats();
  565. };
  566. UI.updateLocalStats = function (percent, stats) {
  567. VideoLayout.updateLocalConnectionStats(percent, stats);
  568. };
  569. UI.updateRemoteStats = function (jid, percent, stats) {
  570. VideoLayout.updateConnectionStats(jid, percent, stats);
  571. };
  572. UI.showAuthenticateButton = function (show) {
  573. Toolbar.showAuthenticateButton(show);
  574. };
  575. UI.markVideoInterrupted = function (interrupted) {
  576. if (interrupted) {
  577. VideoLayout.onVideoInterrupted();
  578. } else {
  579. VideoLayout.onVideoRestored();
  580. }
  581. };
  582. module.exports = UI;