You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 26KB

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