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

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