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

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