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 23KB

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