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

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