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.

UI.js 22KB

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