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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. var UI = {};
  2. var VideoLayout = require("./videolayout/VideoLayout.js");
  3. var AudioLevels = require("./audio_levels/AudioLevels.js");
  4. var Prezi = require("./prezi/Prezi.js");
  5. var Etherpad = require("./etherpad/Etherpad.js");
  6. var Chat = require("./side_pannels/chat/Chat.js");
  7. var Toolbar = require("./toolbars/Toolbar");
  8. var ToolbarToggler = require("./toolbars/ToolbarToggler");
  9. var BottomToolbar = require("./toolbars/BottomToolbar");
  10. var ContactList = require("./side_pannels/contactlist/ContactList");
  11. var Avatar = require("./avatar/Avatar");
  12. var EventEmitter = require("events");
  13. var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
  14. var Settings = require("./../settings/Settings");
  15. var PanelToggler = require("./side_pannels/SidePanelToggler");
  16. var RoomNameGenerator = require("./welcome_page/RoomnameGenerator");
  17. UI.messageHandler = require("./util/MessageHandler");
  18. var messageHandler = UI.messageHandler;
  19. var Authentication = require("./authentication/Authentication");
  20. var UIUtil = require("./util/UIUtil");
  21. var NicknameHandler = require("./util/NicknameHandler");
  22. var CQEvents = require("../../service/connectionquality/CQEvents");
  23. var DesktopSharingEventTypes
  24. = require("../../service/desktopsharing/DesktopSharingEventTypes");
  25. var RTCEvents = require("../../service/RTC/RTCEvents");
  26. var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
  27. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  28. var eventEmitter = new EventEmitter();
  29. var roomName = null;
  30. function setupPrezi()
  31. {
  32. $("#reloadPresentationLink").click(function()
  33. {
  34. Prezi.reloadPresentation();
  35. });
  36. }
  37. function setupChat()
  38. {
  39. Chat.init();
  40. $("#toggle_smileys").click(function() {
  41. Chat.toggleSmileys();
  42. });
  43. }
  44. function setupToolbars() {
  45. Toolbar.init(UI);
  46. Toolbar.setupButtonsFromConfig();
  47. BottomToolbar.init();
  48. }
  49. function streamHandler(stream) {
  50. switch (stream.type)
  51. {
  52. case "audio":
  53. VideoLayout.changeLocalAudio(stream);
  54. break;
  55. case "video":
  56. VideoLayout.changeLocalVideo(stream);
  57. break;
  58. case "stream":
  59. VideoLayout.changeLocalStream(stream);
  60. break;
  61. }
  62. }
  63. function onDisposeConference(unload) {
  64. Toolbar.showAuthenticateButton(false);
  65. };
  66. function onDisplayNameChanged(jid, displayName) {
  67. ContactList.onDisplayNameChange(jid, displayName);
  68. SettingsMenu.onDisplayNameChange(jid, displayName);
  69. VideoLayout.onDisplayNameChanged(jid, displayName);
  70. }
  71. function registerListeners() {
  72. APP.RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  73. APP.RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED);
  74. APP.RTC.addStreamListener(function (stream) {
  75. VideoLayout.onRemoteStreamAdded(stream);
  76. }, StreamEventTypes.EVENT_TYPE_REMOTE_CREATED);
  77. APP.RTC.addListener(RTCEvents.LASTN_CHANGED, onLastNChanged);
  78. APP.RTC.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (resourceJid) {
  79. VideoLayout.onDominantSpeakerChanged(resourceJid);
  80. });
  81. APP.RTC.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  82. function (lastNEndpoints, endpointsEnteringLastN, stream) {
  83. VideoLayout.onLastNEndpointsChanged(lastNEndpoints,
  84. endpointsEnteringLastN, stream);
  85. });
  86. APP.RTC.addListener(RTCEvents.SIMULCAST_LAYER_CHANGED,
  87. function (endpointSimulcastLayers) {
  88. VideoLayout.onSimulcastLayersChanged(endpointSimulcastLayers);
  89. });
  90. APP.RTC.addListener(RTCEvents.SIMULCAST_LAYER_CHANGING,
  91. function (endpointSimulcastLayers) {
  92. VideoLayout.onSimulcastLayersChanging(endpointSimulcastLayers);
  93. });
  94. APP.statistics.addAudioLevelListener(function(jid, audioLevel)
  95. {
  96. var resourceJid;
  97. if(jid === APP.statistics.LOCAL_JID)
  98. {
  99. resourceJid = AudioLevels.LOCAL_LEVEL;
  100. if(APP.RTC.localAudio.isMuted())
  101. {
  102. audioLevel = 0;
  103. }
  104. }
  105. else
  106. {
  107. resourceJid = Strophe.getResourceFromJid(jid);
  108. }
  109. AudioLevels.updateAudioLevel(resourceJid, audioLevel,
  110. UI.getLargeVideoState().userResourceJid);
  111. });
  112. APP.desktopsharing.addListener(function () {
  113. ToolbarToggler.showDesktopSharingButton();
  114. }, DesktopSharingEventTypes.INIT);
  115. APP.desktopsharing.addListener(
  116. Toolbar.changeDesktopSharingButtonState,
  117. DesktopSharingEventTypes.SWITCHING_DONE);
  118. APP.connectionquality.addListener(CQEvents.LOCALSTATS_UPDATED,
  119. VideoLayout.updateLocalConnectionStats);
  120. APP.connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
  121. VideoLayout.updateConnectionStats);
  122. APP.connectionquality.addListener(CQEvents.STOP,
  123. VideoLayout.onStatsStop);
  124. APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  125. APP.xmpp.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  126. messageHandler.openMessageDialog(
  127. 'dialog.serviceUnavailable',
  128. 'dialog.gracefulShutdown'
  129. );
  130. });
  131. APP.xmpp.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  132. var title = APP.translation.generateTranslatonHTML(
  133. "dialog.reservationError");
  134. var message = APP.translation.generateTranslatonHTML(
  135. "dialog.reservationErrorMsg", {code: code, msg: msg});
  136. messageHandler.openDialog(
  137. title,
  138. message,
  139. true, {},
  140. function (event, value, message, formVals)
  141. {
  142. return false;
  143. }
  144. );
  145. });
  146. APP.xmpp.addListener(XMPPEvents.KICKED, function () {
  147. messageHandler.openMessageDialog("dialog.sessTerminated",
  148. "dialog.kickMessage");
  149. });
  150. APP.xmpp.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  151. //FIXME: use Session Terminated from translation, but
  152. // 'reason' text comes from XMPP packet and is not translated
  153. var title = APP.translation.generateTranslatonHTML("dialog.sessTerminated");
  154. messageHandler.openDialog(
  155. title, reason, true, {},
  156. function (event, value, message, formVals)
  157. {
  158. return false;
  159. }
  160. );
  161. });
  162. APP.xmpp.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  163. messageHandler.showError("dialog.error",
  164. "dialog.bridgeUnavailable");
  165. });
  166. APP.xmpp.addListener(XMPPEvents.USER_ID_CHANGED, function (from, id) {
  167. Avatar.setUserAvatar(from, id);
  168. });
  169. APP.xmpp.addListener(XMPPEvents.CHANGED_STREAMS, function (jid, changedStreams) {
  170. for(stream in changedStreams)
  171. {
  172. // might need to update the direction if participant just went from sendrecv to recvonly
  173. if (stream.type === 'video' || stream.type === 'screen') {
  174. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  175. switch (stream.direction) {
  176. case 'sendrecv':
  177. el.show();
  178. break;
  179. case 'recvonly':
  180. el.hide();
  181. // FIXME: Check if we have to change large video
  182. //VideoLayout.updateLargeVideo(el);
  183. break;
  184. }
  185. }
  186. }
  187. });
  188. APP.xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
  189. APP.xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
  190. APP.xmpp.addListener(XMPPEvents.LOCALROLE_CHANGED, onLocalRoleChange);
  191. APP.xmpp.addListener(XMPPEvents.MUC_ENTER, onMucEntered);
  192. APP.xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
  193. APP.xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
  194. APP.xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
  195. APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
  196. APP.xmpp.addListener(XMPPEvents.MUC_LEFT, onMucLeft);
  197. APP.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
  198. APP.xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
  199. APP.xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
  200. APP.xmpp.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, onAuthenticationRequired);
  201. }
  202. /**
  203. * Mutes/unmutes the local video.
  204. *
  205. * @param mute <tt>true</tt> to mute the local video; otherwise, <tt>false</tt>
  206. * @param options an object which specifies optional arguments such as the
  207. * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
  208. * specifies whether the method was initiated in response to a user command (in
  209. * contrast to an automatic decision taken by the application logic)
  210. */
  211. function setVideoMute(mute, options) {
  212. APP.xmpp.setVideoMute(
  213. mute,
  214. function (mute) {
  215. var video = $('#video');
  216. var communicativeClass = "icon-camera";
  217. var muteClass = "icon-camera icon-camera-disabled";
  218. if (mute) {
  219. video.removeClass(communicativeClass);
  220. video.addClass(muteClass);
  221. } else {
  222. video.removeClass(muteClass);
  223. video.addClass(communicativeClass);
  224. }
  225. },
  226. options);
  227. }
  228. function bindEvents()
  229. {
  230. /**
  231. * Resizes and repositions videos in full screen mode.
  232. */
  233. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  234. function () {
  235. VideoLayout.resizeLargeVideoContainer();
  236. VideoLayout.positionLarge();
  237. }
  238. );
  239. $(window).resize(function () {
  240. VideoLayout.resizeLargeVideoContainer();
  241. VideoLayout.positionLarge();
  242. });
  243. }
  244. UI.start = function (init) {
  245. document.title = interfaceConfig.APP_NAME;
  246. if(config.enableWelcomePage && window.location.pathname == "/" &&
  247. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  248. {
  249. $("#videoconference_page").hide();
  250. var setupWelcomePage = require("./welcome_page/WelcomePage");
  251. setupWelcomePage();
  252. return;
  253. }
  254. if (interfaceConfig.SHOW_JITSI_WATERMARK) {
  255. var leftWatermarkDiv
  256. = $("#largeVideoContainer div[class='watermark leftwatermark']");
  257. leftWatermarkDiv.css({display: 'block'});
  258. leftWatermarkDiv.parent().get(0).href
  259. = interfaceConfig.JITSI_WATERMARK_LINK;
  260. }
  261. if (interfaceConfig.SHOW_BRAND_WATERMARK) {
  262. var rightWatermarkDiv
  263. = $("#largeVideoContainer div[class='watermark rightwatermark']");
  264. rightWatermarkDiv.css({display: 'block'});
  265. rightWatermarkDiv.parent().get(0).href
  266. = interfaceConfig.BRAND_WATERMARK_LINK;
  267. rightWatermarkDiv.get(0).style.backgroundImage
  268. = "url(images/rightwatermark.png)";
  269. }
  270. if (interfaceConfig.SHOW_POWERED_BY) {
  271. $("#largeVideoContainer>a[class='poweredby']").css({display: 'block'});
  272. }
  273. $("#welcome_page").hide();
  274. VideoLayout.resizeLargeVideoContainer();
  275. $("#videospace").mousemove(function () {
  276. return ToolbarToggler.showToolbar();
  277. });
  278. // Set the defaults for prompt dialogs.
  279. jQuery.prompt.setDefaults({persistent: false});
  280. VideoLayout.init(eventEmitter);
  281. AudioLevels.init();
  282. NicknameHandler.init(eventEmitter);
  283. registerListeners();
  284. bindEvents();
  285. setupPrezi();
  286. setupToolbars();
  287. setupChat();
  288. document.title = interfaceConfig.APP_NAME;
  289. $("#downloadlog").click(function (event) {
  290. dump(event.target);
  291. });
  292. if(config.enableWelcomePage && window.location.pathname == "/" &&
  293. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  294. {
  295. $("#videoconference_page").hide();
  296. var setupWelcomePage = require("./welcome_page/WelcomePage");
  297. setupWelcomePage();
  298. return;
  299. }
  300. $("#welcome_page").hide();
  301. document.getElementById('largeVideo').volume = 0;
  302. if (!$('#settings').is(':visible')) {
  303. console.log('init');
  304. init();
  305. } else {
  306. loginInfo.onsubmit = function (e) {
  307. if (e.preventDefault) e.preventDefault();
  308. $('#settings').hide();
  309. init();
  310. };
  311. }
  312. toastr.options = {
  313. "closeButton": true,
  314. "debug": false,
  315. "positionClass": "notification-bottom-right",
  316. "onclick": null,
  317. "showDuration": "300",
  318. "hideDuration": "1000",
  319. "timeOut": "2000",
  320. "extendedTimeOut": "1000",
  321. "showEasing": "swing",
  322. "hideEasing": "linear",
  323. "showMethod": "fadeIn",
  324. "hideMethod": "fadeOut",
  325. "reposition": function() {
  326. if(PanelToggler.isVisible()) {
  327. $("#toast-container").addClass("notification-bottom-right-center");
  328. } else {
  329. $("#toast-container").removeClass("notification-bottom-right-center");
  330. }
  331. },
  332. "newestOnTop": false
  333. };
  334. SettingsMenu.init();
  335. };
  336. function chatAddError(errorMessage, originalText)
  337. {
  338. return Chat.chatAddError(errorMessage, originalText);
  339. };
  340. function chatSetSubject(text)
  341. {
  342. return Chat.chatSetSubject(text);
  343. };
  344. function updateChatConversation(from, displayName, message) {
  345. return Chat.updateChatConversation(from, displayName, message);
  346. };
  347. function onMucJoined(jid, info) {
  348. Toolbar.updateRoomUrl(window.location.href);
  349. var meHTML = APP.translation.generateTranslatonHTML("me");
  350. $("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")");
  351. var settings = Settings.getSettings();
  352. // Add myself to the contact list.
  353. ContactList.addContact(jid, settings.email || settings.uid);
  354. // Once we've joined the muc show the toolbar
  355. ToolbarToggler.showToolbar();
  356. var displayName = !config.displayJids
  357. ? info.displayName : Strophe.getResourceFromJid(jid);
  358. if (displayName)
  359. onDisplayNameChanged('localVideoContainer', displayName);
  360. }
  361. function initEtherpad(name) {
  362. Etherpad.init(name);
  363. };
  364. function onMucLeft(jid) {
  365. console.log('left.muc', jid);
  366. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  367. '>.displayname').html();
  368. messageHandler.notify(displayName,'notify.somebody',
  369. 'disconnected',
  370. 'notify.disconnected');
  371. // Need to call this with a slight delay, otherwise the element couldn't be
  372. // found for some reason.
  373. // XXX(gp) it works fine without the timeout for me (with Chrome 38).
  374. window.setTimeout(function () {
  375. var container = document.getElementById(
  376. 'participant_' + Strophe.getResourceFromJid(jid));
  377. if (container) {
  378. ContactList.removeContact(jid);
  379. VideoLayout.removeConnectionIndicator(jid);
  380. // hide here, wait for video to close before removing
  381. $(container).hide();
  382. VideoLayout.resizeThumbnails();
  383. }
  384. }, 10);
  385. VideoLayout.participantLeft(jid);
  386. };
  387. function onLocalRoleChange(jid, info, pres, isModerator)
  388. {
  389. console.info("My role changed, new role: " + info.role);
  390. onModeratorStatusChanged(isModerator);
  391. VideoLayout.showModeratorIndicator();
  392. if (isModerator) {
  393. Authentication.closeAuthenticationWindow();
  394. messageHandler.notify(null, "notify.me",
  395. 'connected', "notify.moderator");
  396. }
  397. }
  398. function onModeratorStatusChanged(isModerator) {
  399. Toolbar.showSipCallButton(isModerator);
  400. Toolbar.showRecordingButton(
  401. isModerator); //&&
  402. // FIXME:
  403. // Recording visible if
  404. // there are at least 2(+ 1 focus) participants
  405. //Object.keys(connection.emuc.members).length >= 3);
  406. if (isModerator && config.etherpad_base) {
  407. Etherpad.init();
  408. }
  409. };
  410. function onPasswordReqiured(callback) {
  411. // password is required
  412. Toolbar.lockLockButton();
  413. var message = '<h2 data-i18n="dialog.passwordRequired">';
  414. message += APP.translation.translateString(
  415. "dialog.passwordRequired");
  416. message += '</h2>' +
  417. '<input id="lockKey" type="text" data-i18n=' +
  418. '"[placeholder]dialog.password" placeholder="' +
  419. APP.translation.translateString("dialog.password") +
  420. '" autofocus>';
  421. messageHandler.openTwoButtonDialog(null, null, null, message,
  422. true,
  423. "dialog.Ok",
  424. function (e, v, m, f) {},
  425. function (event) {
  426. document.getElementById('lockKey').focus();
  427. },
  428. function (e, v, m, f) {
  429. if (v) {
  430. var lockKey = document.getElementById('lockKey');
  431. if (lockKey.value !== null) {
  432. Toolbar.setSharedKey(lockKey.value);
  433. callback(lockKey.value);
  434. }
  435. }
  436. }
  437. );
  438. }
  439. function onMucEntered(jid, id, displayName) {
  440. messageHandler.notify(displayName,'notify.somebody',
  441. 'connected',
  442. 'notify.connected');
  443. // Add Peer's container
  444. VideoLayout.ensurePeerContainerExists(jid,id);
  445. }
  446. function onMucPresenceStatus( jid, info) {
  447. VideoLayout.setPresenceStatus(
  448. 'participant_' + Strophe.getResourceFromJid(jid), info.status);
  449. }
  450. function onMucRoleChanged(role, displayName) {
  451. VideoLayout.showModeratorIndicator();
  452. if (role === 'moderator') {
  453. var messageKey, messageOptions = {};
  454. if (!displayName) {
  455. messageKey = "notify.grantedToUnknown";
  456. }
  457. else
  458. {
  459. messageKey = "notify.grantedTo";
  460. messageOptions = {to: displayName};
  461. }
  462. messageHandler.notify(
  463. displayName,'notify.somebody',
  464. 'connected', messageKey,
  465. messageOptions);
  466. }
  467. }
  468. function onAuthenticationRequired(intervalCallback) {
  469. Authentication.openAuthenticationDialog(
  470. roomName, intervalCallback, function () {
  471. Toolbar.authenticateClicked();
  472. });
  473. };
  474. function onLastNChanged(oldValue, newValue) {
  475. if (config.muteLocalVideoIfNotInLastN) {
  476. setVideoMute(!newValue, { 'byUser': false });
  477. }
  478. }
  479. UI.toggleSmileys = function () {
  480. Chat.toggleSmileys();
  481. };
  482. UI.getSettings = function () {
  483. return Settings.getSettings();
  484. };
  485. UI.toggleFilmStrip = function () {
  486. return BottomToolbar.toggleFilmStrip();
  487. };
  488. UI.toggleChat = function () {
  489. return BottomToolbar.toggleChat();
  490. };
  491. UI.toggleContactList = function () {
  492. return BottomToolbar.toggleContactList();
  493. };
  494. UI.inputDisplayNameHandler = function (value) {
  495. VideoLayout.inputDisplayNameHandler(value);
  496. };
  497. UI.getLargeVideoState = function()
  498. {
  499. return VideoLayout.getLargeVideoState();
  500. };
  501. UI.generateRoomName = function() {
  502. if(roomName)
  503. return roomName;
  504. var roomnode = null;
  505. var path = window.location.pathname;
  506. // determinde the room node from the url
  507. // TODO: just the roomnode or the whole bare jid?
  508. if (config.getroomnode && typeof config.getroomnode === 'function') {
  509. // custom function might be responsible for doing the pushstate
  510. roomnode = config.getroomnode(path);
  511. } else {
  512. /* fall back to default strategy
  513. * this is making assumptions about how the URL->room mapping happens.
  514. * It currently assumes deployment at root, with a rewrite like the
  515. * following one (for nginx):
  516. location ~ ^/([a-zA-Z0-9]+)$ {
  517. rewrite ^/(.*)$ / break;
  518. }
  519. */
  520. if (path.length > 1) {
  521. roomnode = path.substr(1).toLowerCase();
  522. } else {
  523. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  524. roomnode = word.toLowerCase();
  525. window.history.pushState('VideoChat',
  526. 'Room: ' + word, window.location.pathname + word);
  527. }
  528. }
  529. roomName = roomnode + '@' + config.hosts.muc;
  530. return roomName;
  531. };
  532. UI.connectionIndicatorShowMore = function(id)
  533. {
  534. return VideoLayout.connectionIndicators[id].showMore();
  535. };
  536. UI.getCredentials = function () {
  537. var settings = this.getSettings();
  538. return {
  539. bosh: document.getElementById('boshURL').value,
  540. password: document.getElementById('password').value,
  541. jid: document.getElementById('jid').value,
  542. email: settings.email,
  543. displayName: settings.displayName,
  544. uid: settings.uid
  545. };
  546. };
  547. UI.disableConnect = function () {
  548. document.getElementById('connect').disabled = true;
  549. };
  550. UI.showLoginPopup = function(callback)
  551. {
  552. console.log('password is required');
  553. var message = '<h2 data-i18n="dialog.passwordRequired">';
  554. message += APP.translation.translateString(
  555. "dialog.passwordRequired");
  556. message += '</h2>' +
  557. '<input id="passwordrequired.username" type="text" ' +
  558. 'placeholder="user@domain.net" autofocus>' +
  559. '<input id="passwordrequired.password" ' +
  560. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  561. ' placeholder="user password">';
  562. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  563. true,
  564. "dialog.Ok",
  565. function (e, v, m, f) {
  566. if (v) {
  567. var username = document.getElementById('passwordrequired.username');
  568. var password = document.getElementById('passwordrequired.password');
  569. if (username.value !== null && password.value != null) {
  570. callback(username.value, password.value);
  571. }
  572. }
  573. },
  574. function (event) {
  575. document.getElementById('passwordrequired.username').focus();
  576. }
  577. );
  578. }
  579. UI.checkForNicknameAndJoin = function () {
  580. Authentication.closeAuthenticationDialog();
  581. Authentication.stopInterval();
  582. var nick = null;
  583. if (config.useNicks) {
  584. nick = window.prompt('Your nickname (optional)');
  585. }
  586. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  587. };
  588. function dump(elem, filename) {
  589. elem = elem.parentNode;
  590. elem.download = filename || 'meetlog.json';
  591. elem.href = 'data:application/json;charset=utf-8,\n';
  592. var data = APP.xmpp.populateData();
  593. var metadata = {};
  594. metadata.time = new Date();
  595. metadata.url = window.location.href;
  596. metadata.ua = navigator.userAgent;
  597. var log = APP.xmpp.getLogger();
  598. if (log) {
  599. metadata.xmpp = log;
  600. }
  601. data.metadata = metadata;
  602. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  603. return false;
  604. }
  605. UI.getRoomName = function () {
  606. return roomName;
  607. };
  608. /**
  609. * Mutes/unmutes the local video.
  610. */
  611. UI.toggleVideo = function () {
  612. UIUtil.buttonClick("#video", "icon-camera icon-camera-disabled");
  613. setVideoMute(!APP.RTC.localVideo.isMuted());
  614. };
  615. /**
  616. * Mutes / unmutes audio for the local participant.
  617. */
  618. UI.toggleAudio = function() {
  619. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  620. };
  621. /**
  622. * Sets muted audio state for the local participant.
  623. */
  624. UI.setAudioMuted = function (mute) {
  625. if(!APP.xmpp.setAudioMute(mute, function () {
  626. VideoLayout.showLocalAudioIndicator(mute);
  627. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  628. }))
  629. {
  630. // We still click the button.
  631. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  632. return;
  633. }
  634. }
  635. UI.addListener = function (type, listener) {
  636. eventEmitter.on(type, listener);
  637. }
  638. UI.clickOnVideo = function (videoNumber) {
  639. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  640. if (remoteVideos.length > videoNumber) {
  641. remoteVideos[videoNumber].click();
  642. }
  643. }
  644. //Used by torture
  645. UI.showToolbar = function () {
  646. return ToolbarToggler.showToolbar();
  647. }
  648. //Used by torture
  649. UI.dockToolbar = function (isDock) {
  650. return ToolbarToggler.dockToolbar(isDock);
  651. }
  652. module.exports = UI;