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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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 MemberEvents = require("../../service/members/Events");
  29. var eventEmitter = new EventEmitter();
  30. var roomName = null;
  31. function notifyForInitialMute()
  32. {
  33. messageHandler.notify(null, "notify.mutedTitle", "connected",
  34. "notify.muted", null, {timeOut: 120000});
  35. }
  36. function setupPrezi()
  37. {
  38. $("#reloadPresentationLink").click(function()
  39. {
  40. Prezi.reloadPresentation();
  41. });
  42. }
  43. function setupChat()
  44. {
  45. Chat.init();
  46. $("#toggle_smileys").click(function() {
  47. Chat.toggleSmileys();
  48. });
  49. }
  50. function setupToolbars() {
  51. Toolbar.init(UI);
  52. Toolbar.setupButtonsFromConfig();
  53. BottomToolbar.init();
  54. }
  55. function streamHandler(stream, isMuted) {
  56. switch (stream.type)
  57. {
  58. case "audio":
  59. VideoLayout.changeLocalAudio(stream, isMuted);
  60. break;
  61. case "video":
  62. VideoLayout.changeLocalVideo(stream, isMuted);
  63. break;
  64. case "stream":
  65. VideoLayout.changeLocalStream(stream, isMuted);
  66. break;
  67. }
  68. }
  69. function onXmppConnectionFailed(stropheErrorMsg) {
  70. var title = APP.translation.generateTranslatonHTML(
  71. "dialog.error");
  72. var message;
  73. if (stropheErrorMsg) {
  74. message = APP.translation.generateTranslatonHTML(
  75. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  76. } else {
  77. message = APP.translation.generateTranslatonHTML(
  78. "dialog.connectError");
  79. }
  80. messageHandler.openDialog(
  81. title, message, true, {}, function (e, v, m, f) { return false; });
  82. }
  83. function onDisposeConference(unload) {
  84. Toolbar.showAuthenticateButton(false);
  85. }
  86. function onDisplayNameChanged(jid, displayName) {
  87. ContactList.onDisplayNameChange(jid, displayName);
  88. SettingsMenu.onDisplayNameChange(jid, displayName);
  89. VideoLayout.onDisplayNameChanged(jid, displayName);
  90. }
  91. function registerListeners() {
  92. APP.RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  93. APP.RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED);
  94. APP.RTC.addStreamListener(function (stream) {
  95. VideoLayout.onRemoteStreamAdded(stream);
  96. }, StreamEventTypes.EVENT_TYPE_REMOTE_CREATED);
  97. APP.RTC.addStreamListener(function (jid) {
  98. VideoLayout.onVideoTypeChanged(jid);
  99. }, StreamEventTypes.EVENT_TYPE_REMOTE_CHANGED);
  100. APP.RTC.addListener(RTCEvents.LASTN_CHANGED, onLastNChanged);
  101. APP.RTC.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (resourceJid) {
  102. VideoLayout.onDominantSpeakerChanged(resourceJid);
  103. });
  104. APP.RTC.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  105. function (lastNEndpoints, endpointsEnteringLastN, stream) {
  106. VideoLayout.onLastNEndpointsChanged(lastNEndpoints,
  107. endpointsEnteringLastN, stream);
  108. });
  109. APP.RTC.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
  110. function (devices) {
  111. VideoLayout.setDeviceAvailabilityIcons(null, devices);
  112. })
  113. APP.statistics.addAudioLevelListener(function(jid, audioLevel)
  114. {
  115. var resourceJid;
  116. if(jid === APP.statistics.LOCAL_JID)
  117. {
  118. resourceJid = AudioLevels.LOCAL_LEVEL;
  119. if(APP.RTC.localAudio.isMuted())
  120. {
  121. audioLevel = 0;
  122. }
  123. }
  124. else
  125. {
  126. resourceJid = Strophe.getResourceFromJid(jid);
  127. }
  128. AudioLevels.updateAudioLevel(resourceJid, audioLevel,
  129. UI.getLargeVideoJid());
  130. });
  131. APP.desktopsharing.addListener(function () {
  132. ToolbarToggler.showDesktopSharingButton();
  133. }, DesktopSharingEventTypes.INIT);
  134. APP.desktopsharing.addListener(
  135. Toolbar.changeDesktopSharingButtonState,
  136. DesktopSharingEventTypes.SWITCHING_DONE);
  137. APP.connectionquality.addListener(CQEvents.LOCALSTATS_UPDATED,
  138. VideoLayout.updateLocalConnectionStats);
  139. APP.connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
  140. VideoLayout.updateConnectionStats);
  141. APP.connectionquality.addListener(CQEvents.STOP,
  142. VideoLayout.onStatsStop);
  143. APP.xmpp.addListener(XMPPEvents.CONNECTION_FAILED, onXmppConnectionFailed);
  144. APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  145. APP.xmpp.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  146. messageHandler.openMessageDialog(
  147. 'dialog.serviceUnavailable',
  148. 'dialog.gracefulShutdown'
  149. );
  150. });
  151. APP.xmpp.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  152. var title = APP.translation.generateTranslatonHTML(
  153. "dialog.reservationError");
  154. var message = APP.translation.generateTranslatonHTML(
  155. "dialog.reservationErrorMsg", {code: code, msg: msg});
  156. messageHandler.openDialog(
  157. title,
  158. message,
  159. true, {},
  160. function (event, value, message, formVals)
  161. {
  162. return false;
  163. }
  164. );
  165. });
  166. APP.xmpp.addListener(XMPPEvents.KICKED, function () {
  167. messageHandler.openMessageDialog("dialog.sessTerminated",
  168. "dialog.kickMessage");
  169. });
  170. APP.xmpp.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  171. //FIXME: use Session Terminated from translation, but
  172. // 'reason' text comes from XMPP packet and is not translated
  173. var title = APP.translation.generateTranslatonHTML("dialog.sessTerminated");
  174. messageHandler.openDialog(
  175. title, reason, true, {},
  176. function (event, value, message, formVals)
  177. {
  178. return false;
  179. }
  180. );
  181. });
  182. APP.xmpp.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  183. messageHandler.showError("dialog.error",
  184. "dialog.bridgeUnavailable");
  185. });
  186. APP.xmpp.addListener(XMPPEvents.USER_ID_CHANGED, function (from, id) {
  187. Avatar.setUserAvatar(from, id);
  188. });
  189. APP.xmpp.addListener(XMPPEvents.STREAMS_CHANGED, function (jid, changedStreams) {
  190. for(stream in changedStreams)
  191. {
  192. // might need to update the direction if participant just went from sendrecv to recvonly
  193. if (stream.type === 'video' || stream.type === 'screen') {
  194. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  195. switch (stream.direction) {
  196. case 'sendrecv':
  197. el.show();
  198. break;
  199. case 'recvonly':
  200. el.hide();
  201. break;
  202. }
  203. }
  204. }
  205. });
  206. APP.xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
  207. APP.xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
  208. APP.xmpp.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, onLocalRoleChanged);
  209. APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, onMucMemberJoined);
  210. APP.xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
  211. APP.xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
  212. APP.xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
  213. APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
  214. APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, onMucMemberLeft);
  215. APP.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordRequired);
  216. APP.xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
  217. APP.xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
  218. APP.xmpp.addListener(XMPPEvents.AUTHENTICATION_REQUIRED,
  219. onAuthenticationRequired);
  220. APP.xmpp.addListener(XMPPEvents.DEVICE_AVAILABLE,
  221. function (resource, devices) {
  222. VideoLayout.setDeviceAvailabilityIcons(resource, devices);
  223. });
  224. APP.xmpp.addListener(XMPPEvents.AUDIO_MUTED, VideoLayout.onAudioMute);
  225. APP.xmpp.addListener(XMPPEvents.VIDEO_MUTED, VideoLayout.onVideoMute);
  226. APP.members.addListener(MemberEvents.DTMF_SUPPORT_CHANGED,
  227. onDtmfSupportChanged);
  228. APP.xmpp.addListener(XMPPEvents.START_MUTED, function (audio, video) {
  229. SettingsMenu.setStartMuted(audio, video);
  230. });
  231. }
  232. /**
  233. * Mutes/unmutes the local video.
  234. *
  235. * @param mute <tt>true</tt> to mute the local video; otherwise, <tt>false</tt>
  236. * @param options an object which specifies optional arguments such as the
  237. * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
  238. * specifies whether the method was initiated in response to a user command (in
  239. * contrast to an automatic decision taken by the application logic)
  240. */
  241. function setVideoMute(mute, options) {
  242. APP.RTC.setVideoMute(mute,
  243. UI.setVideoMuteButtonsState,
  244. options);
  245. }
  246. function onResize()
  247. {
  248. Chat.resizeChat();
  249. VideoLayout.resizeLargeVideoContainer();
  250. }
  251. function bindEvents()
  252. {
  253. /**
  254. * Resizes and repositions videos in full screen mode.
  255. */
  256. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  257. onResize);
  258. $(window).resize(onResize);
  259. }
  260. UI.start = function (init) {
  261. document.title = interfaceConfig.APP_NAME;
  262. if(config.enableWelcomePage && window.location.pathname == "/" &&
  263. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  264. {
  265. $("#videoconference_page").hide();
  266. var setupWelcomePage = require("./welcome_page/WelcomePage");
  267. setupWelcomePage();
  268. return;
  269. }
  270. if (interfaceConfig.SHOW_JITSI_WATERMARK) {
  271. var leftWatermarkDiv
  272. = $("#largeVideoContainer div[class='watermark leftwatermark']");
  273. leftWatermarkDiv.css({display: 'block'});
  274. leftWatermarkDiv.parent().get(0).href
  275. = interfaceConfig.JITSI_WATERMARK_LINK;
  276. }
  277. if (interfaceConfig.SHOW_BRAND_WATERMARK) {
  278. var rightWatermarkDiv
  279. = $("#largeVideoContainer div[class='watermark rightwatermark']");
  280. rightWatermarkDiv.css({display: 'block'});
  281. rightWatermarkDiv.parent().get(0).href
  282. = interfaceConfig.BRAND_WATERMARK_LINK;
  283. rightWatermarkDiv.get(0).style.backgroundImage
  284. = "url(images/rightwatermark.png)";
  285. }
  286. if (interfaceConfig.SHOW_POWERED_BY) {
  287. $("#largeVideoContainer>a[class='poweredby']").css({display: 'block'});
  288. }
  289. $("#welcome_page").hide();
  290. $("#videospace").mousemove(function () {
  291. return ToolbarToggler.showToolbar();
  292. });
  293. // Set the defaults for prompt dialogs.
  294. jQuery.prompt.setDefaults({persistent: false});
  295. VideoLayout.init(eventEmitter);
  296. AudioLevels.init();
  297. NicknameHandler.init(eventEmitter);
  298. registerListeners();
  299. bindEvents();
  300. setupPrezi();
  301. setupToolbars();
  302. setupChat();
  303. document.title = interfaceConfig.APP_NAME;
  304. $("#downloadlog").click(function (event) {
  305. dump(event.target);
  306. });
  307. if(config.enableWelcomePage && window.location.pathname == "/" &&
  308. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  309. {
  310. $("#videoconference_page").hide();
  311. var setupWelcomePage = require("./welcome_page/WelcomePage");
  312. setupWelcomePage();
  313. return;
  314. }
  315. $("#welcome_page").hide();
  316. // Display notice message at the top of the toolbar
  317. if (config.noticeMessage) {
  318. $('#noticeText').text(config.noticeMessage);
  319. $('#notice').css({display: 'block'});
  320. }
  321. document.getElementById('largeVideo').volume = 0;
  322. if (!$('#settings').is(':visible')) {
  323. console.log('init');
  324. init();
  325. } else {
  326. loginInfo.onsubmit = function (e) {
  327. if (e.preventDefault) e.preventDefault();
  328. $('#settings').hide();
  329. init();
  330. };
  331. }
  332. toastr.options = {
  333. "closeButton": true,
  334. "debug": false,
  335. "positionClass": "notification-bottom-right",
  336. "onclick": null,
  337. "showDuration": "300",
  338. "hideDuration": "1000",
  339. "timeOut": "2000",
  340. "extendedTimeOut": "1000",
  341. "showEasing": "swing",
  342. "hideEasing": "linear",
  343. "showMethod": "fadeIn",
  344. "hideMethod": "fadeOut",
  345. "reposition": function() {
  346. if(PanelToggler.isVisible()) {
  347. $("#toast-container").addClass("notification-bottom-right-center");
  348. } else {
  349. $("#toast-container").removeClass("notification-bottom-right-center");
  350. }
  351. },
  352. "newestOnTop": false
  353. };
  354. SettingsMenu.init();
  355. };
  356. function chatAddError(errorMessage, originalText)
  357. {
  358. return Chat.chatAddError(errorMessage, originalText);
  359. };
  360. function chatSetSubject(text)
  361. {
  362. return Chat.chatSetSubject(text);
  363. };
  364. function updateChatConversation(from, displayName, message, myjid, stamp) {
  365. return Chat.updateChatConversation(from, displayName, message, myjid, stamp);
  366. }
  367. function onMucJoined(jid, info) {
  368. Toolbar.updateRoomUrl(window.location.href);
  369. var meHTML = APP.translation.generateTranslatonHTML("me");
  370. $("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")");
  371. var settings = Settings.getSettings();
  372. // Add myself to the contact list.
  373. ContactList.addContact(jid, settings.email || settings.uid);
  374. // Once we've joined the muc show the toolbar
  375. ToolbarToggler.showToolbar();
  376. var displayName = !config.displayJids
  377. ? info.displayName : Strophe.getResourceFromJid(jid);
  378. if (displayName)
  379. onDisplayNameChanged('localVideoContainer', displayName);
  380. VideoLayout.mucJoined();
  381. }
  382. function initEtherpad(name) {
  383. Etherpad.init(name);
  384. }
  385. function onMucMemberLeft(jid) {
  386. console.log('left.muc', jid);
  387. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  388. '>.displayname').html();
  389. messageHandler.notify(displayName,'notify.somebody',
  390. 'disconnected',
  391. 'notify.disconnected');
  392. if(!config.startAudioMuted ||
  393. config.startAudioMuted > APP.members.size())
  394. UIUtil.playSoundNotification('userLeft');
  395. // Need to call this with a slight delay, otherwise the element couldn't be
  396. // found for some reason.
  397. // XXX(gp) it works fine without the timeout for me (with Chrome 38).
  398. window.setTimeout(function () {
  399. var container = document.getElementById(
  400. 'participant_' + Strophe.getResourceFromJid(jid));
  401. if (container) {
  402. ContactList.removeContact(jid);
  403. VideoLayout.removeConnectionIndicator(jid);
  404. // hide here, wait for video to close before removing
  405. $(container).hide();
  406. VideoLayout.resizeThumbnails();
  407. }
  408. }, 10);
  409. VideoLayout.participantLeft(jid);
  410. };
  411. function onLocalRoleChanged(jid, info, pres, isModerator)
  412. {
  413. console.info("My role changed, new role: " + info.role);
  414. onModeratorStatusChanged(isModerator);
  415. VideoLayout.showModeratorIndicator();
  416. SettingsMenu.onRoleChanged();
  417. if (isModerator) {
  418. Authentication.closeAuthenticationWindow();
  419. messageHandler.notify(null, "notify.me",
  420. 'connected', "notify.moderator");
  421. }
  422. }
  423. function onModeratorStatusChanged(isModerator) {
  424. Toolbar.showSipCallButton(isModerator);
  425. Toolbar.showRecordingButton(
  426. isModerator); //&&
  427. // FIXME:
  428. // Recording visible if
  429. // there are at least 2(+ 1 focus) participants
  430. //Object.keys(connection.emuc.members).length >= 3);
  431. }
  432. function onPasswordRequired(callback) {
  433. // password is required
  434. Toolbar.lockLockButton();
  435. var message = '<h2 data-i18n="dialog.passwordRequired">';
  436. message += APP.translation.translateString(
  437. "dialog.passwordRequired");
  438. message += '</h2>' +
  439. '<input name="lockKey" type="text" data-i18n=' +
  440. '"[placeholder]dialog.password" placeholder="' +
  441. APP.translation.translateString("dialog.password") +
  442. '" autofocus>';
  443. messageHandler.openTwoButtonDialog(null, null, null, message,
  444. true,
  445. "dialog.Ok",
  446. function (e, v, m, f) {},
  447. null,
  448. function (e, v, m, f) {
  449. if (v) {
  450. var lockKey = f.lockKey;
  451. if (lockKey) {
  452. Toolbar.setSharedKey(lockKey);
  453. callback(lockKey);
  454. }
  455. }
  456. },
  457. ':input:first'
  458. );
  459. }
  460. /**
  461. * The dialpad button is shown iff there is at least one member that supports
  462. * DTMF (e.g. jigasi).
  463. */
  464. function onDtmfSupportChanged(dtmfSupport) {
  465. //TODO: enable when the UI is ready
  466. //Toolbar.showDialPadButton(dtmfSupport);
  467. }
  468. function onMucMemberJoined(jid, id, displayName) {
  469. messageHandler.notify(displayName,'notify.somebody',
  470. 'connected',
  471. 'notify.connected');
  472. if(!config.startAudioMuted ||
  473. config.startAudioMuted > APP.members.size())
  474. UIUtil.playSoundNotification('userJoined');
  475. // Add Peer's container
  476. VideoLayout.ensurePeerContainerExists(jid,id);
  477. }
  478. function onMucPresenceStatus(jid, info) {
  479. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  480. }
  481. function onMucRoleChanged(role, displayName) {
  482. VideoLayout.showModeratorIndicator();
  483. if (role === 'moderator') {
  484. var messageKey, messageOptions = {};
  485. if (!displayName) {
  486. messageKey = "notify.grantedToUnknown";
  487. }
  488. else
  489. {
  490. messageKey = "notify.grantedTo";
  491. messageOptions = {to: displayName};
  492. }
  493. messageHandler.notify(
  494. displayName,'notify.somebody',
  495. 'connected', messageKey,
  496. messageOptions);
  497. }
  498. }
  499. function onAuthenticationRequired(intervalCallback) {
  500. Authentication.openAuthenticationDialog(
  501. roomName, intervalCallback, function () {
  502. Toolbar.authenticateClicked();
  503. });
  504. };
  505. function onLastNChanged(oldValue, newValue) {
  506. if (config.muteLocalVideoIfNotInLastN) {
  507. setVideoMute(!newValue, { 'byUser': false });
  508. }
  509. }
  510. UI.toggleSmileys = function () {
  511. Chat.toggleSmileys();
  512. };
  513. UI.getSettings = function () {
  514. return Settings.getSettings();
  515. };
  516. UI.toggleFilmStrip = function () {
  517. return BottomToolbar.toggleFilmStrip();
  518. };
  519. UI.toggleChat = function () {
  520. return BottomToolbar.toggleChat();
  521. };
  522. UI.toggleContactList = function () {
  523. return BottomToolbar.toggleContactList();
  524. };
  525. UI.inputDisplayNameHandler = function (value) {
  526. VideoLayout.inputDisplayNameHandler(value);
  527. };
  528. UI.getLargeVideoJid = function()
  529. {
  530. return VideoLayout.getLargeVideoJid();
  531. };
  532. UI.generateRoomName = function() {
  533. if(roomName)
  534. return roomName;
  535. var roomnode = null;
  536. var path = window.location.pathname;
  537. // determinde the room node from the url
  538. // TODO: just the roomnode or the whole bare jid?
  539. if (config.getroomnode && typeof config.getroomnode === 'function') {
  540. // custom function might be responsible for doing the pushstate
  541. roomnode = config.getroomnode(path);
  542. } else {
  543. /* fall back to default strategy
  544. * this is making assumptions about how the URL->room mapping happens.
  545. * It currently assumes deployment at root, with a rewrite like the
  546. * following one (for nginx):
  547. location ~ ^/([a-zA-Z0-9]+)$ {
  548. rewrite ^/(.*)$ / break;
  549. }
  550. */
  551. if (path.length > 1) {
  552. roomnode = path.substr(1).toLowerCase();
  553. } else {
  554. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  555. roomnode = word.toLowerCase();
  556. window.history.pushState('VideoChat',
  557. 'Room: ' + word, window.location.pathname + word);
  558. }
  559. }
  560. roomName = roomnode + '@' + config.hosts.muc;
  561. return roomName;
  562. };
  563. UI.connectionIndicatorShowMore = function(jid)
  564. {
  565. return VideoLayout.showMore(jid);
  566. };
  567. UI.showLoginPopup = function(callback)
  568. {
  569. console.log('password is required');
  570. var message = '<h2 data-i18n="dialog.passwordRequired">';
  571. message += APP.translation.translateString(
  572. "dialog.passwordRequired");
  573. message += '</h2>' +
  574. '<input name="username" type="text" ' +
  575. 'placeholder="user@domain.net" autofocus>' +
  576. '<input name="password" ' +
  577. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  578. ' placeholder="user password">';
  579. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  580. true,
  581. "dialog.Ok",
  582. function (e, v, m, f) {
  583. if (v) {
  584. if (f.username !== null && f.password != null) {
  585. callback(f.username, f.password);
  586. }
  587. }
  588. },
  589. null, null, ':input:first'
  590. );
  591. }
  592. UI.checkForNicknameAndJoin = function () {
  593. Authentication.closeAuthenticationDialog();
  594. Authentication.stopInterval();
  595. var nick = null;
  596. if (config.useNicks) {
  597. nick = window.prompt('Your nickname (optional)');
  598. }
  599. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  600. };
  601. function dump(elem, filename) {
  602. elem = elem.parentNode;
  603. elem.download = filename || 'meetlog.json';
  604. elem.href = 'data:application/json;charset=utf-8,\n';
  605. var data = APP.xmpp.populateData();
  606. var metadata = {};
  607. metadata.time = new Date();
  608. metadata.url = window.location.href;
  609. metadata.ua = navigator.userAgent;
  610. var log = APP.xmpp.getLogger();
  611. if (log) {
  612. metadata.xmpp = log;
  613. }
  614. data.metadata = metadata;
  615. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  616. return false;
  617. }
  618. UI.getRoomName = function () {
  619. return roomName;
  620. };
  621. UI.setInitialMuteFromFocus = function (muteAudio, muteVideo) {
  622. if(muteAudio || muteVideo) notifyForInitialMute();
  623. if(muteAudio) UI.setAudioMuted(true);
  624. if(muteVideo) UI.setVideoMute(true);
  625. }
  626. /**
  627. * Mutes/unmutes the local video.
  628. */
  629. UI.toggleVideo = function () {
  630. setVideoMute(!APP.RTC.localVideo.isMuted());
  631. };
  632. /**
  633. * Mutes / unmutes audio for the local participant.
  634. */
  635. UI.toggleAudio = function() {
  636. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  637. };
  638. /**
  639. * Sets muted audio state for the local participant.
  640. */
  641. UI.setAudioMuted = function (mute, earlyMute) {
  642. var audioMute = null;
  643. if(earlyMute)
  644. audioMute = function (mute, cb) {
  645. return APP.xmpp.sendAudioInfoPresence(mute, cb);
  646. };
  647. else
  648. audioMute = function (mute, cb) {
  649. return APP.xmpp.setAudioMute(mute, cb);
  650. }
  651. if(!audioMute(mute, function () {
  652. VideoLayout.showLocalAudioIndicator(mute);
  653. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  654. }))
  655. {
  656. // We still click the button.
  657. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  658. return;
  659. }
  660. }
  661. UI.addListener = function (type, listener) {
  662. eventEmitter.on(type, listener);
  663. }
  664. UI.clickOnVideo = function (videoNumber) {
  665. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  666. if (remoteVideos.length > videoNumber) {
  667. remoteVideos[videoNumber].click();
  668. }
  669. }
  670. //Used by torture
  671. UI.showToolbar = function () {
  672. return ToolbarToggler.showToolbar();
  673. }
  674. //Used by torture
  675. UI.dockToolbar = function (isDock) {
  676. return ToolbarToggler.dockToolbar(isDock);
  677. }
  678. UI.setVideoMuteButtonsState = function (mute) {
  679. var video = $('#video');
  680. var communicativeClass = "icon-camera";
  681. var muteClass = "icon-camera icon-camera-disabled";
  682. if (mute) {
  683. video.removeClass(communicativeClass);
  684. video.addClass(muteClass);
  685. } else {
  686. video.removeClass(muteClass);
  687. video.addClass(communicativeClass);
  688. }
  689. }
  690. UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
  691. VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
  692. ContactList.userAvatarChanged(resourceJid, contactListUrl);
  693. if(resourceJid === APP.xmpp.myResource())
  694. SettingsMenu.changeAvatar(thumbUrl);
  695. }
  696. UI.setVideoMute = setVideoMute;
  697. module.exports = UI;