您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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